« September 2006 | Main | November 2006 »

October 30, 2006

Tortillas

A basic tortilla recipe. I prefer whole wheat tortillas, mainly for the extra protein, iron, and flavor. Serves one hungry person, or maybe two.

Ingredients

  • Grains & Legumes

    Cook the rice in advance, as it can be refrigerated and used over the next several days. Aim for dry, well separated rice, as a starchy sticky mass does not fry well. I use brown basmati rice, and often mix in lesser amounts of wild rice or Bhutanese red rice. Toast the oil coated rice with mild spices (coriander, saffron) before boiling it for additional flavor.

    Canned black beans work well, though some canned varieties are worse than others. Buy around and experiment before stocking up. Azuki beans are a great replacement for black beans. Mix 1-½ cups grains and legumes together prior to cooking.

  • Fruits & Vegetables

    Chop around 1-½ cups onion, carrot, and red pepper and mix well. Other vegetables, such as celery or green peas work well. Fresh pressed lime juice is essential, though lacking that, use a small amount of mild vinegar. The lime juice serves two purposes: integrating flavor, and to improve iron absorption, as does the vitamin C from the red pepper.

  • Spices

    I’ve had best luck with a mix of white pepper, black pepper, and ajwain: interesting mix and heat enough for me, without the tasteless burning of hotter spices. For fun, experiment with curry powder or garam masala. Add the spice mix to the oil before adding the vegetables. This helps incorporate the oil soluble spices into the oil.

Method

Preheat skillet to medium high, add some grapeseed (or mild olive) oil, spice mix, then cook the fruit and vegetables briefly with some salt. Add 1-½ cups rice and black beans, mix well. Add fresh pressed lime juice (½ or whole lime, depending on size of lime), reduce heat to low, and cover. By the time tortillas (two to three, depending on their size) warmed in another pan, lime juice should be reduced to almost nothing. If not, remove the cover, and increase heat slightly.

The lime juice may also be added after cooking the filling. This promotes browning reactions the lime juice otherwise prevents while being cooked off.

Technorati Tags:

October 27, 2006

Minimal Perl Review

Reviewed Minimal Perl: For UNIX and Linux People on Amazon. Learned new commands, such as the often overlooked nl(1), and uses for sed(1) and awk(1) had never learned since I started out with Perl.

On a related note, Tim Maher is presenting at Seattle Area System Administrators Guild November 9th.

Technorati Tags: , ,

October 26, 2006

Evil Perl Function Calling

Evil Perl, not for use anywhere near production code. Means to bypass prototype (and strict) restrictions in Perl.

#!/usr/bin/perl -wl use strict; sub noproto { print "Got: @_"; } sub proto($$) { print "Got: @_"; } # fails, as expected #proto(42); { local @_ = 42; &proto; } # these work &proto(42); &proto(); # not happy #&proto 42; # this bypasses 'strict' and prototypes, but adds # 'main' to @_ my $be_evil = 'proto'; main->$be_evil(42); # there we go... __PACKAGE__->can($be_evil)->(42);

Technorati Tags:

October 22, 2006

Music on the Brain

Highly recommend Daniel J. Levitin’s This Is Your Brain on Music. Picked up copy after attending an Amazon Fishbowl lecture on the book: great talk, entertaining speaker.

Interesting trivia: the Catholic Church at some point banned polyphonic music (two voices somehow challenge the unity of God) and augmented fifths (C to F♯ or a tritone or Diabolus in musica). However, the 6% increase in frequency between each semitone of the Western music system makes any sequence such as C-C♯-B-B♯ represent three sixes of change. Diabolus in musica, indeed.

Music by Bach delightfully polyphonic, so will have to research the bans in more detail. Some searching turns up the motu proprio by Pope Pius X on Sacred Music.

October 19, 2006

25 for $25

The twenty-five Seattle restaurants participating in 25-for-25 this November. $25 (minus Wines and other eccentricities) for a prix fixe dinner at a Very Expensive restaurant. Downside: some places get crazy busy during this period, such as Restaurant Zoë. Some venues offer only selected menu items at $25, others rotate the menu items throughout the month.

October 15, 2006

Improve Log Messages

Many programs either contain poor or nonexistent logging, or log so much that any useful messages drown in the noise. This post concerns improving logs generated by scripts running on Unix, which usually suffer from the poor or nonexistent logging. Witness the succinct ! log message from the original ed(1) in contrast to Java stack trace barfs. Middle ground for usable logs can be found.

Technorati Tags: , ,

Hard to Match Messages that lack Critical Information

# Perl to open a named file, # or exit script with error open my $fh, '<', $filename or die "Couldn't open $filename\n";

The above failure log exhibits two problems: the error message is difficult to match using Unix command line tools, and worse, the log omits the system error message contained in the special $! variable (errno in C). Improve the log by omitting the apostrophe, and including the system error message:

open my $fh, '<', $filename or die "could not open $filename: $!\n";

Now the error message can be grepped without special handling required for the apostrophe due to Unix shell quoting problems, and the reason the file cannot be opened will be included.

# the awkward $ grep '^Couldn'\''t open ' script.log # becomes instead $ grep '^could not open ' script.log

Missing Metadata

The use of a script must be considered, as the context a script is run in will change the format of the logs. If the script will run in a Unix pipe chain, include the name of the script in all logs:

open my $fh, '<', $filename or die "$0: could not open $filename: $!\n";

Without this information, the error would be difficult to tie to the specific command:

$ foo-util input | bar-util | zot-util > output bar-util: Could not open /var/empty: no such file or directory

I also recommend each log contain a severity level, such as debug, info, notice, warn, error, and fatal. This information simplifies log analysis, and allows rules whereby all fatal logs page someone, and so forth.

open my $fh, '<', $filename or die "$0: fatal: could not open $filename: $!\n";

Regroup Metadata

Consider moving the $filename away from the log message, and into a metadata section. This improves log message portability, if translating to other languages, and will help future searches of the data by providing more structure to match against.

open my $fh, '<', $filename or die "$0: fatal: could not open: " . "file=$filename, errno=$!\n";

This format suits a log handling subroutine that accepts the severity, log message, and a hash of metadata to display. The log handling subroutine can then add the program name as appropriate, direct or duplicate the logs to syslog(1), or other needs as appropriate. Use the example subroutine as a starting point.

sub remark { my $priority = shift; # string my $message = shift; # string my $attributes = shift; # hash reference chomp $message; my $attr_str; if ($attributes) { $attr_str = join ', ', map { $attributes->{$_} ||= q{}; "$_=$attributes->{$_}" } sort keys %$attributes; } print STDERR "$0: $priority: $message" . ( $attr_str ? ": $attr_str" : q{} ) . "\n"; return 1; }

Example invocation of this subroutine:

remark('debug', 'test message', { pid => $$, line => __LINE__ } );

October 14, 2006

crush-png - handy wrapper around pngcrush

The crush-png script wraps pngcrush, allowing multiple files to be processed with the options I prefer. For GIF, try SuperGIF to compress data. GIF will usually reduce smaller than any corresponding PNG image. On a related note, patent encumbrances recently cleared from GIF.

October 12, 2006

Goji Berries

Discovered Goji Berries in Uwajimaya while looking for snack food. The dried berries have a fairly unique taste, mixing sweet, sour, and other notes. Somewhat difficult to gnaw on dried. Interesting when mixed into oatmeal in place of raisins, very mellow if given time to hydrate.

Other sources recommend mixing them into Chinese style soup somehow, will have to experiment more. Should be great replacing dried cranberries in Couscous Risotto with Maple Syrup.

Technorati Tags:

October 10, 2006

Daylight Savings vs. Cron

“In the U.S., clocks change at 2:00 a.m. local time. In spring, clocks spring forward from 1:59 a.m. to 3:00 a.m.; in fall, clocks fall back from 1:59 a.m. to 1:00 a.m.” — http://webexhibits.org/daylightsaving/b.html

Therefore, Unix systems using a United States timezone that migrates must not run cron(8) jobs between 01:00 and 02:59 in the morning on Sunday, unless those jobs can handle running twice or not at all when daylight savings changes. Consult the page above for rules in other countries, and upcoming changes in the United States.

Audit Unix systems for problematic crontab(5) entries via the following command. Note that hyphens or other special syntax may cause an early morning run without 1 appearing in the hours field for the entry.

$ crontab -l | \ perl -lane 'print "@F" if $F[1] =~ m/1/'

Technorati Tags:

If possible, run systems in the UTC timezone, to avoid daylight savings time flops. Another option: use better scheduling that only runs a job if not recently run. CFEngine, for instance, can avoid the problem by permitting multiple hours under which the command may run, but requiring an interval since the last run to avoid multiple runs during those hours:

classes: time_early_morning = ( Hr01 Hr02 Hr03 ) shellcommands: time_early_morning:: "/path/to/some/command" ifelapsed=1440

That is, attempt to run /path/to/some/command each time CFEngine runs between 01:00 and 03:59, but only if the previous run was over 1440 seconds ago.

At the very least, schedule biannual reviews of the crontab data in advance, and fix any problematic entries, before critical jobs run twice or not at all.

October 09, 2006

Strange Earthquake

Earthquake, or something else? No significant nearby historical seismicity, and depth pretty much at ground level. Brushing off Geodynamics and my rusty math skills yields an explosion of around 51T. This calculation pretty accurate when used against the seismic events resulting from the nuclear tests in Pakistan. To verify my numbers, energy (E) in Joules given by: log10E = 1.44M + 5.24 where M is the magnitude (4.2 in this case). From there, calculate Kilojoules, then work out the volume of TNT by the arms control definition.

Renaissance

Saw Renaissance: mixed feelings, as movie ranges between wooden acting (English voices, not French) and the cliché versus excellent backgrounds, lighting, and vision of a future Paris (where the present day Metro still runs, judging by the rail car noises). Not as captivating as cyberpunk work by Masamune Shirow; would have to watch more film noir to compare in that direction.

October 08, 2006

Perl function calling conventions

Great summary of function calling conventions for Perl.

# disfavored for some reason! push @_, 42 && &churn_away;

Technorati Tags:

Character 2647

Browsing through the Unicode character charts recently, and ran across the ♇ character for Pluto. How should Unicode address the diminished status of Pluto? Maybe make the character a dwarf character? Just wondering.

Technorati Tags:

Amazon おまかせ

Testing Omakase links…

Apparently will display (somewhat?) random links until learns the site and users better?

October 07, 2006

KILL only if not already dead

Process restart scripts on Unix will normally send TERM (-15) signal via kill(1) or kill(2) then move on, or send a brutal KILL (-9). Neither approach should be used: a TERM signal may leave a process running, and a KILL must only be sent as a last resort. KILL prevents cleanup of shared memory, temporary files, and other open resources. Instead, send a TERM signal, then check whether the process has exited properly. If not, only then use the KILL signal.

The following script will help test processing killing code. The script ignores the default TERM signal, requiring some other signal to stop the process, such as INT (-2, or ctrl+c) or KILL. The perlipc documentation contains more information on signal handling in Perl.

#!/usr/bin/perl -l print $$; $SIG{TERM} = 'IGNORE'; $SIG{INT} = sub { print "whoa"; exit }; sleep 3 while 1;

GNU ps contains options to match running processes, such as:

pid_check=`ps ho pid $pid` if [ -z "$pid_check" ]; then echo "info: process not running: pid=$pid" fi

However, these options do not work on other ps(1) implementations. Inspecting the result of kill -0 $pid should be more portable, though must be tested on each new flavor of Unix. Example shell code to kill a process and ensure it exits:

#!/bin/sh # Returns 0 if supplied pid not found, # 1 if still running. Back-off delay # allows slow processes to spin down. confirm_process_exit () { PID=$1 for delay in 0 1 2 3 5 8; do echo -n . sleep $delay if ! kill -0 $PID >/dev/null; then return 0 fi done return 1 } # Kill process, then ensure exits kill $1 confirm_process_exit $1 STATUS=$? if [ $STATUS -eq 1 ]; then kill -9 $1 fi

The Portable Shell Programming book covers ps(1) and other shell portability concerns. If possible, use Perl or another modern language, as the loop handling code around kill(2) will be more testable and portable than the equivalent shell code.

Slow to exit applications will also require special handling, as they may take upwards of a minute to spin down. Java embedded with Oracle… uggh.

On a somewhat related note, ensure new application code load tested before seeing production use. Systems often exhibit unexpected behavior under heavy CPU or memory load.

Technorati Tags: ,

October 04, 2006

Novarupta® Aerosol Spray

If a volcano in Alaska flaps its wings…

October 03, 2006

Napa Wines & Other Fun

Tasted some 25 wines from various Napa dealers over last Saturday. Perhaps too many, though for a first trip on limited time, what can one do? Visited Cakebread, Grgich Hills (yay for grape tasting off the vines), Heitz Cellars, Beringer, Duckhorn Vineyards, and Silver Oak Cellars. Wine ranged from decent but overpriced to amazingly good. Picked up a bottle of Heitz Bella Oaks Vineyard Cabernet for additional study.

Ferry building much more open and focused than eclectic Pike Place Market. Travel light, so only browsed around. Peet's Ferry Building espresso very Italian, with a Double Shot espresso served in a cup, rather than a shot glass. Decent crema, though neither sweet nor robust. Lingered well. Stopped by Spanish Table Berkeley store: much larger, same great selection of Spanish products.

Limón in the Mission area serves excellent drinks, amazing Peruvian/fusion cuisine. Only downside: packed and loud, though it was a Friday. Tartine bakery & café serves excellent French morning fare. For dinner, Breads of India very much worth the wait for dinner (Ajanta promised longer wait at the time, so moved on). Chinese for breakfast at Koi Palace unusual. Arrived early to beat the weekend rush, amazing Dim Sum ensued.

Technorati Tags: ,

Of Dictionaries

Never indoctrinated with American dictionaries, so favor:

  • The Chambers Dictionary. If I only had one English dictionary, it would be this one. Plenty of eclectic words, reasonably portable, and without the mind numbing depth of the

  • Compact Oxford English Dictionary. Now a tall tome, rather than the old two volume set. Comes with half-sphere magnifying glass that must be slid across the pages, and thus hard to magnify definitions near gutter. Eight entries for grue, numerous pages dedicated to salt, and much, much more. :)

  • Dictionary of Imaginary Places. Simply fun to browse!

  • The Dictionary of Lanaguages includes very interesting coverage of world languages. Includes example words for comparison, shows geographic distribution of languages, and many interesting facts. Highly recommended.

  • The Highly Selective Dictionary For The Extraordinarily Literate - good starting point for dictionary searches. Most useful for its word use distinctions.

Use the DICT Development Group or the taxing-on-the-ad-blocker Dictionary.com for online lookups. An OED subscription would be great, though costly…