Ben Dodson

Freelance iOS, Apple Watch, and Apple TV Developer

Website upgrades finally completed

Some of the more regular visitors amongst you may have noticed that for the past month or so, has been in a mild state of flux - I'm happy to say that everything is now completed and working fully!

I hurried the uploading of the new design as I had some spare time at Mashed and thought it would be a good idea to get the new site up and running in any state. Then, the knowledge that my site might not be working would spur me on to fixing it. A good theory, but apparently not good in practice.

There were several bugs in IE6 (there always are), the site was taking too long to load, and the contact form didn't work at all.

But now, the site has been optimised to a grade A level (according to YSlow), the IE6 bugs have been fixed, and email now works from my server so the contact form is working again!

I'll be continuing to make little tweaks and upgrades here and there, but I'll also be returning to the blogging scene and keeping the site regularly updated with various development news. As a taster, I have recently been playing with a new iPhone 3G, fire eagle, a montage making script that uses flickr, and Google Optimizer (although not all at the same time) so stay tuned!

New website goes live!

I've finally got around to giving the site a visual refresh which can now be viewed here at - There are a few bugs (mainly IE6) to iron out but on the whole it should be working!

The site was redesigned by Liza Hayes who took her inspiration mainly from Doctor Who! I've been building it slowly over the past few months, but I'm currently at Mashed so decided whilst I had the time dedicated to coding I really should get on and finish it!

There will be various updates to the site over the next few days so keep posted!

RSS Feed of the London Underground Tube Status

Please note that this page is now outdated - for any updates to the London Underground, you should use my dedicated Tube Status API and RSS feeds

I've been spending some time making an RSS feed of the London Underground tube status as I've been working on a few projects that could use one. You would think that Transport for Londons nice web 2.0 style website would provide this basic requirement but alas they don't. There are a few developers out there who have written some scraping scripts to convert this information, but most of them no longer work as they haven't been updated to work with the new site.

Previously I have used the script at to power any projects requiring a tube RSS feed but this went down a few weeks ago when I was in the middle of some crucial testing. So, like any other crazy developer would, I decided to write my own PHP scraping script that would generate me a nice RSS feed to basically tell me TFL had messed up my journey home!

For those of you just looking for an RSS feed of the London Underground tube delays, you can find it at - This is automatically updated every minute and will email me if anything goes wrong so I can fix it! If you are going to use it for any projects, please let me know so that I can monitor bandwidth, etc. If you are interested in how it works, then the code that powers this is below - feel free to use and modify it for your own projects:


// This file should be run on a CRON job every 5 minutes.
// The server will need to be able to write to this folder in order to create the XML file.

$array = array(
        'east london',
        'hammersmith & city',
        'waterloo & city'

$i = 0;
foreach ($array as $ref) {
    $id = str_replace(' ','',$ref);
    $id = str_replace('&','and',$id);

    $lines[$i]['id'] = $id;
    $lines[$i]['name'] = ucwords($ref);
    $lines[$i]['url'] = 
        '' . $id . '-now.html';


$i = 0;
foreach ($lines as $line) {
    $file = file_get_contents($line['url']);
    $needle = strtoupper($line['ref']) . ' LINE:';
    $pos = strpos($file,$needle);
    if ($pos !== false) {
        $pos += strlen($needle);
        $end = strpos($file,'</div>',$pos);
         $status = strip_tags(substr($file,$pos,($end-$pos)));
    } else {
        $status = 'A good service is currently running.';
    $lines[$i]['status'] = $status;

$now = date('r');

$xml = <<<XML

<rss version="2.0">
        <title>London Tube Updates</title>
        <description>The latest London Underground tube update information</description>
        <webMaster> (Ben Dodson)</webMaster>
        <generator>PHP script by Ben Dodson</generator>
            <title>Transport for London</title>
            <description>Transport for London Logo</description>

foreach ($lines as $line) {
    $xml .= '<item>' . "\r\n";
    $xml .= '<title>' . htmlentities(ucwords($line['name'])) . '</title>' . "\r\n";
    $xml .= '<link>' . $line['url'] . '</link>' . "\r\n";
    $xml .= '<description>' . htmlentities($line['status']) . '</description>' . "\r\n";
    $xml .= '</item>' . "\r\n";
$xml .= '</channel>' . "\r\n";
$xml .= '</rss>';



As I mentioned earlier, I am working on a few projects that utilise this script and I shall be making those available shortly. However, for a sneak peek, you can check out Tube Updates, an API for any developer that would like to make use of this data. There are still a few improvements to be made but you get the general idea!

Firefox extensions updated for Beta 3 compatibility

I've spent some time updating my firefox extensions so that all of them work with Firefox 3 Beta 3. At present they can only be downloaded from this site as it takes the Mozilla Addons team a few days to approve updates. My extensions page is now back up and running though and contains details on all 3 of my Firefox Extensions (Font Finder, Stop! Hammertime!, and STOP in the name of love) as well as download links for the new releases.

I won't be making any further updates to the stop buttons (apart from making them work with future version of Firefox) but I will be continuing development on Font Finder which could benefit from a visual overhaul as well as a clipboard function! I'll be updating on here when it happens so sign up to the RSS feed for the latest news!

Google extended encoding made easy!

I've been having a play around with Google Charts recently but came across a problem with the range of values that can be used. With simple encoding, you can only have values between 0 and 64, and with text encoding only values between 0 to 100. This is annoying when dealing with things such as tracking website hits or weight when values are typically much higher.

I played around with some functions to try and factorise the numbers so that they would be in the range of 0 to 100 but this didn't go so well so I decided to tackle Google's extended encoding.

This is a system of encoding that basically takes a pair of alphanumeric characters and translates them into a number between 0 and 4095 (much better!). So for example, B9 translates to 125 and .a would translate to 4058. However, although this has a much larger range, it's a bit harder to get your head around and so what is needed is a simple function (or two) to convert to and from the extended encoding. Predictably, I have said PHP functions here:


function array_to_extended_encoding($array)
    $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';

    $encoding = '';
    foreach ($array as $value) {
        $first = floor($value / 64);
        $second = $value % 64;
        $encoding .= $characters[$first] . $characters[$second];

    return $encoding;


function extended_encoding_to_array($string)
    $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';  

    for ($i=0;$i<strlen($characters);$i++) {
        $first[$characters[$i]] = $i * 64;

    for ($i=0;$i<strlen($characters);$i++) {
        $second[$characters[$i]] = $i;

    $pairs = str_split($string,2);
    foreach ($pairs as $pair) {
        $value = $first[$pair[0]];
        $value += $second[$pair[1]];
        $values[] = $value;

    return $values;


They work fairly simply by taking advantage of PHP's casting methods in that a string can be interpreted as an array.

In the first function, array_to_extended_encoding(), an array of numbers should be passed e.g. array(250,39,400,1904,2). The function first lists all of the extended encoding characters in order as one string named $characters. It then loops through our array of numbers, and creates two variables; $first and $second. In $first, we store the number from our array divided by 64 and rounded down using the floor() function. For $second, we use the modulus operator (%) to find the remainder once the number from the array is divided by 64. We then take both $first and $second and work out the encoding by looking up the numbers from within the $characters cast as an array. This gives us 2 characters which make up the extended encoding for the number. We keep extending the value of $encoding until we end up with a string representing the full extended encoding of the array passed to the function.

The second function, extended_encoding_to_array(), is slightly more advanced. It accepts a string as its only parameter which should be an extended encoding (e.g. $encoding = 'AA..B9aC'). We first list all of the characters in a string as we did for our previous function, but then we create two arrays which will contain all of the numbers we need to decode the extended encoding. In $first, we create an array of each character in the $characters string as a number multiplied by 64 (so the letter b would be 64 as it is signified by number 1 in the array multiplied by 64). Within $second we perform a similar operation but instead just assign the number of the character rather than multiplying it by 64. This gives us two arrays, with keys relating to each character that can be used as an encoding and values as the numerical equivalent. It is now a simple case of splitting the string that was passed to the function into chunks of 2 characters using str_split() and looping through the returned array setting the value of each character within the pair from the arrays we created. We then add the two returned numbers together to give us the decoded figure and add it to an array which will be returned by the function.

Simple? It has certainly made things a lot easier for the functions I'm writing for a PHP wrapper for Google Charts and hopefully it will help somebody else as well. If you have any questions or comments, please get in touch.

Firefox Extensions page will be right back!

As some of you may have noticed, the new site design has caused the Firefox Extensions page to go awry. This will return shortly (along with a few new extensions) but for the time being you are better to go the Mozilla Addons site to download the extensions.

Stop! Hammertime -
Font Finder -
Stop in the Name of Love -

Update: The extensions page is now up and running again and can be viewed at

Newer Entries »