Window functions in Postgres with Rails time

Back when Ruby on Rails was moving to use Postgres as its default database, there was a lot of comparison articles and videos. From one of them, I remember a simple query which surprisingly works in MySQL: SELECT category_id, COUNT(*), email FROM users GROUP BY category_id OK, we want to get the number of users is each category identified by its ID and an e-mail. Which e-mail? I don’t remember if MySQL returns the first or last in each group but it does not complain and it returns something. Read On →

Elm Prague meetup talk

Last Wednesday I gave a second talk about Elm at Elm Prague Meetup. This time I talked about a toy project animating SVG bubbles received over a WebSocket inspired by Listen to Wikipedia. The source code for the application is available on GitHub, the slides are available as well.

Gokit: HTTP transport

In our services written in Go, we quite heavily rely on Go kit. You can build anything with just Go’s standard library. It has very little opinions about how to do things and gives you a lot of latitude when architecting your application. That’s great for trying things out or even if you have a single application, but when you develop multiple services in a team, it’s useful to have a common baseline for routine tasks and Go kit does exactly that. Read On →

Greedy Elm

At the end of May, we gave a talk about Elm and JS interop at Prague Elm Meetup. One of the sections naturally talked about native modules and their dangers, so it shouldn’t come as a surprise that they came to bite us just a few days later. The initial manifestation was that some parts of the Elm application were using the wrong copy, more specifically a wrong language of the copy. Read On →

Custom flags decoder in Elm

I’m preparing a talk about Elm and JS interoperability for Prague Elm Meetup and I got to the topic of flags, i.e. how to initialize an Elm app with data passed in from JavaScript. Looking into it, I realized how much I don’t know and had to find out. There was one special question which bothered me from the moment I tried using flags: Elm automatically decodes the data which limits it to elementary types and their combinations. Read On →

Switching on custom types in Golang

Last week I ran into an unexpected behaviour in Go regarding type switching. In the end, it makes perfect sense but the initial reaction was complete confusion. The algorithm in question needed to perform different types of actions based on incoming messages. Each message could provoke different number of reactions which could take form of different data structures or operations to be performed later. Message handlers therefore returned a slice containing either values of struct A, B or C, or an anonymous function. Read On →

Go race detector

Recently, we developed a web application which involved the use of multiple goroutines. As a result data races were just around the corner. Fortunately, Go comes with go race detector — an incredible tool which makes them easier to detect. Let’s look at a simplified example: var servedDevices []Device devicesToProcess := make(chan []Device, 1) go func(devicesToProcess chan[]Device) { select { case devices := <- devicesToProcess: for _, device := range devices { go func(device Device) { // Operations on Device servedDevices = append(servedDevices, device) }(device) } } }(devicesToProcess) A channel for slices of Devices is passed as an argument to a goroutine. Read On →

I said nil, not nil

Last week, I was working on extending goworker to use Sentinel, a Redis HA solution, instead of plain Redis. The high level goal was clear enough, but the way there was anything but. The root problem which made me go through all stages of programming: that’s easy; huh, strange; WTF?; smashing head agains a wall; and facepalm/double facepalm/n-facepalm turned out to be that nil != nil. At least not always. In this particular instance, I was returnig nil to a pool of Redis connections, when the checked out connection was either dead (= no PONG response) or the instance it was connected to had been demoted to a slave. Read On →


While updating styles for Enectiva to make it more responsive I came across a problem with flexbox — there are some restrictions in particular browsers. For instance, one issue I encountered was that some HTML elements can’t be used as flex containers. For instance, we wanted to use fieldsets because of their semantics both alone and combined with legends and make them flex containers. This, however, doesn’t work in Chrome. The following example shows that using the same CSS properties (display: flex; flex-flow: row nowrap) the elements inside the fieldset are in a row in Firefox but not in Chrome. Read On →

Breaking in Go

One of Go’s advantages is its familiar syntax and vocabulary. Parentheses, brackets, and braces have the meaning you expect. Programs are composed of well known keywords like var, const, for, or return. This familiarity, however, means that one might forget that Go might have slightly different semantic for those terms. One such example is the keyword break. Recently, we wrote a program which boiled down to an equivalent of: for i := 0; i < 10; i++ { fmt.Println("Line:", i) switch i { case 5: break } } The desired output was to terminate the loop when a condition was reached inside the switch statement. Read On →