Main | August 2006 »

July 31, 2006

Mirin Sauce

A sweet sauce, with heat depending on the amount of ginger and pepper used. The six tablespoons of liquid should result in sauce for roughly one serving of food. Expand amount of liquids (and the cooking time) as appropriate.

Mix the mirin, herbs, and spices. Reduce until mirin lightly caramelized. Strain out herbs and spices. Add white wine, and cook until reduced by half. Tricky to reduce at first for the unskilled, but fairly easy otherwise. Be careful with the amount of spices, as the sauce will become very hot even with modest amounts of white pepper and ginger. Serve tea or chocolate afterwards, to help reduce the negative effects caramelized sugars have on the teeth.

July 30, 2006

Favorite Piano Music

I played music by all these composers on the piano. Could play the piano well, but never figured out sight reading, so learning new works took months of memorization.

By and large do not like Chopin: too flashy, not enough substance, even in the excellent Piano Sonata No. 2. Similar mixed feelings about Mozart.

July 29, 2006

On Call Fun

Like the circus, except with more animals. On the down side, running systems blind to remote connectivity problems is a Bad Thing. On the plus side, Monorail Espresso serves a great shot on Saturdays, and port checks can be automated with a little bit of Perl and IO::Socket.

July 28, 2006

Regular Expressions poorly match Internet Addresses

Internet addresses (IP) lead to highly complex regular expressions (regex) that attempt to match only valid addresses. Regex deal poorly with number ranges, and must account for optional portions of the IP address. For example, \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} matches the invalid 999.999.999.999 string, and fails to match the valid IP address of 127.1:

$ ping -c 1 127.1 PING 127.1 (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=0.062 ms --- 127.1 ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/std-dev = 0.062/0.062/0.062/0.000 ms

Instead, use a well tested and community supported regex from Regexp::Common or similar module. Another option: perform a loose match, then feed the results through the inet_aton and inet_ntoa functions:

$ perl -MSocket -le 'print inet_ntoa inet_aton shift' \ 127.1 127.0.0.1 $ perl -MSocket -le 'print inet_ntoa inet_aton shift' \ 999.999.999.999 Bad arg length for Socket::inet_ntoa, length is 0, should be 4 at -e line 1.

These functions also provide quick hostname resolution:

$ perl -MSocket -le 'print inet_ntoa inet_aton shift' \ sial.org 69.90.43.86

Matches may also fail if IPv4 mapped addresses appear, for example when performing OpenSSH security checks.

Technorati Tags: ,

July 27, 2006

Fluff

Fluff

Some clouds. Well, a sphere with an expensive volumetric texture.

July 26, 2006

crontab Management Tips

  • Avoid early morning jobs
  • Jobs scheduled to run between 2AM and 3AM may run afoul daylight savings time shifts. This can be avoided by configuring systems to use the UTC timezone, or by more intelligent scripts that try to run multiple times. Something like: “try to run every hour, but only if last good run took place more than 24 hours ago”.

  • Personal crontab file backups
  • If paranoid, backup crontab(5) files to your home directory. This allows a $HOME backup to catch the files, and helps transition jobs to new systems.

    # save crontab(5) 23 23 * * * crontab -l > $HOME/.cron.`hostname`

    This scheme will work on multiple systems, but will fail if two users share the same home directory (bizarre and incredibly rare). Be sure to run Another option: wrap the crontab(1) command to save automatically into another repository. Also consider whether any at(1) jobs need to be backed up, or whether some other utility can regenerate them if lost from the system directory.

  • Use @reboot

    Some crond implementations support @reboot. This may allow jobs to be run when the system starts or reboots:

    @reboot $HOME/bin/do-something

  • Easy e-mail filtering
  • If supported by crond, set a custom MAILTO e-mail address. This allows a single e-mail filter to catch all e-mail generated from cron. Check with your mail administrator for the proper mail syntax to use; some systems use username+detail, others username-detail, and others will need to create a custom e-mail alias.

    MAILTO=username+cron

Technorati Tags:

July 25, 2006

One True Language

As seen in Mordor: the One True Coding Language! Spend a few years on an IRC channel, and experience the stream of “what’s the best language to code with?” questions and resulting hilarity. Ugh.

  • Looking for a job? Pick a language used in the field or company that interests you.
  • Unix systems administration? Learn shell scripting, and try out Perl, Python, or Ruby, and see what you still use five years from now (if anything).
  • Experimenting? Pick something at random. Or at least from a different family of programming: functional versus object oriented and so forth.
  • This language sucks! Patches welcome, or see above.

For the record, I use Perl, plus a dash of Unix shell scripting. Perl suits me perfectly: great for text processing, systems administration, and other random tasks. Huge amounts of code available in CPAN. No need to learn another language for my job (gainful computer entropy reduction), and other projects more important right now.

Next week: the One True Filesystem Layout!

Technorati Tags: ,

July 24, 2006

Being Somewhat Vegan

Thoughts on gainful diet hacking. First! Some food for thought:

Base current diet around the four food groups: fruit, veggies, grains, and legumes.

If humans mindlessly consume milk, why not also pig milk? Suck ’em dry before carving them up. Pancetta in a pig cream sauce with pig noodles (blend pig into slurry, form into noodles). And why stop at pig milk? I’m sure someone can milk a Kangaroo, and there’s lots of those. What would the dairy industry do? Fight the fluid “that’s for baby pigs, unlike milk”, or embrace it?

Baby cow food surprisingly easy to eliminate from my diet. Needless saturated fat, and a strong correlation to diseases I'd rather not suffer. Can get plenty of calcium from veggies and legumes.

Like triple certified coffee? Try triple certified beef!

  1. Sun grown in a clear cut field.
  2. Natural corn and antibiotic diet.
  3. Shipped thousands of miles before consumption.

I’m sure everyone will warm to this, given time. The resulting CO2 certainly has nothing better to do.

Eliminated red meat a while ago: hard to digest, fattening. Other meats more difficult to give up, as need a fair amount of protein due to excerise, and love occasional sushi. Meat consumption now somewhere in the zero to four ounce per week range? Meat spikes in an otherwise mostly vegan diet produce interesting reactions I need to study more.

For B12 and whatnot, take supplements. Wish vitamin makers would use less than +100,000% of the recommended allowances, as the excess just goes down the drain. Some food makers now offer fortified soy, rice, and ceral products that never top 40%. Prefer to get vitamins directly from natural foods, though on-the-job stress and limited foraging time can scuttle that goal.

Avoiding oxolate rich foods, like spinach. Plenty of other veggies out there that lack vitamin and mineral binding support.

Mostly vegan diet gives me more energy (biking again after giving that up for a few years, taken up rock climbing), and appears to grant better tolerance for cold weather. Downside: trouble sitting still for long periods of time. Especially when getting my hair cut.

Seattle great for vegetarians: plenty of suitable restaurants and food sources.

July 23, 2006

Chamber Music

If at all possible, hear string quartets in concert, and sit close to the stage.

July 22, 2006

New Road Bike

Rawal LakePicked up my first road bike from Elliot Bay Cycles, after long addiction to mountain bikes. Tried road bike back in high school, though it was way too large for me. Islamabad had crummy roads, plus the nearby Margalla Hills to bike through, so mountain bike better choice then. Mainly do road commuting inside Seattle now, and spent far too much time in top gear on my mountain bike. Road bike has skinny tires, larger gears, and a good steel frame, and avoids tire/front gear swapping on a single bike. Had to shorten the handlebar stem, probably due to my negative Ape index?

Fun to learn a new bike while commuting through downtown Seattle during rush hour, in spite of some crummy road sections and potholes. Third avenue open only to bikes and buses during peak times, good if you don’t mind dodging between busses instead of random cars going random directions. Going back North from the International district tricky, as either have to head up 4th uphill, or sneak over to 1st or the waterfront via the Pioneer Square area. Waterfront bad for biking North: small bike/pedestrian trail, though has many intersections, and no good way to get up into downtown due to steep or non-existant roads up hill.

Technorati Tags:

July 21, 2006

Rock Climbing 101

Recently took up rock climbing at Stone Gardens. Great introduction and basics classes taught there, in addition to extensive bouldering space for ropeless practice. Can now climb all the V0 bouldering routes except one, and can climb a few of the V1 routes. Think of route climbing as a 3D puzzle with yourself as the puzzle piece.

Fair amount of strength required to climb, though the advanced climbers do not waste strength like the beginners do: straight arms, flowing along the routes instead of clawing their way up. Knowing a few tricks (smearing, swapping feet on nubbins you think cannot possibly hold you, and so forth) helps a lot, as otherwise end up stuck where a route requires a particular move.

Picked up basic set of equipment at REI, on recommendation of their lenient return policy for members. Shoes tricky, as foot should be curved, with toes pointing down, and no spare room up front. Get a stretching book to help avoid injury: moving up a route can strain tendons in unexpected ways.

Technorati Tags:

July 20, 2006

Blue Tree Squares

Treesquared-Blue

Next, a CMYK series! Or maybe EBCDIC.

More grep Tips

In addition to grep -v grep, consider the following Unix shell script improvements when using grep(1), to impress your coworkers or babes:

  • Count matching lines: grep foo | wc -l. Replace with: grep -c foo.
  • Find something, then apply awk(1): grep foo | awk '{print $1}'. Omit the useless grep via: awk '/foo/{print $1}/'.
  • Calculate disk usage: du -k . | grep -v '/.*/' | sort -n. Old shell alias I keep around. Now mostly use my diskusage Perl script, which collects and templates the output from du(1). But I digress.
  • Fun with pipes and remote systems:
  • ssh -n $hostname crontab -l | grep -v somecronjob | \ ssh $hostname crontab -

    Though Configuration Management should be used to edit system configuration, as random shell scripts like this do not handle future systems of the same type, nor account for unavailable nodes. Also, guess what happens when the following script runs multiple times against the same system(s)?

    ( ssh -n $hostname crontab -l cat <<'EOF' # cleanup logfiles poorly @daily find /var/log/foodir -mtime +30 -print0 | xargs -0 rm EOF ) | ssh $hostname crontab -

Now I'm really off topic.

$ exunt stage left

Technorati Tags:

July 19, 2006

Programming Aptitude

The Camel Has Two Humps. Great paper on programming aptitude.

Amazon Groceries First Impressions

Ordered groceries from Amazon Grocery. Quick to ship, and now have handy stash of Clif Bars when trapped at work or biking, and a bunch of ceral boxes to cart home over the next few days. Wacky nuts from the Himalayas taking longer to ship. Disappointing only processed nuts available; would love to order whole walnuts, and process them when needed. Disclaimer: I work for Amazon!

Rhapsody Revisited

Music purchased due to Rhapsody thick client use late 2005 through mid 2006. Cannot use Rhapsody now that I am at Amazon, as prefer the thick client, which requires Windows, which I do not run at home. Also, I buy the actual music, not Digitally Restricted Music (DRM) audio. Rhapsody is great for streaming and finding new music, though one should start with a lossless source, and skip the DRM shackles. Disclaimer: I used to work for RealNetworks.

By way of background, my music tastes run from Bach through bebop to bizarre by way of metal, notably minus certain genres.

Three kinds of music: bad, stream only, or buy. Despise radio, as they either yammer, or worse, put on advertisements. A directed streaming service like Rhapsody lets you control what gets streamed (exactly via playlist, or roughly via radio options), and listen long enough to decide whether to buy or not.

Some online services sell music unencumbered by DRM, though the library sizes and samples did not suit me when I looked at them.

July 18, 2006

Red Tree Squares

Redsquaredtree

Variation on green tree image. Well, shadow of a tree reflecting from a plane with a funky texture on it. Now in red!

July 17, 2006

grep -v grep

In Unix shell scripting, grep -v grep wastes yet another call to grep(1). Some Unix now ship with pgrep(1). If the script requires portability, deal with the vendor ps(1) options (BSD versus SysV), then use a regular expression that excludes grep(1) from matching itself: ps -axo pid,command | grep 'ss[h]'. Another option: first gather the results from ps(1), and loop over them in a while loop. This method avoids false positives on the username or other columns, if only searching the command:

ps -axo pid,command | while read pid command; do # deal with $pid and $command … done

Peruse this and other Unix shell scripting tips.

Technorati Tags:

Tree Squares

Treesquares

July 16, 2006

Recipe Improvements

  • Quinoa Pilaf. For a simple, clean taste, mix freshly ground coriander into oil, coat quinoa well and toast, then cook down in water. Add carots and brocolli near end of cooking with some salt.
  • Tofu Shake. Use white peaches or asian pears when in season.

July 15, 2006

Spring Tree

Recover Deleted Files

Files on Unix may be deleted, but still held open by another process. While most Unix would require a utility to read a file by the filesystem and inode(5) number, the special /proc filesystem on Linux allows the recovery of deleted but held open files:

  1. Use lsof(1) to discover the deleted file, and record the Process ID (PID) and File Descriptor (FD) open to this file.
  2. Recover the file: cp /proc/$PID/fd/$FD /var/tmp/recovered

The deleted file should appear as a broken symbolic link under the /proc/$PID/fd directory. Despite this, /proc still allows the file to be copied elsewhere. For related information, see how to debug Unix systems.

Technorati Tags:

July 14, 2006

Unix Filesystem Tips

On Unix, all filesystem objects are files, including directories, sockets, and other types. The stat(2) manual covers the various file types. Interesting consequences:

  • Directory sizes do not reflect the size of the files inside the directory.
  • Instead, the size of a directory shown by ls(1) reflects the number of files contained by a directory (and the length of the filenames). Consider an empty directory versus one with 10,000 subdirectories:

    $ ls dir* ls: dir*: No such file or directory $ mkdir dir1 dir2 $ (cd dir2 && perl -e 'mkdir $_ for 1..10000') $ ls -ld dir* drwxrwxr-x 2 jmates jmates 68 Jul 13 23:53 dir1 drwxrwxr-x 10002 jmates jmates 340068 Jul 13 23:55 dir2 $ rm -r dir*

  • Files would need an array to store the different hardlink filenames. Instead, these names are stored in the directory, and point to the same underlying inode:
  • $ mkdir dir1 $ cd dir1 $ touch file1 file3 $ ln file1 file2

    Dir-File-Links-2

For more information, I recommend:

Technorati Tags:

July 13, 2006

OS X vs. Windows XP

Initial thoughts on using Windows XP. Long time Mac, Mac OS X, and Unix user, now running with Windows XP laptop at job.

  • Command Line Interface (cmd.exe)
  • Utter joke, compared to the Unix shell. Pitifully difficult to copy and paste data between shell and other utilities. Need to try the CLIP command. Luckily, found zsh for Windows. Downside: no idea where dotfiles hidden on Windows, so configuration will take some time.

    Will also need to patch any number of my 150+ utility ~/bin scripts (of which I really only use around 20 of on a regular basis) to work under Windows, and somehow obtain the required Perl modules for them. On Unix, I simply rsync around the portable scripts and libraries, then use CPAN or the vendor package systems to obtain the required supporting data.

  • Firefox
  • No anti-flash and make-the-page-hold-still plugins installed by default. Need to figure out the desktop system security policy, or otherwise get the help desk to install these.

  • Outlook 2003
  • Calendar nice, though mostly unused by me, as I am not meeting bound. Somewhat easy to setup a Getting Things Done (GTD) method using Contacts and Tasks tricks. Recurring tasks a nice feature. E-mail interface mostly a pain, no threading support I've found yet, text editing clumsy compared with vim. Spent long time finding all the options required to make e-mail mostly readable, as default view emphasizes sender, not subject, and shows a short date.

    Rules support seems extensive, though much time consuming clicking around required. Would prefer procmail style filtering, as have a decade of experience with it, and can easily pipe messages to arbitrary commands and various mailbox formats.

    Slow to display messages, several “Outlook must close now!” crashes. Cannot remember ever having vim or mutt crash on me. Outlook likes to unmark messages as read when moving between folders, or otherwise reluctant to quickly mark things as read. This wastes my time.

Finally found a ClearType utility, to make the fonts look less crummy. No where near as nice as the fonts on Mac OS X. Still need to find a QuickSliver type application.

Dell laptop running Windows XP weak: trackpad pretty much unusable (especially with tap-to-click enabled by default, and no obvious way to disable it), and keyboard nub annoying. Unlike Mac OS X, no double-touch to scroll support. Slow to sleep and wake.

Overall: functional, but nothing special. Extreme virus and spyware threat on Windows stops me from running Windows at home.

July 12, 2006

International District Lunch Options

I recently switched jobs from RealNetworks to Amazon, so now have easy access to the many restaurants in the International District of Seattle. Thoughts on various lunch options:

  • Bush Garden. Excellent lunch sushi special, all around better than Fuji’s (Ahi tuna wonderful, small serving size, lower price).
  • Fuji Sushi. Busy at lunch, bento box too large, and good but not excellent sushi.
  • Isami Restaurant. Part of the Uwajimaya complex. Expensive, but good. Fancy sushi presentations available, but as yet untried by myself.
  • Schezuan Noodle Bowl (8th and King). Still makes great noodles, green onion pancakes.
  • Tropics (606 South Weller Street). Okay Thai food. Only had Pad Thai Something there; Teapot Vegetarian House offers a better Pad Thai Tofu.
  • Vegetarian Bistro (668 South King Street). Pricy and large serving sizes, but otherwise excellent. Need to try the Dim Sum.

July 11, 2006

Earth - dark water

Earth1

Desktop image in use on one of my systems. Two spheres with reflective earth texture on them, and the camera in between.

July 10, 2006

Seattle Coffee Shops

I dislike corporate coffee. Starbucks coffee tastes muddy, perhaps due to the low quality of bean and long delays between roasting and consumption. Luckily, Seattle has no lack of good coffee shops. My current favorites:

Dearly departed: Hines Public Market Coffee from Eastlake. Charming (teetering, unsafe) building razed to make way for … more condos! And probably another Starbucks.

Technorati Tags:

Recipe for World Peace

Not quite what I had in mind…

world-peace-recipe.png

July 09, 2006

Match the first unique character in a string

Possible job interview question:

“Write a program to match the first unique character in a string.”

First, clarify what character means, as a C program without libraries will act differently on Unicode data than other languages might. One solution, using Perl:

#!/usr/bin/perl # # Returns first unique character in a string passed as argument. use warnings; use strict; die "Usage: $0 the string\n" if not @ARGV; my @characters = split //, "@ARGV"; my %char_count; for my $char (@characters) { $char_count{$char}++; } for my $char (@characters) { if ($char_count{$char} == 1) { print $char, "\n"; last; } }

Note the use of warnings, strict, a script usage message, and the quick summary at the top of the script. These enable better code checks, and help people unfamiler with the script or code learn without wasting time looking through the code. Scripts without these elements should be fixed before production use. Avoid bad code from the start by creating a template for new scripts. This template should include standard option handling, leading documentation and license information, and for longer scripts, a perldoc section.

Another challenge: only use a Perl regular expression instead of the data structures shown above.

Technorati Tags: ,

Challenge: write a Perl regular expression that matchs the first unique character in a string. An initial attempt matched a character not followed by itself:

$ echo abc | perl -nle 'print $1 if /(.)(?!.*\1)/' a

However, this expression fails on the string aab. The expression treats the second a as unique, lacking knowledge of the preceding a:

$ echo aab | perl -nle 'print $1 if /(.)(?!.*\1)/' a

This leads to a testing problem: how to identify a successful expression apart from the (many) buggy ones? One solution: test driven development with the Test::More module. Building Testing Libraries discusses testing in more detail. A sample test script:

#!/usr/bin/perl # Test script: regular expression to match first unique character # in a string. use warnings; use strict; use Test::More qw(no_plan); my $regex = qr{ (.) (?! .* \1) }x; while ( my $line = ) { chomp $line; my ( $string, $expected ) = split ' ', $line, 2; $expected ||= q{}; cmp_ok( ( $string =~ m/$regex/ )[0], 'eq', $expected, "$string:$expected" ); } # test string, space, expected character (omit if no match) __DATA__ a a ab a aab b abab

Invalid expressions now quickly show errors:

$ ./regex-test ok 1 - a:a ok 2 - ab:a not ok 3 - aab:b # Failed test (./regex-test at line 15) # got: 'a' # expected: 'b' not ok 4 - abab: # Failed test (./regex-test at line 15) # got: 'a' # expected: '' 1..4 # Looks like you failed 2 tests of 4.

Now other regex can be experimented with. However, I have not yet found a regular expression (excepting, possibly, with (?{code})) that returns the first unique character of a string.

Obligatory Pirate Reference

Pirate movies justify the use of the Unified Modelling Language (UML) like nothing else does.

July 08, 2006

Got blog working.

Finally setup blog for journal type entries unsuitable for posting to the main site. More to come, hopefully.