Signature

I made my daughter a book for her first birthday.

Apr 17, 2014

Made? Yes, made – not wrote. See below.

My day is a grab-bag of abstract concepts, data as shapes moving from system to system on pathways built with tools I love dearly. However, every now and then I want to inject some characters and narrative into my life.

A previous, on-ice-yet-ongoing foray into Story Land is when we learnt we were pregnant. My world was shaken, and in a nervous panic I wanted to surround myself with things that will cleanse my mind, prepare my heart, and re-awaken the child in me. All in preparation for the Little Being that was to join us in June 2013.

I was going to write a picture book. The poem it’s based on came to me on a train journey to the Cotswolds. It was going to be perfect. But, I had to practice. Doodle, draw, illustrate. Devour colours. Try and not be precious about my Moleskine notebooks. Scribble, then scribble some more. Rip out pages, and throw stuff away.

I started in earnest, but truth be told that a Picture Book is not an overnight endeavour.

Meanwhile, Little One was born. Slow and considered sketches were soon replaced by frantic nightly dashes finding nappies and milk. My fountain pen dried up and clogged sooner than one can say “priority shift”.

A few months ago it dawned on me that she’ll turn one soon. I started to think of her first ever gift. The picture book was still months away from being completed. All along our Little Beloved pointed at “C for Cat” on her alphabet toy, and a light bulb appeared above my head: a cat book!

The birthday is now imminent, and something needed to be sent to the print shop pronto. Inspired by “famous cats” from a pub quiz, I went on to create this. Heavily cribbed and everything stolen from far flung corners of the Interwebs, but hey – it’s not like I’ll be making money off it!

Fun was had, and Father Time once again looks down favourably on my poem-inspired work of art which will soon sit alongside our Little One’s other precious things.

More jq fun

Jan 29, 2014

I’ve written about jq before, but I mention it again here as a very useful tool for parsing JSON on the command line.

I needed to grab some England Bank holidays for a quick hack the other day, and found that the GOV.UK team made web better by allowing you to append .json to any of their links to get to the data.

Hold onto yer hats:

2103 — the year's code and tooling in review

Dec 31, 2013

I saw the #code2013 hashtag on Twitter last night and joined in. It got me thinking about the stuff around the programming languages I use, and my professional skillset in general.

I’ll briefly touch on how a few major events in my life forced me to cut the fat and become more focused.

A few notes, then.

The programming languages

Scala

My new, old favourite. My go-to language since 2009. I can’t add much for 2013 apart from that I’m happy to see the community mature around it. We’ve gone from “How we adopted Scala at company X” to “How to go back in time using Akka, Play! and XYZ”. Oh, and then the reactive course was fun too, and highlighted a few holes in my Akka education.

Java

Java still mostly pays the bills, and I’m writing even better Java thanks to Scala. My editor is told to highlight everything in a shade of gray, apart from re-assignables which are red. It all just flows.

Python

I’m a big fan of Pylons and have used Python since 2006-ish for tiny webapps, but this year sees me going down the finance route with SciPy and Pandas thanks to a handful of courses I did recently.

R

Strangely addictive. I did a data analysis course with the famed Johns Hopkins university earlier this year, and thought I would be “learning” R along the way. If anything, it felt like I already knew R, and the thing that I learned was making a good analysis, writing it perfectly and succintly, and performing an honest peer review. R is perfect for slicing and dicing your data, and it doesn’t get in the way.

Dart

The main attraction to Dart for me was the promise of compiling to a better Javascript which you can ever hope to write by hand. The Dart syntax itself is familiar, and then you have the odd goodies like the cascade operator (borrowed from Smalltalk) which lets you chain methods without having to return the instance in your API, and being a Scala guy, I love having rockets (=>) scattered all over my code (Dart’s syntactic sugar for concise getters).

Javascript

Being a backend programmer by trade, I usually don’t go for frontend gigs, but a client this year said they don’t mind me learning on the job, and I’ve heard good things about AngularJS, so I dove right in. I’ve touched on Javascript a lot in the past, but this year I spent a significant tenth of my professional time fiddling with it.

Haskell

Yes, I really did spend the tiniest amount of time with Haskell, but enough to mention it here. I downloaded, chopped and changed the XMonad code and the take-away for me was that 2014 will see more Haskell.

Other languages, not-so-much-languages, and tools

My starter Dart project is a game (where do I find the time?), hence WebGL and subsequently GLSL. I’m particularly excited about getting my hands even dirtier with shaders with Mozilla recently announcing live-editing of shaders using Firefox.

I’ve always used Capistrano and Chef for my provisioning and configuration needs, but this year I gave Ansible a shot. I hope Ansible stays the way it is: small, simple, elegant. No agents; just SSH.

Conclusion

2013 was a bumpy ride. We had a beautiful daughter in June, and I quit my job soon after to freelance from home and be 2 flights of stairs away from her. To be able to learn a few new skills and do 4 courses, I had to make some changes. There are the 5AM starts, the highly-condensed exercise routine in the morning, diligently deleting anything which doesn’t contribute to the plan I have for our life (this includes articles, emails, etc), and just generally getting things done.

The Polar Bear who might have eaten Xmas The game I mentioned seems like a distraction, but I feel it’s important that I do it. I’ve been in love with doodling since I was a kid, and really took it up this year. I’m an able musician, and since I can code I thought I’d bring these ingredients together and make something nice. (Those umpteen characters and storylines in my head will finally be unleashed!).

Thanks for reading this far. May you have a great 2014.

I leave you with a doodle I made a few days ago entitled “The Polar Bear who might have eaten Xmas”. (Don’t worry — this isn’t one of my games ideas ;-)

Using single and double pipes in Scala conditionals

Dec 27, 2013

In a nutshell, use a single pipe if you want all the expressions in your conditionals to be evaluated, and a double pipe to conk out as soon as you have true.

scala> def a = { println("a") ; true }
a: Boolean

scala> def b = { println("b") ; true }
b: Boolean

scala> def c = { println("c") ; true }
c: Boolean

scala> if (a || b || c) println("true") else println("false")
a
true

scala> if (a | b | c) println("true") else println("false")
a
b
c
true

Heuristics

Dec 13, 2013

I recently saw a talk by Jack Dorsey where he iterates a list of commandments for this life, and number three is “drink only lemon water and red wine”.

I love red wine, and was intrigued by this lemon water idea. I investigated and it led me to an article which asks how much lemon water is needed. They quote a heuristic:

For those who weigh less than 150 pounds, squeeze half a lemon’s worth of juice into a glass of water. If over 150 pounds, use an entire lemon’s juice.

This is a heuristic, and it is beautiful. It saved the author from quoting an entire “weight in pounds to amount of lemon” table.

The heuristic is one of my favourite concepts of all time. During engineering school in the late nineties it became ever more apparent what a powerful concept it is, e.g. using lookup tables when designing flow systems with complex flow dynamics. It makes applied rocket science a bit easier. Or when solving path finding problems where the brute force method is just not a viable option in terms of time complexity.

Anyhoo, I’ve reached my 10 minute limit for writing ★, and since I can’t do this powerful concept any justice with just a few words, I’ll let the editors of Wikipedia englighten you further.

★ this is my own heuristic (aka “rule of thumb”) for not spending too much time on writing.

Project Euler 18 and 67 in Scala using foldRight, zip and sliding

Nov 28, 2013

I’ve recently applied to Toptal and sucked miserably at the entry exam. My algo chops were blunt and I thought I’d rectify it by revisiting Project Euler. With the startup last year and the baby this year I just haven’t been able to find the time for programming challenges, but that has to change.

Looking at my Project Euler source directory, I saw that I left it at problem 17, so next up will be 18. The problem description, however, mentions that the problem repeats itselt as 67, but with a bigger input that will run 20 billion years if you go the brute force route.

I worked a little on this problem last night, and decided to by-pass the brute force solution completely. It was a bit late, though, and I pulled my eyelids open far enough to make it to bed. I then went on to dream about the damn problem all night. I knew there had to be a simple bottom-up fold-based solution, and the voila moment came for me when I realised I had to seed the fold computation with the base layer in the triangle.

Here you go:

A little explanation

The triangle is represented as a nested list, like so: List(List(1), List(2, 3), List(4, 5, 6)) and so forth.


     1
    / \
   2   3
  / \ / \
 4   5   6    <- this is the "base layer" in my explanation.

Since you need to add the maximum of the two immediate children to the layer above, a foldRight wouldn’t give me all the info I need in the curent iteration. Foldright for me means “the data is coming FROM the right”, i.e. List(4, 5, 6) will be processed first, then List(2, 3) but at no point in the iteration will they be available together so I can do the sum. List(4, 5, 6) would need to come into the iteration with List(2, 3) in another way, and I realised I can use the foldRight’s accumulator for that by seeding the foldRight with the base layer in the triangle (aka the last list List(4, 5, 6)).

The easiest way was to just seed the foldRight with a list of zeros one element larger than the base layer. You then break it up into pairs using sliding(2,1), take the max of the pairs, and sum the max with the corresponding (thanks to zip) element in the layer above.


      1
     / \
    2   3
   / \ / \
  4   5   6
 / \ / \ / \
0   0   0   0    <- this becomes the new "base layer", or "seed"

No mutable state; no recursion; simple to understand. As Erik Meijer would say: “baby code”.

A webwords Chef cookbook

Nov 10, 2013

There are a lot of new examples up on the Typesafe website, a few with the word “Reactive” in them to drive home the credo behind the framework. One of my favourite examples, however, seem to have been demoted but still remains one of my favourites: webwords.

The old Heroku link to the live running instance of webwords does not seem to be up anymore, so I whipped up a quick Chef cookbook with which to spin up your own local instance.

You can find the Github repo here. Spin it up and have fun.

BTW, join us in doing the Principles of Reactive Programming course

Pretty-print JSON in vim

Nov 05, 2013

jq to the res-q. TL;DR A quick way to pretty-print JSON in vim with no dependencies (here’s looking at you, Perl). Download jq then :%!jq ‘.’

Computational statisticiansData scientists have some the funnest tools, and I found a good write-up of a few more I didn’t know about called 7 command-line tools for data science. The first thing the article mentions is a gem called jq.

I found jq to be especially useful for formatting JSON in vim. So, before ado can in any way be furthered:

curl http://stedolan.github.io/jq/download/linux64/jq -o ~/bin/jq   chmod +x ~/bin/jq

In vim, open your unformatted JSON file, then: :%!jq ‘.’.

There you go, ladies and gents — a command so short, you don’t even need to put it in your vimrc!

Dell XPS 13 LE

Nov 02, 2013

The portal to my livelihood. TL;DR If you’re a laptop-toting *nix user, then this is the laptop for you. Also, upgrade the kernel before you do anything else, for the best experience.

This advice is highly unqualified, though. The last time I ran *nix on a laptop was when I ran some flavour of Gentoo on an old Centrino-loaded HP in 2005. I’ve been a Mac user ever since those darned iPhones came out.

It’s just that I ran out of space on my 128GB SSD Air for the umpteenth time, and shuddered at the thought of breaking off glued-down components according to some iFixit guide. (Damnit! I just looked again, and there’s no glue involved in upgrading the SSD. Oh, well — the missus needed a new laptop anyway, and this was a welcome hand-me-down. Besides: new toys!)

First thing’s first

When you do get one of these bad boys, the first thing I recommend you do is this:

That will get you the latest kernel without upgrading everything. As any Linux user would know, upgrading to fix one problem introduces a thousand other problems, and this felt like a nice trade-off.

The reason for the above command is that I did have some wifi stability issues to start with, so I hope to save you that initial few dropped connections.

Once again, kudos to popey over on the #ubuntu-uk IRC channel for the advice.

Wifi has been stable and pretty quick. I suppose it’s not all down to the new kernel and drivers: I have Virgin 60Mb fibre optic, and my walls are refreshingly free of tin foil.

The gear

The XPS 13 comes packed with some great specs which you can gloss over here, but I’ll re-iterate the key components: Intel® Core™ i7-3537U CPU @ 2.00GHz × 4, 8GB RAM, 256GB SSD of which 230-odd usable and a mega bright 13.3" screen all on a pretty little laptop that feels like an 11" one. I never put the brightness above a third of the available level, and at 1920 x 1080 it looks great.

The keyboard still sports a Windows button, but it’s the new Windows logo which I’m not familiar with yet, and I pass it off in my mind as a generic “dashboard” type button, so it’s all good. A Tux button would probably be a bit weird. I mean, what would a penguin button do? Summon a troop of penguins? Nah. Besides, penguins — just like seals and dolphins — can be dirty little scumbags.

The ever-so-scientific bench test

I needed GIMP for something last night, and when I installed it and launched it for the first time, the realisation hit me that it all took about 30 seconds.

So, I purged GIMP and re-did it for your viewing pleasure:

Apart from this, I’m running about multiple Java server apps (for this thing I’m working on), plus a couple of VMs, plus some Python scripts that are running some numbers. My software does make efficient use of all the available cores, and CPU hasn’t been a problem for me in a while.

All the Linux games available on Steam runs like a dream. Just the addition of Steam of a *nix system feels like we’ve come full circle.

Qualms

It’s early days — a lot might still happen. In fact, Murphy’s Law states that I’ll publish this favourable review and it will be shortly followed by the i7 going up in smoke.

Anyway, here are some of my initial qualms:

  • The mouse is triggered sometimes whilst typing. This is configurable, and I have switched it to disable the mouse whilst typing, but to no avail.
  • The password box looses focus more times than not, and you end up typing your password in unfavourable places. This could be related to the previous issue discussed.
  • Keyboard is ever so slightly flimsy, because sometimes letters will double up. Perhaps this is just a keyboard I need to get used to. Besides, I’ve used the Mac chiclet-style keyboards exlusively since 2009.
  • The palm rests — even though they feel great to the touch — seems to get a bit streaky after a while. My fingers are constantly greasy from chowing on ginger biscuits and stuff like that, and it doesn’t wipe down well.
  • The backspace button does make a slight squeaky sound sometimes, but this could be because my pinky finger “pulls” on the button due to the angle I attack it with. Still — I don’t think this should happen.

Outro

If anything else pops up, or if the XPS 13 makes my life significantly better in any other way, I’ll come back here to amend. (I won’t do those silly UPDATE things at the bottom — you can look at the Git history of this page for changes.)

This is my first ever piece of Dell equipment, and it doesn’t look nor feel like a grey, impersonal piece of office equipment. Also, Mr. Mark Hails-From-The-Same-Home-Town-As-I Shuttleworth got things very right with Ubuntu. Linux has certainly come a long way since that day in 1995 when my mate dropped off 25-odd floppies of Slackware.

I’m more productive than ever and won’t be going back to Apple. I certainly don’t want to shoehorn OSX into a usable system with macports any time soon.

AngularJS and Internet Explorer woes

Nov 01, 2013

Aka endless clicking on crossbrowsertesting.com and why I love being a backend programmer.

AngularJS and Internet Exporer woes A few weeks ago, one of my clients tasked me with building a public-facing single page app for their credit monitoring business. They’ve heard good things about AngularJS and said they wouldn’t mind if I learned it on the job. (I love those kinds of clients!)

At this point we’ve already solidified the backend API (Scala + Play! 2.1.3) and felt like getting my hands dirty with our good friend Javascript.

At first, it was easy

I knocked the first version out quickly and got it working on the latest Chrome and Firefox on a Macbook Air. As we all know, my setup represents a small slice of humanity, so onto cross-browser testing I went.

And then, it wasn’t

I’ve been solely a backend programmer for a good few years now, and I soon remembered why: building something for to work with every browser/platform combination in the world is a royal PITA. I wasn’t going to give up, though, and the tool I used to achieve this goal comes with an A+ thumb’s up 5 stars from me. I was saved the cost and effort of running every other major browser/platform combination.

But, still — this is how it all panned out: load the page, load dev tools, and then the clicking begins. The endless clicking through thousands of lines of AngularJS and jQuery code to find the point where things fall over, and then just before the Eureka moment, the connection would drop. Or IE devtools would throw a wobbly and loose its place in the source code. All of this via a Flash frame stuck with IE devtools. IE DEVTOOLS, people! Not fun.

Which is why this isn’t a detailed bug report: I merely stumbled onto a solution after pulling all my hair out and trying something different.

The issue

Now, I’ve done exactly what the good AngularJS folks told me to do, but my scenario seemed unique. It turns out that if you use a custom directive from a partial in IE, it won’t be callable as an element (‘E’), but only as an attribute (‘A’), e.g. of a DIV.

I explain via two examples over here. If you are the lucky owner of a Windows box loaded with IE8 or smaller, please go and try it out and then lodge a proper bug report with the jQuery folks. Yes, yes — I know it sounds like this article is about AngularJS, but the real issue seemed to be with jQuery.

Something to do with target.appendChild(elem); on line 6,050 of the latest version of jQuery at the time of writing.

In the mean time, I hanker after my beloved Scala backend servers, where I get to choose exactly which platform and which flavour of VM I run on.