linux and windows tips, mathematics, and some recipes

Sunday, April 09, 2006

Reviews: Kernighan and Pike, The UNIX Programming Environment

A real classic of its genre, this is the first book ever written on UNIX, published in 1984 and still in print today. While some of the details may have changed, the book remains relevant by expounding timeless principles of good programming practice.

The authors are true gods in the pantheon of computer science. They worked together at Bell Labs in the early days of UNIX and have since been instrumental in the development of computing. Rob Pike co-developed UTF-8 with Ken Thompson and now works at Google. Brian Kernighan[1] co-wrote The C Programming Language with Dennis Ritchie, a book widely regarded as the bible of C. Kernighan is now a professor at Princeton University.

The wit and sagacity of these men is evident in their book. Each new idea is fully reasoned out and they take delight in presenting novel solutions with the minimum of raw material. My favourite example is their 'bundle' shell script from Chapter 3. This is a 10-line program which creates self-extracting archives by using the principle of 'here documents'.

In content, the book is split into two parts. The first four chapters deal with the details of using UNIX: simple commands, the file system, interacting with the shell, pipes, redirection, and a little on awk, grep, and sed. Chapters 5 through 9 are more directly concerned with programming. In particular, shell programming is covered in Chapter 5, culminating in the development of a version control system! Chapters 6 and 7 discuss the stdio library and UNIX system calls. Chapter 8 brings it all together with the implementation of 'hoc', a programmable calculator. Kernighan and Pike take the time to develop it organically, building up hoc from a simple four-function calculator. This chapter introduces the yacc parser generator and the lex lexical analyzer generator. As a matter of historical interest, document preparation using troff is discussed in Chapter 9 — this system is used to create UNIX manual pages.

The only real drawback of this 20 year old book is that some of the examples don't work correctly, or are irrelevant. It is unlikely that you will use the 'mail' command to read your mail, or the 'ed' editor to write your documents. Running 'od -cb .' no longer prints out the contents of the directory-as-a-file. However, these are minor issues. Learning 'ed' is a good introduction to regular expressions, and you may have occassion to use 'mail' in a shell script!

If you only buy one book on the UNIX programming environment this summer, make it this one.

[1] the 'g' is silent

Thursday, April 06, 2006

Internet Tools, Web2.0, and the new Community

Water, water, every where,
And all the boards did shrink;
Water, water, every where,
Nor any drop to drink.

Samuel Taylor Coleridge - The Rime of the Ancient Mariner

Since the dawn of the Web we've struggled to find useful information from amongst the flotsam of irrelevant websites. The first torchbearers to guide us through this mess were search engines, tracing their lineage to the pre-Web Internet. The modern age has sprouted a new generation of tools and services which depend on the collaborative force of diverse users. Collectively, these advancements are being referred to as Web 2.0. Some of the more sucessful manifestations of this ideal include Wikipedia, blogs,, flickr, StumbleUpon, Freecyle, and Slashdot.

These sites broadly fall into two camps: (1) 'Web Finders' deliver up relevant Web pages. Examples are Google,, and StumbleUpon; (2) 'Web Tools' are Internet resources which provide a useful service. Examples are Wikipedia, flickr, and Slashdot. Naturally, there is a certain ambiguity. Slashdot could fall into either of the two camps.

Many of the above examples will be familiar to the majority of users. I'll illustrate Web Finders and Web Tools with two lesser-known examples from each group:


Traditional search engines suffer from one major drawback - they can only show you what you're looking for. In the words of Pablo Picasso, "Computers are useless. They can only give you answers".

We've all had the experience of being alerted to a cool website by a friend or a magazine. The type of website we never would have found by googling for 'cool website'. The point is that we all have a different notion of what is cool. There cannot be a canonical list of great sites that would suit all tastes.

Coming to our rescue is StumbleUpon. You mark the sites you like and those that you don't. Based on your personal preferences, StumbleUpon will suggest sites which like-minded Stumblers enjoy. A simple idea brilliantly executed.


Freecycle is a great example of a global technology acting on a local level. In a sense, it is a marketplace for free goods, bringing together people with things to give away and people in need of those items. I belong to my local freecycle group in Oxford, England. As I'm without a car, Freecycle is a great way for me to get rid of unwanted possessions! When I have material needs you can be sure that Freecycle will be my first port of call.


In all cases, the new breed of websites make positive use of community spirit. In our modern age of nuclear families and increasing alienation, it is as though the Web has stepped into the breach to create new communities of like-minded individuals. Each such community carves out its own slice of the Internet, adding order and cohesion where once there was chaos.

For the moment social networking is in the ascendency, but the one certain truth about the Internet is change. It is unlikely that social networking will disappear, but it will ultimately transform into something else. The leaders of tomorrow's Net will be at the helm of this change.

Wednesday, April 05, 2006

Thunderbird Upgrade Problems - version 1.5

You may have experienced problems upgrading from Thunderbird 1.07 to version 1.5. I did! In particular, upgrading caused failure of Enigmail, and there were issues using the United Kingdom / Great Britain spell checker.

One thing to bear in mind is that you will not have to delete your old Thunderbird profile, which will save much heartache if you can't recover your profile.

If you have problems after installing Thunderbird, follow these simple steps:
  • Start by uninstalling Thunderbird (for Windows users this would involve the Add/Remove programs applet from the Control Panel).
  • Delete the main Thunderbird folder, which should be located at C:\Program Files\Mozilla Thunderbird.
  • Reinstall Thunderbird.
Then reinstall your extensions. If this doesn't work, rinse and repeat.

The spell checker is particularly problematic. I found that the UK dictionary wasn't included even though I chose to download the British version of Thunderbird. Moreover, the spell checker marked every word as being misspelled. You can find the appropriate dictionary from Mozilla's dictionary page. Install the file as you would for any other extension. Note that the dictionary will not appear in your list of extensions. To activate the British (or other) dictionary, go to Tools → Options → Composition → Spelling. Make sure "Enable spell as you type" is checked, then choose the dictionary you want. You may have to restart Thunderbird a few times before the dictionary begins to work properly.

Tuesday, April 04, 2006

Reviews: Bartle and Sherbert, Real Analysis

This is a superb introductory text on real analysis. It is the recommended text for first year undergraduates at the University of Oxford and covers sequences, series, limits, continuity, differentiation, integration, and uniform convergence. There is even a short section on Lebesgue integration.

The book is rigourous yet readable, contains copious exercises and is complemented with short biographies of famous mathematicians, adding a human touch to the proceedings.

The authors eschew the more informal style of some introductory texts and prepare the students for the Definition - Lemma - Theorem technique of higher mathematics. It can be somewhat terse in places, but this has the advantage of focussing the student's mind on the essentials.

Miscellaneous Pages

Mathematics Pages

Computer Pages

Recipe Pages

English-Style American Hamburgers

This is my own take on a classic American dish. I substitute (English) muffins for burger buns and use real cheese instead of American cheese-substitute.

Ingredients (serves two)

  • 250g (½ lb) lean minced beef
  • 1 clove garlic, finely chopped
  • 3 sticks of celery, sliced
  • 4 slices (hand-sliced!) mature Cheddar
  • 1 handful of chopped red onion
  • 2 (English) muffins
  • salt, pepper, olive oil


Gently mix the beef, olive oil (about 1 tbsp), salt, pepper, and garlic in a bowl. Divide the mixture into two balls and press into patties. As with dough making, this is a sensual delight, so enjoy the experience.

Take a skillet of generous size and line it with olive oil. Place the pan on a high heat then add the patties when the oil is hot. You will need to turn the patties once, and be aware that the insides may not be cooked even if the surface is crisp — hence you should keep cooking for about five minutes after the outside seems done.

Prepare the muffins by cutting down the middle and thinly spreading Dijon mustard. Add the cooked patties followed by layers of cheese, red onions and celery. The celery will spill over onto the plate, this provides a little decoration. Now eat with your hands.

Monday, April 03, 2006

Converting DVDs to mp3s

Scenario: you have a DVD and you'd like to make an mp3 of a particular track / soundclip. The simplest solution (especially for Linux users) is to use mplayer and lame, which are freely available and open source.

Basic Ripping

Mplayer will produce a wav file from the DVD, and you can then use lame to convert the wav file to an mp3. The general mplayer command line is as follows:

mplayer $SOURCE -ao pcm -af resample=44100:0:0 -aofile $WAVFILE -vc dummy -vo null

Here $SOURCE is the recording source and $WAVFILE is the output file.
There are many ways of specifying the source. If you wished to record chapters 2 to 4 from dvd title 2, the appropriate invocation would be:

mplayer dvd://2 -chapter 2-4 -ao pcm -af resample=44100:0:0 -aofile outfile.wav -vc dummy -vo null

The final stage is conversion from the wav file to the mp3 file. You do this using lame, and the correct command is:


where $MP3FILE is the desired mp3 file name.

Mplayer and lame are available for Windows, but there may be problems playing the later chapters in a DVD, as there seems to be a 2Gb limit imposed by the underlying software.

If you don't have Linux, it may be better to try a non-free alternative. A search through Tucows comes up with a large array of Windows tools, including "A1 DVD Audio Ripper", "AoA DVD Copy", "DVD Audio Extractor", and many others!

Advanced Ripping

The previous section should be sufficient for most purposes, but there are a few more tricks which may make the process smoother. Linux users can eliminate the need for a large intermediate wav file by using named pipes. First create the named pipe with

mkfifo $WAVFILE

You can now issue the lame command, followed by the mplayer command (preferably on different consoles). Delete the $WAVFILE file once you've finished the process.

Mplayer has a large variety of options. We've already seen how to specify the chapters you want to record. Another alternative is to specify the seek time. For example, to start recording from 1hr 30mins 40s, issue the following command:

mplayer dvd://2 -ss 01:30:40 -af resample=44100:0:0 -ao pcm -aofile outfile.wav -vc dummy -vo null

To find out more about mplayer, read the manual page.

Saturday, April 01, 2006

Moon at St Barnabas

Moon at St Barnabas
Originally uploaded by Gihan Marasingha.
We've spent some time looking at the Moon in Oxford. Here's a calm picture of the Moon sitting by St Barnabas church tower in Jericho, Oxford. This photograph was taken by Maggi and we can see an acacia tree in the foreground.