Pattern Substitution as Funky Iterator

I have a project in which I have a row of cells, and a number of segments of given lengths, and I need to try out all of the ways in which the segments can fit into the row. If you like, think of it as: how many ways can “eye”, “zygote”, and “is” be placed, in that order, on a row of a Scrabble board?

I’m doing this in Perl, so naturally I’d like to play to Perl’s strengths (pattern matching and substitution) rather than its weaknesses (arithmetic). And I’ve discovered a nifty little hack.

Continue reading “Pattern Substitution as Funky Iterator”

Why Name A Newspaper After an Insect?

One question that’s been bugging me (sorry for the pun) is why any newspaper would call itself the “Town Name Bee”. Thankfully, the Sacramento Bee has an explanation (summary: the bee represents industry, as in “busy as a bee”).

Naturally, if I point out that there’s a town in Arkansas called De Queen, you won’t be surprised to learn that its newspaper is De Queen Bee.

Truncated Songs on iPod

Every so often, I’ll update the MP3 file for a given song. For instance, if I record an LP to MP3, then buy and rip the CD, I’ll just update the MP3 file on the back end and tell iTunes to reread it (with open -a itunes /path/to/file.mp3, for those who care).

Unfortunately, when I do this, I’ve noticed that iTunes plays the new file properly, while the iPod tends to hang a few seconds befor the end of the song, or, in more extreme cases, reset itself.

Continue reading “Truncated Songs on iPod”

Making Emacs Do Stuff at Startup

Like many users, I start an emacs session in .xinitrc and use it throughout the day. Since I’ve recently started using Emacs Planner, I wanted it to start up automatically in that first Emacs session (but not subsequent ones, if I just want to edit a file).

Continue reading “Making Emacs Do Stuff at Startup”

How to Prevent Lines from Wrapping in Emacs

By default, Emacs’s buffer list truncates lines at the right edge of the screen: if you’re editing a file with a long name, it doesn’t wrap around; you have to use C-x < and C-x > to scroll the viewport left and right.

I’d always wondered how to do that, since it can be useful when editing files like ~/.ssh/known_hosts, where the useful information is at the beginning of the line, and the wrapped keys get in the way.

Now I know:

(setq truncate-lines t)

Removing Accents in Strings

I’ve been ripping and encoding a bunch of music. Since I’m a hacker, naturally I have scripts that take a file with artist, album title, and track titles, and finds the corresponding .wav or .aiff source files, encodes them as MP3 and tags them.

A lot of the music I have is in French or German (and some Spanish and Russian), so there are accented letters in names and titles. My input files are in UTF-8 format, so that’s cool. But one problem is that of generating a filename for the MP3 files: if I want to play the song “Diogène série 87” by H.F. Thiéfaine on his album “Météo für nada”, I don’t want to have to figure out how to type those accents in the file and directory names. I want the script to pick filenames that use only ASCII characters.

Continue reading “Removing Accents in Strings”

How Do You Spell the Names of the Months?

One construct that I’ve seen (and used) a lot in Perl is a hash that maps month abbreviations to numeric values that can be fed to POSIX::strftime:

our %months = (
    "jan" => 0, "feb" => 1, "mar" => 3, ...

This is useful for parsing log files and such. It works, it’s quick and easy, and it doesn’t require a whole tree of dependent modules (which are always on the wrong side of the Internet) to be installed.

But what’s always bugged me is that this is the sort of thing that the machine ought to know already. And besides, it’s US-centric: what if the person running the script is in a non-English-speaking country?

Fortunately, I18N::Langinfo knows the names of the months. Continue reading “How Do You Spell the Names of the Months?”

iTunes Podcast Problem Solved

I’d been having an annoying problem in iTunes 7.0.2: although I’d set the podcast preferences to “Keep: Last 5 episodes”, it was still keeping old episodes around, long after they should have been deleted.

After rooting around in Apple’s discussion fora, the solution turned out to be:

  1. Select “Podcasts” in the left bar
  2. Select everything with Apple-A
  3. Right-click (or Ctrl-click, for a one-button mouse) on the mass of selected episodes, and select “Allow Auto Delete”

When I next updated the podcasts, it deleted the old episodes, just as it should have. Presumably some podcasts or episodes got marked as “Do Not Auto Delete” somehow, perhaps when I upgraded iTunes, or moved stuff from the old Mac.

The annoying part is that there’s no indication in iTunes that Auto Delete has been disabled. That seems like just the sort of UI thing that Apple would have added, given that there are a zillion other status indicators.

Update, Dec. 2, 2006: Apparently when you click the “Get” button to manually download a podcast episode, it is automatically (and invisibly) marked as “do no auto delete”.

Typically this happens to me when I subscribe to a new podcast: iTunes downloads the latest episode automatically, but I normally download several more, in case I like it. Those episodes don’t get deleted automatically.