Archive for the ‘code’ Category

Posting to IBM Connections from WP7

Friday, February 24th, 2012

IBM Connections is something we use at work: an internal, intranet-hosted social network for work stuff.

I use stuff like the wikis, file sharing, and bookmarks, quite a lot. But I don’t make status updates as often as I could.

I wonder if that’s because I couldn’t do it from my phone? I know that I certainly started using Facebook a lot more since getting a phone with support for posting to facebook and twitter built-in.

So I set up a way for me to post to Connections from my phone with just one tap on the home screen.

Well, one tap, plus all the taps to actually type the status message… plus another tap on the Send button. But you get the idea.

(more…)

Generating a list of REST APIs in JAX-RS

Saturday, January 14th, 2012

Overview

Using Java Reflection to generate a list of REST endpoints defined in JAX-RS code

Background – JAX-RS

I’ve been working on a project that uses JAX-RS – the Java API for RESTful web services. If you don’t know JAX-RS, you write web services in Java using annotations to specify what REST endpoint a Java method implements.

For example, you can use @Path annotations on a class to define the root URI for methods in the class, and then use annotations like @GET, @Produces(MediaType.APPLICATION_JSON) and @Path on the individual class methods to define the endpoints that they implement.

The problem?

Reading from code to the web service is straightforward enough. By which I mean, if I’m looking at a Java method, it’s easy enough to look at it and know what endpoint it is implementing.

Going the other way can be a little trickier.

Once a project gets bigger, you can have REST endpoints spread around a large number of classes. And methods can inherit attributes from other classes than the one they’re in, through annotations like @Parent.

What if I’m using one of the project’s REST APIs, and want to look at the source for the method that’s handling it, whether to extend it or fix a bug? How can I remember which method in which class is responsible for the REST endpoint I’m using?

Using Reflection

Documentation is one way. As I develop the code, maintain a list of the mapping of Java methods to web services endpoints. And keep that up-to-date as I make any changes to the code.

But that’s very manual, and doesn’t seem very smart.

This got me thinking yesterday evening. I’d not used Java Reflection before, but thought it must be possible to work it out from the Java annotations in the same way that my JAX-RS provider must.

So I spent a bit of time trying it out and thought it might be useful to share what I came up with. It’s not terribly elegant or efficient. It’s the result of a few hours tinkering. But it shows the basic idea, and that seems useful enough to warrant sharing.

(more…)

My first experience using BlueVia APIs

Sunday, October 2nd, 2011

I wrote yesterday about a quick hack I did at Over The Air using the BlueVia API. I thought it was worth a quick post to show just how simple it was.

Read yesterday’s post for background to the idea behind the hack, but in essence, what I wanted was:

  • monitor the location of my mobile phone
  • send an SMS to a different mobile number when my phone goes into a predefined known area

BlueVia provides an API that let me doing this using network operator data. In other words, nothing needs to run on my phone itself as location data is obtained from where O2 thinks my phone is.

This means there is no battery-life impact on the phone for this monitoring.

It also means this will work with any phone – from iPhones and Androids to cheap feature phones.

The whole thing took me less than an hour and needed only 90 lines of Python.

This is how I did it.

(more…)

Over The Air 2011

Saturday, October 1st, 2011

I’m back from Over The Air 2011 – a mobile tech conference with an overnight hack-a-thon challenge.

This was the fourth year I’ve been to OTA, and I normally submit some random hack.

In fact, this is the first time I didn’t stay up all night, in a 15-hour non-stop coding splurge writing a massive, over-ambitious beast of a mobile app. I must be getting old… this time I wrote a couple of quick hacks, each of which under a couple of hundred lines long, and had eight hours sleep instead. Much more civilised.

This is what I managed to come up with:

hack 1: a crap husband helper

photo of a hack

Sometimes I stop at the shop on the way home from work because I want something. Invariably, I don’t think to check with Amy if we need anything. I get home with a shopping bag, and get something along the lines of “Why didn’t you tell me you were going to the shops? We need nappies.” At which point, I feel like I should dutifully volunteer to go back out to the shop.

Going to a talk on the BlueVia API gave me an idea.

I wrote a bit of Python to run on my home server, that will keep an eye on where my phone is using the BlueVia Location API.

If I go near the shops, it will send a message to my wife using the BlueVia Send SMS API, to say “I’m near <insert shop name here>, do you need me to get you anything?”.

90 lines of Python is all it takes to make me look like a thoughtful and considerate husband. Huzzah.

(more…)

Making a birthday e-card

Saturday, September 24th, 2011

Today is Amy’s birthday – which means that I’ve been helping the kids with present making.

Grace’s idea for a homemade birthday card was particularly geeky, so I thought it was worth a quick post.

The idea was that she’d design an e-card, and record a variety of voice clips, which would be played when you clicked on various bits of the card. She did after-school French lessons last term, and she hears some Greek from my mum, so she’s kind of interested in the idea of other languages. So we came up with the idea of a card with a Happy Birthday message in lots of different languages.

It turned out that my multi-lingual efforts to assist her were a bit lame, so I convinced her to scale it down from “Happy Birthday” in dozens of languages to “I love you” in nine langauges. We settled on a design with a bunch of flags – clicking on a flag plays Grace’s voice saying “I love you” in that language.

It looked like this, but click through here for the live version.

flagscard

It was pretty simple, but I thought I’d share a few comments about how we did it.

(more…)

Annotating photos with tweets

Sunday, September 11th, 2011

I have a lot of digital photos.

An insane amount – something like 40,000 photos that go back over a dozen years since I first got a digital camera at University.

I store them based on the date that they were taken, using a folder structure like this:

screenshot of folder structure where I store photos

For a while, I used to drop a readme.txt text file into some of the folders saying where the photos were taken or what I was doing. This was partly so that when I look at the photos ten years later I’ve got something to remind me what is going on, but mainly to make it possible for me to search for photos of something when I can’t remember the date it happened.

But in recent years, I’ve been too lazy to keep that up, and rarely ever add a readme file.

I thought that my tweets might be a good alternative. There is a reasonable chance that if I took a photo of something interesting, that I might have tweeted sometime that day about where I am or what I’m doing.

I wanted to populate each of my folders with a day’s photos in it with a tweets.txt text file containing tweets posted on that day.

(more…)

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…)