Archive for January 2006

Cleaning up in ~/.ssh/known_hosts

I just noticed that Debian’s ssh does the right thing and uses hashes rather than IP addresses in ~/.ssh/known_hosts. So, how do you keep the list of known hosts minimal if you can’t delete entries manually any longer? ssh-keygen has two commandline options that help

% ssh-keygen -F <hostname>
% ssh-keygen -R <hostname>

The first will list the entry for the host, the second will delete it (a backup of known_hosts is made first).

I also noticed that ZSH’s command line completion doesn’t know about these options yet.

Beginning to play with MochiKit

I haven’t written any JavaScript for years. The only lingering memory was of pain–pain to find information, pain to use the API, pain to debug… There were probably a few more pains, but I’ve managed to successfully repress those memories. So, why return? Well, I want to some day be able to debunk the AJAX hype in any discusion I partake in :-)

MochiKit is used in turbogears to make the life of a “web developer” easier. Given the comments on the turbogears site I tought I’d take a quick look at it… I was surprised. There was a lot less pain this time.

Of course I started with some silly experiments. First off playing with the DOM tree a little. The HTML part ended up like this:

<html>
  <head>
    <title>Experiment 1</title>
    <script type="text/javascript"
            src="MochiKit-1.1/lib/MochiKit/Base.js"></script>
    <script type="text/javascript"
            src="MochiKit-1.1/lib/MochiKit/Iter.js"></script>
    <script type="text/javascript"
            src="MochiKit-1.1/lib/MochiKit/DOM.js"></script>
    <script type="text/javascript"
            src="exp01.js"></script>
  </head>

  <body>
  <table id="theTable">
  </table>
  <a href="#" onclick="addEntry();">Add entry</a>

  <div id="theText">
  </div>
  <a href="#" onclick="addText();">Add text</a>
  </body>
</html>

Nothing really exciting there. Here’s the two toy functions:

var i = 0

function addEntry() {
    var row = TR(null,
        TD(null, 'Hello'),
        TD(null, i));
    row.id = 'row' + i
    appendChildNodes('theTable', row);
    i += 1;
}

function addText() {
    var txt = getElement('theText');
    if (txt.text) {
        txt.text += ' Hello';
    } else {
        txt.text = 'Hello';
    }
    replaceChildNodes(txt, P(null, txt.text));
}

Wonderfully easy to navigate and modify the DOM tree.

Well, this was somewhat silly. Hopefully there’ll be something more interesting to write about soon enough.

Epilicious 0.7

Release 0.7 of Epilicious has been out in the free for 5 days now. It didn’t contain anything really interesting at all for the user. That is unless the user has problems running the damn thing :-)

The python plugin for Epiphany is a wonderful thing, but debugging python plugins is a pain. The current solution to the problem is logging. I was motivated by a user with Epilicious problems (thanks Chris).

csplit and procmail

I had misconfigured my procmail slightly, which resulted in 223 mails ending up in an mbox rather than sorted into my maildirs. At least they weren’t lost!

After correcting my procmail setup came the next problem–how to get them all sorted out of the mbox? The easiest way seemed to be to re-deliver them. The procmail man-page says nothing about it being able to handle several emails at once. I didn’t feel adventurous, mails are too important! Instead I went looking and found a new command csplit. The following split my mbox into files containing one email each:

csplit mbox '/From /' '{*}'

The first file it creates, xx00, is of zero length, so I deleted that. Then I passed all files to procmail one at a time:

for f in *; do echo $f; procmail < $f; done

(It took so much time that I interrupted it once and added the “progress reporting”.)

CherryPy sessions

I almost started pulling my hair over this. The part of the CherryPy book on sessions said that the following code would turn on sessions in CherryPy 2.1:

cherrypy.config.update({'session_filter.on' : True})

However trying to access session data after that resulted in a “500 Internal Error” page telling me that sessions weren’t enabled. Huh?

Luckliy I found this post on the topic. There’s apparently a typo in the book, the line should read:

cherrypy.config.update({'sessionFilter.on' : True})

Cheetah vs. kid: 1 – 0

I should have spent my Sunday doing a million other things, e.g. trying to clean up muttprint‘s build system. Instead I decided to take a quick look at TurboGears and its parts. The Arch packages for it didn’t quite build so I ended up spending some time with CherryPy, Cheetah and Kid. I’m an utter beginner when it comes to “programming the web”, I’ve just never been very interested in it. It might be changing now though :)

CherryPy is truly impressive. A simple Hello World web service hints at just how easy it is to use. It’s written in Python, and it’s very pythonic indeed. However CherryPy isn’t what I wanted to write about. Another area I’ve not looked at is templating systems, I haven’t found a need for it yet. That’s possibly because I’ve never really understood what they are and what they do. That’s changing too.

TurboGears uses Kid so that’s were I started. I downloaded a simple example consisting of two files. The template:

<html>
  <head>
    <title py:content="title">Title</title>
  </head>
  <body>

    <h1 py:content="title">There should be content</h1>

    <ol py:if="title">
      <li py:for="line in lines">
      <span py:replace="line"></span>
      </li>
    </ol>

    <dl>
      <span py:for="n, line in enumerate(lines)" py:omit="">
        <dt py:content="'Line %s' % n"></dt>
        <dd py:content="line"></dd>
      </span>
    </dl>

    <p py:replace="'End of page'+title"></p>

  </body>
</html>

The second file is the CherryPy modules that combines the template with values:

import cherrypy
import kid

class HomePage:

    @cherrypy.expose
    def index(self):
        test = kid.Template(file='kid_test.kid')
        test.title = "Test Kid Page"
        test.lines = ['qwe','asd','zxc']
        return test.serialize(output='xhtml')


if __name__ == "__main__":
    cherrypy.root = HomePage()
    cherrypy.server.start()

This, I think, is rather cool. Very clean, very nice. Still I thought it’d be interesting to take a look at Cheetah (one main reason was that their homepage mentioned that reddit.com, which is funded by Paul Graham, uses it). It was a good decision, I think.

I wrote a Cheetah template producing the same output as the Kid template I downloaded.

<html>
  <head>
    <title>$title</title>
  </head>

  <body>
    <h1>$title</h1>

    <ol>
      #for $l in $lines:
      <li>$l</li>
      #end for
    </ol>

    <dl>
      <span>
        #for $n, $l in $enumerate($lines):
        <dt>Line $n</dt>
        <dd>$l</dd>
        #end for
      </span>
    </dl>

    <p>End of page $title</p>
  </body>
</html>

The matching CherryPy module is very similar to the one above.

import cherrypy
from Cheetah.Template import Template

class HomePage:

    @cherrypy.expose
    def index(self):
        tmpl = Template(file='cheetah_test.html', \
                searchList=[{'title': 'Test Cheetah Page', \
                    'lines': ['qwe', 'asd', 'zxc'],
                    }])
        return str(tmpl)

if __name__ == '__main__':
    cherrypy.root = HomePage()
    cherrypy.server.start()

Now, what do I think? I guess the title of the post betrays my preference ;-)

I spent very little time reading documentation to do this. I needed some help to write the Cheetah template since I had to do it myself. However, I think that if I’d had a Cheetah example and tried to create a matching template using Kid, I wouldn’t be writing this right now. The Kid syntax just seems more confusing to me. I think I’d have to read more documentation as well as spend more time with Kid to reach the same level of confidence I have with Cheetah already after 30 minutes with it.

Now I just need to find some nice little project to verify that my first impressions are correct, both relating to Cheetah and to CherryPy. Any ideas?

Upgrade to WordPress 2.0

Absolutely painless! The admin interface looks a lot nicer and of course the blog itself looks just the way it did before. I could stop using the Smart Comment Link plugin, that functionality is now built into WordPress (this required some minimal changes to the theme). Getting Markdown Extra and Search Everything was a walk in the proverbial park.

Oh, it also looks like I haven’t lost any entries :-)

Arch and mkinitrd

A few days ago I ran into some problems after updating my kernel. It was almost certainly due to my own ignorance, however I did solve it and everything was good. Or so I thought. Yesterday I started seeing artefacts on my screen that shouldn’t be there. Squares and lines would appear out of nowhere and disappear as soon as I forced redrawing of the area. Having had problems earlier with frame buffers in Linux I listed the loaded modules. Whooaa! I didn’t spend that much money on my system. I had 133 modules loaded, just a few more than exptected. I received some help on the mailing list.

I turned on the autodetection in /etc/mkinitrd.conf and reduced the ramdisk by more than 50%. When using the --show argument for mkinitrd I noticed that a few extra filesystems were included. There’s a comment that AUTODETECT will limit the included filesystems but it didn’t seem to deliver on that promise. Modifying the list of filesystems does impact what’s included. Then I removed the entire CDROM subsystem, I really don’t need it during boot.

These are the modified lines after the changes:

REMOVE_CDROM=1

AUTODETECT=1

FILESYSTEMS=ext3

The Arch Wiki has an excellent page on initrd of course.

The Eindhoven trip — the full story

We are amazingly lucky Dita and me. We have some amazing friends and we got to spend Christmas and New Years with them this year. On the 21st I took half a day off and went into Cambridge to meet Dita and pick up a hired car. The next morning (night) we got up at 3am and drove down to Stansted to catch the 6:45 plane to Eindhoven. We arrived on time in the spanking new terminal building in Eindhoven. At least something had changed since we moved.

We went to Aissa to have my hair cut, Dita took the opportunity to catch up on what’s happened since she left TNT. In the evening we went to the cinema and saw Narnia. The next day, Friday, we went to Aachen to catch the last day of the Christmas market. In the evening we met up with Felix and Siarhei at Trafalgar. Good beer, good conversation. Interesting to hear the latest on what’s going on at Philips in general and research in particular

The next two days were filled with “Christmas stuff”. Cooking food, eating food, Tim had some excellent wines, and good friends came visiting. All in all an excellent Christmas!

The days in between Christmas and New Year’s were either filled with activities. We had friends and ex-colleagues to visit, we went to Belgium (twice) and of course we went shopping. All the time it felt just a little bit strange. We were in Eindhoven, but we didn’t live there. Weird feeling somehow.

For New Year’s Eve we ended up in Belgium again, ‘t Hoeveke in Peer. Yet another good nice evening that was over too soon. True to tradition we went to the cinema on New Year’s Day. We saw The Constant Gardner, a very good movie, well worth the admission.

For our last evening in Eindhoven this time around we went to Touch of India with our hosts. A perfect ending to a very good holiday. I hope it won’t take too long until we can go back… or until we have visitors.

Linux and explaining the Swedish(-speaking) people

I found the following in Linux Journal. It can be found on this page, I’ve copied it verbatim since I couldn’t find a link that leads straight to the interesting part!

Might Be Just Right

by Doc Searls

At LinuxWorld in Boston earlier this year, I got together with an old Swedish friend. She’s a nurse, not a technologist, but she was curious about my work and the conference that brought me to town. Somewhere in the midst of my explanation of Linux and its virtues, she said, “Ah, Linux is lagom”. She explained that lagom is a Swedish term that conveys a sense of balance, proportion and appropriateness. “Not too much, not too little…just right.”

When I told her that Linus Torvalds’ first language and surname were both Swedish, she said, “Well of course. There you go.” (I’m half-Swedish myself, though I’m not sure that matters.)

So I put the question “Is Linux logom?” to The Man Himself in an e-mail. He debugged my spelling and declined to commit:

Lagom, with an “a”.

And yes, it means “just right”, in the sense of “not too much, not too little”. See en.wikipedia.org/wiki/Lagom

Then he added, in a following e-mail:

They still end up confusing “lagom” with finding the “optimal” amount. That’s pretty much missing the point. It’s not that something is “lagom” because it’s the best possible or “optimal”. Quite the reverse. Something being “lagom” very much involves not caring too much about what the optimal amount even is. Or possibly questions where “optimal” simply doesn’t make sense.

So I began checking other sources. The best I found was from “In Other Words”, published in AskOxford, published by the Oxford English Dictionary (www.askoxford.com/worldofwords/wordfrom/otherwords). It lists lagom among a handful of “the most insightful, intriguing, and satisfying expressions on the planet-for which there are no English equivalents”. It says:

Swedish commentator Dr Bengt Gustavsson argued that the lagom mentality can be seen as the trait that gives Swedish society its characteristic stability and yet an openness to external influences. The word alludes subconsciously to the avoidance of both conspicuous success and humiliating failure, which is deeply ingrained in the Swedish psyche. It is the inclination among Swedes to shun ostentation, accept modest rewards, be good team players-to fly beneath the radar.

Beneath the Radar was also the title of Bob Young’s book about starting and guiding Red Hat to success. Coincidence?

Perhaps characteristically, Linus adds these final words to the matter: “but whether that applies to Linux I have no idea.”