Projects

Cellular automaton #3 – Get to coding

Last week I finally implemented something, an elementary cellular automaton with one hardcoded rule. I also added some development tools (debugger, testing framework). Not much, but I’m happy that I could see some results and now I have some base for next iterations.

More setup

Debugging

Pry – debugger and powerful tool, is a popular choice for development in Ruby.
To use it, we just need to add in Gemfile this: gem 'pry', and then this line in code where we want a break point:

require 'pry'; binding.pry

gem_pry

Testing

RSpec – when it comes to testing (especially in Rails apps), this is the most used framework and DSL. After adding gem 'rspec' in Gemfile, we can generate initial config for it:

$ rspec --init
 create .rspec
 create spec/spec_helper.rb

There is good RSpec documentation and guidelines on the web.

Environment groups

In Sinatra default environment is “development” and since there is no config for that – all dependencies are required in every environment. In order to fix this and also
to introduce “test” environment I needed to make some configuration tweaks.

For testing, I’ve added this line on top of spec/spec_helper.rb:

ENV['RACK_ENV'] = 'test'

For dependencies, we can group them in Gemfile as described in Bundler docs.
To require gems in particular group I’ve added this line on top of config.ru:

Bundler.require(:default, ENV['RACK_ENV'].to_sym)

Implementation

Elementary (one-dimensional) cellular automaton is really easy to code in Ruby. My first implementation has 40 lines of code. It’s a class with few instance methods. Object created from it can hold a generation in an array. Elements of an array are cells, their state is defined by integer (0 or 1). Method named “step” (no idea if it’s good name) returns new array generated basing on neighborhood of cells and some rule, in this case rule 30. (more…)

Cellular automaton #2 – First deploy

TL;DR: Nanobox is free but requires paid service on DigitalOcean or AWS, so I deployed to Heroku.

I wanted to use something other than Heroku but after all it’s still the best free platform for small web applications. I spent about 2 hours setting up Nanobox Desktop just to discover that it will create Amazon EC2 instance of $6/month cost (Nanobox itself is free for open source apps) when I connected AWS as cloud provider, which I could do on the beginning. I don’t need 100% uptime or advanced managing, monitoring and scaling features for that small application, good old Heroku will be just fine and quick. There is AWS Free Tier for 12 months but I expect some longer fiddling on the first time, I might try it later for other projects.

In this post I will present some steps done with Nanobox.

Installing Nanobox Desktop

After creating Nanobox account I had to install Nanobox Desktop to start development.

nanobox_desktop

(more…)

Cellular automaton #1 – Intro

Hello again! Week is ending soon almost finished, it is time for a second post.

I wanted to keep some schedule for posts publishing or at least for one, but I’m afraid this is impossible at the moment. Simply I’m not used to this and I had to handle something else over the week.

About me

I didn’t introduce myself before so let me do it quickly now.
I am a young programmer that recently started his career as a web developer. Before that I was studying computer science. Generally my main interests were always around computers, PC games, software,  Internet and how it all works. My language of choice is Ruby, which I learned while doing final project in the college. Currently I’m working as a full time back-end developer using Ruby (mostly Ruby on Rails), Elixir and JavaScript.

About project

After very long thinking on what to do or what technology to use I’m going to do web application that will allow sort of playing with cellular automata (this is plural form, singular is: automaton). Ever heard of Game of life? If not then it is actually a two-dimensional cellular automaton. The topic itself is very well described here.

Maybe it isn’t very ambitious but now I just want to have some fun and do something in the fairly comfortable environment for me. Basic implementation  (1-D cellular automaton specifically) can be done in one evening – I guess, as it’s just algorithm with input and output. However there are many variants and visualization is another thing. If I will finish early, then I can add more features that I already thought about.

Technologies

Why web app? Clearly there won’t be any advanced calculations and there is no need for persistence so using server in this case seems like big overkill. All stuff could be done on client side. I’m not sure yet about all features and if I will need database, then there is no problem with adding it.

Last details: I will start with Sinatra framework, application will be deployed with nanobox (first time trying out this platform). Later I will try to extract cellular automata logic to a gem (which is Ruby library or package).

Next part: Initial setup.