Sorting DNS records

I don’t update my DNS records often, but when I do I like these records sorted. A DNS record consists of the following fields: domain name, type and prio (for some types). I use these fields to determine the order of the records. That is also the order in which these fields should be ordered. The first insight I had about sorting domains was that the domain names consist of parts separated by a period....

September 4, 2014

Rotate one to the left

Last week I wrote a small function in Perl that rotates and array to left. The function takes the item from the front and appends it to the back. # precondition: @list >= 1; sub rotate_left_by_one { my $ar = shift; my $item = shift @$ar; push @$ar, $item; return; } After calling this function as many times as the length of the array, it leaves the items in the same order they started in....

August 18, 2014

Low level code

Google released the PDF code of Chrome just a few days. I took a look at it. This file (core/src/fpdfdoc/doc_vt.cpp) is an example of how the code looks. Sometime later it dawned on me that this code is built out of only low level pieces. There are almost no algorithms extracted to functions. An example would binary search. There are five copies of binary search hidden in just that file. No wonder this file is 1864 lines of code....

May 23, 2014


I always forget what strict weak ordering means, but it’s quite simple, actually. My explanation is based on the Programming Conversation of last week and I hope this will help me remember the next time I hear about this. Let’s start with ordering. A relation is an ordering if it is transitive. ordering --> for all a, b, c: r(a, b) and r(b, c) => r(a, c) And now strict....

May 13, 2014

Broken interface of Math.min

In an article about creating a column layout I found the following two lines of code: var min = Array.min(blocks); var index = $.inArray(min, blocks); This first finds the minimum value in blocks and then the index of that value. This combination of lines is very strange. Array.min already knows the index of the minimum element and throws it away. Then the programmer needs to find the index again with a linear search....

April 29, 2014

Stability in column layout

I was reading the notes on programming PDF and found a discussion about writing min and max functions for multiple arguments. I didn’t what to use this for. Also there was a discussion about stability. Stability is when you leave elements in the same position when they’re the same. This seems to be about sorting. At the same I was implementing a Pinterest like column layout. I already had a working version....

April 29, 2014

Renewed interest in C++

In the previous post I showed a playlist of presentations by Alexander Stepanov, the creator of STL. In these videos he talks about algorithms and data structures (written in C++). This principled explanation of programming makes a lot of sense to me. And has me take a renewed look at C++.

April 22, 2014

Programming conversations

April 6, 2014

Use ZeroMQ to control a receipt printer

A customer needed a solution to the following problem. There are multiple web POS systems that need to print to a receipt printer. The web server is not in the same place as the POS terminals, but they are connected to a network. To solve the problem I used ZeroMQ to connect the web server to the receipt printers. The current solution consists of four parts. Web app Web server (connects a PUSH socket to a PULL socket) ZeroMQ device (a multiplexer receives from a PULL socket and sends these to a PUB socket) Computer with receipt printer (a sink that receives on a SUB socket subscribed to its own address) First a user in a browser clicks the button to print a receipt....

November 20, 2013

Redis queue design choices

In a previous post I wrote about simple job queue in Redis. In this post I like to write a bit about the design choices. I think these choices illustrate a point about design. Job handle The job handle in the code is create by the client (with help from the Redis server). This job handle is passed to the queue in Redis and picked up on the other side by the worker....

September 6, 2013