Quickly Solving the “Instagram Engineering Challenge: The Unshredder”

Today I have read about the Instagram Engineering Challenge: The Unshredder, and decided to give it a try. The task is simple to explain: Create a program that can unshred this image (do not try the challenge on this image, try the original PNG source instead!):

I have postet here that I think I can solve it in 2 hours, and got some downvotes for that; so I have decided to really give it a try. Long story short, it took me about 2 hours and 35 minutes.

Before I started developing, I made some quick assumptions to simplify things:

  • I want to code it in Ruby, this is the language where I am most productive.
  • I can assume the size of the stripes is well known, and I have hardcoded this size.
  • The image can be converted to RAW with an external tool, and written into RAW.
While coding I timed myself, and created a little timeline of my trials and errors. Since I wanted to finish as quickly as possible, the code is very ugly: no tests, some hardcoded constants, etc.

Continue reading “Quickly Solving the “Instagram Engineering Challenge: The Unshredder””

Single N-Back

I have just created my first Android app. It is a simple game, called Single N-Back. It has been shown in multiple studies that this game can improve your fluid intelligence.

You can get it here:

Continue reading “Single N-Back”

Download Bitcoin Logos

I have recently joined the bitcoin network, and generated PNG images from these excellent bitcoin vector graphics. I have extracted all relevant images, and converted each one into a PNG with transparancy, and in 60, 90, 300, and 600 DPI. All PNGs are recompressed with optipng -o9 to be as small as possible.


The zip file contains these images in 60, 90, 300, and 600 DPI:
Continue reading “Download Bitcoin Logos”

Smallest working QR Code

I’ve been playing a bit with QR code generators, and tried to generated a very small one for this homepage. This is the result:

The file is 21×21 pixels, and has just 178 165 bytes. It works with my cellphone from a distance of about 7cm, and gets you to http://martin.ankerl.com/.

How did I create it?

  • Create very short URL to the link you want to create the QR code for. I’ve used j.mp with the customize link feature, and played a bit with special characters like _ until I got a working link.
  • Create a QR code for this link, with low error code correction. This generator has this option.
  • Open the file with your favourite image editor, cut off the border, resize it by factor 1/4 with resample to get a QR code where each black dot is one pixel wide.
  • Save as .png, without any additional information.
  • use IrfanView’s PNGOUT, and afterwards optipng -o9 to recompress the picture.

Can you make a smaller QR code with working weblink?

Have fun!

Cleverness Considered Harmful

I have just read this nice quote at the stackoverflow question “Why is cleverness considered harmful in programming by some people?“:

Fools ignore complexity; pragmatists suffer it; experts avoid it; geniuses remove it.
— Alan Perlis

Which reminds me of a little code piece I have written recently. I’ve recently tried to implement a small, little parser for a very simple custom data format, in C++. To do this, I have tried several approaches:

1. Boost.Spirit

Since we use Boost in our projects, I have started reading about Boost.Spirit, and took some time to decipher the tutorials which contains code like this:

After half an hour I got annoyed because it simply is too much effort. I don’t care how well thought out the library is and how powerful it is, it is simply unusable. Maybe I am too stupid, but I am sure that even when I manage to understand it enough to write a decent parser, half a year later I can never debug my code again: it’s simply too clever.

2. Coco

I’ve ditched Boost.Spirit, and tried to use Coco. I am unfamiliar with this but have seen a colleague use it, so I gave it a try. I was reading the documentation, which looks nice but has 42 pages and since I am a lazy bastard I stopped right there because I just want to get something working, and quickly.

3. Hand Written Large Switch

I have ditched Cocomo, and started to write my own, very simple code that basically looked like this:

After just 10 minutes I got a minimal parser that worked good enough and was extremly readable and understandable code. Everybody with basic C++ understanding can skim over this code and get it. The number of WTF’s per minute when reading this code is close to zero. I am very happy with this approach, and it really rocks because it is so dead simple.

You can rightfully say that a simple switch is very inflexible, and not extensible. You are right, but who cares? Almost all code that I have seen that was planed ahead for flexibility that you might need, gets too complicated because what you planed ahead for might never be needed; even worse: most of the time you need flexibility that you cannot know in advance, it only becomes apparent when you have something and running and use it for a while.

Final Words

Back to the original quote, based on my experience I would extend it a bit:

Ignorants add complexity; fools ignore complexity; pragmatists suffer it; experts avoid it; geniuses remove it.
— Martin Ankerl

If you find this interesting you might also like consider reading the Three Laws of Software Development.

What do you think?