Today is Leap Day, the 29th of February. Reading this article on The Register earlier and in particular the comments, it looks like the logic behind calculating whether a year is a Leap Year is still fuzzy for some. This is an essential calculation to get right in any software that deals with dates (that is, most of them), so here are all the gory details.
Friday, 29 February 2008
Tuesday, 19 February 2008
The Dangers of Alcohol
I am in Chesterfield tonight, for work. I just had dinner with colleagues and came back to my hotel, picked up the key from reception and started walking back towards my room. On the way there, I met a couple who had had a few too many drinks. They were so pickled with booze that they first needed a few minutes to identify which room was theirs. Then they realised that inserting the key into the lock was way too challenging so they asked me for help. I obliged and the lady managed to spittle a drunken thank you. I have the feeling that tomorrow morning will be a difficult time for them both.
Monday, 11 February 2008
Vodafone Handset Warranty: The Plot Thickens
I posted a rant about Vodafone a few months ago and followed it up yesterday with an update. Someone called Edward Peter, who apparently works for Vodafone UK, commented on the update in a way that confuses matters further.
Let's recap: I had an 18 month Vodafone contract that came with a free handset, namely a Nokia 6234. Said handset started mis-behaving 15 months into the contract. When I contacted Vodafone support at the time, I was told that because the warranty of the handset was 12 months and that I wasn't due an upgrade before another 3 months, they couldn't replace the handset. This incident convinced me to leave Vodafone, which I did when my contract expired. I then got a phone call from a customer relationship manager who, when I explained why I was leaving, said that the support people had not advised me correctly and that all handsets had a 2 year warranty. The comment left on yesterday's entry states: If you get a handset directly from Vodafone its warranty matches the length of conttract you're on; 12 months for 12 months, 18 for 18 and so on
. So this leaves us with 3 options:
- The warranty is 12 months, irrespective of the duration of the contract, which means you are toast if you have an 18 or 24 months contract and your phone packs up after 12 months;
- The warranty is 24 months, irrespective of the duration of the contract, which means that you're covered because whatever the length of your contract, you are due for an upgrade before or at the same time as the warranty expires, that is until Vodafone start offering 36 month contracts;
- The warranty matches the length of your contract, which means you're covered as you are aligible for an upgrade as soon as the warranty expires.
The last option would be the most sensible one. The first one is a trap for customers and one of the reasons why I left Vodafone even though it seems not to have been Vodafone's policy, just a misconception from support staff.
So if someone knows the answer, please tell me and tell the support guys at Vodafone: giving correct advice may help them retain customers. In the meantime, make sure you check that the length of the warranty for your handset matches the length of your contract, whoever you take your contract with.
Sunday, 10 February 2008
Vodafone Support
Stop press: Vodafone are not evil, it's just that some of their support staff don't have a clue. Now that's a surprise!
Following my rant about Vodafone contracts and phone warranties, I did not contact the Office of Fair Trading as I said I would. However, a few weeks ago, as my Vodafone contract was about to expire, I took up a contract with 3 and made sure the phone I was getting had a warranty that extended beyond the duration of the contact. I then requested my PAC code from Vodafone to move the number over to the new contract. Of course, that triggered someone at Vodafone to call me and ask why I was leaving. I explained that they had lost me as a customer three months ago after the phone warranty incident. It appears that what I had been told originally was incorrect: all Vodafone handsets have had a 2 year warranty for quite some time so I should have been able to get my handset replaced without a problem. I was then assured that the support manager would be made aware that some of the staff were wrongly advising customers so that this would not happen again. Ah well, too little too late Vodafone.
Funnily enough, getting the PAC code and transferring the number went without a glitch after that: perfect service both from Vodafone and 3.
For tales of PAC code woos, check Coofer Cat.
Subversion on Ubuntu
The Cunning Plan
One of the planned functionality for my new silent server was to offer a Subversion repository for code and documents that I could access via WebDAV. By doing this, I would be able to save important documents on the server and benefit from version control. Version control is essential for computer code but can also be very useful for other types of documents by allowing you to have multiple versions, revert to an old version, etc. So without further ado, let's get into the nitty gritty of getting it to work on Ubuntu 7.10.
Resources
- Version Control with Subversion, the book about Subversion, which you can download for free,
- Install Subversion with Web Access on Ubuntu by the How-To Geek.
Installing the software packages
We need to install Subversion, Apache and the Subversion libraries for Apache. As this is all part of the standard Ubuntu distribution, it is extremely easy.
sudo apt-get install subversion apache2 libapache2-svn
And that's it, you have a working Subversion installation! It doesn't do very much yet so we need to create repositories for documents.
Subversion Repositories
Subversion is extremely flexible in the way it deals with files and directories. There are a number of standard repository layout that are well explained in the book. Then there's the question of whether you'd rather put everything in the same repository or split it. This is also well explained in the book. My rule of thumb is to only create multiple repositories if you need to keep things completely separate, such as having one repository per customer, or if you need different settings. In my case, I need to store code and documents, the code being accessed via an IDE that competely supports Subversion, the documents being accessed as a network folder. Both usage scenarios require different settings in Apache so this is a typical case where several repositories are a good idea. However, there is no need for splitting the code or the document repositories further. You can create your repositories where you want in the file system, I chose to create them in a specific top level directory.
$ sudo mkdir /svn $ sudo svnadmin create /svn/docs $ sudo svnadmin create /svn/dev $ sudo chown -R www-data:www-data /svn/*
The svnadmin command created a complete structure:
ls /svn/dev conf dav db format hooks locks README.txt
The last command changes ownership recursively of both repositories so that the Apache instance can read and write to them. This is essential to get WebDAV to work.
Configuring Apache
Next, we need to configure Apache so that it can provide access to both repositories over WebDAV.
$ cd /etc/apache2/mods-available $ sudo vi dav_svn.conf
In this file, I defined two Apache locations, one for each repository, with slightly different options. As this is a home installation, I don't need authentication. If you want to add authentication on top, check the How-To Geek article. The extra two options on the documents location are meant to enable network clients that don't support version control to store files. See Appendix C of the Subversion book for more details. Note that if you wanted to use several development repositories, such as one for each of your customers, you could replace the SVNPath option with SVNParentPath and point it to the parent directory.
<Location /dev> DAV svn SVNPath /svn/dev </Location> <Location /docs> DAV svn SVNPath /svn/docs SVNAutoversioning on ModMimeUsePathInfo on </Location>
The last thing to do is to restart Apache:
$ sudo /etc/init.d/apache2 restart
Subversion Clients
Now that the Subversion server is working, it's time to connect to it using client software. For development, I use Eclipse for which there is the Subclipe plugin. It all works as expected. For the documents repository, Apple OS-X has built-in support for WebDAV remote folders. Go to the finder, select the menu Go > Connect to Server and type in the folder's URL in the dialogue box that appears, in my case http://szczecin.home/docs. It's also possible to browse both repositories using a web browser, which is a good way to provide read-only access.
Conclusion
That was a very short introduction to Subversion on Ubuntu. There's a lot more than this to it, a lot of it in the Subversion book. In particular, you can add authentication and SSL to the repositories once they are available through WebDAV. There are also a lot of options as far as Subversion clients are concerned and you can find free client software for every operating system you can think of.
Saturday, 26 January 2008
Playing with KML
The Idea
When I came back from holidays, I thought about creating a map of the journey in a way that I could share with friends. So I decided to try to do that using KML, the description language used by Google Earth. Google has tutorials and reference documentation about KML that got me started. In practice, what I wanted to do was very simple: lines showing the route and location pins showing the places I had visited on the way.
Document Structure
KML is a fairly straightforward XML dialect and the basic structure is very simple:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
Content goes here
</Document>
</kml>
Route
For the route, I wanted lines that would roughly follow the route I had taken. To do this in KML is simple: add a Placemark tag containing a LineString tag that itself contains the coordinates of the different points on the line. So a simple straight line from London to Hamburg looks something like this:
<Placemark>
<name>Outward flight</name>
<LineString>
<altitudeMode>clampToGround</altitudeMode>
<coordinates> -0.1261270000000025,51.50896699999998
9.994621999999991,53.55686600000001
</coordinates>
</LineString>
</Placemark>
The name tag is not essential but this is what will show in the side bar in Google Earth so it's better to have one. The clampToGround value in the altitudeMode tag tells Google Earth that each point on the line is on the ground so you don't have to specify the altitude in the coordinates. In the coordinates tag is a space separated list of coordinates. In this case, each point is specified by a longitude and a latitude separated by a comma, the altitude being implied. Longitude is specified with positive values East of the Greenwich meridian and negative values West of it. Latitude is specified with positive values North of the equator and negative values South of it.
That's good but another thing I wanted to do was specify different colours for the different types of transport I used during my holidays. KML has the ability to define styles that you can then apply to Placemark tags. This is done by adding a number of Style tags at the beginning of the document. You then have to specify the style using a styleUrl tag. Applying this to the simple line above, we get:
<Style id="planeJourney">
<LineStyle>
<color>ff00ff00</color>
<width>4</width>
</LineStyle>
</Style>
<Placemark>
<name>Outward flight</name>
<styleUrl>#planeJourney</styleUrl>
<LineString>
<altitudeMode>clampToGround</altitudeMode>
<coordinates> -0.1261270000000025,51.50896699999998
9.994621999999991,53.55686600000001
</coordinates>
</LineString>
</Placemark>
Note that the value for the color tag in the LineStyle is the concatenation of 4 hexadecimal bytes. The first byte is the Alpha value, that is how opaque is the colour, in our case the value ff specifies it is completely opaque. The next three bytes represent the Red, Green and Blue values, in our case a simple green.
Places
For places, I wanted a simple marker that showed more information when you clicked on it. This is also very simple in KML: a Placemark tag containing a name, a description and a Point tags. The name needs to be a simple string but the description can contain a full blown HTML snippet inside a CDATA node so you can include images, links and all sorts of things. Note that the box that will pop up when you select the place mark is quite small so don't overdo it. Here is an example for London:
<Placemark>
<name>London</name>
<description><![CDATA[<p><img src="some URL" /></p>
<p><a href="some URL">More photos...</a></p>]]></description>
<Point>
<coordinates>-0.1261270000000025,51.50896699999998,0</coordinates>
</Point>
</Placemark>
Note that the coordinates here include the altitude as well as the longitude and latitude. You could also apply a style to the location place marks, in the same way as was done for the lines.
KML or KMZ
Once you've created your file, you need to save it with a .kml extension. You can then open it in Google Earth. When you're happy with it, you can also zip it and rename it with a .kmz extension: Google Earth will be able to load it as easily but the file will be smaller. Both files can also be used with Google Maps and can be shared online. So here is my complete holiday map built with KML.
Tips and Tricks
Getting the exact coordinates of a particular place can be cumbersome. To make it easy, just find the place in Google Earth, create a temporary place mark if there is none you can use, copy it with the Edit > Copy > Copy menu option and paste it in your text editor: you'll get the KML that defines the placemark, with exact coordinates.
The clampToGround option in the altitudeMode tag specifies that the points you define in the coordinates are at ground level. The line between two points will be straight, irrespective of what lays between said points. So if you have a mountain range in between, you will see your line disappear through the mountains. To correct this, you should insert intermediary points where the highest points are located. This is why on my map the flight between Izmir and Paris has intermediary points so that the line can go past the Alps without being broken.
If you want to do more complex stuff, be careful that Google Maps only supports a subset of KML. Of course, the whole shebang is supported by Google Earth.
Conclusion
KML is a nice and simple XML dialect to describe geographical data and share it online. It certainly beats writing postcards to show your friends and family where you've been and it doesn't get lost in the post.
Silent Server
A few months ago I set up a home server using an old box. Unfortunately that old box died shortly afterwards. Furthermore, it was quite noisy as it had been originally spec'ed as a high end workstation. So I went in search of a replacement, with a view to have a server that would be as silent and energy efficient at possible.
In this quest, I came across VIA, a Taiwanese company that specialises in low power x86 compatible processors and motherboards. You can get most of their hardware in the UK from mini-itx.com. But I'm not good at building a box from scratch so I really needed something already assembled. I found that at Tranquil PC, a small company based in Manchester. Here is the configuration I ordered from them:
- An entry T2e chassis with DVD-R drive, colour black.
- A VIA EN15000 motherboard. I choose this one as it is the only one that they offer that comes with a Gigabit Ethernet port and the new 1.5GHz VIA C7 processor, which is one of the most power-efficient.
- 1GB RAM. Experience tells me that this is more than I need but having extra RAM should enable the machine to take on more tasks in the future.
- A 100GB 2.5" HDD. I could have gone for a larger 3.5" HDD but I don't currently need the extra space and laptop drives are significantly more energy efficient and silent than desktop ones.
I received my T2e a week or so later. Unfortunately, it had been damaged in transit and the DVD drive was not working properly anymore. The support people at Tranquil PC were very nice and very efficient and arranged for the machine to be collected and sent back to them. It came back a week later in full working order.
I replicated the original install that I had done on the old server. Having done it once, it went very smoothly, everything working first time. The obvious difference from the start was how little noise the T2e makes. In fact, the only audible noise came from the DVD drive spinning the installation CD. Otherwise, it's as if the machine was switched off. Impressive! And it looks really cool with the blue glow coming out of the front panel. As I have a plug-in energy meter, I decided to check how much power this machine drew. So, once the installation was finished and the machine was up and running, I restarted everything with the meter in between the wall socket and the PC's plug. Results:
- Max power consumption when starting up: 30 Watts.
- Standard power consumption once in operation: 25 Watts.
In other words, this machine consumes about the same as a small standard light bulb without ACPI enabled. Once I've enabled ACPI and tweaked it somewhat, I should manage to make it consume even less.
This proves that a server doesn't have to be a big power hungry and noisy box, it can be a small machine that is so silent you forget it's switched on. There are currently few suppliers for that sort of hardware but my guess is that it will become more common. In the meantime, head to Tranquil PC to find one of those.
Sunday, 6 January 2008
More Music, Less DRM
According to Wired, Sony BMG have decided to start offering their music online without DRM. This makes them the last of the major labels to do so.
This is good news for everybody as it means we will start seeing more music sold online without DRM. Then again, music is not limited to major labels, there are lots of Indie labels out there that produce great music. And there are more and more online outfits that enable artists to distribute their music. Check out Magnatune, Amie Street or Jamendo for a few examples.
Saturday, 29 December 2007
Photographic Metadata
When I first started with an SLR camera, some 13 years ago, all camera magazines had the same advice for beginners: to improve your pictures, write down all the settings you used, such as aperture or shutter speed, so that you can go back to this information once you have the prints and understand why they came out the way they did. As a result, a serious photographer would always have a small notebook with him to write all this down. It was quite a time consuming process but essential for who wanted to improve. In this age of digital photography, it would seem sensible for the camera to store this information with the picture so that you can retrieve it later. And indeed they do, in metadata called EXIF data that is embedded in the image file. Software like Photoshop is able to read EXIF data but it's a bit overkill to fire Photoshop just to look at this data. And it would also be nice to be able to write scripts based on it, such as a script that selects all pictures taken at a particular focal length.
Such a tool exists: it's called, quite simply, ExifTool. The tool is written in Perl so should work on any system that has Perl installed. There is a package for Mac OS-X that makes it really trivial to install. A proper install on Linux is slightly more convoluted so here's how to do it on Ubuntu:
- Download the latest version from the web site, in my case version 7.08;
- Extract the content of the file:
$ tar -xzf ./Image-ExifTool-7.08.tar.gz
- Install the Perl libraries so that they can be used by other Perl scripts:
$ cd ./Image-ExifTool-7.08 $ perl Makefile.PL $ make $ make test $ sudo make install
- Install the main script:
$ sudo cp exiftool /usr/local/bin
Alternatively, you can use ExifTool directly from the directory where you extracted it if you just want to try it out. Using ExifTool in the command line is very easy, just call:
$ exiftool myfile.jpg
And it will output all the metadata tags it knows about. There are a number of options available, in particular, you can select what tags you want to see. It's all very well explained in the man page. And if you run exiftool without arguments, it will actually display said man page. So what sort of fun stuff can we do now? Here is an example that selects all the files with a .JPG extension in the current directory and below that are photographs taken with a focal length of 105mm:
$ for f in `find . -name "*.JPG"`; do > if [ -n "`exiftool -FocalLength $f | grep '105.0mm'`" ]; then > echo $f > fi > done
Note that ExifTool formats its output such that it prints out the name of the tag followed by a colon and the value. If you want to strip that name and only keep the value, you can do something like this:
$ exiftool -FocalLength myfile.jpg | sed 's/^[^:]*: //'
An interesting application, if you have a GPS receiver is to combine the GPS trace log with the EXIF time information to geo-tag your photographs. There are a number of links on the ExifTool web site that point to such utilities. Once geo-tagged, online photo sites like flickr will use this information to position the pictures on a map. Or more simply, to come back to what I was talking about at the beginning of this article, you could compare basic shot settings between pictures to understand why one is better than another.
Note that there are other tools than ExifTool to do this, some of them offer a graphic front-end that may be easier to use for those who are not comfortable with the command line, but ExifTool is by far the most complete and powerful. Just google for exif reader
if you want to find other options.
Friday, 21 December 2007
Zend Framework on XAMPP
I am currently experimenting with the Zend Framework, using XAMPP on a Windows laptop and following Rob Allen's excellent tutorial. With a default installation of XAMPP, you get a nasty Error 500 whenever you test your system. This is because XAMPP doesn't enable the Apache mod_rewrite extension by default. So here's how to do it. Find the Apache configuration file, called httpd.conf, which on my install is in C:\xampp\apache\conf and uncomment the following line:
LoadModule rewrite_module modules/mod_rewrite.so
Restart XAMPP and it should all work.