Updates Instagram Photography Projects About Contact

Image Entropy

27 December 2012

For some time I’ve been interested in the concept of “smart cropping”. While there have been lots of articles about various approaches used, most are relatively abstract. So in order to better understand the techniques I decided to use Christmas down-time to experiment myself.

I wrote two little toy-scripts that use entropy to calculate the interestingness of parts of the image. It was also an excuse to play with <canvas>, to do all the processing on the client.

Take a look »

Automount Drobo FS on Mac OSX

2 December 2012

My PC died so I’m seeing if I can live with a Mac as my primary machine, one of the big annoyances so far is having to manually mount my Drobo FS network drive. This means backup scripts and other tools can’t see the drive until I access it through Finder.

I seem to have found a solution. Posting here for personal memory and the off chance it helps someone else.

  1. Open “System Preferences”
  2. Select “Users & Groups” under System
  3. Select “Login Items”
  4. Click the + symbol at the bottom of the list
  5. Browse to the network drive and open up the folder you want to automount
  6. Click Add
  7. Check newly added item in the list

Now, theoretically, whenever you login the drive should be already be mounted.

I also stumbled across the command mount_afp, this might prove useful in backup scripts, for example, I have the following:

if [ -e "$DIR" ]; then
 echo "$DIR already mounted"
 mkdir $DIR
 mount_afp afp://Drobo-FS._afpovertcp._tcp.local/Dan $DIR

Here are some other tidbits.

To query whether the volume is already mounted you can do:

mounted=$(df | grep "/Volumes/Dan")

And then you can force finder to refresh and show the volume, it didn’t seem like this was always needed but sometimes helped:

disktool -r


20 November 2012

If you are interviewing for a programming job it is almost inevitable that you will be asked to do some coding on a whiteboard. While there has been some criticism of the practice, it is widely employed by the tech giants—Google, Facebook, Microsoft, Amazon—and startups alike.

In this post I’m not commenting on the validity of this style of interview (though I do personally find whiteboard coding a useful way to see how candidates work through problems) but instead pointing out some common pitfalls that can be avoided, given that this is how tech companies interview.

Continue reading on Medium »

Why have a blog?

18 November 2012

It has started to feel weird, still having a blog.

These days, if I have something quick to share I am most likely to post it on Google+. For all its criticisms I think it is a great product, and because many of my friends use it (googlers *cough*), it works really well for me.

The chronological, diary-style format of a blog has always felt a bit forced to me, and I am often left feeling guilty that I haven’t posted in months. This is one of the reasons I am excited to be working on Medium. And if I have something longer to write I will probably write it there in the future.

So where does that leave this site?

I think it becomes an aggregator for my online presence. If for no one else’s consumption than my own and my family’s.

I recently hooked up If-This-Then-That to pipe my Instagram posts here and today I wrote a little node server that will allow me to do the same for my public G+ posts. It’ll be interesting to see how it turns out, but I figure few enough people read this that it’s worth trying.

We’ll see.

Velocity vs. Quality

11 November 2012

At some point in every software development project the question of velocity vs. quality inevitably comes up. The idea being that cutting some corners will allow you to move faster and get to your goal sooner.

This is a topic I have wrestled with over the years and have come to believe that the argument itself is a dangerous false dichotomy, and that reframing the discussion can lead to both a better product and a faster moving team.

Continue reading on Medium »


25 May 2012

For the last couple of years I’ve had a lot of thoughts bouncing around my head on the topic of complexity, primarily in the context of software. I’m still trying to formalize my thoughts better, but I thought it was time to start keeping a list of related quotes.

Complexity has nothing to do with intelligence, simplicity does.
Larry Bossidy

Simplicity is hard to build, easy to use, and hard to charge for. Complexity is easy to build, hard to use, and easy to charge for.
Chris Sacca

Controlling complexity is the essence of computer programming.
Brian Kernighan

More »


21 December 2011

I recently redesigned this site with the primary goal of improving my photography portfolio. If you don’t care about web dev you can stop reading now and just go take a look at the photos. Let me know what you think.

Ok, so here are some tech notes on the implementation, though this is all pretty standard these days.

For the photos page I wanted to make use of the HTML5 History APIs. But rather than make the photo page standalone I decided to “Ajaxify” the whole site. The site dynamically loads content, avoiding full page loads, using similar patterns to the ones we employed in Gmail and Google+.

If you navigate directly to a certain page it will be rendered on the server. Once the page has loaded, the JavaScript will listen for clicks, intercept any links that can be handled client side, request the page contents via an XMLHttpRequest, update the UI, and change the browser location using history.pushState. For all pages except the photos page, the XHR simply requests the page with ?mode=body which tells the sever not to render the chrome.

This was made simpler by the fact that I’d already written a small library (Surface) that does all the heavy lifting and simplifies the management of single-page applications. The trickiest part was getting WordPress to work properly and unfortunately meant changes that will need to be reintegrated after every WordPress update.

The photos page is all rendered client-side and simply requests the photo data from the server. The photos are stored on Flickr and I actually use the Flickr API to get the list of photos for each album rather than hard coding them.

The top navigation uses Raleway from the Google Web Fonts archive.

The site works best in the latest Chrome and Firefox builds, but IE degrades to using full page navigations, though the photos page only works in IE9+.

Web Audio Tone Generator

3 October 2011

Recently I was playing with the new Web Audio API. While there are a bunch of examples on the Chromium site, they are rather more complex than you want in a hello world sample.  So for posterity here’s a super simple tone generator that uses AudioContext#createJavaScriptNode and the onaudioprocess handler.


26 February 2010

At the beginning of 2006 Erik and I started a 20% project to write a JS library for Google. Today it is used by many projects within Google and was recently open sourced.

On its own, the Closure Library isn’t very compelling for the average web developer. The dynamic loading is intended for unit tests and development, and using it in production would cause users to download masses of unused code.

Luckily for us, the Closure Compiler was open sourced at the same time. The compiler knows about a lot of the idioms used in the Closure Library and does a really good job of removing dead code and optimizing what remains. The team also launched a web service with a RESTful API so you don’t even have to run the compiler yourself.

Even with the web service, the development-debug cycle isn’t ideal. So when I found myself wanting to use some of the Closure Library for my new photo site I hacked together a PHP class that provides a convenient interface to the compiler web service, caches the optimized code, and recompiles when the sources have changed. Pretty basic, but quite useful I think.

I know PHP is looked down upon by many programmers, but it is easy, convenient, and widely available. If you have a PHP based site and want to use the Closure Library and/or the Compiler, it might be worth heading over to the project page and seeing if it might be useful.



15 May 2008

Mark Pilgrim’s project to document the web launched today as DocType. This is a really great resource, with topics ranging from security to cross browser DOM wrangling, and it’s only going to get better as it is completely open.

A lot of the example JS code is based on the project Erik and I started, and some is available for download from the SVN depot.

MS Patches IE6 GC

17 December 2007

Microsoft released their GC patch to the JScript engine on automatic update, if you didn’t get it and ever use IE, even for testing, I recommend downloading it. See my post from March on the problems with IE6 GC.

Day Job

30 October 2007

You can read about what I’ve been working on here.

My favourite feature: visible history means shareable searches.


7 May 2007

Post-Cinco-de-Mayo-tequilla-hangover == no skydiving. Instead I knocked together a little experiment for a geographical traceroute. Not polished or well coded.

Garbage Collection in IE6

7 March 2007

I’m not an avid blogger, and when I do post it’s rarely tech related. But recently I have had cause to do some investigation into the effects of Internet Explorer’s garbage collection routines on performance, and I thought it would be useful to summarize some findings.

Eric Lippert posted about the internals of IE’s garbage collector back in September 2003, though he skimmed over the important bits, which were later noted in the comments. The crux of the problem is that IE’s script engine uses allocations to determine when to run the GC; that is after 256 variable allocations, 4096 array slot allocations, or 64kb of strings have been allocated. Not only are allocations a bad indicator of garbage, but these limits are such that any decent sized application is going to make the GC run pretty regularly.

To compound this problem, the running time of the garbage collection routine is dependent on the size of the working set (O(N^2) as described in Lippert?s article, though the results below show a linear relationship). So as your application gets bigger the garbage collection runs slower.

Back in the day this didn?t really matter, but as web applications are getting more complex there is the potential to hit a performance wall. More code being executed means the garbage collector will be run more frequently; and because the applications contain more state on the client; and have larger code bases, the object graph that the garbage collector has to traverse gets bigger.

To demonstrate the effects of this on performance I?ve used a simple benchmarking function which creates 5000 object literals with random properties, and then sorts them. The function is then run on a simple HTML page, pre-populated with a further O-objects, each with P-properties, which will always remain in scope.

The following results show the mean execution time of the create-and-sort test as O increases for constant P=50 on Firefox 2.0 (red) and IE6 (blue) on the same computer.


Try the test for yourself.

Now, the test environment is quite contrived in that it creates the literals as homogeneous global variables in a simple scope, but the effects are the same if you create objects dynamically, with scope chains exposed via event handlers and closures.

I doubt there are many web applications that are big enough to be seriously impacted by these problems, though it is worth bearing in mind, since performance is proven to be strongly linked to adoption of web apps.

Microsoft issued a hot fix that allows you to increase the allocations, this gives a significant performance boost, but you don?t want to force all your users to patch IE so this isn’t a viable solution. IE7 seems to have solved this problem by having dynamic allocation thresholds that scale to the size of your application, but rollout of IE7, particularly to corporate users, is likely to be slow for the rest of 2007. The other options can be painful and basically involve optimizing your application by reducing code size and finding the balancing point between improved performance from keeping state local and keeping your working set to a manageable size. Always explicitly dispose objects when they are no longer needed by removing event handlers and dereferencing properties.


Eric Lippert’s 2003 post: “How Do The Script Garbage Collectors Work”

Micrsoft Support Article: “You may experience slow performance when you view a web page that uses Jscript in Internet Explorer 6”

Levenshtein Distance in SQL Server

11 January 2005

Merry Christmas, Happy New Year, and all that. This is a kind of dull post but I know some people who come here will find it useful:

I have found an implementation of the Levenshtein distance function in TSQL. This allows you to calculate the similarity between two strings, which is particularly useful for searching features. You will also need a simple user-defined function called MIN3 that is not listed at the above link, here’s the super quick one I wrote:

1   CREATE function Min3( @a int, @b int, @c int ) returns int AS
3   	DECLARE @Retval int
4   	if @a <= @b AND @a <= @c
5   		BEGIN
6   		SET @Retval = @a
7   		END
8   	if @b < @a AND @b <= @c
9   		BEGIN
10  		SET @Retval = @b
11  		END
12  	if @c < @a AND @c < @b
13  		BEGIN
14  		SET @Retval = @c
15  		END
16  RETURN @Retval
17  END

New IE Vulnerability

17 December 2004

A new and very dodgy vulnerability has been found in IE that allows fraudsters to create web pages that pose as other sites; and it is increadibly simple to set up. A few weeks ago an ex-colleague asked some advice after receiving an email with a link to a spoofed version of the e-commerce section of their site, so as you can see this is could be pretty nasty. You can find out more information at Secunia.com.

Basically, be very careful using e-commerce links from emails and untrusted websites. Or else use FireFox.

DHTML: Event Based Animation Demo

9 October 2004

At someone’s request I have set up an example demonstrating event based animations in DHTML. The "Toolkit" code is extracted from a Thirteenth Parallel project that never got completed, as such it is not all that stream lined or complete; however this example should illustrate a neat and quick way for developing complex animations.

To put the example into context: you could use an animation object and a 5-dimensional curve to animate an expanding panel while changing it’s colour (2d for the element’s y-position and height; 3d for the red, green and blue components of it’s colour). Also, because the animation object is not tied directly to any element or property, the on-animate event handlers could be used to animate anything from colours, widths and element positions, to frame sizes and window positions.

PHP graphing classes

14 June 2004

Not quite as interesting as my previous post on quitting my job, but nevertheless some people may be interested in this small collection of classes for drawing graphs in PHP.