April 25, 2011

Walhalla, Victoria

Walhalla, Victoria

This Easter, I spent some time in the lovely small town of Walhalla, after a night camping near Thompson Dam.


April 21, 2011

Helpful date helper

A useful php function for presenting a date in a short easy to read format wrapped in an <abbr> tag that displays a longer version of the date.

Your mileage may vary.

function helpful_date($date, $sd_format = 'd/m/y', $ld_format = 'g:ia, l jS F Y', $non_date_return = 'n/a'){

    // send back any non applicable dates.
    // send back any unconvertable dates.
    if( $date == '' || !( $time = strtotime($date) ) ){ return $non_date_return; }

    // adjust time for time difference
    //$time += Config('timediff');

    $long_date  = date($ld_format, $time);
    $short_date = date($sd_format, $time);

    return '<abbr title="'.$long_date.'">'.$short_date.'</abbr>';

}

April 20, 2011

St Kilda

St Kilda


April 09, 2011

Harbour Bridge

Harbour Bridge


April 09, 2011

Skyrail

Skyrail to Kuranda


March 01, 2011

Portsea

Portsea


February 24, 2011

Realisation

I realised today that I have spent more of my twenties living in Australia than I have in England. A slightly useless but fun fact I guess.


February 18, 2011

Super Meat Boy

After the disappointing experience that was Force Unleashed II, I have been playing a lot of XBLA games to tide me over until Arkham City is released (as evidenced by completing Limbo a little while ago).

Whilst hunting for a new platform style game, I came across Super Meat Boy, a nice slice of fiendishly difficult, super high paced fun. I am playing through it at the moment, but watch the video below for an indication of the game play style.

http://www.youtube.com/watch?v=2ohjyhICYco

I would highly recommend this game to anybody with an Xbox 360/Wii/PC, even though I know for a fact that I will never complete this game...

Well, unless I grow an extra pair of fingers and start taking speed... actually that's quite the idea...


February 01, 2011

Limbo

First computer game I have bothered to complete in years.


December 29, 2010

Removing Google Analytics cruft from urls

So I have decided to be productive over the Christmas break and continue work on my super secret, somewhat stalled twitter app. So apparently I am also going to blog about it here.

Warning: nerdery ahead, no cat photos.

The Problem

Today, I have begun work on a part of the application that processes the url's posted within tweets and attempts to normalise them as much as possible. By normalising them, I mean expanding short urls, such as bit.ly links and also removing certain pieces of tracking code within the url itself. The main culprit I have come across so far has been the tracking code inserted as part of Google Analytics campaigns.

It is a very common pattern to see in urls, and looks very similar to:

?utm_source=twitter&utm_medium=social&utm_campaign=Our+vain+attempt+to+track+you

Why is this a problem?

If someone posts a link without the google tracking code and then an automated tool, such as twitterfeed or similar posts a shortened link with google tracking code inserted, I want my application to see that they both point to a single url.

The easiest way I can see to do this, is to remove the google tracking code. So I need to employ everyone's favourite hammer, regular expressions.

The Solution

I took a selection of 500 url's containing google tracking code and looked for the common factors in the urls. My first attempt at matching the tracking code involved looking at the various parameters in order and matching their possible values. The regex pattern came out like this:

/(\?)utm_source=[^\r\n]+\&utm_medium=[^\r\n]+\&utm_campaign=[^\r\n]+/

I ran a preg_replace against the 500 urls and found that it worked as expected about 95% of the time. Issues came from url's that were missing the utm_campaign parameter and url's where the parameters were in a different order to the majority of the urls.

How to solve this issue? The obvious change to the regex was to match the parameters of the tracking code individually and then the order or the lack of a parameter wouldn't affect the matching. I came up with the following regex to achieve this:

/((\?)?(\&)?utm_source=[^\&]+|(\?)?(\&)?utm_medium=[^\&]+|(\?)?(\&)?utm_campaign=[^\&]+)/

This worked a lot better and had numerous improvements. However, it seemed far too verbose and lead to me discovering a fourth parameter in google tracking code, utm_content.

Refactoring

Hmmmm, should I get even more verbose or can I refactor? Refactoring is always my preferred answer.

I find that when I need to refactor code, the best starting point is always to look at what you are trying to do again and work out if you understand the problem as well as you could. In this case, the problem I started with was that I had a specific list of parameters, in a specific order that I wanted to get rid of from a url.

I had already worked out that they cannot be in order and now I was looking for each parameter individually and each parameter begins with "utm_"...

There we go, we have the catalyst for refactoring, lets adjust the regex to match any parameter that begins with "utm_"

The Finished Solution?

Adjusting the regex to match any parameter starting with utm_ was just a case of replacing the name part of the parameter with a pattern to match repeating lowercase letters and removing the redundant parts of the rest of the pattern.

/(\?|\&)?utm_[a-z]+=[^\&]+/

I tested this against the 500 urls and it worked 100% of the time.

Bingo, a short and concise regular expression to strip out Google Analytics tracking code from urls.

See it in use here.

A Disclaimer...

This was tested with PHP's preg_replace function, mileage in other environments will vary.

You can see how it is used here.

I am terrible at regular expressions compared to some. I welcome all and any suggestions or feedback via the comments or via email.


June 25, 2010

Sydney Harbour

Sydney Harbour


June 25, 2010

Relaxing

Max just chilling.

I know I keep posting this elsewhere, but it makes me laugh every time I see it.


April 26, 2010

Portarlington

Portarlington


February 28, 2010

Bowlarama.

I spent last weekend in Bondi for the annual Bowlarama competition. It was a blast and I managed to do a write up for Caught in the Crossfire. You can read it here.

I also met Steve Caballero and Lance Mountain.

Photos by Sam Barker.


January 31, 2010

Let me help!

Kitteh wants moleskine


January 25, 2010

Abyss

CNV00026


January 24, 2010

Pigeon

Pigeon


January 08, 2010

Thorn

http://www.youtube.com/watch?v=DYp2LGKOF_M

(Testing Wordpress's oEmbed support...)


January 06, 2010

Venus Bay

DSC00833.JPG

Great way to spend Xmas and New Year.


January 06, 2010

New Rig

Sometimes you have to buy your own christmas presents...

New Rig

  • Anti Hero, Andrew Allen 8
  • Thunder 147 mid's (Switched from Indy 139 hi's, the change in geometry completely changes how I manual it seems)
  • Red's
  • Girl 52mm wheels