[1 of 3] Updating your brightkite location using Google latitude

BrightKite is a service, much like twitter actually, but that uses your location to find interesting stuff. It could be a great tool to create ad-hoc gatherings of some group of people, for instance coders. If there were a lot of BrightKite users in Bergen for instance, I could leave a message on brightkite that I and some other Python coders were going for a beer at Henriks, and that any others that is interested could join if they wanted, together with the GPS coordinates for Henriks.

Great news in the software world

During the last week there has been a couple of great releases in the software I use every day. First out was Python 3.1. It was released June 27th and features An ordered dictionary type Various optimizations to the int type New unittest features including test skipping and new assert methods. A much faster io module Tile support for Tkinter A pure Python reference implementation of the import statement New syntax for nested with statements Next out was Mozilla Firefox 3.

Merging two lists

Lets say you have two lists, one of them containing the values [1,2,3] and the other one containing the values [4,5,6], and you want to combine these two lists into one list, like this one: [1,2,3,4,5,6]. Let’s see how this can be done in different (high level) programming (or scripting or templating) languages. Java Java has multiple list implementations, lets start with the most basic one, the builtin array.

New howto: Using apache to create an authenticated proxy

Chumby phone

The chumby device is an interesting device, being one of the few open source electronic gadgets and all. But sadly, its the hardware that’s open source. And for me that is really a bummer, since I’m a software hacker. I’m not that confident with the soldering iron. That means that the fact that the hardware in this device is open source doesn’t matter that much to me, especially since I’ve found only one producer and reseller of the Chumby, namely the chumby store.

Unreadable code

If you’re really trying, you will always be able to write completely unreadable code in any programming language. All the language designers attemts to force you to write readable code, and even making it so the easiest way ahead, even for quick hacks is to write it as readable and reusable code will fail if you’re really trying to write unreadable code. This guy is obviously concerned about “job security”. (not the blog author, but the code author)

The value of tool…

… is greater than zero. Python is a dynamically, strong typed programming language. In my opinion that makes it more important to have good tools than for statically typed languages. Sadly, it also makes it more difficult to create great code analysis tools and IDEs. Meanwhile, I find more people in the Python community that is happy coding with Vi(m) even for quite large projects, than in the Java community. My guess is that that is because the tool support for Python has been poor.

Static typing VS. Unit tests

Okay. It’s kind of stupid to put static typing up against Unit tests. Even so, lots of people does so a lot of times in the discussion between dynamic and static programming languages.

Static typing provides you with a security net when it comes to typos. Alhough, it doesn’t give you any security against logical errors.

Blog meme: Phrase From Nearest Book

I spotted this meme on Steve Holden’s blog. Grab the nearest book. Open it to page 56. Find the fifth sentence. Post the text of the sentence in your journal along with these instructions. Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST. So. In my case, the closest book to me when writing this post was Python phrasebook by Brad Dayley.

the right tool for the job

So, you’re going to parse a webpage, to extract some information. For instance if you want to get the tracking information for your last online order, and you want to display the tracking information changes using growl, dbus notifications or xosd.

You know regular expressions, so you go to the job with your long range missiles ready. But wait a minute, you’ll probably solve the problem but is regular expressions really the right tool?

The pro for regular expressions is that you can use the same tool you always use for parsing jobs, but then again you doesn’t learn anything new out of this. You might fortify your position as regex wizard even more, but how about something completely different?

Now. Most webpages is written in HTML, and some even in XHTML, for HTML documents languages like Python has a built-in parser, after the model of the SAX-parser. (It’s probably the other way around, the SAX parser is built on the base of the HTML parser…) Most programming languages has good support for XML, so for XHTML documents, you can use the HTML-parser, a SAX-parser or even the XML-DOM parsers.

The benefit of doing it this way is that your parser will probably be more robust to minor changes in the webpage. You don’t reinvent the wheel (The best way I’ve found to parse HTML documents using regular expressions is to make a specialized SAX-like parser anyway). Your code will probably be readable in a year, and others might even be able to understand your code. And finally, you learn something new, which might give you a fresh view on a lot of problems.

Now back to the original issue, to make a parser for the parcel tracking of your postal service. Here’s an example parsing the shipment tracking page of posten, the norwegian postal service.