Friday, May 26, 2006

Firefox and Manpages

I prefer to read manpages in a web browser rather than in a terminal or a text editor. Konqueror formats manpages very nicely [screenshots here], but I use Firefox, and do not use KDE.

I wish there were a Firefox extension to handle manpages in a similar way to Konqueror. Instead, I use man2html. I setup a Smart Keyword so that typing man firefox for example retrieves the manpage for Firefox.

Unfortunately I feel its output is not as pleasing as Konqueror's. As a stopgap measure, I use the Greasemonkey Firefox extension to add some CSS to make the pages more to my liking.

  • script.js: Greasemonkey script that activates every time man2html is invoked on localhost. Adds a CSS file to the page.
  • man2html.css: CSS file that changes the look of the manpages.

Tuesday, April 11, 2006

Web Syndication and Atom Feeds

Due to popular demand ;-) I added a web feed for my blog. [Much to my surprise I discovered today that there is at least one occasional reader of this blog besides me. Thanks for your kind words.]

I experimented with web feeds when I first heard about the Live Bookmarks feature of Firefox. It wasn't so long ago, and the process was straightforward: I created a few RSS 0.91 files, and filled them with bookmarks, each entry using a title, description and link tag.

Now I find that RSS has forked into two different formats, confusingly named “RSS 1.0” and “RSS 2.0”. (In fact, there are more versions of RSS.) A third contender, Atom has surfaced.

It seems Atom 1.0 is the most fashionable choice, so I wrote a script to generate an Atom feed for this blog.

Atom is more complicated than RSS 0.91. Dates must be included and have to be in RFC 3339 format. Unfortunately the date command in Debian stable is too old to support the --rfc-3339 switch, so instead I used

date +%Y-%m-%dT%H:%M:%S%z $* | sed 's/..$/:&/'

Some sort of ID is also required, and I'm not sure exactly what the purpose of this is. The specifications refer to some Internationalized Resource Identifier as defined by RFC 3987 but that's one standard too many for now. At the moment I use the relevant URL as the ID.

Ideally the mime-type of an Atom file should be served as “application/atom+xml”, which in Apache can be accomplished by adding

AddType application/atom+xml .atom

in a configuration file.

In a HTML file, one should add something like:

<link rel="alternate" type="application/atom+xml" title="Title" href="http://some.url/something.atom">

and perhaps also lines like:

<a href="http://some.url/something.atom"><img src="http://some.url/feed-icon-16x16.png" alt="Site Feed" height="16" width="16" /></a> <a href="http://some.url/something.atom">Site Feed</a>

where the feed icons can be downloaded from feedicons.com.

Monday, April 10, 2006

Git and Cogito

Somehow, I have managed to avoid revision control systems until recently. I set it up for a typical reason: I wanted to be able to work on my thesis from different computers without worrying too much about keeping different copies in sync. Also, it's nice to be able to keep track of my progress. I don't expect to ever revert to an older version, but seeing a detailed log of changes makes me feel I've accomplished something.

Perhaps it's a good thing I put off learning about version control for so long. Back when I first thought about using it, CVS was the most popular open-source choice, Subversion was immature, and Linus Torvalds didn't use any system for the Linux kernel.

Now a new generation of source control tools has materialized, and are being improved rapidly. Development of the Linux kernel has benefitted ever since Linus started used revision control systems years ago.

So it seems it is a better time than ever to delve into version control. The old systems were plagued with various flaws and annoyances. The latest systems resolve these issues, but I wouldn't know. I never used the older systems so I have no idea what the problems were.

Things have gone smoothly for me with Cogito (basically some shell scripts based around Linus Torvalds' git tool). Even though it's designed to be a distributed source code management tool, it works well for one person editing a few files.

The only problem is that I can't easily host the repository on my Debian-stable server since git is too new, though Debian backports exist. I could just use rsync, but this method is deprecated and highly discouraged. [Also explained in this git tutorial; search for “rsync”.]

Monday, March 27, 2006

Mathematical Go

I was taught to play go as a child, but it wasn't until a few years ago that I learned how complex the rules are, at least the ones used in tournaments. I had previously thought the rules were elegant and simple.

Actually, mathematicians have devised elegant and simple rules of go. [Broken? archived version] Unfortunately the mathematical rules are rarely used. Instead, there are several popular rule sets with different properties.

Luckily in most games the complicated cases never arise, but it is irritating to know that in general, the outcome of the game can depend on the legality of suicide, and in many cases it is unclear whether a group is live or dead if the mathematical rules are not followed. [Link broken; the FAQ can be found in the nextgo package.]

Evidently when the game was first invented, nobody thought about the messy corner cases. It seems as each one was discovered, an ad hoc solution was proposed, and over time these cumulative patches to the basic rules eroded the austere grace of the game.

As one might expect, starting afresh and approaching the game from a mathematician's point of view not only restores clarity and precision, but also yields unexpected results. For example, Berlekamp and Wolfe describe bizarre positions where highly nonintuitive moves are required to win. Even though such situations never occur in real play, studying them hints at the richness and depth of this ancient game. Unsurprisingly, it was a mathematician who first drew my attention to the flaws in traditional go rule sets!

I am not sure why the mathematical rules have not caught on. Are they too difficult to implement in a tournament? Is the grip of tradition is too strong? Or is it simply that most in the go world are unfamiliar with these recent developments?

Sunday, March 26, 2006

Blog Basics: Permalinks

I wrote some scripts to add permalinks, which a typical blog should have. I can understand why many people use dedicated blogging software, but I'm content to reinvent this wheel, as I'm comfortable with, and even enjoy, writing shell scripts. I also have more control this way.

I have one directory for every date I've posted. Inside there is one file per blog entry, containing an HTML snippet with the title in a h2 tag, and the date within a h3 tag. One script converts this to a page to be permalinked, while another pastes the entry into the main blog HTML files.

Inspired by the official Google blog, the permalink's filename is the title converted to lowercase with spaces converted to dashes, and all other characters removed.

I should eventually look into how the popular blogging software organizes things, but this scheme appears to work well.

Tuesday, March 14, 2006

Geometry Algorithms

Happy Pi Day!

Once in a while I visit ACM Programming Contest Problem Set Archive. Reading and trying out a problem or two reminds me of a time when I was eligible to compete. But mainly it makes me realize how little I knew back then, and how much I still can learn. For example, as mentioned in a previous post, I only came across the Dancing Links algorithm recently which comes in handy for several contest problems.

Many problems require simple geometry algorithms. Back in the day I thought I could derive what I needed on the fly for these sorts of problems. I still believe inventing algorithms is a good thing to do, but at some point one should learn what has been done before, as it is easy to miss clever and elegant optimizations.

For example, consider the simple problem of determining which side of a line a given point lies, where the line is defined by two given points. In the past, I would have naively computed the equation for the line and substituted the point in to see which side it lies on, but now I know that it is much easier to calculate the signed area.

Friday, February 17, 2006

Calculus Using Infinitesimals

I only recently became aware that it is possible to formalize the methods that Newton and Leibniz first used when developing calculus. In fact, not only is it possible, but it is quite easy to understand, and the notation is more elegant than those of limits.

I had always looked down on the pseudo-proofs I was shown in physics lectures, handwavy sloppy arguments that defied the rigour and precision that centuries of mathematics fought for. I tolerated them because I needed the results. But it seems with a few definitions, you can have your cake and eat it.

One introduction to this subject is a free online book: “Elementary Calculus: An Approach Using Infinitesimals” by H. Jerome Keisler.