« October 2007 | Main | December 2007 »

November 24, 2007

Random Tea Research

Originally planned an article on tea temperature testing, but found interesting background material along the way:

Back to the topic of tea temperatures: tea brewing charts are available online, though none cite how they derived or tested their numbers, and different charts show a wide range of acceptable temperatures, time, and tea amounts…

Technorati Tags:

ShUnit - shell code unit testing

2008-05-11 update: shUnit2 is a unit testing framework for shell scripts modeled after the JUnit framework. It is designed to make unit testing in shell as simple as possible. I have not had a chance to review it yet, though may serve shell unit testing needs better than ShUnit (detailed below) does.

ShUnit is a unit testing framework for Bourne shell code. It does not ameliorate problems with syntax errors, but will confirm that the code behaves as expected, to the depth that unit tests can be written. Scripts bereft of modular design will benefit the least, as discrete functions offer more testing opportunities. The say_something script, shown below, employs a say_something function. This function is called directly from the unit test script. Additional unit tests could also run the say_something script and parse the output. Without this modular design, the unit test would be restricted to running the script and inspecting the output.

#!/bin/sh # say_something - a testable script say_something() { echo "$1" } broken_say_something() { echo $$ } say_something "uh oh I ran"

#!/bin/sh # say_something.test - unit tests for say_something . ShUnit-1.3/shUnit # source here requires no modification of the script being tested . say_something TestSaySomething() { EXPECTED="this is a test" RESULT=`say_something "$EXPECTED"` test "${EXPECTED}" = "${RESULT}" shuAssert "Test say_something" $? } TestBrokenSaySomething() { EXPECTED="this is a test" RESULT=`broken_say_something "$EXPECTED"` test "${EXPECTED}" = "${RESULT}" shuAssert "Test broken say_something" $? } InitFunction() { shuRegTest TestSaySomething shuRegTest TestBrokenSaySomething } shuStart InitFunction

$ sh say_something.test uh oh I ran ****** say_something.test ****** 2 tests to run: Test 1: TestSaySomething . Test 2: TestBrokenSaySomething E "Test broken say_something" failed. 2 tests run. 1 test succeeded.

However, whether sourced or executed, the code tested will run, evidenced by the uh oh I ran output, above. This may require an “is this the test mode?” workaround in the script, or that all the functions be moved to a library file that both the actual and any unit test scripts read from (an excellent design idea).

After my admittedly brief investigation, shUnit requires more code per test than Test::More for Perl. However, the included shUnitPlus library contains additional convenience functions that could further simplify the shell code. As a final plus, ShUnit employs clean design and clever code, and therefore makes for an edifying study.

Technorati Tags:

November 21, 2007

Copyright Alliance desires Death of Public Domain

Boo! Hiss! Copyright Alliance asks presidential candidates for more restrictive copyright laws. That that chilling travesty—the DMCA—doesn’t go far enough represents a frankly alien thought process. I favor weaker—much weaker—copyright, and the least possible legal entanglement for creative work. Standing on the shoulders of Giants is not possible whilst begging permission from a faceless entity.

Technorati Tags:

黒酢 - Rice & Wheat Vinegar

Kurozu Bottle

黒酢 denotes “black vinegar”. The kurozu I found—the only rice & wheat vinegar in Uwajimaya—with others being black, but wheat free—smells something like an acidic soy sauce. The vinegar, once diluted, begins with a mild rice taste, and ends with a stronger and long-lasting malt flavor. “Solid farmentation” produced this vinegar.

In a test soup with buckwheat noodles, the vinegar did very well:

  • 2 cups cold water.
  • Bonito flakes. Bring to mild boil in water, drain out once fish scent released.
  • 4 medium sized Shiitake. Add to water after straining out the bonito.
  • Green onion, diced. Mix with soup near or at end of cooking.
  • Noodles (here buckwheat).
  • Sesame seed oil (to taste). I did not use much, having mostly run out.
  • Sichuan peppers (4-5 husks), ground.
  • Kurozu to taste (didn’t really measure, probably could have used more).

Cook the noodles al dente, then drain and place in a bowl. Add the sesame seed oil, sichuan peppers, and a dash of kurozu. Mix the the noodles up. Then pour the soup over the noodles.

This was a very mild soup, though I wanted to emphasize the kurozu flavor, so omitted the usual miso or ginger or shallots microplaned to a pulp. However, the taste was excellent, one of my best soups to date. The early rice sweetness mixed well with the mushroom, and the malty hops made for a good aftertaste. Granted, I was hungry, having first taken photos:

Soup with Noodles

One flaw: the sichuan peppers concentrated into the last dredges. Folks say to mix them in near the end. In soups with noodles, I’ve had better luck mixing these peppers into the broth early, combined with sesame seed oil. Perhaps the mushrooms soak up the flavor?

Next experiment: kurozu reduction (simmer down over very low heat with spices). This works well for commercial—this is, not hundred dollar plus—balsamic vinegars, and could provide another vector for Sichuan peppers.

Technorati Tags:

November 17, 2007

Fresh Truck

Amazon.com Fresh Truck

First Amazon Fresh truck I’ve spotted in the wild. They offer pickup at work, but that leaves me lugging the groceries home as usual, and not much different from wandering through Uwajimaya. Time to give the service a try…

Technorati Tags:

November 13, 2007

A Brief Primer on Unix Environment Variables

The shell used will not make a significant difference, assuming one adheres to the Bourne—or ideally a Bourne derived—shell. At present, I favor ZSH.

$ echo $SHELL is being used /bin/zsh is being used $ echo this shell uses $(tty), process id $$ this shell uses /dev/ttyp8, process id 19741 $ echo $MY_ENV_VAR $ MY_ENV_VAR="something of value" $ echo $MY_ENV_VAR something of value $ $SHELL $ echo this shell uses $(tty), process id $$ this shell uses /dev/ttyp8, process id 19875 $ echo $MY_ENV_VAR $ exit $ echo $MY_ENV_VAR something of value

Note that though MY_ENV_VAR shows a value in the first shell, it does not in the subshell (opened via the $SHELL command). After closing the subshell, the custom MY_ENV_VAR is still defined in the original shell. Moving on, under the same session:

$ export MY_ENV_VAR $ echo $MY_ENV_VAR something of value $ $SHELL $ echo this shell uses $(tty), process id $$ this shell uses /dev/ttyp8, process id 22585 $ echo $MY_ENV_VAR something of value $ exit $ echo $MY_ENV_VAR something of value

The export builtin ensures child processes inherit the custom environment setting. The export only needs to be done once on the variable. In modern Bourne shells, this can either be done via a single export SOME_ENV=some_value command, or, as shown above, separate commands.

Processes may strip environment variables, usually for security reasons. This would account for otherwise exported variables not being present in child processes. For confirmation, run ktrace or strace on the process, and determine what—such as setenv(3), or the %ENV hash in Perl—manipulate the evironment.

Technorati Tags:

November 10, 2007

Principles of Geology

The contention of the rival factions of the Vulcanists and Neptunists had been carried to such a height, that these names had become terms of reproach, and the two parties had been less occupied in searching for truth, than for such arguments as might strengthen their own cause, or serve to annoy their antagonists.
— Charles Lyell, Principles of Geology, Volume I, Page 71.

Or Republicans vs. Democrats, or vi vs. emacs, or other—innumerable—dualistic debates. A difficult read due to the archaic prose and sheer breadth of the text. Lyell’s dregs and sediments, as the wheelwright would have it, by necessity goes into great detail of the “causes now in operation” to establish uniformitarianism. Contrast this prose with the visual style in The Orphan Tsunami of 1700, replete with diagrams, photos, and prose. I find my eye wandering over these pages, absorbing information and relationships, a very different experience than Lyell.

November 09, 2007

Even Another Way

The & operator provides another way to check whether a number is even or odd, for example when interleaving new data following each even line number:

$ (echo 1; echo 2; echo 3; echo 4) \
| perl -nle 'print; print "stuff" unless $. & 1' 1 2 stuff 3 4 stuff $ (echo 1; echo 2; echo 3; echo 4) \
| perl -nle 'print; print "stuff" unless $. % 2' 1 2 stuff 3 4 stuff

That is all.

November 08, 2007

Shogi SFEN

MacShogi offers no feature to edit the board, which makes position reproduction difficult. A web search revealed a FEN-like format for Shogi (SFEN hereafter), a great improvement over images or even text diagrams. Consider the following example. (For those unversed in Shogi, the Kings usually do not end up this close, which is mostly a testament to my poor 詰 [つめ: tsume] skills (the opposing King fled from a decimated Mino-Gakoi castle).)

Gote (w): 3P L N R 9 8 7 6 5 4 3 2 1 ---------------------------------------------- | Lw | Nw | Sw | | | | | | Lw | a ---------------------------------------------- | | Gb | | | | | | | | b ---------------------------------------------- | | Pw | Pw | Pw | Pw | | | | | c ---------------------------------------------- | Pw | | | | | Rb | | | Pw | d ---------------------------------------------- | | | Bb | Pb | | | | Pw | | e ---------------------------------------------- | Pb | Sb | | | | | | Pb | Pb | f ---------------------------------------------- | | Kw | Sb | | Pb |+Pw | | | | g ---------------------------------------------- | | Gb | | Gb | | | | | | h ---------------------------------------------- | Lb | Nb | | Kb | | | | Nb |+Bw | i ---------------------------------------------- Sente (b): 2P S G

Using Shogi SFEN, the position above would become:

lns5l/1G7/1pppp4/p4R2p/2BP3p1/PS5PP/1kS1P+p3/1G1G5/LN1K3N+b w GS2Prnl3p 1

A SFEN to board display conversion program would help display games, plus parsers to convert ASCII diagrams into SFEN. There exist Japanese sites that allow game replay, though these are all in Japanese. Time to start learning a new language or two…

In contrast, Java Shogi Board uses the FEN notation [FEN "1nn6/2S+P1+L1P1/kgs4+R1/1lpP2pp1/KP2Sp3/l1P3P1p/+b1N1SP3/4G3R/3G3N1 200011 0/4000000 s 55"]. I dislike this format, as the pieces in hand are not clear from the magic numbers.

Technorati Tags:

November 04, 2007

Free Rice

Free Rice donates rice while you build your vocabulary. Multiple choice, so guessing can get you into deep waters. This site converts time into charity; the charity navigator helps find the best means to convert money into charity. For instance, ASH, which has a horrible website, but good ratings, and good material on why finding a smoker-free apartment is a healthy choice.