Omar Khan

Mind the Gap

Inspired by this feature in the New Yorker, this is my attempt to learn d3 while grappling with the UK neighbourhood statistics API.

The visualization shows income inequality along London tube lines. My only rule here was to use only d3 (no jquery!). I can confirm that DOM APIs are indeed horrible, and that's without even trying to support IE.

For what it's worth I don't think the d3 API is very nice either, unless you really like lots of chaining. I just don't find long chains of method calls very readable.

Khanival Photobooth

When my brother got married in 2012, he wanted a photo booth so that guests could take memorable pictures of themselves in a wide variety of silly outfits. Being a young musician, he couldn't afford the real deal, so I was given the task of hacking one together using an old netbook and his DSLR.

The hastily-written is code responsible for some very embarrassing pictures. It works as follows:

  • A nodejs server script serves a single page with some client code.
  • The client code uses getUserMedia to display the webcam image on the screen, as well as a helpful 'press a key to take a picture' message.
  • When a drunk guest presses a key, the client notifies the server over websockets using socket.io.
  • The server then shells out to gphoto2, which takes 4 pictures using the attached camera balanced just above the webcam.
  • Once the pictures are ready, the server thumbnails them and notifies the client over websockets.
  • The client displays the images, everyone is amused.

CoffeeDoc

I loved CoffeeScript when I first discovered it, back when the language was picking up steam in 2011. I was just getting to grips with javascript, and coming from python I found the indented, curly-brace free language far more readable.

I was looking for some tools to generate documentation for a project, and came across Docco. It could generate some nice-looking annotated source pages, and was written by none other than the creator of CoffeeScript. But after playing around with it I couldn't really see any benefit from generating annotated source pages - why not just read the source? The comments are in there.

I needed something that would show useful documentation for complex class hierarchies spread across multiple files. After some messing about with the CoffeeScript compiler, I had a working documentation tool.

It relies on a commenting convention based on python docstrings, so it might not be an ideal fit for existing codebases, but if you're starting a new project and you have a python background, you might like it. Have a look at the lovely wintersmith.io docs to see what it can do.

httptrail

I needed a simple way of logging requests and responses to a web api backend to help with writing integration tests. I couldn't find one, so I wrote this node.js based logging http proxy.

SpiderTrap

A pure-python http server that responds with an ever-expanding web of links. Use it to test, benchmark, and confuse web crawlers.

flickrstock

Do you need a whole bunch of stock photos for your latest project? Or maybe some images to flesh out a prototype? This command line tool fetches photos with a Creative Commons licence using the flickr API.

CoffeeKup Optimization

Back when I was getting to know CoffeeScript, I loved it so much I wanted to use it for everything, including frontend templates. I found CoffeeKup, which seemed to offer everything I was looking for - not quite as nice looking as Jade, but it meant I could write my whole project, front-to-back, in the same language.

The only problem was, it was a bit slow. Frontend pages need to be fast, and slow templates can make things unresponsive... ah who am I kidding, it was fast enough, I just got caught up in some serious premature optimization. So much fun!

The idea was to compile the templates to javascript, do some static analysis of the resulting code with uglify-js, and move things around so that as much as possible of the work that CoffeeKup was doing at run time was done at compile time. The results were pretty good.

Home in Rome

An abortive attempt to create a booking engine for B&Bs in Rome. My first django project.