blog archive contact about feed

Rob's Blog - November 2004

Contents

Here are Rob's Blog entries for November 2004.

Blog entries for other months can be found in the main blog index.

Commercial Bluejacking

Bluejacking, the process of sending random messages to bluetooth devices, is being used commercially for the first time by clothes retailer Blue Inc at its Manchester store.

Shoppers with bluetooth enabled on their handsets will be sent text messages, animations or streaming video advertising Blue's products as they pass the shop.

The store hopes that the campaign will generate word of mouth advertising as people say how they were bluejacked.

I wonder if this falls foul of regulations on unsolicited email? I know that personally I'd be pissed off getting random commercial messages like this, though I do like the idea of using it for person to person communication. If this idea takes off, it would be one of most invasive methods used in marketing since the invention of spam. We've long since lost control of our email inboxes to marketing and spam, I'd hate to loose my phone as well.

Entered: 2004-11-30 21:37:03

Caribe Bluetooth Virus

install caribe.sis? A few people in the office are infected with the Caribe / Cabir virus on their Nokia series 60 phones.

This virus is really a worm, and once installed continuously tries to send itself to any bluetooth device in range. Because of the constant bluetooth use, it really shortens the battery life of the infected phone. It also means bluetooth enabled phones in the area are constantly being spammed with messages requesting it be installed.

There is a removal tool however, and it's available free from the nice people at F-Secure. Download the free caribe removal tool from F-Secure and follow the simple on screen instructions to clean the infected device.

Those interested in the technical details of the virus should read the Cabir virus bulletin.

Entered: 2004-11-30 11:56:38

Bye Nan

My Nan died a few hours ago :-(

This lovely lady is now at peace.

PERMALINK - Bye Nan
Entered: 2004-11-23 10:23:39

The Current UK Population In JavaScript

One interesting webpage going round the office yesterday were the UK Population Statistics.

Looking at the figures for 2002-2003 we saw the total UK population grow from 59,321,700 people to 59,553,800 people.

That means the population grows by approximately 1 person every 2 and a half minutes.

I've knocked together a quick JavaScript that can calculate the approximate population of the UK assuming this increase is constant.

We work out the per minute increase in population. We also know the starting population of the UK on the 1st January 2003, all we have to do is work out how minutes have elapsed between then and now, and multiply that by the population growth per minute.

var startDate = new Date("January 1, 2003 00:00:00"); var perMinuteIncrease = 232100 / (365 * 24 * 60); var startPop = 59553800; // return the estimated current population of the UK. function currentPopulation() { var currentDate = new Date(); var diffMinutes = Math.floor((currentDate.getTime() - startDate.getTime()) / 60000); return Math.round(startPop + (diffMinutes * perMinuteIncrease)); }

To get the current population you just call the currentPopulation() function.

Let's see what the approximate current UK population is now according to this script...

Just reload/refresh the page to get an updated population count.

Entered: 2004-11-11 10:01:16
Modified: 2004-11-11 10:05:54

5th November Fireworks In Colchester

Here are a few of my photographs of the 5th November 2004 firework display at Colchester's Castle Park.

Unfortunately my pictures of the two Daleks blasting fireworks at each other while the Dr Who theme tune played didn't come out.

Castle Park fireworks - photo 1

Castle Park fireworks - photo 2

Castle Park fireworks - photo 3

Castle Park fireworks - photo 4

Entered: 2004-11-10 09:32:52

J2ME SHA-1 Implementation

I've been doing quite a bit of J2ME programming recently.

I needed a SHA-1 hash for a project I was working on and I came across Sam Ruby's Base64 SHA-1 for J2ME.

It's very simple to use, just drop it into your app's directory when using the Java Wireless Toolkit. It is called using the following code...

String myHash = SHA1.encode(myString);

So thanks to Sam, Russell Beattie and Paul Johnson for the good work on this.

Entered: 2004-11-10 09:04:08

Querying RDF In Perl With RDFStore

Apart from RDF::Core and Redland, another option for parsing and querying RDF in Perl is RDFStore. This also provides the Perl RDQL::Parser module used by the very useful DBD::RDFStore driver.

Following on from the previous examples showing how to extract information from my FOAF file using RDF::Core (Query RDF In Perl With RDF::Core) and RDF::Redland (Querying RDF In Perl With RDF::Redland), here I'll re-implement the query using RDFStore.

As a quick recap from the previous articles, here is the bit of RDF we want to extract information from.

<foaf:knows> <foaf:Person> <foaf:nick>Cal</foaf:nick> <foaf:name>Cal Henderson</foaf:name> <foaf:mbox_sha1sum>2971b1c2fd1d4f0e8f99c167cd85d522a614b07b</foaf:mbox_sha1sum> <rdfs:seeAlso rdf:resource="http://www.iamcal.com/foaf.xml"/> </foaf:Person> </foaf:knows>

The solution used to extract the data from the RDF looks a lot more Perl-like than the previous examples we have seen.

If you have ever queried databases using SQL in Perl, then you have certainly come across the powerful DBI module. This abstracts the common database usage making it possible to very easily port your applications between various databases. One of the best things about using RDFStore is that it provides a DBD driver allowing you to use standard DBI methods when querying your RDF data. Unlike other modules that make you create triple stores and factory methods, RDFStore lets that be hidden from you.

To start with we'll need to create a database handle using DBI and the DBD::RDFStore modules and store it in the variable $dbh.

my $dbh = DBI->connect("DBI:RDFStore:");

This creates a database on the fly, but we can connect to an existing database on a local or remote server if we so wished.

Now we need to create our RDQL query. It looks very similar to the query we used in the Redland example.

my $query = $dbh->prepare(<<QUERY); SELECT ?name ?nick ?seeAlso ?mbox_sha1sum FROM <file:foaf.rdf> WHERE (?x <rdf:type> <foaf:Person>), (?x <foaf:name> ?name) (?x <foaf:nick> ?nick) (?x <rdfs:seeAlso> ?seeAlso) (?x <foaf:mbox_sha1sum> ?mbox_sha1sum) AND (?nick eq 'Cal') USING foaf for <http://xmlns.com/foaf/0.1/>, QUERY

Here we're selecting the values the name, nick, seeAlso and mbox_sha1sum triples for a Person with the nick of Cal. We've explicitly set where our triples come from using the FROM clause. In this case, it's the file foaf.rdf, which contains my FOAF information.

We have the query in the variable $query, so lets execute it.

$query->execute();

We can use standard DBI methods to fetch the data from our query. Here I'm going to create some bound variables to keep any matching data in.

my ($name, $seeAlso, $mbox_sha1sum, $nick); $query->bind_columns(\$name, \$nick, \$seeAlso, \$mbox_sha1sum);

Now we just have to fetch each row that matches our query and print them out.

while ($query->fetch()) { print $name->toString, "\n"; print $nick->toString, "\n"; print $seeAlso->toString, "\n"; print $mbox_sha1sum->toString, "\n"; }

The values returned are either RDFStore::Literal or RDFStore::Resource objects, so we have to use their toString methods to print them.

To tidy up, we'll finish our query and disconnect from our database.

$query->finish; $dbh->disconnect;

That's it! It really is as simple as that.

Let's put this all together now to produce our final example code listing.

#!/usr/bin/perl -w ## An example showing how to use RDFStore and RDQL::Parser to ## extract information from a FOAF file. ## Copyright 2004 - Robert Price - http://www.robertprice.co.uk/ use strict; use DBI; ## create a DBI connection to our NodeFactory. my $dbh = DBI->connect("DBI:RDFStore:"); ## prepare our query. my $query = $dbh->prepare(<<QUERY); SELECT ?name ?nick ?seeAlso ?mbox_sha1sum FROM <file:foaf.rdf> WHERE (?x <rdf:type> <foaf:Person>), (?x <foaf:name> ?name) (?x <foaf:nick> ?nick) (?x <rdfs:seeAlso> ?seeAlso) (?x <foaf:mbox_sha1sum> ?mbox_sha1sum) AND (?nick eq 'Cal') USING foaf for <http://xmlns.com/foaf/0.1/>, QUERY ## execute the query. $query->execute(); ## define some holding variables and bind them to our query results. my ($name, $seeAlso, $mbox_sha1sum, $nick); $query->bind_columns(\$name, \$nick, \$seeAlso, \$mbox_sha1sum); ## while we have results being returned... while ($query->fetch()) { ## print out the values. ## As these can be RDFStore::Literal or RDFStore::Resource's we ## need to use the toString method of these objects to print. print $name->toString, "\n"; print $nick->toString, "\n"; print $seeAlso->toString, "\n"; print $mbox_sha1sum->toString, "\n"; } ## end the query and disconnect. $query->finish; $dbh->disconnect;

In conclusion, RDFStore provides a very clean and Perlish interface to querying RDF data. The code implements a DBD module allowing standard DBI methods to be used, making it quick and simple for Perl developers to learn and use effectively.

Entered: 2004-11-05 08:50:58

Ensuring IE Shows Your Error Pages

Sometimes it doesn't pay to be efficient with your page size.

One example of this was when we needed to put up some custom error pages for the websites at work.

We were using Apache's ErrorDocument to return nice 404 and 500 HTTP error pages. However Microsoft Internet Explorer refused to show them, preferring to use it's own pages instead of ours.

It turns out that IE will ignore error pages with a size of less than 512 bytes and use it's own. So the solution is to make sure your error pages are 513 bytes or more in size.

This is detailed in Microsoft Knowledge Base item Q234807.

Entered: 2004-11-04 11:17:17