Malleable Musings

September 12, 2010

Leicester West

Filed under: simple hacks — Tags: — Brendan @ 9:08 pm

Someone mentioned to me that they had been asked how many applicants and students originally came from the Leicester West constituency.

Whilst our student record system holds all manner of data it naturally enough doesn’t record an applicant’s parliamentary constituency. Therefore I spent a bit of time investigating the data this weekend and downloaded some data and re-combined it into a lookup database.

The files I took were the National Statistics Postcode Database (NSPD) Open, August 2010 edition
and the Westminster Parliamentary Constituencies file.

This then allowed me to produce a simple database that told me that 2,156 LE postcodes from the NSPD map to the Leicester West constituency.

It’s the first time I’ve looked at any of the OS/ONS data and it’s not obvious which field is which as I haven’t been able to find a key to the data. I’m also not sure that all of the postcodes listed are still valid.

However I think I’ve recognised the key fields that I’m interested in. In addition to the Westminister Constituencies these are the Easting and Northing of each postcode as this will enable me to calculate (using Pythagoras) as the crow flies distance to the University from applicant’s home postcodes.


July 28, 2010

A digression

Filed under: PHP, RSS Feeds, simple hacks, Wordpress — Brendan @ 11:39 pm

I was invited in to a meeting at work a couple of weeks ago in which we were talking about blogging. After the meeting Stu threw a document up on Digress.It.

The document got a few mentions around the place and soon it started gathering a few comments (60 at the time of writing).

Digress.It is a really interesting platform however I think something went wrong with the comments.

I got a call of frustration from a member of the Marketing and Comms team earlier this week, who had been away on annual leave. She was amazed at how many really useful comments there had been. She’d seen some of them but wasn’t sure that she’d read them all of them and she certainly couldn’t do what she wanted which was to print off all of the comments alongside the original document.

I said I’d help and started by working out which RSS feeds were actually functioning (the comments by authors and the comments by numbered paragraph both seemed OK but the later certainly wasn’t displaying properly on Digress.It).

I realised early on that I was never going to manage to script a whole solution and it took a little while, until tonight, when I managed to clear enough time to complete this little digression. So I settled for a quick hack of an existing PHP script with some manual intervention.

What I did was to re-create the document in a Google Spreadsheet alongside the paragraph numbers (which are the keys for the RSS feeds of paragraph comments) and hacked the PHP script to include a request parameter. I also changed the end output slightly so it allowed me to pull down the comments and place them in to the cell next to the original text.

I know there must be a more elegant way of doing this but the document wasn’t that long whilst my time was short and my CSS and PHP skills and knowledge of ASCII/ANSI characters and regular expressions are all a little rusty.

From the spreadsheet it was a simple matter to copy and paste columns C&D in to a table in Word, run a couple of find and replaces, add some minor formatting and hey presto we have something more readable.

It was a nice little refresher for me as I’ve a feeling that I’m going to need to get reacquainted with regular expressions over the coming weeks.

March 27, 2010

So how many is that. Where, what and who…

Filed under: Data Visualisations, simple hacks — Brendan @ 12:03 am

I often have fairly complex sets of data that I need people to understand.  Often what I need to represent is geographical market information, i.e. country related data.

The sort of common questions I get include things like who and where are our students, how are courses growing in certain markets etc.

I’ve found that this sort of data is often best represented in some graphical format.

So I’m always interested  when I see a new way of laying the data in new ways that can be easily understood.  The latest I’ve discovered is producing kml output that uses the Google Chart api and opens in Google Earth to produce images like this.

It’s a shame that the kml doesn’t quite work the same way in Google Maps as it does in Google Earth.  Maps is more accessible in that it doesn’t require a plugin to work on the web. However the pie charts are icons and in Google Maps the icons are apparently automatically scaled to 32×32 pixels.

Because of wordpress limitations I can’t easily show the Google Earth version above and have opted for a screenshot instead. Although if you have Google Earth installed you just use the spreadsheet to produce a kml file and simply open it to get the full effect.

To enable me to generate these sort of images quickly I’ve made a spreadsheet in to which I can quickly enter data and then when I flip to the KML tab I can just copy and paste the text that’s produced into notepad.

Then it’s just a simple case of saving the file and double clicking on it in to open it up in Google Earth.

What I love about this method is how flexible it is.  I may well alter the spreadsheet so the output can be customised more easily.  e.g. at the moment on the settings tab I just allow the name, description and something that helps manage the scale of the charts to be customised.  I could easily see how I could customise the chart further (e.g. include the dataset labels, choosing colours, choosing the type of chart etc) or maybe even customising the numbers of data series used.

April 25, 2009 and the iPhone – Part 3 (Twitterfon)

Filed under:, iphone, PHP, simple hacks — Tags: , , — Brendan @ 10:04 pm

Twitterfon is definitely my favourite Twitter client for the iPhone.  Although I still haven’t tried Tweetie but according to this post there really isn’t much in it.  So I was excited earlier this evening to discover the bookmarklet on the Naan Studio website (hadn’t realised that they also produced the excellent Twitterfox add-in for Firefox as well).

On using the bookmark I noticed whilst it posts shortish URL’s in full for long URL’s it uses the shortener.  I’ve nothing against tinyurl, in fact many years ago I used to use them extensively when sending bulk email however today there are much better URL shortners to choose from.  So I hacked together a little PHP script to create private (N.B. you’ll need to add your API key in the place indicated).

$url = $_GET['url'];
$title = $_GET['title'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "
              key=[API key goes here]&appid=BFphpscript&url=".urlencode($url)."&title=".urlencode($title));
$output = curl_exec($ch);
header("location: twitterfon:///post?".$output);

You’d then need to call it in the usual way – i.e. via a bookmark of

javascript:(function(){'[location of php script]?url='

I’m hoping that eventually I’ll figure out a better final line of the php script, i.e. something that can transfer more than just the URL over to Twitter, unfortunately there’s very little documentation for Twitterfon, the only thing I found other than on the Naan website was this piece from someone who had a similar idea of using a php script a couple of weeks ago.

March 25, 2009

Php files and the iphone

Filed under: iphone, PHP, simple hacks — Brendan @ 7:07 am

I’m beginning to think that php files offer an unrivalled way of doing things quickly with the iPhone.

Simply save the file and add the link to the file as a bookmark in Safari.

My most recent effort is a quickly hacked together page which updates my location on Twitter. I simply call the page and my location is updated, a process that otherwise I find quite convoluted (it’s the one missing feature from Twitterfon, although Twitterfon does allow lat/long coordinate updates).

Generally I am in one of three places, at home in Cov, in London at work or in between on the train. So I have four php files (all based on twitter.lib.php file from php classes) bookmarked in Safari, one for each of the three common locations and one for if I am elsewhere (this script has a text input box rather than the location value hard coded).