Archive for the ‘code’ Category

Counting my key presses

Friday, June 3rd, 2011

Overview

Counting and visualising which keyboard keys I press the most often

keypress distribution

Background

the left Ctrl buttonI noticed something yesterday.

The lettering on my left Ctrl button is a lot more faded than the lettering on my right Ctrl button.

I must press the left Ctrl button more often than I do the right one.

That got me looking at the rest of the keys on the keyboard. Some of them are faded, too. Some a little, some a lot.

the right Ctrl buttonI must press some of those keys more than I do others.

I’ve played hangman, so I know that there are some letters that occur more frequently in English words than others. So I could have just said that those are the keys I probably use the most and left it at that.

But… I don’t spend that much time writing documents or large chunks of English.

I’m a code monkey. I’m not sure that distribution would necessarily apply to me.

For example, I probably use the semi-colon key quite a lot – at the end of every line when writing in some languages. That wouldn’t be true for people writing English.

So I wondered how much I use each keyboard key in comparison to each other.

Being an obsessive compulsive geek, I couldn’t leave that as an idle wondering. I had to find out. I had to go and get the data.

(more…)

Where did I meet you?

Tuesday, May 31st, 2011

a vcard importer for AndroidOverview

A bit of Android code to add comments to contacts imported from vCards to remind you how you know the person behind the vCard.

Background

Remember poken? (Actually, “remember” isn’t fair, because they’re still around. I’ve just not seen them in an age.)

If you don’t, they were key-fob-sized gadgets. When you met someone, you tapped your poken against theirs, and it would handle exchanging contact details. They were a geeky way to exchange business cards.

They suffered from a bootstrap problem, in that, finding anyone else with a poken to tap against often proved a challenge. But I digress…

What I loved about them was that it didn’t only store the contact details, but details about when you met.

(more…)

Your Google Latitude history as a heatmap

Sunday, May 8th, 2011

Overview

I made a web tool that draws a heatmap to show where you’ve been if you upload your history file from Google Latitude.

What I made

See a heatmap of where I’ve spent the most time at heatmapforlatitude.appspot.com.

If you like it, you can upload a Latitude history file and make a heatmap of your own.

(more…)

Fighting with WebSockets

Monday, April 18th, 2011

Overview

A long, rambly and very geeky post without a proper ending about some of the challenges I recently had getting WebSockets to work with mobile Safari on the iPhone/iPad.

Background

I wrote last week about a recent project of mine – a proof-of-concept using a custom WebSockets server implementation to push messages to web apps.

A target platform for one of the demos that I wrote to go with this was the iPhone. But it wasn’t as straightforward as I’d hoped. And I’ve ranted enough about it to friends and colleagues and on twitter. About time that I did a bit of moaning here 😉

(more…)

MQTT over WebSockets

Sunday, April 10th, 2011

Overview

Extending WebSphere MQ to include support for WebSockets, allowing messaging to web browsers, including mobile browsers, without any additional client software

Background

I’ve talked about MQTT before – a lightweight messaging protocol that I’ve used both on personal projects and my day job.

From mqtt.org:

It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.

I’ve used it in CurrentCost projects, mobile apps and with small and embedded computers like my Slug.

But in all cases, I’ve needed MQTT client software to talk to the messaging server. Whether writing in C, C#, Java or Python, I’ve needed a client library to get me started, something that knows the sequence of packets that make up the MQTT protocol.

It’d be useful to have a zero-install MQTT client: an MQTT client app delivered over the web, without the user needing to install any additional client libraries, or resort to Java applets.

What this does

One possible way to do this could be WebSockets. Part of HTML5, this is a protocol that describes how to do two-way messaging between web servers and web browsers. And I mean proper two-way communication, including push-notification from the server to the browser, without resorting to hacks or kludges like long polling or hidden iframes.

It’s an emerging protocol, still in draft form, but there are a few implementations around so there are already a few browsers that know how to manage WebSockets.

We’ve been exploring recently how this could work with MQTT – the aim was to build in support for WebSockets into an MQTT messaging server: IBM WebSphere MQ (WMQ).

I’ve mentioned WebSphere MQ before, as back in the dim-and-distant past (well, five or six years ago) I used to be a developer of it.

It’s one of the server implementations that support the MQTT protocol.

By adding support for WebSockets to it, it means that WMQ could send and receive messages to web browsers. It means a web app could be a fully-fledged MQTT client.

(more…)

Using MQTT in Android mobile applications

Tuesday, February 1st, 2011

Overview

How to receive push notifications using MQTT in an Android mobile application

Background

I’ve written before about MQTT as a technology for doing push notifications to mobile. When I wrote that, I gave an example Android project. However, it was the first time I’d ever done Android development, and while it was an okay Java MQTT sample, it was a poor Android sample – I didn’t know anything about how Android works as a platform.

I’ve since written other Android MQTT apps, such as a hackday app for pushing updates from websites to your phone and learnt a lot about how to do it properly. Well… if not properly, at least a little better.

But Google is still directing people to my old, and probably unhelpful, sample. So it’s about time that I share something more useful.

I’ve put the full source for a sample implementation below. (Note that I’m using the Java J2EE client library from ibm.com). Hopefully the comments in it are clear enough, but here are a few of the key points.

(more…)

An API for twitter hashtags for TV programmes

Friday, December 31st, 2010

Overview
Hacking together an API that returns commonly-used hashtags for the programme you’re watching on the TV

Background
tweets on TVLast April, I wrote a quick-and-dirty Python script that displays tweets for a given hashtag on my TV screen so that I could follow the twitter backchannel about a programme that I watched.

Considering that it was a random idea that was hacked together in a few minutes, I’ve used it a lot since then: it’s made watching a bunch of programmes much more entertaining – Eurovision is probably the best example (the commentary on twitter is hysterical), but there are many others.

But I never made any changes to the script since I first wrote it. If I’m watching something on TV that I know has a hashtag, I ssh to my set-top box and run my hashtags script, giving it the hashtag to filter on in the command.

I was thinking – it’d be much better if it was all automatic. It’d be better if my set-top box automatically showed tweets with the hashtag for whatever programme I’m watching.

To do this, I needed some way of knowing what was the right hashtag for the programme currently on a given TV channel. I could’ve hacked this into my existing script, but I thought it might be a feature that people might find other uses for, so instead I’ve made a stand-alone thing, available as a web-service.

What it does
I’ve made a web feed that returns a blob of either JSON or XML. You can get either:

  • the commonly-used hashtag for the programme currently on a specified channel (e.g. “what is the hashtag for the programme that’s on BBC 1 now?”)
  • the next programme on TV that has a commonly-used hashtag (e.g. “what are the next five programmes on TV that have hashtags?”)

(more…)

Programmatically identifying DVDs by their barcodes from Android

Thursday, December 30th, 2010

Overview

A few Android code snipperts for how to identify a DVD by it’s barcode

Background

In November, I wrote a simple Android app that lets me add films to my LOVEFiLM list by taking a photo of a movie poster.

It also works by taking a photo of the front of a DVD case, as the DVD covers are essentially mini-posters. But a few people pointed out that using image recognition for the front of a DVD case is overkill, when DVD cases have a machine-readable barcode printed on them.

So I spent an evening adding the ability to scan barcodes to the app – and now you can add to your LOVEFiLM list either by photos of posters or barcodes.

I thought I’d quickly share how I did it, in case it’s useful to anyone else.

(more…)