Storing encrypted configuration in your git repo with DotenvSekrets

Developers who are familiar with the “twelve-factor” app know that configuration should be stored in the environment (loaded via env vars), not in the code. If you’re writing a Rails application you may want to use the dotenv gem, which allows you to store env variable in a handy series of files such as .env, .env.development, .env.test and so on. You can read the gem readme for all the details.

Since configuration varies with time and you may be working with many other developers, it is quite handy to store these env files in your git repository, but there’s a big caveat: you should not store passwords, secrets and tokens inside a git repo for security reasons, unless they’re encrypted.

Continue reading “Storing encrypted configuration in your git repo with DotenvSekrets”

How requirements shaped my code, AKA Rails 5 and ActiveRecord before_destroy callbacks

I recently started a new project with Rails 5, and at some point I found out the code was not behaving as expected.
The initial scenario was quite simple, Admins can have many Phones, as this code suggests:

Continue reading “How requirements shaped my code, AKA Rails 5 and ActiveRecord before_destroy callbacks”

Test RDBMS should == production RDBMS

In Mikamai we developed svelto, our own url shortener application in 2008, but at that time the web was still on IPv4 (and it mostly is today, for what it matters). When registering visits we store also the visitor’s remote ip, and a few days ago we received a visit from an IPv6 number which ended up in an application error:

Continue reading “Test RDBMS should == production RDBMS”

Elixir: an introduction to server architecture and GenServer behaviour

Erlang (and Elixir) strongly advocates concurrency, scalability, and fault tolerance via multiprocessing and the use of specific design patterns based on it.
An Erlang process is not an operative system process: it is faster, lighter, with much smaller memory footprint.
By spawning hundreds, thousands or even millions of these processes you can achieve great scalability, as
this recent post

The server/client architecture builds on such lightweight processes, can handle state, and is one of the keys to the
great results that can be achieved using Elixir.

Continue reading “Elixir: an introduction to server architecture and GenServer behaviour”

Testing with Espec and Elixir

Every (new) language comes with a test library, and Elixir is no exception: the name of the built-in one is ExUnit and
you can find the documentation here.

ExUnit is a good start: it is natively integrated in mix and has a few options to customize its output,
still when I use it I feel its assertion syntax is a bit harsh. So I’ve recently started using Espec,
a different testing library ispired by the awesome ruby Rspec testing framework.

Continue reading “Testing with Espec and Elixir”