Blog posts

2004-11-09 – PHP-ers writing perl

Today, I had the dubious pleasure of hacking a bit of perl which clearly wasn’t written by a Perl coder, but rather somebody who learned “programming” by hacking together PHP or something similar.

Take this little piece of code:

print "<DIV CLASS=\"caption\">";
my $tmp = &htmlize_caption ($info{$pathname}{'comment'}, 'slide');
print $tmp;
print "</DIV>\n";
  • unecessary temporary variable
  • ugly “-escaping
  • three print statements and one assignment rather than a single print statement.

This code should rather read:

print qq[<DIV CLASS="caption">],
      htmlize_caption($info{$pathname}{'comment'}, 'slide'),
      qq[</DIV>\n];

or

printf qq[<DIV CLASS="caption">%s</DIV>], 
          htmlize_caption($info{$pathname}{'comment'}, 'slide');

(Really, it should be using templates, but if you aren’t using templates, well, then you aren’t.)

The code doesn’t use strict, but it uses my, it uses long, long, long sequences of print instead of chaining them or templating.

If you are going to write perl, please learn the language properly rather than writing huge scripts which are hard to fix and maintain.

2004-11-02 – PWM fan controller

I’ve talked a fair amount about my fan controller project earlier, but today, the project entered a new phase. I got it running on my own hardware (earlier, I used a friends STK500 development board, and his computer and so on, so I actually had no code from then). The basic stuff is working: I can adjust the speed from 0% to 90% duty cycle using the small switches.

I now need to get the code needed for a serial protocol going and I’m all set. The code is fairly easy, about 60 lines of C so far and I’m hoping the serial code will be easy as well. In addition, I need to make a proper board with real connectors and everything.

I also took a few pictures, so it’s apparent for the world I can’t solder at all. The Atmel Mega32 microcontroller is a cute piece of hardware, though.

2004-11-01 – Contentfilter (or mod_replace, or whatever) for pyblosxom

Annoyed at Liferea not handling Daniel Silverstone putting &hellip; entities in his blog feed (which really isn’t the fault of him, nor of Liferea, but rather of Planet, which doesn’t make sure it spits out valid XML. So I threw together a small piece of code translating said entity to the unicode equivalent. Stop-gap measure, sure, but it works.

In case you are interested, the code is as follows:

__author__ = "Tollef Fog Heen"
__version__ = "0 (2004-11-01)"
__url__ = "http://err.no/personal/blog"

def cb_postformat(args):
    request = args["request"]
    entry_data = args["entry_data"]
    for k in entry_data.keys():
        entry_data[k] = entry_data[k].replace("&hellip;", "&#8230;")

2004-10-13 – New camera

When I came back from Oslo last night and took in my mail, I discovered that a shop had the fairly new Sony P150 at a bargain. As I had also gotten a fairly big tax return, I decided to buy it. It takes really nice pictures and is just as fast as the P100, which I played with earlier.

Now I just need to get an extra battery and a big chunk of memory.

2004-10-06 – Spamassassin and available memory

It seems like the new Spamassassin 3 has some serious problems relating to memory usage:

7122 root      15   0  660m 332m 4692 D  0.0 43.8   8:18.64 spamd
7123 nobody    15   0  287m 257m 4692 D  0.0 34.0   0:17.01 spamd

As my server “only” has 768MB memory, this causes some problems, in fact, it uses the full 512MB of swap it also has.

This has happened three times in the last hour, and is now getting unbearable.

2004-10-03 – WebDAV

Julien Danjou seems to be looking for “a viable file transfer protocol with encryption support” and mentions that HTTPS isn’t a file transfer protocol. I disagree – if you combine HTTPS and DAV, you have a fairly ok file transfer protocol, which gets rid of a lot of the problems surrounding FTP. Though, you are still stuck with the problem of the user your web server is running as will own all your files. It should be possible to fix, either by doing some apache magic or by using a DAV server which setuid()s to the user doing the access.

2004-09-26 – ARM fun

I’ve gotten my hands on small ARM development board with a LCD touchscreen. It’s a nice piece of hardware, has serial, ethernet and runs on 5V. I’ve gotten the toolchain working nicely on another box (since you really don’t want to compile anything on a 75MHz ARM box with 16MB RAM). Works fine now, and I’m happy, and I hope the owner will be so as well.

I really want to get my hands on one of those boards permanently – there’s a lot you can do with such a small unit which should be able to run on batteries fairly easily.

2004-09-22 – Chasing bugs.

Evolution 2.0 does not work properly on AMD64 in Ubuntu. Tracing this bug, I eventually found out it’s no fault of Evolution. Neither is it the fault of evolution-data-server, which I had the culprit for a long time. It then looked like the bug was in ORBit, which it wasn’t, I was merely confusing myself with debug output.

On returning to evolution-data-server, I eventually found something weird in the file backend. It was, for some reason, unable to open a new libdb database. Weird, I thought. Looked up, and it failed with EINVAL. Googling a bit around, I found out this can be caused by the the usage of the DB_THREAD flag to DB->open. Hacking a bit more around, I found out that evolution at least starts without it. Woo, goodie.

So, how do I make the system support DB_THREAD? Recompile glibc. Of course, enabling NPTL on amd64 causes a whole lot of other failures.

Sigh

2004-09-17 – SVN sucks, again.

Why does Subversion require write access to check out anything of the repository? That’s so totally broken.

2004-08-30 – A followup on the email clients thread - gnus

Some people recommended I take a look at gnus as an IMAP client. I cheated, since I had most of my gnus setup already in place. Gnus is like a battleship – it is big and sturdy, but a bit slow. (It probably didn’t help that I ran it over a forwarded SSH X connection.) It has good IMAP support, it seems.

Gnus also has this excellent concept of “only show folders with unread mails in them”, this means that I don’t get a zillion folders lying about without anything interesting in them. Listing them is a short L away, so it’s not a big issue to find them when you need them. Also, autosubscribing to new groups is easy, just add ^nnimap to the gnus-auto-subscribed-groups variable. It would be nicer if it used the subscribed list from the server, but evidently, it’s not going to do that.

I guess a screenshot is also in order, so you can see how well-ordered gnus is, compared to wanderlust. Gnus screenshot

(And no comments on me having a lot on unread mail, gnus seems to act up a bit until I’ve entered all the folders with it, showing the total number of mails, not the unread number.)