Grouping filter for AngularJS

I wanted to create a bootstrap layout with multiple rows and columns through AngularJS. In order to do that, every six items or so a new row would have to be created, containing the next six list items.

This of course requires slicing the list into groups of six and iterating over those groups at the row level. My idea was then to implement a grouping filter, that could be used as follows:

<div class="row" ng-repeat="group in items | inSlicesOf:6">
  <div class="col-xs-6 col-md-2" ng-repeat="item in group">

After some not-quite-working experimentation and a (to me) somewhat obscure error
Error: 10 $digest() iterations reached. Aborting!
I stumbled upon a snippet, that does exactly what I need:

myModule.filter('inSlicesOf', function($rootScope) {
  return function(items, count) {
    if (!count) {
      count = 1;

    if (!angular.isArray(items) && !angular.isString(items)) {
      return items;

    var array = _.groupBy(items, function(val, index) {
      return Math.floor(index / count);

    if (angular.equals($rootScope.arrayinSliceOf, array)) {
      return $rootScope.arrayinSliceOf;
    } else {
      $rootScope.arrayinSliceOf = array;

    return array;

(Note that this requires Underscore.js)

Highly available Samba on Ubuntu 8.04

This is something I worked on over the last few days. I was confronted with a particular network infrastructure, where a central Samba fileserver stores all important business data. Of course there is a working backup strategy, however – that server being a single point of failure – the situation wasn’t quite optimal. Usual failure recovery times where as long as 2 days over which the critical data was only partly available. Thus the idea was born to move Samba onto a high availability setup. It’s implemented as a two-node cluster using Ubuntu 8.04 Server Edition, DRBD and Hearbeat.

In this article I will guide you through all the necessary steps to implement such sytem.

Read More

Fedora LiveCD without CD drive

Yesterday I wanted to give the new Fedora 11 alpha a spin. Unfortunately it seems that Virtualbox doesn’t like Fedora – the system would always run unusably slow.
I started looking for a way to run the LiveCD without actually using a CD. Ubuntu has some good documentation on that, but I could not find anything similar for Fedora. So I had to figure it out myself and after a little tinkering I present to you the simple instructions on how to boot Fedora LiveCD’s from hard disk.

  1. Download the LiveCD
  2. Mount the CD Image and copy its contents to an unused partition (this *should* work with a in-use partition actually… but don’t blame me for lost data) like so:
    $ mkdir /tmp/fedora-cd
    $ mount -o loop F11-Alpha-i686-Live.iso /tmp/fedora-cd  # as root
    $ mkdir /tmp/installer
    $ mount /dev/sda4 /tmp/installer  # as root
  3. Now you have to edit your boot loader configuration. For grub this will typically be done in a file called /boot/grub/menu.lst or something like that. Add the following lines:
    # adjust these settings for the device you're actually using
    title Fedora 11 Alpha LiveCD
    root (hd0,3)
    kernel /isolinux/vmlinuz0 root=/dev/sda4 rootfstype=auto ro liveimg quiet rhgb
    initrd /isolinux/initrd0.img

Now you can boot into the LiveCD from the according Grub menu entry.

On the Theme Hospital project

There’s a new comment on one of the theme hospital posts.

Just wondering. Is this project still going on? Hospital could do with an open source (enhanced) version.

I know some people are busy on it at but this project is going very very slow.


Now here is my answer:

Unfortunaltely I haven’t had much time for this lately. But indeed, there was some progress just a week ago – I made a few additions and cleanup-work in the wiki and also worked a bit on the viewer-program. When there was some good progress about a year ago, I initially expected other interested people would build upon my findigs. This has not been the case yet. Well…. I think there will be more stuff going on, but it may take some time – at least for the reverse engineering, as I kinda ditched the open-source-clone thing for now.

The latest THViewer brings improvements in file-handling and a completely Java based RNC decompressor. If you’re interested in the sourcecode, you can get it from GitHub:

git clone

Seam Carving

Intro and Overview

If you have already seen the video on content aware image resizing at then you probably know what seam carving is. If not, I recommend you to do so.

Seam carving is a method to resize an image that takes the image’s content into account – and can therefore produce really great results. This is my attempt to provide the reader with an easy to understand explanation of how seam carving works.

Read More

Litter, Shadow, Heads and Sound

I’d say this looks quite Theme-Hospital-like doesn’t it?

The few things that were done since the last post:

  • figured out how shadows and litter is represented in a savegame
  • I worked out how the animation layers are stored; this is why the people have heads and different clothes on the new screenshot
  • soundfiles; yeah right! I messed with the sound files format and I now know how this works… well at least to a large extent

And as always I also updated the wiki and implemented the new stuff in my TH Viewer. Get the latest version here.


With the last bits waiting to be uncovered comes the time to think about the next steps.

Finish the savegame format

The next coupe of days/weeks are still mainly for finishing up the reverse engineering and getting the wiki in the right shape. Savegames are crucial in getting a feeling for “how Theme Hospital does stuff” without having to go through many painful debugging sessions. So that is something I’d like to get done.

Finish other reverse engineering

Not too much left and not really that importent – unless of course we want a clone that is fully compatible with the original game.

Toolchain evaluation

I will probably stick with java for a programming language, however I’m still not quite sure what graphics/media libraries to use. SDL may be a good choice but I also consider choosing a LWJGL based engine.

Spread the word

I already received an email from Ted Tycoon recently, who expressed his interest in the project. I would also like to see what other people have to say and if there are more players and developers interested.

Savegame rendering

The last days I did some work on the savegame format. It’s far from complete, but I thought it would be nice to share some progress. Click on the image to the right.

As you can see there are still some things to do – but I guess that it’s all not that complicated. Note that this is not a playable game – it is just a rendered image, using the information from a savegame.

I also updated the wiki with the new information.

Looks like Theme Hospital

I have made some good progress on the reverse engineering of theme hospital’s data formats since the last time I wrote about it. My “Theme Hospital Viewer” is now able to render animations and maps.

Still, there are some unknown pieces to the whole specification. But my guess would be that we are now at about 75% done and nearly all files classified by their format. By now it should be already possible to begin a theme hospital clone – if not even complete it.

So without further ado, I present to you:

The Sourcecode of THViewer includes the sourcecode of dernc. Please read the readme.

A word of warning: the source code of THViewer is quite a hack and the whole thing is more like a proof of concept / test-tool. It is by no means “user friendly”.

What I've been up to

These last weeks I was mostly occupied with a somewhat more extensive Java application. At first the goal was to convert an Excel table into another file format.

As time went on though, additional factors turned out to play a role, which would make the whole thing not quite that simple.

Small Overview

I had an example Excel table, that was layed out in the same way as all the other tables that need to be converted. There was also twenty-page specification of the target document format.

The issue with Excel tables: in principle they are not structured. For rows and columns there is no fixed format and users can put data in a cell that - in relation to the target format - doesn’t make a lot of sense. Due to the fact that there’s no unambiguous mapping from the source to the target data, some kind of interactive user interface is a must-have. The user needs to have a way to edit the converted data and, where needed, make manual corrections.

Read More

A bit of reverse engineering

I spent the last two days to tease out the data from the files of TGEB’s tariff data files. The actual data is compressed first and then encrypted with some kind of cipher feedback/chaining mechanism.

While it was relatively easy to follow the decryption process in a debugger, the compression was a bit of a obstacle for me at first.

In the end I was able to implement two small Java snippets. The first one decrypts the data and the second one creates a lzh file from the output. Extractable with any archive app, provided it supports extracting files where the CRC-16 check sum does not validate.

Read More
← Older


Alexander Gitter
contact at agitter net