Here's a short note about this blog. You can syndicate it using my RSS 0.91 or RSS 1.0 feed. Older entries can be found in the archives. I have a home page and another blog in Swedish.

2006-08-21

Combining several images into one PDF document

I had a bunch of scanned hand-written documents in GIF format that I wanted to print two pages per paper. The print dialog in OS X is quite helpful when it comes to printing two-ups, unless you have a bunch of separate documents, just like my scans.

ImageMagick to the rescue! Here's all it took: convert -adjoin *.gif combined.pdf. Sweet.

2006-07-19

OS X launchd not waiting for disks to mount?

If you create a launchd.plist(5) to start a program, make sure that program is stored somewhere on /, else launchd won't find it and the program will not be started, ever.

I'm not sure to how work around this problem, short of installing the program on the root filesystem (or write a second program that sleeps until a certain path appears — which sounds like the perfect job for wait4path(1), but I just can't make it work — and put that program just in front of the first program in a wrapper script that will then start the first program when the given path becomes available; just don't forget to put the wrapper script and the first program on /).

Anyway! I just installed the damned thing I wanted to run in the first place on / hoping this issue will be solved in the future. I'll be a good citizen and report a bug.

2005-06-09

D-Link DFL-200 and packet DUPs

We've had a problem with a D-Link router/firewall. Communication within the DMZ interface was crippled by a lot of duplicate packets while communication to and from other interfaces just worked, and we just couldn't figure out why. After some experimenting earlier today we found out that the problem had to do with the switch connected to the DMZ interface. For some reason the D-Link and the Micronet switch didn't like each other. When we replaced the Micronet switch for a small D-Link switch the problem went away. For the record: the hardware that didn't play well together was a D-Link DFL-200 and a Micronet SP586A EtherFast 10/100 Mbps Dual Speed Hub. The replacement switch that solved the problem was a D-Link DES1005D.

2005-04-18

Testing from the view in Rails

I've been playing with Ruby on Rails for a few days and I must say it's been and still is a great experience. I like the focus on automation, for example by providing the necessary facilities to run unit and functional tests. I've taken the view centered approach in writing some of my functional tests (by means of the REXML-library), because that's one thing that in my experience has been hard to do in other environments. My first reactions are that

  1. it's great to get instant feedback on your actual output, as REXML screams at you if you feed it invalid XML, and
  2. the tests you write tend to be long.

I don't like the second point. Tests should be kept short and simple. Tests should be easy to write and easy to read. A lot of short, simple tests is better than a few big, complex ones.

I suspect the main reason my tests got big is that REXML requires me to verify not only the existence of specific elements but also their location within the XML output. That's not good because changing the layout doesn't necessarily mean changing the behaviour of the app. What I want to verify is that there is a div in my document with certain properties and there is a certain kind of link somewhere inside that div and so on. This is what I came up with to solve the problem:

module XPathExtensions
  def find_elements(xml=nil, tag_spec=nil)
    matched = Array.new
    e = REXML::XPath.match(xml,tag_spec)
    matched.concat(e)

    REXML::XPath.each(xml) { |each|
      arr = REXML::XPath.find_elements(each,tag_spec)
      matched.concat(arr)
    }
    matched
  end
end

I saved the code above in a file called lib/xpath_extensions.rb (I have some unit tests for it as well) and appended the following code to test/test_helper.rb to load the module.

require 'xpath_extensions'
REXML::XPath.extend(XPathExtensions)

Now I can simply call REXML::XPath.find_elements(xml, "a") to get back an array of all links in xml. I'll probably add a few assertions based on this method as well, perhaps something like assert_num_elems_matching, assert_elem_in_elem and so on, which would bring us down to one-liners to verify the existence of specific elements in the output.

I'm not a Ruby expert so the above code might not be the greatest. For one thing, I suppose it's a bit slow. Also, I haven't included the namespace parameter (mainly because I don't use namespaces in my output). It should be a trivial task to add. Finally, there might be ways to accomplish what find_elements does using nice Ruby one-liners or some feature of REXML that I'm missing. I just don't know how.

2005-02-20

Peter on building software

Don't miss Peter's very interesting and constantly ongoing thoughts and reflections on building software and how it relates (and doesn't relate) to brick-and-mortar architecture. For example, take a look at todays topic . There's a lot of obligatory reading over at Tesugen.

2004-10-01

Reading and writing YAML in Objective-C

YAML is a cool thingy and Will Thimbleby has written a YAML-parser in Objective-C. Check it out!

2004-08-18

LaunchBar and Quicksilver

Tomas Jogin has apparently bought a PowerBook and writes about some first impressions. A few commenters raves about LaunchBar and Quicksilver. I've tried them both, like them both and I'm currently using LaunchBar (mainly because LaunchBar is a bit faster on my machine, or at least it was when I last checked).

There's something with Quicksilver however, that I really like, and that is the ability it gives you to form sentences so to speak. You type a (very short) series of letters and voilą: you've created a mail with a file attached to it and sent it off to a few recipients, and it took you almost no time. Doing the same thing the traditional way would have taken a lot more effort using both mouse and keyboard to switch to the mail application and start a new message, find and attach the file, select recipients, and finally send the message.

If find the concept intriguing. What if the operating system could supply this kind of interface to all applications by default? A Finder on steroids! For example, what if the operating system could remember the name and location of all files recently saved by each and every application? Download a file in your browser, bring up the Quicksilver-like sentence builder, find the downloaded file with a few keystrokes and build up sentence to open it in your favorit editor, mail it to a friend or some colleagues, move or copy it to another disk or folder, and so on. The traditional do-it-with-the-mouse-and-keyboard-way would still be there so noone lose; it's a win-win situation.

There are probably a lot of interesting features based on this simple user interface concept just waiting to be exploited.

2004-08-14

Problems mounting and creating disk images after system upgrade

After upgrading my TiBook to Mac OS X 10.3.5 I suddenly couldn't open disk image files (.dmg extension). Couldn't find any solution on the net, but this line from /var/log/system.log gave me a hint:

Aug 13 07:50:51 localhost kextd[84]: a different version of dependency extension /System/Library/Extensions/IOStorageFamily.kext is already loaded

Something seemed to be wrong with a kernel extension. I vaguely remembered something about the kernel extensions being cached. How to update the kernel extensions cache is described here. Simply mark the extensions folder "dirty" by touching it (as root), touch /System/Library/Extensions, and the cache will be rebuilt.

This operation solved the problem for me.

2004-07-22

poll() and EOF

Richard Kettlewell compares how the poll() system call behaves on seeing EOF on different platforms (see here).

2004-07-07

Recent MS patent and viruses

Neil Gaiman writes:

And I see from the Guardian that Microsoft have now patented using the human body as a network. Which, apart from anything, brings a whole new meaning to the concept of viruses.