Jakob Külzer Ninja Coding Monkey goes Canada

3Jan/100

Building a CMS using XML, XSLT, Ant and ImageMagick

Not so long ago a freelance client approached me with some updates for their website. The site has been growing organically since 2000 and therefore was a big mess. Several attempts to port the site to a CMS driven system failed largely because those CMS systems are usually to complex for our needs (Typo3) or not flexible enough (Joomla, Wordpress). So as I was faced with updates to all the updates including image updates which in turn needed thumbnails to be generated. The same day I stumbled randomly over the xsl:result-document function in XSLT 2.0 which allows you to transform a single XML file into several output files. That sparked an idea with me: why not use that to build a CMS system using XML technologies? I've toyed around with Cocoon a couple of years ago but that was not what I was looking for. So I looked for other technologies...

This post is a write-down of my experiences building a XML/XSLT driven simple CMS system. In it I will show you the required technologies, my approaches and my solutions to problems I've encountered. You'll need a solid understanding of XML at least, understanding of Ant and XSLT helps a lot, too.

This post contains tons of XML and I tried my best to format it in a readable way — in fact I've spent hours to get everything nicely on the screen.

24May/091

Panorama Stitching with Hugin

I recently moved into a new place and the view from the 38th floor is just amazing. So I came up with the idea of creating a nice panorama picture of it. After playing around with a few freeware and shareware solutions I stumbled accross Hugin, a open source panorama stitcher. I did my initial trial with pictures from my mobile phone and they turned out to be not really good. I re-took the images with my Canon Powershot in high res and spent some time to create a lot of control points and the result is amazing and very, very big. The original result file from Hugin was a 300 MB TIFF file. I scaled it down for the web, so enjoy the view over Toronto:

panorama_1_web

Panorama View over Toronto

18Mar/0911

Settlers 2, Pathfinding and Writing Code for Fun!

Last week or so I dug up something very amazing on The Piratebay. Someone packed up good old DOS classics into a Dosbox wrapper for Mac OS X, so I could start and run those games in a window on my Mac. Simply amazing. So I started up Settlers II, one of the best games I've ever played. (Don't gimme any crap about pirating games! I own this game. And the expansion. What do you think have I been doing during my childhood? ;-) )

So for all that don't know the game here's Settlers II in a nutshell: every player starts out with a headquarter, a limited amount of building materials, goods, tools, settlers with different skills and a small strip of land. The surroundings offer everything you need to build up your small empire: woods that can be cut down by lumberjacks, granite that can be cut by stone cutters, mountains that offer coal, ore and gold and flat land that can be used to grow crops. On of the major challenges of this game is to get all the production chains right: let's take for example a lumberjack. A lumberjack cuts down trees. The logs then needs to be transported to a sawmill where they get cut into handy boards. (Picture 1 shows such a production chain.) These boards in turn then need to get to a stock or to construction sites. And if you don't build a forester your lumberjack will run out of trees very soon. That was one of the easier production chains. Let's look at something more sophisticated: production of meat. You'll start of with a farm that grows crops. Then you need a pigfarm that takes the crops grown by the farm and water from a well to breed pigs. And finally, to get to your tasty meat, you'll need a slaughterhouse. So, all in all, getting those production chains right tricky and very rewarding. Nothing better than seeing wares running smoothly form source to destination (at least for me ;-) ).

Picture 1: Production chain for lumber

Picture 1: A production chain for lumber. On the bottom left there is the forrester. The guy living in that building just keeps planting trees. The building at the top left and to the right are lumberjacks.They cut down trees. Those trees then get transported to the building to the top right, the sawmill where they get cut up.

The other big challenge, and actually the reason why I'm blogging about this, is the way system. All the production facilities mentioned above are connected by a road system. Each of those buildings has a flag in front it and whenever a building "finishes" producing an item, the item gets dropped at the flag (I won't go into the hygienically implications of dropping food on flag on a dusty road... ). Connected to the flag is a road that leads to another flag and standing on that road is a carrier, a poor guy who's job it is to just carry stuff from the one flag to the other flag. See Picture 2 to get a better understanding. So eventually this road leads to another building that actually needs what has been produced. In the picture below that would be the small pig on the flag to the right that needs to get to the slaughterhouse to the left (Hey, it's biological after all!).

Flags, roads and items.

Picture 2: Flags, roads and items. Notice the pig on the flag on the right.

So getting the way system right is crucial to your success in that game. If your roads are too long, it will take forever to complete things. If you don't set enough flags, the actual capacity of a given road segment will drop - after all there is only one guy standing between two flags and he can carry only one item at once (an exception are the donkeys that you get after a road has been in heavy use but that still only gives you two items per segment).

Now, you have an understanding of what that game is about. If you don't, get yourself a copy and play it a bit. But be careful, it's addictive.

So while I was playing a bit I started to wonder, how all this worked. How do wares get routed from one flag to another flag. How to flags eventually reach their destination? How is ensured that wares don't run in circles? How is ensured that best possible route is taken? All those thoughts kind of reminded me of my excellent algorithms and data structures lessons at the Hochschule München, where graphs and different algorithms on graphs where a big subject. So I got really curious how to implement something like that. After all, at university we implemented a lot of the data structures and algorithms but never for a "real" problem.

Later that night I started up Eclipse and got churned out some code to actually represent a hexgonal map (Settlers 2 uses a hexagonal grid as opposed to most modern games that just use isometric rectangular maps), render out that map to the screen and some classes to represent flags and roads. And then the fun started...

My first goal was to implement a pathfinding algorithm that actually finds a good route from one given hexagon to another hexagon. Sounds easy but is a really hard problem. There are a couple of algorithms out there that actually solve that problem but I decided to go with the simplest one, Dijsktras algorithm that is guaranteed to produce the best solution. However implementing that algorithm wasn't as easy as I anticipated. My first test run produced some rather... unexpected results:

Picture 3: Pathfinding done wrong!

Picture 3: Pathfinding done wrong. The goal was to find the shortest possible route from the one green flag to the other green flag... The gray zig-zag line is the path my implementation found...

Obviously that was not the best possible solution! Eventually it took me a couple of hours to get my implementation right. But then I got it right:

Picture 4: Pathfinding done right!

Picture 4: Pathfinding done right! Made the paths red in that screenshot for better visibility. Note how the red paths connecting the green flags are the shortest possible.

My conclusion after a couple of hours trying to get that right: It was a lot of fun and kudos to the developers of Settlers 2! I did not spend too much time on that but it became quickly obvious that building a game as "simple" as this old DOS game is all but easy. Building even simple pathfinding imposed quite a challenge on me. Building a whole game like that seems one hell of a task...

The next step is now to build a pathfinder that is actually aware of terrain (you can't build roads on water!) and won't allow to cross roads. With that in place i can finally start to play around with the actual routing of goods in this graph. The technical more adept might argue that I actually don't need all the stuff that I wrote so far to calculate some spanning trees on a graph. And they're right. But otherwise it wouldn't be as much fun!

Depending on how much spare time I have I'll keep playing around with this and keep you posted...

18Feb/090

refundroadtrip.ca goes live on Grails

Ok, I'm a bit late on this but I've been quite busy the last weeks. Tomás already blogged about this quite some time ago but now I want to showcase what we did as there is a lot of interesting technology in there. The page we built is live on http://www.refundroadtrip.ca/ and sports an interesting Google Maps mashup and YouTube integration.

At this point I want to thank all the great people that worked so hard with me to get this project done.

Thank you.

If I find some time I will blog about my experiences integrating all those technologies. Might be some time though.

Update 19/02/2009: We made it to the Marketing Mag! Yeay!

7Nov/082

Songbird – an iTunes Alternative

For all who are far from satisfied with iTunes: you should check out Songbird, an open media source player open source media player. It's great. It can play all those formats iTunes cannot play (which basically is only MP3).

Songbird features a real plugin system, it's skinnable and has lot's of neat features! Go for it!

Filed under: Cool Tech 2 Comments
26Sep/080

Good old Games

Just stumbled accross Good old Games, they are planning to re-release old classic games. I'm really excited about this! I love old games, but getting them to run on recent hardware is a pain. And the best part: without any crappy DRM! Hope they start business soon. :)

Filed under: Cool Tech No Comments
19Sep/087

Grails and LiquiBase – How to use

In my current project I'm now at a point where the application has come pretty far but is still far from finished. The domain model is not perfect, but very stable at this point -- changes however, are still possible.

To get going with the application we are planning to perform tests with some real data. The problem at this point is that entering real data into a database that might be wiped due to changes in the domain model is a very tedious task, at least for the person responsible for entering the data. And the reason for running such a test is to find problems with the domain model which lead to the dreaded changes in the domain model. This cat bites her own tail...

As wiping out the database and re-entering the data is not an option at this point, I decided to look into LiquiBase which as been sitting on my delicious list for quite a while.

This post is an attempt to write down my experiences and learned lessons with LiquiBase. The documentation of LiquiBase is technically complete and extensive but lacks more information about how to use it in a real project. This is an attempt to create a guide on how to leverage LiquiBase in a real world project.

21Jul/080

Virtuelles, genopptes Plastik

LEGO

LEGO

Gestern Abend habe ich eine großartige Software gefunden, den Lego Digital Creator (LDD), den man kostenlos herunterladen kann. Der LDD ist eine virtuelle Lego-Box mit sehr sehr vielen unterschiedlichen Teilen (obwohl ich doch schon einige nicht finden konnte, z.B. Differentialgetriebe oder diese Schutzblechdingens die alles in allem 5 oder 6 Noppen lang waren und die Radladerschaufeln sowieso... ) und einem unerschöpflichen Vorrat an Steinen in alle Farben -- ich hab schon versucht sie alle mal aufzubrauchen, aber es sind einfach nicht weniger geworden ;) . Der LDD kommt mit einer schicken 3D-Oberfläche daher, die Steuerung ist intuitiv und bietet neben dem eigentlichen Bauspaß mit der Explosionsanimation, bei der das eben Erbaute in alle Einzelteile explodiert und sich dann wieder zusammenfügt, auch Befriedigung für die eher destruktiv veranlagten. Und ja, es gibt eine Mac-Version! Danke Lego!

Wenn man mit dem was man erschaffen hat zufrieden ist, kann man sogar sein Modell bei Lego bestellen; bei fast allen Modellen die ich bis jetzt gebaut habe, wurde ich dann aber darauf hingewiesen das bestimmte Steine nicht bestellt werden können, und somit mein Modell nicht bestellbar ist. Aber das ist ja nicht so tragisch -- das zusammenbauen alleine macht schon so viel Spaß!

Darüber hinaus gibts hier noch das heutige Bild!

15Jul/080

Der Nahkampfregenschirm

Einfach irre, ich will auch so einen unkaputtbaren Nahkampfregenschirm: http://blog.wired.com/gadgets/2008/07/unbreakable-fig.html

14Jul/080

Reactable

Reactable in Aktion

Den Reactable habe ich das erste mal in einem kurzen Bericht im Fernsehen gesehen und war sofort fasziniert; ein Tisch mit einer reaktiven Oberfläche der bei Auflegen von "Bausteinen" Geräusche erzeugt. Die Videopräsentationen muss man sich einfach ansehen: Basic Demo #1, Live in Berlin. Das ist so cool!

Interessanterweise stellen die Macher des Reactable ihr Framework für die "Benutzeroberfläche" zur Verfügung. Damit ließen sich wirklich tolle Sachen machen, man stelle sich einfach die Möglichkeiten eines absolut intuitiven und Hilfsmittelfreien Systems vor! Wo bekomme ich jetzt so einen Tisch her?

Filed under: Cool Tech No Comments