Blog ported to WordPress

I’ve just finished porting my blog to WordPress.
My blog was originally written in Java before most blogging platforms existed.
This means that the code for it is old, and becoming increasingly difficult to maintain.

I wanted to make a small change recently and very quickly hit dependency hell.
So I decided maybe I should just port it all to WordPress and have one less legacy project to maintain.

Importing it was simple enough.
I generated a full RSS feed (remember those?) and used one of the provided importing tools.
The tricky part was maintaining permalinks.
Most people don’t seem to bother with this step when migrating blog platforms.
But I think it’s still pretty important.
It’s a permalink after all.

The way my blog generated them was different from the way WordPress does them.
So I ended up writing a script that converted them to WordPress format then tested each URL against the deployed site.
Any that resolved emitted the code for an Apache redirect into a text file.
Any that didn’t I had to fix up by hand.

Finally I was able to paste the redirect codes into my Apache config and send it live.

The only thing I’ve not been able to do yet is grab the old blog comments.
That’s still on my todo list.

How I am getting things done with Trello Workflows

As the resident Trello* fanboy amongst my friends I recently put together an email explaining a couple of ways that I get the most out of Trello.

I call these “Trello Workflows”.

In the interests of “sharing the knowledge” I’m converting that email into a blog post.

* Disclaimer: I get a month of free Trello Gold if you sign up using that link above.

The workflow for day to day stuff

The first of these workflows is for tracking day to day tasks.

Workflow for day to day stuff

The initial idea is explained in part 2 of this post by Ryan Carson.

Before you do anything, take 19 minutes and organize your todos for the day. I wake up at 4:54am every day, grab a coffee and open up my personal Trello Board and prioritize. Limiting this to 19 minutes keeps you focused and ensures you don’t spend all your time prioritizing instead of doing.

Please note that you don’t need to get up at 4:54am to do this.

I discovered this system from Leo Babauta of Zen Habits who has a few things to say about it too.

I’ve reworked this system a little and “made it my own” but the basic ideas are the same.

Changing it to suit you is quite important. I don’t like to have lots of non-critical cards in my Later list so I eventually created a “Rainy Day/Ongoing” list where I could put all of the tasks that are non-essential but that I’d still like to get around to one day.

I’ve been following that system for about 18 months and it’s amazing the amount of stuff I manage to get sorted now.

I no longer have to worry about forgetting to do things – I just make sure I track them on the board.

The only thing I have to remember to do is a quick daily review and then to have the discipline to add cards to it whenever new tasks roll in.

The other nice thing is that if you set a due date on a card and add yourself as a member Trello will email you a reminder when it’s due.

I’ve set up a template Trello board based on this that you can clone and start using.

The workflow for Big Goals

The second workflow is for managing the big goals.

You know, learn Spanish, climb Mount Everest, the kind of stuff that takes months or even years to accomplish.

Workflow for Big Goals

Again, there’s an excellent blog post explaining it all.

Some people call them “dreams”. Some call it a bucket list. I call them big, gray, looming rocks. No matter what you call them, we all have them: the things we want to do and experience before we die. Making your own bucket list gives you some perspective on your life and what you want out of it. But writing bucket lists and creating vision boards around them can only do much. Emptying that bucket calls for action.

The basic principle is to break down each task into smaller and smaller chunks until you’re left with 2-3 small things to do in a given week.

For example, one of my goals is to speak Spanish fluently (I’ll get around to climbing Mount Everest next year), my tasks for this week are to complete the next two stages of an online course I’ve signed up to.

Each of those steps is probably only 20 minutes work so I’ve committed to spend less than an hour a week on it.

This means that I’m not going to overload myself and burn out which then means that I have a better chance of achieving my goal.

I’ve only been doing this latter one for a few weeks but I’ve already felt the benefits.

I’ve found that I am making time to do these tasks whereas in previous weeks I would just completely forget about them.

I’ve set up a template Trello board based on this one as well.

Let me know how you get on with these by contacting me through the blog or pinging me on Twitter.

Running an exim secondary email server on EC2

A while back I set up an exim server on EC2 for secondary email – at the time I tested that it worked and it all looked fine.

It accepted emails for my domain then forwarded them on to the primary as expected.

The one critical thing that I didn’t test was what happened when the primary was down – it seemed like it might be difficult to test so I didn’t bother.

This proved to be a mistake.

Last weekend when the primary email server did actually go down I found out the hard way that my secondary was bouncing all emails.

Investigations determined that it was trying to deliver to itself after discovering that the primary was down.

This caused an email loop which was eventually bounced back to the recipient with the error “Too many received headers”.

This made no sense to me and prompted much head scratching.

After much searching online I figured out what was happening, and more importantly, how to fix it.

When exim detects that a host is down it moves on to the next MX DNS record listed (if any).

It then compares its own IP address(es) against the resolved MX record to make sure it doesn’t try to deliver to itself – this is the part that was failing!

The reason it was failing was that EC2 instances run with a NAT‘d IP address – meaning they have a private range IP address which differs from the elastic IP that I had assigned it (and was effectively recorded in the DNS record).

Exim had no way of knowing that it was trying to deliver to itself – hence its confusion.

The fix was fairly straightforward – exim provides a config setting for this situtation.

extra_local_interfaces = YOUR_ELASTIC_IP_ADDRESS

Add that to your /etc/exim4/conf.d/main/000_localmacros file and restart exim (I’m assuming an ubuntu style setup here).

Finally, on to testing that this fix works properly – it proved to be a simple case of stopping exim on my primary for a few seconds while routing an email through the secondary (using mutt on the command line) and checking the exim logs.

It now accepts emails and puts them upon the queue (sudo mailq) for a fixed amount of time before being forwarded to the primary.

This tip also applies if you’re running an Exim secondary on any sort of NAT network, not just EC2.

TODO: Refactor this

Anyone who’s worked on a sufficiently large code base will have probably come across a comment like this one.

// TODO: Refactor this

No doubt left there by some well-meaning developer and probably ignored by everybody else since.

Sometimes it will be accompanied by a rant about exactly what’s wrong with the code in question.

Comments like this serve no useful purpose!

They may serve as a bit of a stress-relief for the person inspired to write it but other than that are a waste of time. If the person leaving it wasn’t inclined to do the refactoring then what makes them think someone else will?

Or maybe they optimistically think they can come back when they get some free time and do it. They almost never will find that free time – the comment will sit there until the developers on the team no longer even notice it anymore.

Here’s what I like to do when I come across some code that I think could do with some refactoring…

Consider working on it right away

If I have time and/or it’s in scope I’ll try to refactor it there and then.

If I can’t do it right away…

Raise a tech debt ticket in the bug tracking software

This creates an actionable task that can be discussed by the team and tracked.

Leave a TODO comment referencing the bug tracker number

This ties the code in question back to the ticket.

Add my name/initials to the comment

This gives people someone to talk to if they happen across the comment.

Oh yeah, and I save the rants for down the pub!

Fixing UTF-8 encoding on my Tomcat websites

Just spent a few hours fixing some UTF-8 encoding problems on my blog.

I had a problem with non-ascii character being displayed incorrectly.

Turns out that I had a number of different problems to solve.

First I read through Cagan Senturk’s (very useful) UTF-8 Encoding fix (Tomcat, JSP, etc) post.

Fortunately I’d already read Joel Spolsky’s epic unicode post so I had the theory.

First off I needed to make sure all my JSPs had the correct pageEncoding at the top.

I also added the ‘Content-Type’ meta header to my template file.

Next I needed to wire in the EncodingFilter that Cagan so kindly provided.

That meant that non-ascii characters in my JSPs rendered fine but I still had two problems.

Any text that I entered into a form was still being screwed up, as was anything read from the database.

Stack Overflow had the solution (as usual) for the form input.

I needed to amend my Tomcat config to ensure my connector had ‘URIEncoding=”UTF-8″ ‘ added to it.

That fixed the form input problem.

That just left my Postgres database.

I first used ‘psql -l’ to see what encoding my database had.

It was set to ‘LATIN1’ – obviously it needed to be ‘UTF-8’.

To fix this I needed to drop and recreate my database.

Luckily this was only my local development database (my production one was already UTF-8) so that was simple enough.

Finally, after all that was done, I had proper UTF-8 support on my site.

And to prove it – here’s some non-ascii content from the UTF-8 SAMPLER website.

¥ · £ · € · $ · ¢ · ₡ · ₢ · ₣ · ₤ · ₥ · ₦ · ₧ · ₨ · ₩ · ₪ · ₫ · ₭ · ₮ · ₯

Tumblr repost

For some reason a photo I posted to Flickr a few years ago has been reposted like crazy on Tumblr.

I only found out via the stats after a few people faved it on Flickr.

Interestingly, it’s been on Flickr for four years and in that time received 29 favo(u)rites.

Once it was posted to Tumblr It managed 336 likes/reblogs in about a week (not sure how I can check that timespan but it was certainly pretty short).

More grist to the mill for the “Flickr is dying” meme (or I’m just not very popular on Flickr).

Adding Sphinx to your Java website with jsphinx

I’ve been using Sphinx on my FilmDev website to search user’s recipes and it’s been working really well.

So well that I wanted to add it to my Java websites too.

Setting up Sphinx on a rails site is made very easy thanks to the Thinking Sphinx plugin.

Unfortunately there is no such plugin for Java so setting it up requires a little more work (though not too much).

First off I downloaded and configured Sphinx until I could call search on the command line and get results back from my database.

I then grabbed the sphinxapi.jar from the downloaded package and dropped it into my WEB-INF/lib directory.

The Java source for that jar is included in the downloaded package – plus a file called “” that I used as the starting point for my own code.

The code works but is fairly basic, I’ve expanded upon it a fair bit and have put it in a github project called jsphinx.

Feel free to grab this code and use and amend as appropriate for your own site.

I encourage you to share any changes you make by forking it on github.

Bear in mind it’s coded against the 0.9.9-release version, I have no idea if it works with the 2.0.1-beta version.

The code includes examples for doing weighting, filtering and ordering.

The command object also supports pagination.

I’m using the code on this blog right now and it works great.

The final thing in that code is something to handle delta indexing.

That’s enough of an involved topic to warrant another blog post…

A problem with the Internet

A while back I ordered a pair of boots on-line.

When I filled in my details and clicked submit I got an error page.

That sort of thing makes me nervous – did my order go through or not?

I checked my email and had no order confirmation email, but decided to leave it for a day to be sure.

So, the following evening as I had no confirmation email I tried again – this time the order went through perfectly and I got my confirmation email.

All good.

Two weeks later I got an email saying my boots had shipped, again, all good.

Five minutes later (I think you can see where this is going) I got a second email saying that my boots had shipped – this one had a different order number though.


I replied to the second order and told them I had only ordered one pair of boots (I decided not to tell them about the error page as I figured it might confuse matters).

I got a swift reply:

So sorry about that, there must of been a problem with the internet at that time. Your card has been refunded for the second order.

“Problem with the internet”?

Problem with their crappy website more like!

Blog repurposement

I started writing this blog in June 2002.

This was before the days of making money from blogs – back then it was all about linking to interesting stuff you found on the web and posting brain dumps about various things in your life.

Back then it was just another blog – not a particularly insightful or popular blog but a blog nonetheless.

Nowadays most blogs are different, they are targeted to a particular niche and usually written by someone with a “blogging strategy”.

The point about having a strategy means they are blogging for an ulterior motive (promote a product, earn money through advertising etc.) rather than blogging for the sake of blogging.

At this point I recommend you go read Rise of the Tablog as it makes the point about the current state of blogging far better than I can.

At some point in 2006 I decided I should try to only post about stuff related to software engineering and computers. That’s right, I’d also decided to target a niche.

I didn’t really have a strategy – I’d just seen where everyone else was going with their blogging and felt I should do the same.

This was the point my blogging slowed down – mainly because I was only posting when I had something to say on the subjects I’d decided I should write about – rather than my original “any old crap” brief.

Around 2007 I bought a bike (the first I’d owned in 20 years) and decided to blog about the experiences of taking up cycling again.

In line with my above thinking I started a bike blog.

That seemed to work well at first as I had about 5 or 6 posts in mind when I started it.

The problem was after writing those posts I didn’t really have that much more to say on the subject of cycling. I tend to add one or two posts a year now if that.

I’d also created a photoblog which originally just contained photos but then I decided to use it for all my photography related posts too.

This leads me to where I am now – three different blogs, all neglected in one way or another.

And only feeling able to blog on the subjects of software, photography or cycling.

What about if I take up Kayaking and want to blog about it?

Do I start a Kayaking blog too?

Note: I have no plans to take up Kayaking.

So, I’ve decided to fix this rather untenable situation I’ve gotten myself into with the following plan.

1. Make this blog more of a general purpose blog again – ie, post more often on a wider range of topics.

2. Continue posting photos on my photoblog but try to keep the longer stuff on this blog.

3. Move the cycling blog to Tumblr – Tumblr makes posting very simple so this will hopefully remove some of the “posting friction”.

Zsh completion of arbitrary commands

I spent a good few hours over the weekend trying to figure out how do something with zsh completion that I figured would probably be quite simple but I just couldn’t find an example of anywhere.

I wanted to do tab completion based on the output of an arbitrary command.

This was so that I could make full use of AndyA‘s very useful directory shortcut pind script.

Essentially I was porting the _cdpin function from bash to zsh.

function _cdpin() {
$( hasle ~/.pind -cx $cur )

complete -F _cdpin cdpin

It looked like it should be simple but after reading sections of the zsh manual, searching online, looking at the various completion scripts in my zsh installation and trawling Stack Overflow’s zsh content I couldn’t find a succinct example.

Eventually I found the answer in a book called From Bash to Z Shell which I was able to read on my Safari Books Online subscription.

The solution turned out to be ludicrously simple:

function _cdpin() {
compadd $(hasle ~/.pind -cx)

compdef _cdpin cdpin

I could make it even simpler if I stuck if in a file called _cdpin but I wanted to keep it in the same place as the functions.

Now when I type cdpin and hit tab I get a list of my existing entries and I can complete from there.

Annoying that something so simple was so hard to find so I’m posting it here in the hope it helps others.

And as AndyA was smart enough to share his scripts on github I’ve forked it and will add zsh support (via a conditional) and see if I can get him to pull in my changes (I’m sure he’ll do it if I buy him a beer).

As an aside, gotta say I’m loving github – I joined a few months back but have only just started uploading some code to it.

You can see my stuff at