Archive for the 'Programming' Category

Write Small But Useful Programs Every Day

Tuesday, March 7th, 2006

I recommend writing small but useful programs every day. Never mind that someone has written the same or better once. They are not you. You must feel the utility of your own programs to gain a sense of balance between that and complexity.

WardCunningham

Sage advice found here while getting distracted from my main purpose.

Fixing Eclipse 3.1.2 for Debian 3.1

Saturday, March 4th, 2006

The easiest solution is to download the source for the whole of Eclipse, comment out lines 914-916 of plugins/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java then build the whole thing as per instructions here.

No doubt there is a way of just re-building SWT from scratch but I couldn’t work it out.

Irritating Eclipse Bug in Debian

Friday, March 3rd, 2006

I thought I was going mad the first time the Delete key stopped working in Eclipse. This evening (early morning) the Control and Alt keys stopped working.

A quick browse through the readme revealed that this is a known bug:

Key bindings stop working (GTK+ only)
When using Eclipse, most key bindings will stop working. The only way to make the keys start working again is to restart Eclipse. This problem occurs on Debian, using libgtk+2.0 (2.6.4-2 or later). The problem is that a focus issue exists in GTK+ 2.6.7 and earlier, for which SWT has a workaround. This workaround is incompatible with the fix in GTK+. SWT detects the GTK+ version on start-up and decides whether to enable the workaround. Debian backported the focus fix into their libgtk+2.0 (2.6.4-2) package. To workaround this problem, either get the Debian unstable version of GTK+, compile your own GTK+ or hack Shell.gtk_realize(int) and change the version it checks. Please see either Eclipse’s or GTK+’s bugzilla for more information.

Coming on top of a dying mouse that re-interprets single clicks as double clicks at the most inappropriate moments, I’m beginning to think that my machine hates me…

Still, while looking online to verify that I wasn’t going insane, I stumbled upon the following useful Javaworld article: Become an Eclipse Hotkey Showoff. My favourite is “Hippie Completion” - just for the name. Once I get the control keys working reliably on my keyboard again I’ll have to try it

Stack-Based Arithmetic on Linux

Saturday, December 3rd, 2005

I’ve just discovered that you can run ghostscript in a no display mode from the console and use the interpreter as an environment to perform stack-based arithmetic.

tim@withnail:~$ gsnd
GPL Ghostscript 8.01 (2004-01-30)
Copyright (C) 2004 artofcode LLC, Benicia, CA. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
GS>2
GS<1>3
GS<2>stack
3
2
GS<2>add
GS<1>stack
5
GS<1>10
GS<2>mul
GS<1>stack
50
GS<1>quit

stack displays the stack, entering a number pushes it onto the stack, pop removes the top item, add / div / mul / sub remove the top two operands, and add them / divide them / multiply them / subtract second from first then return the result to the stack.

More info here.

One for computer science geeks only.

Take a Minute to Vote Against Software Patents

Friday, November 25th, 2005

You can help bring about greater public awareness of the dangers of software patents by voting on the following two sites:

[Pasted from a ffii.org newsletter]

Today we would like to bring two more online polls to your awareness:

- Corporate Europe Observatory, an organization that keeps an eye on
questionable lobbying tactics, has nominated the so-called Campaign for
Creativity, a Microsoft/SAP pro-patent lobbying entity, for the “Worst EU
Lobbying Award”: http://www.corporateeurope.org/worstlobby/?showcontender=1
“Nominated as a fake NGO brilliantly disguising corporate demands as
grassroots concerns”

Please vote “for” the so-called Campaign for Creativity:
http://www.corporateeurope.org/worstlobby/?vote=1 If they “win”, i.e. if that
campaign is chosen as the worst lobbying initiative in the EU in 2005, then
there will be some additional attention to the methods employed by the
pro-patent lobby.

- IT website Silicon.com, which belongs to the CNET network of IT websites
(ZDNet, News.com, Builder.com etc.), recently named Florian Mueller, the
founder of NoSoftwarePatents.com, among the 50 “Silicon Agenda Setters”. As
always, Florian himself has pointed out that he owes such nominations to our
entire movement.

There is an online poll in which Silicon lets its readers determine their
own ranking among the top 50 people in the IT industry:
http://www.siliconagendasetters.com/vote.htm

Florian is #43 on the ballot, or the 8th from the bottom of the list.

Visit The Foundation for a Free Information Infrastructure (FFII) if you’d like to know more.

Writing Unmaintainable Code

Wednesday, November 23rd, 2005

Bedazzling Names
Choose variable names with irrelevant emotional connotation. e.g.:
marypoppins = (superman + starship) / god;
This confuses the reader because they have difficulty disassociating the emotional connotations of the words from the logic they’re trying to think about.

How To Write Unmaintainable Code offers amusing advice for programmers looking to guarantee a lifetime of employment maintaining their own inpenetrable code.

The Mechanical Turk

Tuesday, November 22nd, 2005

Amazon have taken the idea of outsourcing tasks at which a human outperforms a machine (eg image recognition) and building an API to a marketplace that makes these jobs available and retrieves the results. They call this the Mechanical Turk after Wolfgang von Kempelen’s 1769 pseudo-mechanical chess-playing automaton. Coders can call the Mechanical Turk with a query as though it were a normal RPC request.

It’s a fascinating concept with all kinds of political ramifications I don’t want to think about right now. Read more about the technology side of it here.

Sorting Audio Tracks on the Zen Nano

Tuesday, September 20th, 2005

Podcasting is overrated but I am addicted to IT Conversations.

I’ve been looking for a portable MP3 player that works well with linux for a long time. I wanted something small and light, with long battery life and a backlit display that shows the file name. I wanted to be able to mount the file system and copy files across directly as well as the ability to delete files on the device itself. One gigabyte seemed the ideal size: just enough space to squeeze a few albums in as well for when I need a break from the spoken word.

Finally I’ve found the ideal player for my needs: the 1GB Zen Nano Plus.

Creative Zen Nano Plus

It’s very small, fitting into that tiny jeans pocket for which I’ve never previously found a use. It runs around 18 hours on a single charge, takes AAA batteries, supports drag and drop and uses USB 2.0. (It has a number of extra features too like radio, direct encoding to mp3, voice recorder etc that I do not want or need but one never knows when they might come in handy).

It might lack the smooth finish of an Apple device but it is perfect for my needs. It’s small and light enough to take anywhere and not notice you’re carrying it. Now I can make the most of otherwise dead time spent travelling, queuing, shopping or waiting.

Ordering Tracks
Albums are defined by folders. However, tracks within each album/folder play in alphabetical order rather than track number order. To get round this, the supplied Windows software from Creative manipulates the file names:

When you sort your audio files using ID3 tags, Zen Nano Media Explorer adds a 3-digit prefix (a number from 000 to 999) to each filename. For example, Song 1 is renamed as 001_Song 1.

(From the Creative Windows help files)

Since I’m using linux, I’ve written a quick and clumsy bash script that does the same thing: nanoplaylist.

After ripping a CD to mp3s, cd to the generated directory and run the script to rename each file appropriately.

eg

tim@withnail:~/mp3/WAITS Tom/Small Change$ ls
WAITS Tom - Bad Liver And A Broken Heart.mp3
WAITS Tom - I Can't Wait To Get Off Work.mp3
WAITS Tom - Invitation To The Blues.mp3
WAITS Tom - I Wish I Was In New Orleans.mp3
WAITS Tom - Jitterbug Boy.mp3
WAITS Tom - Pasties And A G-String.mp3
WAITS Tom - Small Change.mp3
WAITS Tom - Step Right Up.mp3
WAITS Tom - The One That Got Away.mp3
WAITS Tom - The Piano Has Been Drinking.mp3
WAITS Tom - Tom Traubert's Blues.mp3
tim@withnail:~/mp3/WAITS Tom/Small Change$ nanoplaylist
tim@withnail:~/mp3/WAITS Tom/Small Change$ ls
001_WAITS Tom - Tom Traubert's Blues.mp3
002_WAITS Tom - Step Right Up.mp3
003_WAITS Tom - Jitterbug Boy.mp3
004_WAITS Tom - I Wish I Was In New Orleans.mp3
005_WAITS Tom - The Piano Has Been Drinking.mp3
006_WAITS Tom - Invitation To The Blues.mp3
007_WAITS Tom - Pasties And A G-String.mp3
008_WAITS Tom - Bad Liver And A Broken Heart.mp3
009_WAITS Tom - The One That Got Away.mp3
010_WAITS Tom - Small Change.mp3
011_WAITS Tom - I Can't Wait To Get Off Work.mp3

The script assumes that you have not modified the mp3s since you ripped them and that your software has ripped them sequentially, first track first. Download nanoplaylist here.

Hans Reiser in Interview

Wednesday, September 14th, 2005

The things that don’t make sense are the most important data collected. Time and again, getting to the bottom of a minor performance anomaly that should not exist reveals a design flaw or failure in my understanding, and curing it leads to an advance in our performance that was well worth having. Time and again I have learned the importance of not letting any code go in without benchmarking it. Things that could not possibly affect performance, do, over and over again, and if you don’t catch it immediately, you might never catch it.

Hans Reiser in interview shares some of the most important lessons he’s learned in his career as a software developer/architect.

Accelerated C++ Student Grading

Friday, July 22nd, 2005

I’m teaching myself C++ with Koenig and Moo’s “Accelerated C++” at the moment.

I haven’t found a book such slow going since struggling through Kant’s “Introduction to the Metaphysics of Morals” as an undergraduate. I should perhaps have chosen a gentler introduction to programming but, from what I have read elsewhere, this is regarded as the best book on the language and I’d rather learn slowly from the best than race through easier texts, picking up bad habits that will later need to be unlearned.

Exercise 5-2 asks you to compare the performance of two student-grading programs, one using vectors, the other lists, against records of different lengths.

I’ve generated some data files to represent student records and am sharing them here in case anyone else wants to use them. They are plain text files. Each line gives a name followed by a list of 10 numbers between 30 and 90 that represent the student’s grades. (NB assuming a pass mark of 60, about half the students fail their course using this data set).

There are four files listing 10, 100, 1000 and 10000 sets of names and results. Download the tarball (linux/unix) containing all four and unpack it with tar -xvzf students.tgz. I’ve also created a zip file for Windows users. Mac users I believe should be able to handle either version. Please let me know if it doesn’t work.

Feel free to use them and save yourself the hassle of generating your own.

(UPDATED: 22 July)