Vim for TextMate Fans

A text editor is the programmer’s lathe, but unlike traditional engineering we can have limitless tools. The question is: how much time do you have to learn about them all?

I’ve used vim a lot over the years, mainly because I spent a long time using Linux and it was there so I used it. The choice was obvious: vim or vi were on almost every machine I had access to, and worked excellently both locally and remotely. Once I’d learnt the basics I was set, I knew enough to get my work done.

Read More →

Rails Time Saving Tips

I’ve created quite a few Rails projects over the last year, some commercial projects, and others are applications released under Helicoid. Here’s a few things I’ve found save time and help make projects as maintainable as possible.

Named routes

You can refer to routes in your forms and links like this: document_edit_url(:id => Isn’t that much nicer than other means? It can often make code easier to understand quickly, thus helping maintainability.

To use named routes, instead of the usual map.connect directive, use map.my_name.

Read More →

Mac-friendly Terminal Cheat Sheet

One of my colleagues wanted help with his mac’s terminal, so I put together a little cheat sheet containing all the commands and keyboard shortcuts I find essential. I marked the most awesome time–saving commands with stars, and even added a few emergency help tips:

Mac-friendly terminal cheat sheet

It’s all basic stuff, but if you’re new to using the command line (and when I say command line I really mean bash), this should help you kick some ass.

Read More →

Textile JavaScript Class

This JavaScript class requires Prototype. It displays help on Textile next to elements with a particular class, and parses the help from a Hash that you can define in the constructor.

I’ve been using it to add help next to textareas that accept textile. All I have to do is create textareas with the class “show–textile–help”, and they get a little div full of useful information. The help text is hidden until the user clicks on the link:

Textile small help text

Read More →

Dismantling Browser Ajax Handling

I’ve been writing some fairly complex JavaScript for a small project designed by my fiancĂ© (she makes demands for features like autosave without realising the amazing trickery required), and I started thinking about threading.

When you use XMLHttpRequest to fetch or send data, you create methods or functions to act as callbacks. At some point the callbacks are run, and data magically appears into your classes. That feels a lot like threading to me, the fact it’s asynchronous. I remember reading Thomas Fuchs saying something about JavaScript being single–threaded, a quick search found the comment: [Rails-spinoffs] Ajax.Request synchronization (onSuccess beforeonComplete?).

How do browsers manage XMLHttpRequest? What if there’s more than one thread? Is there a thread for that handles JavaScript, and new threads for asynchronous requests? How do browsers that are cross platform handle threads if they need to work on different operating systems? I took a look at the gecko and WebKit source to try and figure out some answers.

Read More →

Backpack Automator Plugin

I have a public Backpack page where I upload images to show people. So say I’m chatting to online, I can just cmd–click a file and upload it then paste them a URL to the image. To make this quicker, I created an Automator workflow.

When I want to share an image, I cmd–click it and select Upload to Backpack:

Automator Finder menu

Read More →

Using APIs: Don't Forget About RSS and Atom Feeds

Screenshot from Basecamp Mobile

Sometimes you need to display collated data on a page. For example, Basecamp has a useful dashboard which displays all the latest activity across all your projects. I’ve been working on an application that provides Basecamp access to mobile devices, and I realised that reproducing this dashboard would be far too API–intensive to be usable.

It can take anything from 20–1000ms to complete a request using the API, depending on the number of hops the request goes through over the network and how fast the application at the other end responds. So if you want to gather the data Basecamp displays on its dashboard, you’d need to:

Read More →

Getting Started with Rails Optimisation

I’ve been working hard to improve the performance of Tiktrac, just because it’s been in beta for a few months and I’m really sharpening it up to finally stump up the cash for some serious hardware to run it (and other) applications on.

When I need to improve performance in a rails app, I start off with a few basic questions:

  1. How many queries are being generated on complex pages?
  2. What pages are the slowest?
  3. What partials are the slowest?

At this point, I start loading slow pages and watching the logs. The logs will show you interesting data like this:

Read More →


I’ve been working a lot recently. And when I say a lot, I mean thousands of lines of Rails code across three projects, and thousands of lines of php across many projects. I started to get concerned about RSI. I’ve had vague work–related pain in my wrists in the past, and I think a big contributor to this was the fact that I once broke both my wrists. I’d elaborate on this, but it’s just way too embarrassing for me to slap that on my blog!

Back to RSI. I’ve found these two apps really helped:

Windows: Workrave

Workrave tells you when to take micro breaks, longer breaks, and what kinds of exercises to take. Seriously! The breaks were enough to help me, though.

Read More →

PHP 5's Anonymous Functions

I don’t see much use of anonymous functions in php, yet when I write python or ruby, I use constructs like this quite often. You can do it in php though, with create_function. It’s nothing that fancy, it just lets you create a function whenever you feel like it. This can be placed wherever you need a callback in php.

Callbacks in php must be a function name. You can’t refer to methods in the current class, or hack it by making a function that returns an object: function()->probably_a_singleton->hello(). This is where create_function() comes in.

Here’s an example:

Read More →