« March 2007 | Main | May 2007 »

April 29, 2007

Organic, Local, Fair Trade

Food safety worries mount:

“The effects of melamine on people are thought to be minimal, but no one really knows. Its consumption by humans is considered so improbable that no one has even studied it.”
[allegedly] “added melamine to the gluten in order to boost the measurable protein level and thus the price of the shipment”

Multiple problems here, including:

  • Food is apparently cheaper to transport across the Pacific from China. Does this cost fund the FDA to properly screen imports? Account for the environmental impacts along the entire food collection and distribution chain? If not, who pays?

  • Processed foods. These are difficult or impossible to trace back through the distribution chain, if one or more source is contaminated. This makes finding and holding accountable the responsible parties similarly difficult, for either governments, or consumers looking for a target to protest.

  • Unstudied Chemicals. Melamine rumored in food, rocket fuel in the water supply. How bad are they for humans? How expensive are they to remove from the environment?

Technorati Tags:

April 26, 2007

Debugging CPAN Build Problems

Debugging CPAN Build Problems expanded from the parent Life with CPAN page to better cover common problems encountered when building Perl modules.

On a related note, introducing captive user interfaces into what otherwise would be an automated build process hurts, especially when the prompt routine does not show the question, or indicate why the test process now mysteriously hangs. Instead of relying on fragile interactivity, require environment variables or a configuration file, and bail out with a clear error message if anything required is missing.

Technorati Tags:

April 22, 2007

strftime++

The strftime(3) call should replace convoluted code required after gmtime(3) or localtime(3) calls. For comparison, using Perl, two subroutines that both produce a ISO 8601 calendar date such as 2007-04-14, based on the current time:

sub date_from_gmtime { my ( $mday, $mon, $year ) = (gmtime)[ 3 .. 5 ]; $year += 1900; $mon += 1; return sprintf( '%4d-%02d-%02d', $year, $mon, $mday ); } sub date_from_strftime { use POSIX qw(strftime); return strftime( '%Y-%m-%d', gmtime ); }

strftime requires fewer lines of code, requires no local array slicing and number fiddling, and easily supports different date templates.

Technorati Tags: ,

April 19, 2007

REO

Found Remedy Teas on Capitol Hill (15th and Harrison) after a tip from a work mailing list. Music a tad loud… “You don't mind if we play a little Zen music, right?” KROMP KROMP KROMP KROMP KROMP KROMP KROMP KROMP KROMP. Great selection of tea, on the other hand.

Earth & Ocean produces mixed results during 25 for 25, though currently offers a great “Washington Grown Menu” with a light garlic soup plus olive tartine, excellent gnocchi (best hot though a wee bit overcooked), very well done makizushi-style quinoa with bitter greens and a nice touch of wasabi, finished by a wonderful strawberry and rhubarb dish.

April 16, 2007

Incident Handling

Software applications issue logs, allowing log scanning software to detect and act on these events. For example, sec.pl can detect a disk full log message, and cut a trouble ticket. This article considers a different approach, one that does not rely on log scanners. The method best suits applications with low incident counts, those where new incidents appear on a weekly or longer basis.

Method Overview

Application software, upon detecting a fault, writes an *.error file into an incident directory. These files contain logs and other data concerning the fault. Monitoring software periodically checks the incident directory, and cuts a ticket if at least one error file exists. An operator investigates the issue, and after resolving the problem, moves the incident file aside.

Advantages include simplified monitoring software: alert if an incident file exists, rather than continuously scanning a logfile for rare events. By including relevant data in the error file, the operator need not delve through gigabytes of logs during the investigation. Monitoring software could also submit the entire error file as part of a ticket auto-cut, instead of simply alerting on the presence of error files.

Disadvantages include an operator mistakenly moving aside unresolved incident files, or where a major problem creates a flood of files, well beyond the low numbers this method assumes. I have not yet used this method in practice, so other disadvantages may exist.

Technorati Tags: ,

Incident Generator

Example Perl code to generate incident files. Either use this code as a module in the application, or invoke an incident creation script that accepts the incident file contents on standard input.

use File::Path qw(mkpath); use File::Temp qw(tempfile); use POSIX qw(strftime); # Do not use /tmp, /var/tmp, or any existing # system area. Create a new directory unique to # the application. my $INCIDENT_DIR = '/some/app/var/error'; my $INCIDENT_FILE_SUFFIX = '.error'; my $INCIDENT_FILE_TEMPLATE = '%Y%m%d_XXXX'; create_incident("test"); sub create_incident { my $incident_data = shift; # or create this with configuration management # outside the application if ( !-d $INCIDENT_DIR ) { create_directory($INCIDENT_DIR); } # Lacking XXXX, File::Temp fails if ($INCIDENT_FILE_TEMPLATE !~ m/XXXX/) { $INCIDENT_FILE_TEMPLATE .= 'XXXX'; } my ( $fh, $filename ) = tempfile( strftime( $INCIDENT_FILE_TEMPLATE, gmtime ), DIR => $INCIDENT_DIR, SUFFIX => $INCIDENT_FILE_SUFFIX, UNLINK => 0 ); if ( !defined $fh ) { # TODO handle incident file error } else { print $fh $incident_data, $/; } # return incident filename, so logs can be # written about incident file return $filename; } sub create_directory { my $directory = shift; eval { mkpath($directory); }; if ( $@ or !-d $directory ) { # TODO handle system misconfiguration } }

Incident Detector

At minimum, check the incident directory for at least one *.error file. This check could be run as a standalone daemon, or ideally rewritten as a monitoring system plugin.

# Do not use /tmp, /var/tmp, or any existing # system area. Create a new directory unique to # the application. my $INCIDENT_DIR = '/some/app/var/error'; my $INCIDENT_FILE_SUFFIX = '.error'; while (1) { # TODO add error handling opendir my $dir_fh, $INCIDENT_DIR; FILE: while ( my $file = readdir $dir_fh ) { print "$file\n"; if ( $file =~ m/\Q$INCIDENT_FILE_SUFFIX\E$/ ) { # TODO report incident somehow last FILE; } } sleep 60; }

A Perl module could incorporate both the incident file creation and detection routines, suitable for use from a command line interface, or as part of application software and monitoring system plugins.

Incident Resolution

The operator should move the *.error file into an archive directory. This archive directory, in turn, can be cleaned up by configuration management for incidents older than a specified time period.

April 14, 2007

Recent Readings

April 11, 2007

Leaves III

See also Leaves II and Leaves (the first in particular being in need of some tweaking, but then again that’s where the rest stemmed from).

April 08, 2007

Glass Ligeti

Discovered Solo Piano by Philip Glass after following a Valley of Darkness tip on wikipedia. Reminds me of work by Eric Satie, but different. Less enthused by the chaotic György Ligeti String Quartets and Duets, especially compared with the Rochberg String Quartets.

Technorati Tags:

April 06, 2007

Big / vs. Small /.*s

The LOPSA tech mailing list has a good ongoing discussion on partition layouts. I’m currently in the “one big partition” camp for most servers (user desktops, front-end webservers, and other similar throwaway systems) that can be reimaged and brought back up to speed with configuration management. Have not maintained custom servers in some time—databases, mail servers, and the like—that would justify time spent doing partition layout planning, creation, and maintenance.

More details over on my KickStart page.

April 05, 2007

Particulate Harm

U.S. Supreme Court rules E.P.A. must regulate greenhouse gases, in spite of excellent counter arguments by Chief Justice Roberts:

“Under the [Clean Air] Act’s clear terms, EPA can avoid promulgating regulations only if it determines that greenhouse gases do not contribute to climate change or if it provides some reasonable explanation as to why it cannot or will not exercise its discretion to determine whether they do. It has refused to do so, offering instead a laundry list of reasons not to regulate… These policy judgments have nothing to do with whether greenhouse gas emissions contribute to climate change and do not amount to a reasoned justification for declining to form a scientific judgment.”

“Petitioners’ difficulty in demonstrating causation and redressability is not surprising given the evident mis-match between the source of their alleged injury—catastrophic global warming—and the narrow subject matter of the Clean Air Act provision at issue in this suit. The mismatch suggests that petitioners’ true goal for this litigation may be more symbolic than anything else.” — Roberts, C. J., dissenting.

Source: Supreme Court Ruling No. 05–1120.

Scalia quotes the dated 2001 report on global warming in dissention. The recent 2007 summary for policy makers from the IPCC strengthens the linkage: “Most of the observed increase in globally averaged temperatures since the mid-20th century is very likely (90% confidence) due to the observed increase in anthropogenic greenhouse gas concentrations.”

I welcome the ruling, given that the executive office appears busy suppressing climate research, as part of their “comprehensive approach” to greenhouse gas emissions.

Technorati Tags:

April 04, 2007

Daylight Saving Time Considered Useless

Daylight Saving change useless at best. Deploying DST patches, restarting applications, and figuring out when the meetings Exchange botched actually took place wasted far too much time at work these last few months.

I say, abolish the useless time shift. If congress really wanted to implement energy savings, perhaps they could tax the lumens Americans burn away nightly?

And I’m still trying to abolish useless uses of the localtime call at work, but that’s a different battle.

April 02, 2007

Perl Crossword Puzzle

Dislike newspaper crossword puzzles, as they reference things I know very little to nothing about. Hence, a Perl crossword puzzle!

Technorati Tags: ,

Across

1. Regular expression to match cat.

3. Octal for character given in 42 across, for use in string or regex.

4. Four regular expression modifiers.

7. Defined or introduced in Perl 5.10. Single line comment prefix in other languages.

8. Formatted print function.

11. Perl comment character.

12. Returns epoch time.

13. Name for $! variable in C.

15. Variable used in sort expressions.

16. Like require, but different.

17. Expression to append e to beginning of a variable.

18. A return value of 9 down, formatted with 39 across.

19. Equal to 48 across. Also equal to 18 across as $_ run through the expression $_&1.

21. Variable for process number of current script.

22. -r-------- permissions in octal as recommended for chmod function.

24. Special literal for current line.

25. Perl version released on 581497200.

26. Poorly recommended way to call subroutine named a.

27. RHS expression that will empty a hash on the LHS.

28. Range operator in regex character classes.

31. Variable containing name of script.

33. RHS value lookup of hash key r inside hash reference $y.

34. Statement to assign result of 18 across to $a.

37. Increment operator.

38. An array.

39. printf expression that produces a zero padded two digit integer.

40. Hex code for character in 28 across.

42. Character for 3 across.

43. Product of dump function.

44. Reserved for looping.

46. Environment variable to adjust @INC with.

47. Detect end of FILEHANDLE.

48. Equal to 19 across. See additional qualification in 30 down. Finally, with the last two digits of 3 across in $_, the expression $_&1 must return the same value as in this field.

Down

1. Applies an expression to a list. Contrast with 5 down.

2. Various perlrun command switches.

2½ (unlabeled). Regular expression to match f or r. Knew I missed something…

3. Leaning toothpick syndrome.

5. Applies an expression to a list. Contrast with 1 down.

6. Define a subroutine a that increments the first argument by 1. Subroutine must not be subject to Modification of a read-only value attempted diagnostic messages.

9. Return a number from 0 to less than 42.

10. Like y///, but different.

14. Grants access to file contents and other data.

16. A subroutine call.

20. Poorly named variable.

21. Default space for many operations.

23. String of last pattern match. Also, great way to kill performance.

29. Declare variables local to enclosing block with this.

30. Boolean expression, where LHS not smaller than RHS, and LHS equal to 48 across.

32. String append operator.

33. A special variable.

34. Syntax error message from last eval.

35. A positive thinking function.

36. RHS to define string with five s characters in it.

39. Contains environment variables.

40. Hex code for character used in 1 across and 17 across.

41. Popular general purpose framework, reverse spelling.

43. Common module used in web programming.

45. Show the type of the result of an expression.

Hopefully, no errors in my writeup… this took a bit longer than expected to create. :)