Archive for the ‘code’ Category

What programme was on BBC1 at…?

Monday, July 27th, 2009

After my absence, I thought I’d come back with something quick and fun – the result of half an hour’s playing with a new (to me) API.

The problem that I wanted to look into was: What programme was on TV on a given channel at a given time?

And how can I find this out programmatically?

The first thing that I came across was the getProgrammes service in the beta BBC Web API.

As I expect from the forward-thinking BBC, it’s pretty awesome: a simple API that gives you an XML document containing the programmes schedule for the specified time window.

The documentation on the BBC site is pretty self-explanatory. It gives all the information you need to start playing with the API – either using the form on the BBC page, or by sending it a few requests using wget.

(more…)

Improvements to TwitToday

Wednesday, June 10th, 2009

I’ve been doing too much Java at work recently, so in the interest of keeping my hand in with some low-level C++, I picked up the code for my mobile twitter client, TwitToday, again.

I originally wrote it at a hackday, but I’ve since come back to tweak it a couple of times to get it to spawn background worker threads, add SIP on-screen keyboard support, and improve support for sending special and accented characters.

After another evening of tweaking, I’ve added a few new minor features:

Transparent text box

When not in use, the text box is now transparent. When it has focus, it is coloured in white as usual.

A few people commented that a bright white text box could dominate a dark Today screen too much, so this is hopefully a nice aesthetic improvement.

I did this by creating a custom windows procedure for the text box.

The windows procedure needed to handle a couple of events:

Handling WM_PAINT by using SetBkMode to make the text box TRANSPARENT

Handling WM_ERASEBKGND by using TODAYM_DRAWWATERMARK to draw the background over the text control’s rectangle.

(more…)

How to customise the NavigationToolbar2 toolbar in matplotlib

Saturday, June 6th, 2009

My CurrentCost desktop software is written in Python, and uses the matplotlib library for plotting graphs.

I am a big fan of matplotlib – you can create some very cool graphs with it. It’s not without it’s issues… for example, I’ve still yet to work out how to do realtime graphing with it that isn’t massively inefficient and resource intensive. But that’s for another post 🙂

One of the nice things that you get with it is a toolbar that lets the user switch between different modes that the mouse supports – zooming, panning, and so on.

Adding the toolbar is straightforward – I create an object of the class NavigationToolbar2Wx and add it to a sizer which in turn I add to the graph Plot.

self.toolbar = Toolbar(self.canvas)
self.toolbar.Realize()
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas, 1, wx.EXPAND)
sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
self.SetSizer(sizer)

The NavigationToolbar2 toolbar provides a number of features but it doesn’t exactly meet my needs so last night I had a go at customising it.

I wanted to:

  • remove the configure subplots button – as I don’t use subplots in my graphs
  • add a couple of new buttons – for different navigation abilities

I couldn’t find this documented clearly anywhere, so thought it was worth sharing the code that I came up with.

(more…)

Fire Eagle Guest Pass

Sunday, May 10th, 2009

Imagine you are in a town or city. Perhaps one which you are unfamiliar with.

You’ve arranged to meet someone, and want to help them find you.

They’re not a close friend or family member, so you don’t want to sign up with something like Google Latitude which feels like quite a long-term thing for people who want to always be able to see where you are.

You don’t want to have to ask them to sign up for some new service like Fire Eagle just to find you.

Maybe they’re a client coming to meet you for a meeting. You want to help them find you, but you’re not sure that you want them to be able to see where you go after the meeting, or what pub you go to that evening.

This is the sort of thing that “Fire Eagle Guest Pass” – my hack entry for Open Hack London 2009 – was written for.

I’ve put together a few pictures to explain what it does on slideshare. They’re not exactly fine art, but hopefully they explain the idea 🙂

(more…)

Pretty CurrentCost graphing from Pachube

Tuesday, April 28th, 2009

Last Saturday was the second HomeCamp. This week has been very busy at work, so I’ve not had the chance to pull together a proper post about it yet, but in the meantime I thought I’d share a little Pachube tip that Usman demonstrated at the event.

I’ve been putting the live readings from my CurrentCost meter into Pachube as an input feed for several months now, but not really had much use for it, other than as an easy way to check my CurrentCost data from my mobile.

Usman showed us an app that lets you get a neat Google chart visualisation of a Pachube feed in just a few clicks:

It’s very simple – go to apps.pachube.com/google_viz, give it the ID of your pachube feed, and it generates the short snippet of code necessary to create the Google chart.

It takes no time at all, and really shows the power of being able to easily pipe together different stuff through pachube.

Presenting with the Twitter backchannel

Friday, April 3rd, 2009

I went to Bath for openMIC this week (part conference, part barcamp – a brilliant and informative day on innovation in mobile).

The first half was made up of traditional conference-style presentations, and during one of these presentations, I noticed tweets with the #openMIC hashtag become particularly active: feedback that the presenter was missing.

I wondered about ways that the presenter could have got that feedback before finishing his talk…

thinking about fun ways presenters can get realtime audience feedback via twitter. PowerPoint VB script to embed hashtag search in slides?

This isn’t a new idea: I’ve heard of large US tech conferences where the backchannel is displayed on a second screen or projector next to the presenter’s slides. But I rarely get the chance to present where there is the facility for projecting to two screens at once.

So I got thinking about how a compromise could work: embedding a live twitter search somewhere within a presentation.

I had a bit of free time this afternoon to play with the idea a little more. As is sadly often my way, my first few ideas were needlessly overcomplicated: using macros, VBScript or something like that to try and get data from the web and embed it within my slides.

Fiddly. And prone to a number of fundamental issues, such as trying to avoid reloading the twitter search every time you change slide.

But then I had a flash of what, for want of a better word, I shall call ‘genius’. 😉

Instead of fighting to embed a website within a presentation, what about embedding a presentation within a webpage?

A little bit of playing around with code, and I managed to pull a quick proof-of-concept together.

(more…)

ScriptFu – scripting with Gimp

Wednesday, April 1st, 2009

I wrote on Sunday about my first attempt to use Gimp to script some image manipulation stuff I wanted to do – specifically, combining multiple images into a single, multi-layered image.

A few people have asked me for more info about how to do this, so I thought I’d share my script here. Gimp is an open-source image editor, but it also comes with a batch mode where you can run it’s functions from a script. The scripting language for Gimp is called ScriptFu, and is a Lisp-type language. I’ve not done anything in Lisp since learning Scheme at University… so it felt a little odd at first.

This was my first attempt at writing in ScriptFu, so it’s worth pointing that I’m not an expert, and what I’ve written might not be elegant or the “right” way to do it. But I did manage to get something working in a few hours of playing with it.

To start with, a few tips from how I got started:

The doc – The documentation on scripting at docs.gimp.org is fantastic, and got me off to a quick start. It includes enough snippets and samples that I could see the sort of thing I’d need to do.

Gimp’s PDB – If you launch Gimp, go to Help -> Procedure Browser. It starts up a very neat searchable API doc for all of the Gimp functions. Even when I didn’t know the name of functions I needed, typing a quick guess (e.g. “layer”) into here would show me a few sensibly-named options, and show me the full API info for them all.

Photobucket

(more…)

Creating multi-layered screenshots (a BarCamp London hack)

Sunday, March 29th, 2009

I’m on a slow (gah, engineering works!) train back from an awesome BarCampLondon. I’ve got a ton of notes from so many fascinating talks and sessions, but not quite sure how to share them… they would make for the world’s longest blog post!

But as I have a little time to kill, I thought I’d quickly share a little hack that I pulled together overnight. An old idea, but a fun one – and it’s amazing what beer and interesting people will do for your creativity. 🙂

The hack is a little Windows utility to capture more useful screenshots.

By way of background, when you press the “Print Screen” button, it copies an image of your desktop to the clipboard. Very useful. But it has limitations.

What if a window you want to see in the screenshot image is obscured by another window? Or minimised entirely? That information is lost.

Not with my hack! 🙂

My tool captures “interactive” multi-layered screenshots – a picture of each window is captured separately on it’s own layer. This creates a screenshot that (even after you’ve taken the screenshot) will let you move windows around, hide/restore windows, and change the z-order of windows.

It creates a sort of simulation-like snapshot of what your desktop was like at the time.

(more…)