Archive for Feb 2010

Quick & dirty chocolate milk for chocaholics

IKEA Pokal mugs are quite suitable for this.

I always make this for my girlfriend (and/or myself) on cold swedish nights.

You will need:

  • 40cl mug
  • enough milk to fill it
  • 2 tablespoons of cacao
  • 1 tablespoon of sugar
  • 25 grams of dark chocolate
  • a good pinch of grounded black pepper
  • some kind of whisk (I use a simple milk whisk)

Heat the milk in a pan and throw in the cacao, sugar and pepper. Chop the chocolate into fine shavings and add to the milk. Whisk until the milk is slightly hotter than drinking temperature (it will start to steam) and pour into the mug.

You could add whipped cream if you feel like it...

Or mix in some strong coffee for a totally different experience (but mind the kick of sugar, chocolate and caffeine :P)

And do ease your mind (it is a rather large mug with bittersweet goodness and not a simple cup of tea) by buying fair-trade cacao and chocolate ;-)

Not so different (1)

"Is Sweden any different from the Netherlands?"

That question keeps coming back, but with the olympic games well underway, it just got an extra dimension.

Sven Kramer

The Dutch really are one-trick-ponies when it comes to the winter olympics: speed skating. That is about it. The Dutch have over 80 medals, but only 3 (!) were won on some other discipline (figure skating to be exact). The Canadians might have waited for the first gold medal on home soil; I am waiting for the first medal of any kind on something with a ski instead of small pieces of iron.

However, this creates expectations; if we do not win any gold, the cabinet will collapse... uhr, maybe that will still happen while we win a gold medal, but the media will be screaming for an explanation. The people will not be so kind ;-)

Charlotte Kalla & Anna Haag

Now Sweden... turns out, they are more diverse in their winter specialities, how odd :-P. But the only skating which really gets their attention is ice hockey. But ice hockey is just one-dimensional: men and women. Cross-country skiing really is the speed skating of Sweden. They are very good at it and must always be mindful of the Germans, sounds just like ladies speed skating :-P

But I must say I have enjoyed watching the Swedish skiing competitors (cross-country, biathlon and alpine) so far. They are a lively bunch and I will never forget the giddy Charlotte Kalla wobbling on her chair in the SVT Whistler studio after winning gold.

But that reminded me Sweden is not so different: the commentators, the interviewers and the presenters all have their Dutch "counterparts" or have the same role. When Björn Ferry won the gold, the commentators sounded just like the Dutch commentators when Mark Tuitert and Ireen Wüst took their unexpected gold medals.

PS. If anyone want to check the "other channel", try Eurovision Sports. The Dutch broadcaster is NOS and the Swedish is SVT.

White chocolate apricot cake

It is a lie.

It is surprisingly simple and omnom-delicious.

You need:

150 grams of unsalted butter (1 1/4 dl)
175 grams of chopped white chocolate
  4 eggs
160 grams of sugar (1 1/4 dl)
260 grams of sifted flour (4 1/2 dl)
  1 teaspoon of baking powder
    a pinch of salt
100 grams of chopped dried apricots

Now for the "heavy" lifting:

  1. Lightly coat a rectangular cake pan (about 400 square centimeters; 20cmx20cm or something similar ;-) ) with butter and stick some baking foil on the bottom. Preheat the oven to 180˚C degrees celsius.
  2. Melt the butter and chocolate au bain-marie and stir it into a nice smooth creme. Allow it to cool a little.
  3. Stir the eggs and sugar into the creme and mix it properly.
  4. Add the rest (salt, flour, baking powder, apricots) and do the stirring thing again. You now have pretty solid sludgy cake batter.
  5. Pour the batter into the cake pan and throw it in the now hot oven for 25 to 30 minutes.
  6. Let it cool in the pan for a while.

It is not a problem if the middle is still a bit soft when it gets out of the oven, it will settle when it cools.

Decide for yourself to chop it in nice dices (recommended) or just to leave the knife and eat it entirely (not recommended, but I understand your urge).

As with all cake batters, the batter is delicious as well, so I would recommend not to create it just before any type of scheduled food (breakfast, lunch, dinner).

History

Just ploughed through 130 old blog posts after a mate revived my old server...

PS. I love django's inspectdb+multidb

PS2. I really, really do.

"Ford?" "Yeah?" "I think we need a hovercraft"

They got a frigging hovercraft

"... I know how you feel"

But it probably really is a very good way to move around a lake of ice in case of emergencies. I forgot the camera so I used my mobile phone.

As you might have guessed, I went on the ice again today to get some exercise. I originally planned to think about problems I have with some projects I am working on, but it quickly became apparent that I had no such luck... Skating on a lake means cracks in the ice, cracks in the ice mean no mind-wandering of any kind. That I learned in the first kilometre :-P I was thinking "oh, maybe this... or that", when my balance organs went into overdrive and just kept me on my feet. To make things worse, there were two cracks in the ice... But I remained on my feet, be it a bit shaky.

Lucky kids, they get a awesome ride for free.

It was weekend, so I was not the only one with the idea; it was pretty crowded on the ice, so overtaking was tricky sometimes. Little children are pretty lucky here, and I am not talking about day care or other benefits, but just plain for their hitch-hiking skillz with mom and dad. Well, mostly dad. A lot of sleds with daddy-the-rednosed-reindeer in front, dragging their offspring over the ice.

Although the lack of mind-wandering makes the experience less useful, the pure enjoyment of skating on a lake is terrific.

For some reason London creates some pretty decent music

A friend of mine tipped me on The xx a couple of weeks ago, stating I might like it. Well, I think it is one of those albums that slips by you and you need friends to remember you of. Today I returned him the favour by tipping him about Florence + the Machine. Both bands have become quite famous in 2009, last.fm included them both in their top 40 of 2009, which means a lot of people listened to your album.

The xx - xx

Album cover for The xx - xx

In spite of the repelling album cover art, the album is not irritating at all. In fact, it is a really impressive first album by four people (now three) from London.

xx starts out pretty dark with the functionally named acoustic Intro. I like the dark ambient sound, so that's collecting brownie points alright. The acoustics stop after a short intro in VCR, but the moody ambience continues. The two voices complement each other nicely and I am still enjoying the album.

After Crystalised, Islands, Heart Skipped a Beat and Fantasy I am still waiting for the weakling of the album. Instead, the tender sound of Shelter starts. This is easily the best song on the record, ingeniously beautiful and smooth. It starts with smooth vocals, building up, smoothing down again... rinse and repeat, but does not bore. I do not know why, it just does not :-) I can even let it repeat.

The next song, Basic Space, probably is the most popular one of the bunch and it is with good reasons. The vocals and rhythms are very catchy. The records continues and keeps up the quality. This will be playing in my music player for quite some time during quiet evenings and weekends :-)

Florence + the Machine - Lungs

Album cover for Florence + the Machine - Lungs

Also from London (they keep on popping up) comes Florence + the Machine. This band revolves around its lead singer, Florence, and has a bit more power behind it than the sometimes very minimalistic xx. I am starting to think I find the English accent soothing to listen to, because I get the same feeling with her voice as I did with Kate Nash. Florence's music is less singer-songwrity and more gripping.

The albums starts out rather frivolous and takes a page from Nash's book: up-tempo, but with a more "epic" voice booming from your stereo. The songs range from slower ballads to crazy ramblings (Kiss With a Fist is rather funny), but the main part consists of strong voiced lyrics and a decent tempo.

Highlights for me so far are: Rabbit Heart, Howl, Drumming Song and My Boy Builds Coffins.

1-10, A-F

When I started attending at Stockholm University I quickly discovered they were using the ECTS A-F/Fx grading scheme. No problem, grading is grading, grades are grades, right? But the difference in the ranges can get confusing sometimes, while objectively, they should not.

A and B are more tightly linked with "I did a good job" than C-E. If I get a D here, it feels like a F, while in the 1-10 scale, it is still a 7; not great, but definitely passed. A B feels less that a 9, a C less than a 8...

It is completely subjective, but the fact F covers 1-5 and E-A cover the rest forces you to think twice before you get too disappointed :-P

Fine-grained permission system in Django

The Django web framework which I work with only has a simple permission system and from time to time, that is pretty annoying. But more fine-grained permissions are not trivial and one can discuss for ages on how one should implement these features. For a website I work with, I really wanted a layer of protection so the application server could not access certain parts of data when the user logged in does not have to know stuff.

So I started "hacking" against Django's ORM and soon enough I had a elegant solution with a slightly hackish implementation. It all starts with extending the default Model and wrapping the fields in properties which control access. This access is configured by a Access innerclass (just like the Meta innerclass). The reason it is in the model definition itself is because I see access to that model as directly related. It is not an Admin page definition. The statements in the Access class describe features users must have using the ORM itself.

This control structure lets you limit access to a number of things, namely: reading and updating on attributes, selecting instances from the object's Manager, creating, deleting and saving instances. These restrictions are formulated as functions on the Access class and get the relevant data (user, instance or set, etc). The following is an example for a Person-model; certain fields are readable for everyone, but the rest is pretty restricted:

class Access:
    read    = lambda user, person, field: not (field.attname in 
              ['address', 'phonenumber', 'email', 'banknumber'] 
              and person.get_user() != user)
    update  = lambda user, person, field: person.get_user() == user
    commit  = lambda user, person:        person.get_user() == user

Using the system is easy, just use the restricted Model as superclass, which loads the permission system for that model. By default superusers get full access, but this can be turned off. The system also includes a custom ModelAdmin and a custom ModelForm, which ensure that unreadable attributes get hidden by using the exclude mechanism of Django's ModelForm.

You might ask yourself how the ORM can possibly get hold of the current user? Well, that is part of the hack; it uses thread-local storage for this. This means you have to install a tiny piece of middleware to make the whole thread aware of the current user. Mind you, the user must be present if access is restricted; if no user is specified, it will deny access. This way, if your authentication middleware fails in some way, access is denied. Denying access if there is no user causes a minor problem: using shell commands like dumpdata and loaddata. There is a special ENV-variable to tell the system not to impose any restrictions, but you (I) have to remember to set it when running data-operations O:)

This system has been up and running on the site since Django 1.0-beta and has survived until now (1.2-alpha). I explicitly ignored private functionality in the ORM so it would not break easily. It is not completely finished; there are some minor TODOs left, which are mainly to make things even more robust. I can make a fair guess that it will cost you some performance, but the major part of that will be your own fault: keep your access rules simple.

Also, this is no fail-safe security system, this is just another layer of protection from users in the default environment: doing http requests. If the rest of the code is secure, it will not divulge information you restricted from them, but it will not hold in case of code-injections.

The whole thing comes in around 250-300 lines of code, including ModelAdmin, ModelForm and decorators. E-mail me if you are interested or leave a comment, I might patch it so it survives daylight :-) But I would recommend people thinking about such things, it really helps you grasp the ORM and thus helps with solving problems you might encounter in the future.

Why being unable to run in the forest is not a bad thing

Nordic ice skates Skating run on Edsviken is quite large

Because here in Stockholm that is probably because things are frozen over. This gives you a fair chance some lakes and estuaries look like a solid plaque of ice... with some snow on top. Lucky for us, some people have these cleaning machines and create ice skating tracks on them :-D

As we live in the west of Bergshamra, we are squeezed in between Edsviken and Brunnsviken, both of which have a skating track on them, both are ten minutes walks, both are in a quite enjoyable environment.

Last saturday we decided we really needed ice skates and bought a couple of långfärdsskridskor down town. Not cheap, but totally worth it. They remind me of "friese doorlopers", but those are normally made of wood and not really fashionable back in the Netherlands, but the nordic versions are all over the place.

That is not really surprising if you take a good look. They are quite durable and easy to use. The shoe is not fixed to the iron below and you can walk quite comfortably to the ice, fasten them and go.

We did not finish the 12km track, we did not even made it half way. As it turns out, ice skating is not as forgiving as road skating, so I have to practice a bit more. Tessa did not have that problem, she only had some problems related to the 10 degrees of "minusgrader": she is going to buy a hat which also covers her ears, so they do not freeze off :-P But all problems aside, we had great fun and will enjoy the rest of the Swedish winter on the ice.

Call it what you like, I am still thinking about buying one

It started with this sad feeling: is this the best Apple can do with a tablet? I was not so much focusing on the features, but on the interface. The iPad interface looks like a large iPod touch, while I expected something more outrageously ingenious. I completely expected something which would incorporate some of the things I have been researching here on multi-touch multi-monitor systems. But the next day I switched from thinking what the iPad was not, to what it actually is...

It is like the first generation iPhone, but this time around, everybody was expecting the "revolution" of the iPhone as it has been. Few people remember the lack of GPS, 3G, cut&paste, etc. The iPad is adequate for now, but lacks some major features, both in hardware and software. I get the omission of a fat USB-port, but I really would have liked a SD-card reader. We will probably see some Dock-connector to mini-USB cables for your camera, bypassing the converter. The software will probably see some (major) improvements on the home screen and will incorporate more multitasking elements. The will probably keep a lid on free multitasking, improving push-support to create a viable alternative.

So now to the "why would you want one?"-part. Well, the iPad is not some mobile device in the way we interpret "mobile" now. It certainly is mobile, but I see it more as a pad lying around your house. You could read books on it, but I have to see whether or not the screen is adequate for it, but I want it for reading shorter material. I get flooded in papers and excerpts to read for my courses, or magazine-styled news I want to catch up with. I also like to cook and always walk between my laptop in the study to the kitchen and back to read it. The iPad would be ideal for all those cooking, hobby and reference books we have somewhere (or do not, because we are cheap and we have the internet).

I really did not have any interest - besides curiosity - in an Apple tablet, just like I did with the iPhone introduction. But the iPad is not an Apple tablet, it is an Apple e-reader. Sure, you can do a lot of things on it which have nothing to do with reading, but a lot of features of the iPhone have nothing to do with calling people... It is a device in the format of a phone or e-reader (a pad!) and adds features which are useful in that format.

I could use an e-reader, but do I really need it?