The blagotube home of Sune Kirkeby. Here are rambling rants and some bits of code.

13. Mar
2006

New bestest Firefox extension

I have a new favourite Firefox extension: click2tab.

I can’t count how many times I have pressed ctrl+w in a Firefox textarea, trying to rub out the last word I wrote, and instead been faced with loosing my entire browser. “Grrrr,” is my usual response to this.

In my opinion Firefox should recognize that ctrl+w in a textarea very probably is a Unix person making a bad mistake. Alas, it does not. click2tab does not save me from making the mistake, but it lets me undo the close tab operation. Which is just as swell.

Yay!

This post was written by Sune Kirkeby on 2006-03-13, and claimed to be mostly about rambling.
26. Feb
2006

The Classics

For the past 10 years the only fiction I have read is sci.fi., with a few detours into fantasy. It started some time during late primary school, when the slow, painful death of my literature classes took their toll. Those classes were meant to introduce us to classic literature and good writing in general. I thought all of the books we read were mind-numbingly dull. So depressingly, horribly dull that in spite I didn’t read a single book for literature class all through high school.

The sad thing is, then and now, I love reading. So, the danish primary education system turned a confessed bibliophile off classic literature. Which has bugged me ever since: I always felt there must be a good reason classic literature is considered.. well, classic. So, once in a while, when shopping science fiction, I would also buy a classic, thinking: “Maybe, this one is worth reading.” Alas, those books always went to the bottom of the pile. And stayed there.

But. Recently I dug into the book pile next to my reading chair, and decided to give one of the classics a try. Orwell’s Animal Farm came first. I was right, Animal Farm is a very good book. Next I picked up Kafka’s The Trial. The cover says “the masterpiece of the 20th century”; that must mean the book is a classic. And, so far the story captivates me (pun somewhat intended.)

A whole new world of books. Yay! :)

This post was written by Sune Kirkeby on 2006-02-26, and claimed to be mostly about rambling.
25. Feb
2006

E-mail-disclaimer-virus parody

Noticed this gem in Carlo C8E Miron’s signature:

Disclaimer: If I receive a message from you, you are agreeing that: 1. I am by definition, “the intended recipient”. 2. All information in the email is mine to do with as I see fit and make such financial profit, political mileage, or good joke as it lends itself to. In particular, I may quote it on USENET or the WWW. 3. I may take the contents as representing the views of your company. 4. This overrides any disclaimer or statement of confidentiality that may be included on your message.

That very nicely sums up how I feel about the e-mail-disclaimer virus, which seem to have infected a large number of work-computers.

This post was written by Sune Kirkeby on 2006-02-25, and claimed to be mostly about rambling.
03. Jan
2006

Joel is crotchety, but has a point

From Joel Spolsky is a crotchety old man:

Why does Joel pick out pointers and recursion as the two gatekeeper concepts? Because he found them difficult?

In my experience (from helping fellow comp. sci. students) understanding pointers and recursion requires a level of abstraction beyond most people. Also, those who do understand these concepts, can pretty easily spot those who do not.

So, weeding out those who do not understand pointers and recursion, is a cheap and good enough first step in selecting the best programmers.

This post was written by Sune Kirkeby on 2006-01-03, and claimed to be mostly about rambling.
19. Nov
2005

XHTML-as-HTML middleware updated

I’ve updated XHTMLAsHTMLMiddleware to turn response content into HTML 4.01 Strict, instead of just munging the Content-Type header. This should work better with software which expects the quirks of HTML, such as <br> elements which have no end-tag.

This post was written by Sune Kirkeby on 2005-11-19, and claimed to be mostly about rambling.
08. Nov
2005

Django doctest framework

Inspired by Hugo’s post A Test Framework for Django and his DjangoTesting framework I wrote ibofobi.utils.test. Another Django test-framework which provides the same features plus request/response testing also, but in a different way that I like better.

The big differences are that I built it on top of doctest instead of unittest and the fixtures are written in YAML not Python code. I think doctest is a lot nicer to work with than the Java’ish unittest module; and YAML is good for simple data-structures such as the fixtures. Also, I implemented simple request/response tests on top of Beautiful Soup, which is so cool I almost cannot belive it :). Also, the tests are run in an in-memory sqlite database, inspired by Ian Maurer’s Django Unit Testing post.

To test an application you first create a fixtures directory and put your fixtures in there as *.yml, for example in ibofobi/apps/blog/fixtures/blog.yml I have:

posts:
    hello_world:
        title: Hello, World!
        slug: hello-world
        posted: 1979-7-7 23:12:00.0
        listed: true
        content: A lot of content should go here.

The fixtures are grouped by model-name and each fixture has a name, which you can use in the doctests to refer to the database-object. When you have some fixtures you create a tests module for your doctests, so in ibofobi/apps/blog/tests/__init__.py I have:

"""
>>> hello_world.title
'Hello, World!'
"""

This asserts that the title of the post created from the fixture hello_world has the expected title. Now, I want to test that the month-archive view works, so I also have this in the tests-module:

"""
>>> browser.go('/archive/1979/07/')
>>> browser.soup.li.a.string
'Hello, World!'
"""

The browser object is a helper which invokes the Django handler and parses the result with BeautifulSoup.

If you want to try ibofobi.utils.test get it with:

git clone http://mel.ibofobi.dk/~sune/r/ibofobi.git

And run the django-test script, which will run tests in each application in INSTALLED_APPS. Both PyYAML and BeautifulSoup are bundled, so you don’t have to install the separately.

Alas, the tests are always run in an in-memory sqlite database, so you will need sqlite working for Django. I will fix this wart so the tests can be run with other database-backends in one-shot databases like with django/tests/runtests.py.