fogbound.net




Mon, 1 Sep 2008

Baltasar and Blimunda

— SjG @ 3:56 pm

A translation of Memorial do Convento, written by José Saramago, translated by Giovanni Pontiero, Harcourt Brace & Co, 1987.

I don’t really understand why Saramago’s work is so compelling. And I can’t give a pithy summary as to what this book was about. I could, perhaps, follow the example of countless others and say this book is a love story set in the still-mostly-medieval Portugal of the 18th century, but this would be inaccurate. Yes, there’s the romance between the titular characters, but one that we see as distant outsiders. We know more about the quarrying, transporting, and history of the portico-stone of the Basilica at Mofra or of the peccadillos of the Portuguese royal family than we really do of Balthasar and Blimunda’s love.

If anything, this book is less a romance than a musing on the fundamental inequities of life, a rambling explication of the abuse of power, or a celebration of the lives of simple country folk. Yet these descriptions too do poor service to the book; they leave out the fire, the lyricism, the anger and passion. It’s a powerful monument to the downtrodden and forgotten; a sneer at the Church; an idyll; a history; a tall-tale of music, second-sight, and alchemy.

And, like The Cave (the only other Saramago I’ve read), the language is challenging, funny, brilliant, and the book is hard to stop thinking about.

Filed in:

Fri, 29 Aug 2008

“Save the Planet”

— SjG @ 8:18 pm

Maybe I’m a curmudgeon, but I’m getting heartily sick of the exhortation to “save the planet” (and even the debate about cretinous comments by Rep. Michele Bachmann about salvation).

But here’s the deal — when people say “save the planet,” they don’t mean that. Come on. We puny humans can’t destroy the planet. Sure, we can poison the surface, and make it inhospitable for many of the species who presently inhabit the place (ourselves included). Yes, we can wipe out forests and cause extinctions. But the planet’s been through worse — much worse — and probably will go through worse again.

So let’s can the “save the planet” talk and say what we really mean: preserving conditions that keep us comfortable.

Rant over.


Thu, 7 Aug 2008

Complete Tales of Washington Irving

— SjG @ 10:23 pm

Edited with an introduction by Charles Neider, Da Capo Press, 1998.

(This book is only 798 pages, but I’ve been reading it for over a year. And you thought I’d just given up on posting about books.)

Washington Irving is known for a number of things: being the first professional literary writer of North America, creating of the character Diedrich Knickerbocker (for whom New York is called the Knickerbocker State), originating numerous popular legends (e.g., people though the earth flat until Columbus), and, of course, authoring a few famous stories such as The Legend of Sleepy Hollow, Rip van Winkel, and The Devil and Tom Walker. According to Neider, there was an anti-Irving backlash in the 1930s, which is probably why I was only familiar with the three tales mentioned above.

Irving is an amazing storyteller. Even given nearly two hundred years’ gap, his writing is still crystal clear and humorous and evocative and beautiful. He sketches out the Kentucky frontier, ghost-plagued swamps of New England, pre-Revolutionary War Dutch settlements in New York, medieval Spain, the mountains of Italy, and more with equal skill, each believable and very visually rendered. He tells rip-roaring adventures, satires, or fairy tales in those contexts. Some are simple — predictable, even, twee or corny to the modern reader — and yet the enthusiasm and charm with which he writes them makes it easy to forgive.

What really shines through in this collection of sixty some-odd tales, however, is how much Irving loves storytelling. He likes it so much that many of them are really framing stories, wherein the narrator meets up with some other character who tells a story — which may well itself be a framing story. Sometimes, I found myself popping out of a story-stack five or six deep.

Don’t let Hollywood’s pathetic interpretations sell Irving short. These are a lot of fun to read.

Filed in:

Fri, 18 Jul 2008

Using Regular Expressions for HTML Processing in PHP

— SjG @ 4:16 pm

Well,not really. This is just one example of a bad approach.

The problem: an HTML file is read, but needs to be entity-escaped. However, not all entities need escaping. Specifically, double quotes with anchor tags need to be left alone.

The right solution: process the HTML via a DOM parser, escape nodes that are not anchor tags. Oh, but did I mention these HTML files may be crappy, non-validating files, or even snippets?

The next solution: Use a regular expression. Yes, this is ugly. Yes, it also works 🙂

Originally, I tried using variable-length lookahead, but ran into problems (PHP 4.x). But PHP provides another solution which is perfect for this sort of thing. Here’s the code:

function pre_esc_quotes($inner)
{
return preg_replace('/"/','QUOTE',$inner[0]);
}
function post_esc_quotes($inner)
{
return preg_replace('/QUOTE/','"',$inner[0]);
}
$tmp=preg_replace_callback('/<a([^>]*?)>/s','pre_esc_quotes',$raw_html);
$tmp = html_entities($tmp);
echo preg_replace_callback(('/</a><a([^>]*?)>/s','post_esc_quotes',$tmp);

This, of course, presumes that the string “QUOTE” won’t show up anywhere in your raw html. Consider replacing it with an opaque string (like “JHG54JHGH76699597569” or something creative and long that will choke the interpreter).

This code is furthermore inefficient in a number of ways. It’s not something you should use. But it does show how preg_replace_callback avoids some scary regex work.


Tue, 20 May 2008

Email Round-Robin using Procmail

— SjG @ 2:56 pm

The need arose to have a specific email address round-robin (e.g., cycle through a collection of destination email addresses).

A solution was achieved through use of procmail and a little perl script. It probably could be done more easily and/or better, but I figured other people might find this interesting.

So, first, an alias was created in /etc/aliases (used by postfix in this case, but it should work for sendmail, and variants should work for other MTAs):

rrtest:         |"/usr/bin/procmail -m /etc/postfix/roundrobin_procmail.rc"

Then, the following file was saved as /etc/postfix/roundrobin_procmail.rc:

:0 w:/tmp/rrlock
{
        :0
                dest=|/etc/postfix/rr.pl
        :0
                ! ${dest}
}

And then, of course, we need the perl program. Here’s /etc/postfix/rr.pl:

#!/bin/perl
# ----------------------------------------------------------
@recipients = (
'address1@sample.com',
'address2@sample.com',
'address3@sample.com'
);

$index_file = 'rr-index.txt';

# ----------------------------------------------------------

$index_exists = 1;
open(IN,";
        close(IN);
        $index++;
        }
else
        {
        $index = 0;
        }


if ($index > $#recipients)
        {
        $index = 0;
        }
open(OUT,">/tmp/${index_file}");
print OUT "$index\n";
close(OUT);

print STDOUT $recipients[$index];

exit 0;

Elegant? Not really. But it seems to work 🙂