Monday, 12 November 2007

Flaubert's elephants

The Carthaginians did use elephants in their army, but those beasts were difficult to handle. Here's what Livy says about their drivers:

More elephants were killed by their drivers than by the enemy. They had a carpenter's chisel and a mallet, and when the maddened beasts rushed among their own side the driver placed the chisel between the ears just where the head is joined to the neck and drove it home with all his might. This was the quickest method that had been discovered of putting these huge animals to death when there was no hope of controlling them, and Hasdrubal was the first to introduce it. -- Livy, XXVII, 49

Also, in Salammbô, we read:
He [Hamilcar] organised a phalanx of seventy-two elephants with those which had returned from Utica, and others which were private property, and rendered them formidable. He armed their drivers with mallet and chisel to enable them to split their skulls in the fight if they ran away. -- Flaubert, Salammbô, VIII

Hasdrubal is the son of Hamilcar, and the brother of Hannibal. Flaubert's novel takes place during the Mercenary War (circa 240, Hasdrubal was probably not yet born), and the Livy quotation refers to the Second Punic War, more precisely to the Battle of the Metaurus (207) -- that is, afterwards.

In other words, Flaubert is guilty of anachronism. But he was certainly aware of that, and favored the literary effect over the historical accuracy.

Saturday, 3 November 2007

Hannibal and the vinegar

How Hannibal Barca and his army crossed the Alps to go in Italy to fight against Rome:

At last, when men and beasts alike were worn out by their fruitless exertions, a camp was formed on the summit, after the place had been cleared with immense difficulty owing to the quantity of snow that had to be removed. The next thing was to level the rock through which alone a road was practicable. The soldiers were told off to cut through it. They built up against it an enormous pile of tall trees which they had felled and lopped, and when the wind was strong enough to blow up the fire they set light to the pile. When the rock was red hot they poured vinegar upon it to disintegrate it. After thus treating it by fire they opened a way through it with their tools, and eased the steep slope by winding tracks of moderate gradient, so that not only the baggage animals but even the elephants could be led down.
-- Titus Livius, XXI, 37

Yes, vinegar. I'm full of admiration for this legendary hack.

Tuesday, 30 October 2007

Ubuntu, Dell laptop and hard disk power management

There has been some talk those days on laptop hard disk lifespan. See, for example, what Pascal says about it.

So, after some investigation, I saw that on my laptop (Dell Latitude D420) the BIOS doesn't handle an APM value of 255. By default the startup scripts execute hdparm -B 255 /dev/sda (or other devices) and that actually sets the APM value to 128 (as given by hdparm -I /dev/sda | grep Advanced). (I'm using Ubuntu 7.10 -- the script I'm talking about is /etc/acpi/power.sh.)

On the other hand, using -B 254 seems to disable APM. So here's a way to do it, by default, on every boot:

  • Add those lines to /etc/hdparm.conf:
    /dev/sda {
    apm = 254
    }

  • Make /etc/init.d/hdparm run at startup:
    ln -s /etc/init.d/hdparm /etc/rcS.d/S07hdparm

And now the load cycle count reported by SMART remains stable. Which means that hopefully my hard disk will live longer.

Addendum: if you don't use SMART, you should. Install the smartmontools package, enable SMART on your disks with smartctl -s on, and read the smartctl(8) manpage. Optionally, enable the smartd monitoring daemon (via /etc/default/smartmontools).

Wednesday, 24 October 2007

urxvt + perl

I'm playing with urxvt (a.k.a. rxvt-unicode), a fully Unicode-aware terminal forked off the popular rxvt.

One of the good things with it is that it's fully scriptable in Perl. Here's my first attempt, a small plugin that adds an item in the popup menu (given by the standard Perl plugin selection-popup) to draw in bold font whatever matches the selection. It's not extremely useful, but that's a start.

our $selection_hilight_qr;

sub on_start {
my ($self) = @_;
$self->{term}{selection_popup_hook} ||= [];
push @{ $self->{term}{selection_popup_hook} },
sub { hilight => sub { $selection_hilight_qr = qr/\Q$_/ } },
sub { 'remove hilight' => sub { undef $selection_hilight_qr } };
();
}

sub on_line_update {
if (defined $selection_hilight_qr) {
my ($self, $row) = @_;
my $line = $self->line($row);
my $text = $line->t;
while ($text =~ /$selection_hilight_qr/g) {
my $rend = $line->r;
for (@{$rend}[$-[0] .. $+[0] - 1]) {
$_ |= urxvt::RS_Bold;
}
$line->r($rend);
}
}
();
}


As you can see, this code is pretty small (although not very readable maybe -- I dislike using @+ and @-, but my urxvt isn't compiled against a Perl 5.10 :).

Well, I'm now looking for ideas. What would be cool for a terminal to do for you (and that urxvt doesn't already provide?)

Monday, 8 October 2007

New camera

I just got a new camera, a brand new Canon PowerShot A720 IS. Very nice compact camera. Great optical zoom (6x). Possibility of manual settings. Nice UI (so far). There's no detailed user manual, though -- I still need to learn how to program my modes, etc.

I spent my sunday playing with it. I've uploaded a couple of shots to flickr -- more, of course, are to follow.

Thursday, 6 September 2007

French Perl Workshop 2007

I signed up for the French Perl Workshop 2007 in Lyon, and I proposed two talks: one on the new shiny stuff in Perl 5.10, and a smaller one on encoding::source, one of my scary modules. (I had this last idea while giving an impromptu presentation of encoding::source at the latest Amsterdam.pm meeting last Tuesday.) By popular demand, my presentations will be in French. See you there.

(Now I have to write slides...)

Wednesday, 5 September 2007

Blue versus Pink

Baignade autorisée Found via slashdot, an article on Bad Science criticizing a research in evolutionary psychology about why boys prefer blue, and girls pink. The author says, and rightly:

The “girls preferring pink” thing is not set in stone, and in fact there are good reasons to suspect it is culturally determined.

And then he gives examples. But if I may add another remark to his rant: it turns out that the categories of blue and pink are also culturally determined. Actually, the colour blue didn't even exist as a separate entity before the Middle Ages. Ancient Greek, for example, does not have a word for blue, and Homer speaks about the wine-coloured sea.

I think that the study of colours and their perception is more a subject for historians than for biologists or physicists. On this subject, one of the best books I've read is Blue, the History of a Color, by Michel Pastoureau, in which the last chapter briefly talks about the very recent (and very occidental) association of blue and pink to boys and girls, respectively.

Tuesday, 28 August 2007

On Gravitas

Gravitas is a novel by S. Christopher, centered around a character named Ben, and his evolution at the edge of his thirties. In a few words, Ben lives in a medium-sized American city (that could be Portland, for instance); he's a senior programmer in a small software company; he has a geeky housemate.

The novel has no other real purpose than to depict Ben's life and mind. That has shaped the narrative style, which proceeds by an accumulation of scenes, not necessarily in chronological order, rather than by a well-formed, developing plot. Ben is, by many criteria, successful, but by other traits, he's not strictly in tune with his environment: sometimes he appears to shift by a half-tone, maybe more, leading him to be a spectator of himself (and others). The love (and pain) that a girl will inflict on him will force him out of his shell, at least for a period, and he will live this event as a small, strange trauma, maybe the first of his life, not counting his own birth.

Minor themes are recurrent through the book, indicating that it's better constructed than it would be obvious at a first glance.

One of those themes is the disappearance -- of days, people, words, that seem to slip through Ben's memory, as if reality wouldn't let itself be captured easily as a mind representation, by someone who is reluctant to engage in it fully.

Another theme might be abstraction. I don't find a better word for that capacity -- or defect -- that some people have, to perceive things through an emotionless prism, like one would look at a piece of software, including oneself.

The author uses a dense, rich form of English, full of images. This prolixity suits well the introspective nature of the book.

I enjoyed Gravitas. On an ideal shelf, it would be between P.K.Dick's non-sci-fi novels and Meredith's Egoist.

Monday, 6 August 2007

mysql command-line tricks

I use the MySQL shell a lot. A couple of tricks can make it more usable:

First, prompt customisation. I work with lots of different databases on different hosts. So, I customised my prompt via an environment variable:

export MYSQL_PS1="\\d@\\h> "

This makes mysql display the database name and the hostname instead of the fixed string "mysql":
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 143955 to server version: 5.0.27-standard-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

test@counterfly>

Secondly, readline configuration. When editing long SQL statements, I prefer to use vi-like keybindings. That can be selected by adding the following lines to your ~/.inputrc file:
$if Mysql
set keymap vi
set editing-mode vi
$endif

You can then navigate history and edit like like you would do (almost) in vi. See your readline manual for more details.