Welcome to the simple code page of Rasmus Christian Kaae

Last updated 14. jan. 2007
This page features a short range of shareable scripts and code. Everything is downloadable for your pleasure.
You may, or may not, contact me by emailing me at rasmus at 3kings dot dk.

All code here is free as in free beer, send me a mail and I'll give you my snail-mail for mailing me a special beer of your district.

Simple zip code translator for Danish zip codes

Translating from danish zip codes (postnumre) into their real city names is done easily using this script. Simply feed the function with a zip code and it will return a string containing the city name (if it could be found). The list of zip codes was obtained from wikipedia.
Download PHP script (25kb)

CIA Factbook Parser

One day I realized that I'd like to have an XML file with data on all countries in the world. Google told me that CIA World Factbook was the primary source of inspiration and so I started a brief journey into these data files. The outcome is a data set ready and parseable by (more or less) any XML parser available. In addition I also supply PHP code for transforming the CIA World Factbook data files into readable XML.
Download CIA Factbook 2006 XML file (4mb) Download PHP script (4kb)

Google Map API

Being awefully found of google and all their free services (no beer) -- I set off to try their Google Map functionality. To my surprise it was really simple to interface it, even though I do not approve of writing coding in java script. Anyways, while working with the java script interface I found a need for a small server side library for handling information about lat/long positions, and so I wrote my tiny gmapi interface. All it does is given a location e.g. "Aarhus Denmark" it will return the lat/long position in a Google Maps readable format.
Download gmapi.php Usage example #1 Usage exampe #2 Usage example #3

PHP Continuation

During the JAOO conference in Aarhus this year, I attended a seminar on Seaside: A Radical Web Framework help by Glenn Vanderburg. This seminar inspired me to have a go at continuations using PHP. Seaside is a SmallTalk Web Framework that facilitates continuations and make it possible for the user to step backwards in the "call stack" via the normal browser back and forward buttons.

Why is this interesting? Normally the flow of a web application is controlled by the design implemented in HTML, XHTML, XML, XSLT or whatever. Using the continuations one is able to control the work flow through the application from the core code, e.g. written in PHP. Glenn demonstrated avery simple, but yet impressive, use of continuations. The example was a simple counter, it featured a label indicating the current value and two links one for incrementing the value and one for decrementing the value. Clicking the links modified the value displayed by the label. In normal web frameworks, incrementing the counter a couple of times, say 5, and pressing the back button twice would display the value of 3 in the label. However, refreshing that webpage would update the label with the value that the server thinks is the current state. This may seem correct to some, but it may be annoying to the user -- what if she wanted to revert the system to a previous state? Using the continuations, pressing the back button of the browser will revert the application state to whatever it was previously. In the case of the counter example, putting the application in a state displaying the value 5, followed by two clicks on the back button again followed by an update of the page REALLY should display the value 3.
Download phpcontinuation-0_1.zip

MysqlConnect

Working with PHP and MySQL databases, one is bound to get sick and tired of all those awful mysql_* functions. To avoid that I have made a very simple and basic adapter class that hides all the tedious details for me. In addition, it will also help reducing the number of active connections to the database. If used correctly there will only be one connection open to the mysql database per page view.
Download mysqlconnect.php