« February 2007 | Main | April 2007 »

March 27, 2007

ZSH Parameter Expansion

The Z Shell (ZSH) allows complex parameter expansions, well beyond the simple $VARNAME and similar offered in traditional /bin/sh. For example, toupper(3) case changing functionality can be written without calling a program such as tr(1) or awk(1).

$ echo $PAGER less $ echo $PAGER | awk '{print toupper}' LESS $ echo $PAGER | tr a-z A-Z LESS $ echo ${(U)PAGER} LESS

Finding this feature took several minutes pawing through the zshall(1) manual, searching on the word “case”. See also bash2zsh, which includes a ZSH reference card.

Technorati Tags:

March 25, 2007

Recent Readings

March 20, 2007

Fruits And Vegetables

Americans Still Not Eating Enough Fruits And Vegetables according to several new studies. How hard could adding an apple as a snack, a small salad around lunch, and some form of berries after dinner be? I am biased towards apples, as they are readily available in Washington. Any locally produced fruit, the fresher the better, will work.

Down with fast and processed food! However, many lack the time and training to cook food properly. Seattle now has a fair number of “stick this in the oven, then serve” food options, though I have not tried any yet. Also, various International cuisines (Indian, Thai, Chinese) offer tasty variety and good balances of meats to vegetables, for those who eat out more often.

March 19, 2007

Rochberg String Quartets

Greatly enjoy the Rochberg String Quartets Nos. 3-6, especially the variations on Pachelbel’s Canon in D. The opening of Quartet No. 3 and other parts took some getting used to, given my preference for older forms of classical music.

The music also brings to mind work by György Ligeti and the film 天使のたまご (Angel’s Egg).

March 16, 2007

Phthalates & Thermopylae

Phthalates make not for Spartans, as evidenced by the faux hoplites who wade into battle without the required armor (unless the wrestling loincloth grants full body protection) or tactics (well, beyond the first charge).

March 15, 2007

Word Boundaries

Dangers of mixing word characters and boundaries with grammars such as English:

$ perl -le '$_="Can\047t touch this"; print for /\b(\w+)\b/g' Can t touch this

\w can be expanded to [\w\047], or perhaps words where the single quote is somewhere in the middle of the word, plus handling of 'tis and other oddities, if necessary. Caveat Scriptor

On a related note, Link Grammar is worth experimentation with phrases such as “time flies like an arrow”.

Technorati Tags:

March 12, 2007

Supervolcanos, Titanium, and You

Quito

Trace titanium allows temperature tracking of quartz crystallization in the Long Valley Caldera eruption.

March 10, 2007

Constant Dangers

Perl Best Practices (p. 56-57) warns against use constant, and advises using the Readonly module if possible. use constant constants cannot be interpolated, nor can they be created at run time:

use constant ( PI => 3 ); print 'PI is ' . PI . "\n"; use Readonly; Readonly my $PI => atan2( 0, -1 ); print "PI is $PI\n";

Additional dangers of use constant involve open calls that mistakenly pick a file handle name that conflicts with a constant:

#!/usr/bin/perl -w use strict; use constant ( PASSWD_FILE => '/etc/passwd' ); my $tmp_passwd_filename = shift || die "Usage: $0 filename\n"; # … and much later, a nasty bug results open PASSWD_FILE, '<', $tmp_passwd_filename or die "error: could not open: file=" . $tmp_passwd_filename . "\n";

Instead, always use variables to hold file handles, and avoid the risk of a constant name conflicting with a file handle. This method also avoids conflicts between subroutines imported from other modules and constants:

open my $passwd_fh, '<', $tmp_passwd_filename;

Technorati Tags: ,

March 08, 2007

Sue Spammers

A non-technical method to eliminate spam: court victory for man who took on spammers. British man sues spammers, wins:

"The courts have sent a clear message that spam will not be tolerated," he said. "This is not a technical problem, as technical solutions last only so long and will always be overcome. It is a social and legal problem, and we can do something about it."

March 04, 2007

Slow Queue for Spammers

Slow Queue Setup with Packet Filter (PF) illustrates PF queuing rules and supporting scripts and configuration to relegate traffic from spammers into a slow traffic queue.

For more information on blocking spam, visit JunkBusters.com. This site includes resources and information on blocking telemarketing calls, junk mail, junk faxes, and more.

March 01, 2007

MacShogi

MacShogi, coupled with games databases, makes a good study tool for Shogi. Nowhere near the features or computer-assisted learning in Chess programs, though. Additional commentary in the games would be nice, to answer questions such as “why does the rook back up in this situation” or “what is the player trying to do here?”

Darwin Ports hosts a usable compile of gnushogi, which allows graphical play in xshogi, and computer play capable of trouncing the unwary.