Tweaking Capistrano environment

Recently, we’ve been playing with our database setup in order to improve its resiliency. During the experimentation, we had multiple versions of the database compiled and running. To test everything, we temporarily needed to run db:migrate and related tasks against the new database. Our assumption was that it would be taken care of by changing the credentials for the database to the new instance. The migration runs just fine, but at the end, it dumps the schema to a file. Read On →

We're looking for developers to help us save energy

If you're interested in what we do and you would like to help us save energy, drop us a line at jobs@enectiva.cz.

Duration in Go

We, lazy developers, like when we don’t have to type a lot and things just happen. Naturally, there’s a limit to how much should happen and finding this limit is often the hardest thing. Especially because it keeps moving. Ruby is very friendly in this way and takes care of many things for us, implicit type conversion among them. Go on the other hand requires more guidance from the programmer. Generally, it is a good thing, because it leads to more explicit and predictable code; however, the cost is verbosity. Read On →

Context modifying blocks

In Ruby code in general and in Rails code especially, there are situations when the global state needs to be modified. Yes, global state is bad and ugly but at the same time it’s ubiquitous and we have to deal with it. Apart from “permanent” changes, it is often necessary to change the state just for a moment, i.e. a function needs to run in a limited/altered context. A naïve approach (and the only one possible in some languages) of implementing this might look like: Read On →

Hash and an array as a default value

Recently, I needed to schedule a set of operations over a fixed number of slots so that the number of operations in each slot is uniform-ish1. Because the number of slots was fixed, it made sense to initialize an array so that each item would have a default empty list of operations (thus avoiding the nil test when adding operations to slots). schedule = Array.new(number_of_slots) { [] } This worked nicely for a time, but later came in a requirement to split the operations into groups while keeping a single schedule optimizing the total number of operations in each slot regardless of the type. Read On →

Golang build tags

Go compiler is capable of compiling source code for different platforms in any development environment (which, apparently, is a big deal and not that common). When your code is targeting multiple architectures, there might be parts of the code tailored for each one of them. Two options exist for defining such alternative code: suffixing file names by the targeted architecture (as seen in the os package) or build tags which are essentially just comments at the beginning of a file with a fixed structure. Read On →

The case of case equality operator

Ruby is a nice and easy to read language. There are, however, some quirks which might surprise you. Some of them are easy to deal with when you start learning it, because they come up often enough. Certain keywords fall into this category, probably the most common is elsif not being elseif or else if. A little less common is the switch statement. Most languages have switch as a keyword for the whole decision block and case for each branch, default for the default catch-all case. Read On →

Multitenancy and uniqueness

Enectiva is a multitenant application which means we take care to separate data of different customers and avoid leaks between them. Luckily, there’re are many gems which help with common use cases and augment Ruby on Rails code to restrict queries by default. We’ve been using the multitenant gem since the beginning and it does exactly what we expect it to do. More precisely it did, until we ran into uniqueness validation. Read On →

Go struct tag alignment

Over the past few months, we’ve been moving several computation heavy components of Enectiva from Ruby to Go. Our initial motivation for this move was performance — Go beats Ruby by orders of magnitude. After finishing that process, we’ve started to develop some of the new components of the Enectiva platform in Go from scratch; the most recent addition is API Librarian for collecting readings and other data points from customers. Read On →