Tuesday, December 11, 2007

How to win on Deal or No Deal

[Originally blogged 2006-03-26, updated 2007-12-11 (see below)]

NBC's vapid, but fun, game show Deal or No Deal seems simple enough. I doubt it will be the next Wheel of Fortune, or even the next Weakest Link, but stranger things have happened.

The contestant picks a suitcase out of 26 held up by scantily clad models. A board shows amounts, from 1 penny up to ONE MILLION DOLLARS (-oooh-). The contestant gets to pick some more, revealing the amounts held in them -- will it be ONE MILLION DOLLARS (-oooh-)? The contestant is given the choice to keep the suitcase he has, and win its contents, or go on picking others.

How to decide?

The answer is with expected value, a principle of mathematics that sounds fancy but in this case requires only simple arithmetic.

Expected value normally means finding the sum of all possible outcomes multiplied by their individual probability. It can get unwieldy, but in this simple case the odds of the outcomes are all the same, 1/N, where N is the number of values left on the board.

At any given step, add the total amount left on the board, and divide by the number of entries left. Since each amount left has equal chance of being in any of the suitcases, including your own, the expected value for a given suitcase is just the average.

When the banker calls, if your expected value if you remain in the game is higher than his offer, reject it. If his offer is higher or the same as the expected value, take it.

For instance, suppose you have entries on the board (three suitcases and your own). The amounts are $100,000, $50,000, $10, and $.01. The penny looks scary, but the $100k looks tempting. What to do?

The total is $150,010.01, which you round to $150k for an average of about $37,500. If the banker calls with an offer: $35,000, you should reject the offer. If the offer is $38,000, take it.

The reason this is the best strategy is that if you played the game many, many times, on average you'd win the expected value of what's left.

[Update: After watching this show off and on for a few months, I realized two things. First, the show did become the next Weakest Link. Secondly, simply math wasn't enough to provide a winning strategy, and in fact isn't really needed.

To win, you have to define "winning". There are two kinds of winning: winning lottery-big (a life-altering amount), and walking out with a respectable prize, one that will solve some immediate problems for you: let you open a business, buy/pay off the house, take a less stressful job, whatever.

So that gives us three kinds of numbers the cases can hold:
  • Small: lower than your "respectable" win
  • Respectable: At or higher than your "respectable" expectation
  • Lottery: A number big enough to make your offer close to respectable.
The key to the winning strategy is to decide on the respectable take-home payout you're after, and Accept the Deal when you have only one lottery prize left on the board. As long as you have two big prizes left, you can open another case and still have a reasonable offer.

Think about the end game: you have some small prizes and two big ones, $100,000 and $400,000. If you open a case with a small number, your offer will go up; keep going. Even if you open the $100,000 case, your offer will still not go down that much, and you can accept it with glee. Only if you choose the highest of the lottery amounts will your offer go down significantly, and you walk away with a nice paycheck.

If you reject the offer when you have only one lottery prize left, you risk coming away with nothing when you have a very easy way (at that point) to solve some problems for yourself. If you only have one big amount left on the board, make the Deal.
]

Wednesday, October 24, 2007

Exceed, Cygwin, and Terminal Server

... or "How to waste an afternoon"

I've been having trouble getting the combination of MS Terminal Server 2003, Hummingbird Exceed 2006, and Cygwin to work together.

Cygwin's Xfree86 doesn't work well for Terminal Server, since Cygwin's X has one global X.log file that is owned by and read-only for only one user at a time. So we use Hummingbird Exceed on the Terminal Server.

But Exceed doesn't come with xterm, ssh, etc. They expect you to use rsh, rexec, or a program you configure with their proprietary goo to connect to your remote systems. Not my style.

Background

X programs running on a remote host can display on your computer through the use of a lot of complicated technology, much of which depends on a properly set environment variable named DISPLAY. It's format is

DISPLAY=your.hostname:N.m

where "your.hostname" is either the domain name your ISP gives you, an IP address, or the special name "localhost". All computers on the Internet believe that they themselves are "localhost".

Ssh programs (either the proprietary ones from SSh, Inc., or free versions such as openssh or putty) have a wonderful feature: they can hijack data to be sent to your local computer, encrypt it, send it over their secure connection, and deliver it to your local computer for display. They do this by setting the remote DISPLAY variable to (for example) "localhost:10.0". Remote programs you run send their output to remote display 10, screen 0. Ssh receives the data, encrypts, delivers, decrypts, and sends to whatever your local DISPLAY variable says.

But I've not been able to find a Windows-based Ssh program that is able to tunnel X11 connections with remote hosts to Exceed. In the past, I've just looked at the display number in the Exceed taskbar button and set DISPLAY manually, losing the benefits of tunneling.

A little digging turned up some documentation (pdf), which says:

While Exceed sessions are running, the display numbers are tracked through a dynamic file called Display Snapshot.HumTable. This is located in

C:\Documents and Settings\All Users\Application Data\Hummingbird\Connectivity\11.00\Global\Exceed\Display Snapshot.HumTable

As this is dynamic, it should not be edited manually.
Ok, now I know what to do. I can grab the DISPLAY number from that file, which by the grace of Hummingbird is a text file and not more proprietary goo. Unfortunately, it's a Windows file, with an ugly filename with spaces in it. So I need a script to turn that into a Cygwin name:

In /etc/profile on your Terminal Server, put the following:


HUMTABLE="C:\Documents and Settings\All Users\Application \
\Data\Hummingbird\Connectivity\11.00\Global\Exceed\Display Snapshot.HumTable"

#
# sanify - turn a Windows directory name into a Unix name
# - turns drive letters into /cygdrive/drive,
# - flips slashes, removes enclosing quotes,
# - replaces unusual characters with '?'
function sanify() {
echo ${@} | sed \
-e 's,^[A-Za-z]:,/cygdrive/&,'\
-e 's,:,,g' \
-e 's,\\,/,g' \
-e 's,^\",,g' \
-e 's,\"$,,g' \
-e 's,[^A-Za-z0-9_\.-],\?,g'
}
# disp() grabs the information from the Humtable file
# and puts it in the right format.

DOMAIN=your_windows_domain

function disp() {
EX_LF="`sanify ${HUMTABLE}`"
[ -r $EX_LF ] && {
cat $EX_LF | awk -v d=$DOMAIN u=${USERNAME} \
'BEGIN {FS=","}\
$3 ~ d "." u {print "localhost:" $4 ".0";}'
}
}
export DISPLAY=`disp`


[Updated 20071026 to touch the script a bit]

Thursday, October 04, 2007

Tuesday, September 25, 2007

Script for OpenSSL Certificate Signing Request

[Updated for bugfix 20080722] If you're like me, you need a new SSL Certificate about once a year. You know what to do:
  1. Generate a "Certificate Signing Request" and a key
  2. Send the CSR to your Certificate Authority for signing
  3. Wait for the signed Certificate to come back from the CA
  4. Put the key and the Certificate where your web, email, or other server can find them

I always have to look up the right openssl(1) command line arguments.

This year, I decided to make a script. This script takes an optional argument, the host for which you're making the certificate. I suggest generating the Certificate on the target host, but if you feel bold you can make a CSR for any host you want.

#!/bin/sh
#
#############################
#
# Shell script to automate making
# Certificate Signing Requests (CSR)
# with openssl
#
# tested on v 0.9.8e
# Loren Heal
#
#############################

echodo() {
echo "${@}"
(${@})
}

yearmon() {
date '+%Y%m%d'
}

fqdn() {
(nslookup ${1} 2>&1 || echo Name ${1}) \
| tail -3 | grep Name| sed -e 's,.*e:[ \t]*,,'
}


C=Your_Country_Abbreviation
ST=Your_State_Spelled_Out
L=Your_City
O="Your Company or Whatever"
OU="Your Office or Department or Whatever"
HOST=${1:-`hostname`}
DATE=`yearmon`
CN=`fqdn $HOST`

csr="${HOST}-${DATE}-csr.pem"
key="${HOST}-${DATE}-key.pem"

openssl req -new -newkey rsa:1024 -keyout $key \
-nodes -out $csr <<EOF
${C}
${ST}
${L}
${O}
${OU}
${CN}
$USER@${CN}
.
.
EOF
echo ""

[ -f ${csr} ] && echodo openssl req -text -noout -in ${csr}
echo ""

Thursday, September 20, 2007

Why not to buy an LCD TV

When the Microvision Pico Projector technology spreads and stabilizes, you won't need a screen, just a white wall.

Though I'm told they do it all with mirrors.

Tuesday, September 18, 2007

Paperless Voting Logic Errors

The Information Technology & Innovation Institute has published their report (pdf) on electronic voting, and as advertised in their press release last week, they think a paper trail is unneeded and even harmful. To this end their report employs a series of logical fallacies, hinting that their research began with a premise and attempted to validate it, rather than simply seeking the facts.

The biggest mistake the report makes is a result of the incorrect assumption that all-electronic voting is a worthwhile goal. It fails to think outside the box created by that assumption, which would have revealed a better solution.

The report begins
Americans trust computers to run critical applications in fields such as banking, medicine, and aviation, but a growing technophobic movement believes that no computer can be trusted for electronic voting.
The report could have ended with its conclusion that a computer could be trusted for electronic voting, and saved us all the trouble, but unfortunately it did not.

The fallacies fly beginning with the opening three words: "Americans trust computers" relies on an Appeal to Popularity, and Ambiguity in the words "trust" and "computers". A report intending to provide technical background and subject-matter expertise should not rely on public opinion for its primary argument. That Americans believe a certain thing does not make it true, unless we are talking about the definition of words or something else which is made true by popular acceptance. While "trust" has a variety of meanings to politicians, it has a more specific meaning in the field of computer security and information assurance. That something is trusted means only that its level of insecurity is acceptable, not that it is perfect. And the computers and most importantly the ways they are connected in banking, medicine, and aviation are markedly different than voting machines.

So the report begins by asserting that the paper trail debate is only about trusting computers, even unleashing against those who want a paper trail the ad hominem "technophobic", when in fact there is far more to it than trusting computers. It is about designing a process that doesn't require trusting computers. Many of us seeing the need for a paper trail are among the least technophobic people there are, knowing exactly when to trust a computer and when not to do so.

Most of the report sets up paper-only ballots as a sinister straw man, bringing up the history of paper ballots (e.g., with the sidebar: "How LBJ Stole and Election with Paper Ballots") and insisting that anyone opposed to direct-record electronic (DRE) voting machines must be for that kind of corruption and inefficiency.

Unfortunately, paper-based auditing trails such as these do not allow the voter to verify that the results of an election are accurate. A DRE voting machine can provide up to three different guarantees to a voter: first, that the vote was cast as intended; second, that the vote was recorded as cast; and third, that the vote was tallied as recorded.


Despite the imprecise terminology (misusing the word "vote" for "ballot"), the electronic "guarantees" provided to the voter are not worth the paper they aren't printed on. The guarantees all require trusting the system, which is exactly what we are trying to establish. This is known as "begging the question".

The report goes even further, however, and makes a misstatement of fact, saying "The third property, that the vote was tallied as recorded, is not provided by voter-verified paper audit trails." In fact it is precisely this property which a paper trail provides.

An machine which prints the official ballot and sends an electronic copy to a central location can be far more secure and trustworthy than an all-electronic one. If each voter, or a statistically important sample of them, inspects his paper ballot, then the tally of the paper ballots had better match the electronic one. The reason is this: the ballot box could be compromised, and the electronic data could be compromised, but the task of compromising them both in the same way is exceedingly difficult, equivalent to compromising everyone and everything involved. DRE systems as recommended by this report are incapable of that level of assurance.

All-electronic voting can never be as secure, and especially not as robust, possibly even as paper-only but especially not a hybrid of both. This report may have concluded that if it had not begun with its conclusion already fixed in place.

Friday, September 14, 2007

Poisoning the Well on Electronic Voting

A "think tank" called the Information Technology and Innovation Foundation is due to release a report on Tuesday, September 18, with the counterintuitive conclusion that a paper trail does not add to the security of electronic voting systems. They're holding a briefing, at which the following will explain their conclusion:

Rep. Vernon Ehlers (R-MI)

Robert Atkinson, President of ITIF

Daniel Castro, Senior Analyst with ITIF

They've got a heavy burden of proof to lift, since it's apparent to anyone who thinks about this subject that an all-electronic system can never be trusted.

They also have to show that they were not funded, commissioned, or beholden to someone with a motivation for making electronic voting paperless. Rep. Ehlers fails that burden immediately, because as a sitting member of Congress his insight into secure electronic voting is suspect.

They may say a paper trail doesn't in itself add security, which only applies if the paper trail is done poorly.

With the long development and approval cycle of election systems, there is a gaping hole in any all-electronic system: fault exploits are developed quickly, while the systems have great inertia. An unfixable design flaw may be widely known on election day, and yet the vulneralble system will be deployed because that's how the government works.

I'll have more when they release the report.

Wednesday, August 22, 2007

Programs I Want to Write

A Shell script compiler

A To Do / Project manager

A better (robust, complete, elegant) compiler language

A March Madness tournament picker

A GUI for script writing

Monday, August 06, 2007

Keeping Safe Online

(Reposted by permission from Slashdot)

There is a tendency to want the government to do something about every problem, and the hassle of online scumbaggery is no exception. Individuals (and their guardians) need to take responsibility for their own protection, and not expect either the government to protect them (which it cannot) or for faceless strangers to be kind to them, which a tiny but significant portion will not.

Each of these steps solves roughly half of the remaining problems not solved by the previous ones.

  1. A fool and his unarchived data are soon parted. If you want it, make an offline copy of it.
  2. Switch to Linux, a Mac, or Anything But Windows. Most of the following only apply if this one won't work for you.
  3. Switch to Mozilla Firefox.
  4. Buy and install a firewall box. These are very easy to set up, and will save you a ton of trouble.
  5. Buy and install a virus scanner.
  6. Download and install Lavasoft Ad-Aware or similar spyware detector, even if your virus scanner says it provides that protection.
  7. Don't open email with attachments you aren't expecting, or respond to spam with so much as a single click. You have been warned.
  8. Stay away from porn sites. They're bad for your computer.
  9. Stay away from online games except those you know to be crap-free.
  10. You don't know that any of them are crap-free.
  11. Don't download commercial music except from commercial vendors to whom you pay a fee. Yeah, sucks to be us. But you get what you deserve, and if you're trying to get something for nothing, you'll give something for nothing in return.

So what do you do if your kids download some game, P2P app, or other crapware-laden piece of stupidity? Take away the computer. What if you have several kids, and you don't know who did it? Enlist their aid and hold them all accountable. Tell them that if any of them downloads crapware and the guilty party won't come forward, they all do their homework at the library (for a week or month or whatever).

Saturday, August 04, 2007

A.Rod's Big Day


"The Yankees' Alex Rodriguez became the youngest player to reach 500 home runs on Saturday."

Now, I know it's not really ambiguous, since hitting 500 home runs over the course of a career is still fairly rare.

Just saying.

Oh, and congrats Alex. Maybe now you can get a decent contract and start making some real money.

Friday, August 03, 2007

Making Strings Out of Numbers in C

A while back I was writing a C program and found I needed to convert numbers (integers) into strings. The language has no built-in facility for this. While sprintf() can be used, it has some drawbacks. Sprintf() only works with binary, octal, or hexadecimal bases, and the calling function has to calculate how much space each number needs. In any case, it didn't fit the bill at the time.

So I wrote itoa.c, which does the job. The file also contains a test wrapper with a main() function which may be useful in its own right. It will convert a decimal number on the command line to its representation in any base from 2 to 62.

One feature you may like or dislike is itoa's use of malloc() to get space for the resulting string. Itoa figures out how much space to allocate, which makes for twice the work for it but may save a large hassle in the calling function. I think that's an example of robustness, since it works correctly for any base, but your mileage, etc.

How do I know it works correctly for any base from 2 to 62? By inductive proof. The length for a string whose value is less than its base is 1 plus a null char for C, so the length is 2. So suppose the algorithm works for some base k. Since the same work is being done* when actually filling in the string with ritoa(), we see that working for base k means it works for base k+1. The boundary at 62 also works, so the algorithm is correct.

As always with C, be sure to garbage collect with free() when you no longer need the string.


/*
* Itoa.c
* Copyright 2004, Heal Consulting
* Published under the General Public License. See it at http://gnu.org
*/
/*
A sleeker version is available at:
http://www.cs.princeton.edu/courses/archive/fall96/cs126/examples/itoa.c
*/

#include /* only needed for main, fprintf error*/

static char *ItoaDigits =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

/*
* ritoa
* recursive itoa
*/
long int
ritoa(long int val, long int topval, char *s, int base)
{
long int n = val / base;
if (n > 0)
topval = ritoa(n, topval, s+1, base);
else
*(s+1) = '\0';
*s = ItoaDigits[ topval % base ];
return(topval / base);
}

/*
* itoa
* - mallocs a string of the right length
* - calls ritoa to fill in the string for a given base
*/
char * itoa(long int val, int base)
{
int len;
char *s,*buf;
long int t = val;
for (len=2; t; t /= base) len++ ; /* quickie log_base */
/* printf("len; %d\n", len); */

if((buf = (char *) malloc(len)) == NULL)
{fprintf(stderr,"out of memory in itoa\n"); exit(1);}
s = buf;
if (val < 0)
{
*s++ = '-';
val = -val;
};
len = (int) ritoa(val, val, s, base);
return(buf);
}

/*
* The test program may actually be useful.
* Converts a decimal number (long int) to a base you supply.
*/
int
main(int argc, char *argv[])
{
long int num = 0;
char *s;
int base = 10;
int maxlen = strlen(ItoaDigits);

if (argc >2) { base = atoi(argv[2]); };
if (argc >1) { num = atol(argv[1]); };
if ((argc <= 1) || (base > maxlen ) || (base < 2))
{
printf("Usage:\n\n%s [number [base]]\n", argv[0]);
printf("where number is in decimal and 2 <= base <= %d\n", maxlen);
exit(1);
}
s = itoa(num, base);
puts(s);
return(0);
}


After I wrote it, I found a slightly sleeker (base 2 through 16 only) version from an old Princeton CS class*.


* No, I didn't go to Princeton. That's why I waved my hands in the proof.

Tuesday, July 31, 2007

What To Do With Old Mesh Fruit Bags


Pond filter intake cover

If you have a small garden pond with a filter and pump, a mesh bag over they intake will keep leaves, worms, and minnows out of the filter.

Wash rocks

If you have to clean decorative rocks or gravel, a mesh bag can allow you to spray a hose at the rocks without scattering them.

Big scouring pad

Fill a mesh bag with cotton rags and use as a scouring pad for a boat hull, RV, wood deck, or house exterior.

Recycling container, especially for
  • aluminum cans
  • glass
  • tin cans
Some vegetables come in a looser mesh with very soft strands. These can be used
  • As dust rags
  • In paint preparation, to remove steel wool fibers or wood dust

Eric Wolfram, whence I stole the images here, lists several uses, including:
  • Giving away at farmer's market
  • Holding batteries, cables, and other electronic gear
  • Carrying loose change to the bank
  • Beach bag
Not As A Bird Feeder

Apparently birds get their feet caught in the modern mesh bags. Make a cube out of hardware cloth (wide-mesh heavy gauge screen) instead.

Air Clamp

Some objects that need to be clamped together for gluing cannot stand the stress of a regular clamp. You can combine a mesh bag with something like a plastic bread bag, garbage bag, or folded over piece of plastic sheeting, depending on the size, shape and strength of the objects, to make a clamp to glue them together.
  1. Glue the objects together
  2. Put the objects inside a mesh bag
  3. Put the mesh bag inside your air-tight container bag
  4. Use an aquarium air pump (or preferably something stronger) to take the air out of the bag
  5. Depending on the pump you have, you may either seal the bag or let it continue to try evacuating the bag.
Since atmospheric air pressure is about 14 lb/in2, removing air from inside the bag puts a very strong force uniformly all around the items to be glued, while also helping extrude the glue in a uniform way (for the right kinds of glue). Professionals use specially designed pumps which can maintain a given vacuum pressure, but a DIY alternative is to use a food preservation vacuum sealer.

Monday, July 30, 2007

What To Do With Old Toothbrushes

A toothbrush should be changed every three months, we're told. But what should be done with the old ones? Throwing them away seems awfully wasteful to me, so I keep them around and inevitably find uses for them.

One nice feature of the humble toothbrush is that the plastic handle can be broken, either to remove the head to use just the handle, or to make the handle shorter. With gentle pressure and even low heat, the handle can also be bent into a more convenient shape. The bristles can be trimmed to form a stiffer brush or even removed entirely.

Break the handle to about 3" and use as a fingernail cleaner.

Hang in the shower for scrubbing nails and feet. Make sure to clean (and disinfect) it between uses, or various nastiness can grow on it.

If the bristles are cut off, a toothbrush can be filed down with concrete and sandpaper to a surprisingly sharp point or blade, to make an awl or a scraping tool. An old toothbrush can really come in handy in a variety of settings:

In the garage:
  • General cleaner
  • Clean grease, oil and tar from car parts
  • Clean dirt from garden tools and apply used motor oil as protectant
  • Clean rusty items
  • Car detailing: either inside or out
  • Bike chain and gear cleaner
  • Clean power tools such as jigsaws and Sawzalls™
  • Brush the dust and debris from shop vacuum cleaners
  • Use as applicator for pipe thread sealant
  • Spread wood glue
  • Glue sand to bristles, use as wire brush
In the kitchen
  • Break and bend the handle away from the bristles to better scrub permanent coffee filters or the coffee filter basket
  • Use with baking soda for general cleaning, and also the grooves in a George Foreman grill
  • Clean fruits and vegetables from the garden or grocery
Around the house
  • Painting and paint preparation
  • Ceiling fan duster
  • Laundry stain scrubber
  • Grout scrubber
  • Doggy toothbrush
  • Handle for steel wool, cotton ball, cloth
At ThriftyTips, some other uses came out:
Cleaning combs and brushes, bottles, jewelry, shoes, sliding door tracks, toys, window crevices, screens, toilets, faucets, etc. [using different brushes, obviously]. Use as an eyebrow brush.

Saturday, July 28, 2007

What To Do With Used Motor Oil

[Originally posted 20070722, updated 20070728 with orst.edu link]

Most places have laws about what you can do with used motor oil, such as mandating that it be recyeled* by a licensed facility. In fact, while writing this it was initially difficult to find any information on used motor oil other than pleas to recyele it. Used motor oil is a known carcinogen, so wear gloves and don't eat it.

A lot of the pages on the net that talk about used motor oil take the amount of oil bought and subtract the amount recycled, concluding that this amount is dumped down storm sewers or into lakes and streams. But the thing is, most people don't live near a lake or a stream, and very few people would actually dump used motor oil down the storm sewer, much less their own drain. At least, not twice.

So what do people do with used motor oil if they don't recyele it?
  • Paint the bottom of wooden posts, or anything else that will be in ground contact. If you're really serious, heat the oil to above the boiling point for water and immerse your object in it. The water in the object will boil away, to be replaced by oil and contaminants. Oiled wooden fence posts that are mostly or entirely encased in concrete will not harm the environment. Don't use such posts in standing water or marsh, because the oil will leech into the water.

    [Update: I found this research report from Donald J. Miller of Oregon State University, Service Life of Treated and Untreated Fence Posts: 1985 Post-Farm Report. "Post-Farm" refers to a farm full of posts, not a report after the farm.

    He recommends used motor oil or crankcase oil only as a carrier for creosote, presumably because the oil only increases the useful life of posts by a short amount of time compared to its toxicity (and tendency to soften untreated wood). Using oil to carry creosote proved among the most effective treatments. In a residential or non-farm application, applied to already treated wood, plain appears to help a lot. /Update 20070728]

  • Soak hard-to-burn things like damp wood before lighting (don't breathe the smoke)
  • Paint concrete (again, not for aquatic use).
  • Paint concrete forms so they can be removed more easily taken off and reused
  • Paint a brick foundation, especially the chalky mortar as a way to postpone tuck pointing. This iwill make your eventual tuck pointing job more difficult, since the new mortar will not stick as well with the oil present.
  • Before paving asphalt (or asphalt over concrete), apply a coat of motor oil and allow to soak in overnight (unless rain is expected).
  • Mix with staining colorants, or with old oil-based wood stain or paint. A lot of times there are things that need to be painted that will never show -- you're just painting them to protect them (why else use an oil-based paint?). So combine your leftover stain, paint, varnish, and used motor oil in a paint can and mix well. It probably won't stick to metal, but will last a long time on wood, concrete, or stone. For an effective finish, apply several coats until it is no longer absorbed.
  • Use as chain saw chain oil (a very good use, but watch the splatter)
  • Lubricate a bicycle chain (this is not optimal, because the thick oil tends to collect dirt)
  • Clean rusty metal (paired with an abrasive such as steel wool)
  • Coat outdoor tools such as axes, shovels, and clippers to keep them from rusting
  • Clean road tar off vehicles (take care not to mar finish)
  • Clean old engines such as on lawnmowers
  • Lubricate hinges, latches, and other rough exterior hardware
  • Coat nails to make them drive easier and stay rust-free
  • Mix in 1 part oil with 20 parts diesel fuel and drive around
  • Oil leather (makes a dull, unattractive finish, but functions well) (do not used next to skin)
  • There is a patented process for cooking used rubber tires with used motor oil, producing a variety of hydrocarbons and chemicals.
  • Another (patented) process purifies used oil with acetone and ketone
  • Use a centrifuge to separate impurities
  • Burn in an oil heater designed for used oil
  • Burn it in an oil lamp
What not to do with used oil:
  • Spread it on the ground to inhibit dust or weed growth, as this makes a nasty runoff when it eventually rains.
  • Ingest it or let it contact your eyes or other such areas.
  • Dump it down the drain, as this will clog your drain and mess up the sewer system
  • Put it in a landfill, as this is dangerous and harmful in about six ways.

* I have left the spelling as "recyeled" to allow searchers to find this post by excluding the correctly spelled word.
† ← I've never tried these, but they should be interesting

Wednesday, July 25, 2007

How to Pull Cables with String

The knot to use is called a "stitch", and it is the same technique used in data centers to secure bunches of cables without all of that Velcro mess.
Either the "Right" or "Wrong" style will work, and I describe the "Wrong" method below. This works for Ethernet cable, Romex®, and similar cabling. It's a great technique to use with fish tape, the metallic band on a reel used to fish inside of walls.
  1. Make two loops in the string.
  2. Turn one around.
  3. Stick the cable through the loops.
  4. Pull on the string to tighten (it's OK for the loops to separate). If done properly, the harder you pull on the string, the tighter the knot gets. If done wrong ... just do it again.
  5. Wrap with as little electrical or duct tape as possible to secure the loose end of the string, protect your cable end, and to keep the end of the cable attached to the string so it doesn't wedge as you pull it. Too much tape will snag as you pull it through.

For fish tape, you typically fish the tape from where you want to go to where the cable is. Attach the string to the hole in the end of the tape. The other end of the string gets the procedure above.

Sometimes your intended run is such that you can't get yourself or the fish tape reel to the destination. If you have an open space between two holes, sometimes the fish tape flops around. In those cases, attach the string to the fish tape before fishing it through, so that you can control the tape a bit with tension on the string. You will then have string all the way through the run.

I've used this knot (doubled) for connecting two ropes, since other knots form a point of weakness and this one doesn't (when doubled). Knot the loose ends in a square knot rather than with tape.

What To Do With Old Wire and Cables

This is about copper cable, such as old 2-,4-,or even 50-pair telephone cable, cat-3 or cat-5 Ethernet cable, non-metallic electrical cables (Romex®), or anything similar. Whether you choose to reuse or recycle it, the stuff is getting too expensive just to throw away. This page describes how to use it for audio speaker wire, make rope from it, or even how to use it for some really environmentally awful fun.
  • Copper cable can be recycled, but finding a recycler nearby who deals with it may be difficult. Luckily, Earth911.org provides a recycler locater search box.
  • Use old RG58 Ethernet cables with BNC ends as speaker cables, with BNC jacks in wall plates as needed. This type of cable is designed to carry radio frequency signals, and works even better at lower audio frequencies where impedance is negligible. It's easy to use, way cheaper (if you've got it already) than doing what this guy recommends. The sound is the same.
  • Old twisted-pair (Cat-3 or Cat-5) Ethernet cable works great as a source for color-coded twist ties. Leave the vinyl jacket on until use, then strip off as much as you need. Or you can cut it all up and stand it in a jar.
  • Rope: braid a strand of copper cable with two strands of other cord, of either synthetic or natural fibers. This makes a rope that is stronger than the individual cords and that will never rust.
  • Rope 2: Braid twisted sets of copper wire with strands of cotton or synthetic string of similar thickness, again making a rope. Use as many individual strands as you want, up to a practical limit. You can make the twisted sets of copper wire by attaching one end of a set of wires to an electric drill and the other to something fixed in place. Twist one set of wires clockwise, the other counterclockwise. This can be done in stages without cutting the wires. Twist each section the same amount and as tightly as desired, but avoid knotting. Braid the three (or more) pieces of cable or cord together, taking care to balance the twisting directions (so the resulting cable will tend to kink less).
  • Romex makes a nice pipe hanger for plumbing work, since it's flexible but stays in shape. The individual strands (solid wire only) also make excellent heavy-duty twist ties.
  • PVC-coated copper makes a pretty, multicolored flame when it burns on a campfire. The smoke is toxic, of course, and so not really good for the air, but still, it's pretty.

Tuesday, July 24, 2007

What To Do With Old Wooden Pallets


If you ever take a bulk delivery on materials, you may find yourself with several wooden pallets, and not know what to do with them beside burning them or begging the garbage man to take them away. Wikipedia suggests they can be used for a number of really clever things. Here are some not-so-clever but very easily completed projects for anyone with a hammer and nails. All of these work very well because wooden pallets are made not to come apart.

Note: most inexpensive pallets are made from untreated pine or other softwood, which will ensure that the part of the pallet exposed to the ground will begin to rot soon. Rarely, you may find a pallet made from treated pine. (If you burn it, don't breathe the smoke.) It will take a few years before the compost bin falls apart, which gives you plenty of time to find more pallets. Hardwood pallets may last longer, but are often subject to a deposit.
  • Make a workbench
    I did it a few years ago. I had to cut one of the pallets in half for some reason, but I don't remember why. I ended up using a scrap 2x4 as a support on the back, and some masonite or fiberboard as the top.

  • Make a compost bin

    Just nail three pallets together in a 'C', with the deck boards facing in. They don't have to be vertical, but it makes the composting part work better. Nail in a couple of diagonal supports on top if it won't stay rigid. Just face the back toward the neighbors and fill. You'll never have to burn leaves or buy fertilizer again.

    (Image from the National Wood Pallet & Container Association, under fair use)

  • Build a dog house
    If you have a dog, even one that mostly lives inside, using three or four pallets you can make a nice, sturdy spot for your little wolf.
    1. Lay a pallet on the ground
    2. Lean two more pallets together on top of the first one, with the bottom edges of the top two resting between two deck boards.
    3. Nail the roof-walls together, optionally using a couple of boards to make cross-pieces at the open ends.
    4. Secure the roof-walls to the bottom, either by nailing them directly together or by some means left to your creativity to devise
    5. Cover it with plywood, shingles, or any other weatherproof material so that Fido has a spot out of the rain and sun and off the ground.
    6. Throw in a piece of old carpet or welcome mat for that homey touch.

Monday, July 23, 2007

Troublesome Filenames

smith: In my public_html directory there are subdirectories called "~backup" and "~smith". "Backup" is the name we use for file archival of old work. When I cd to them I'm taken to some home directory. What's going on?

me: That looked funny at first, but I think it's ok.

A ~ (tilde) character is shell-ese for a home directory, either your own by itself or that of a given user with "~username". So when you entered "cd ~smith", it actually took you to your home directory. The /public_html/~smith thing is a real directory with a tilde as the first character of the name. You can create a directory with that name by typing

        mkdir public_html/~smith
The tilde is only interpreted as a home directory when it's the first character of a directory name, and only by csh/tcsh/zsh/ksh. Shell scripts are typically interpreted by the Bourne shell (/bin/sh), which doesn't know what "~smith" means, so sometimes shell scripts will create files named like that.

Entering

        cd ~smith/public_html/~smith
took me to a directory that didn't look like your home directory. I renamed public_html/~backup to public_html/backup and public_html/~smith to public_html/smith.

There are other misbehaving filenames. Usually they come about the same way the "public_html/~smith did: UNIX file systems allows filenames to contain characters that are special to some command interpreters. For example, a mistaken cut-and-paste operation can generate several spurious commands, perhaps creating files with random names. Misbehaved filenames may make it hard to work with files, even in the newer shell programs.

For instance, files beginning with a hyphen ("-") will confound some commands. If you have a file named "-h" and try to do anything to it, the usual commands such as mv, cp, or rm will interpret the name as a command line switch and tell you you're typing the command incorrectly:

~/temp me@server 8:48> ls -l
total 0
-rw-r--r-- 1 me mygroup 0 Feb 20 08:46 --help
-rw-r--r-- 1 me mygroup 0 Feb 20 08:46 -h

~/temp me@server 8:48> rm -h
rm: illegal option -- h
usage: rm [-fiRr] file ...
zsh: exit 2 rm -h

~/temp me@server 8:48> mv -h goodname

mv: illegal option -- h
mv: Insufficient arguments (1)
Usage: mv [-f] [-i] f1 f2
mv [-f] [-i] f1 ... fn d1
mv [-f] [-i] d1 d2
zsh: exit 2 mv -h goodname
The solution is to specify a path name for the file, either an absolute path as in /usr/local/bin/--badfile, or a relative path such as "./" (dot forward-slash, meaning the current directory).
~/temp me@server 8:48> rm ./-h    
~/temp me@server 8:48> mv ./--help goodname
~/temp me@server 8:48> ls -l
total 0
-rw-r--r-- 1 me mygroup 0 Feb 20 08:46 goodname

Other inconvenient filenames can require a "\" (backslash) to quote characters that are special to the shell, such as "-" (hyphen), "~" (tilde), " " (space). The newer shells offering command-line completion will automatically quote the characters for you.

Advanced users may wish to apply the stream editor sed to the problem.

For a list of names of punctuation marks, I recommend the Wikipedia entry.

Sunday, July 15, 2007

Six Flags St. Louis

We went to Six Flags St. Louis on a 90°F July Sunday.

We got there at 9:30am, though the park opens at 10:30. There were about 20 cars ahead of us at the gate, and by the time they opened the gate to let us in the parking lot, there were at least 100 cars waiting. We parked, showed our Internet tickets to the cashier, and then waited until 10:15 at the entrance turnstyles. We made our way toward the first ride of the day, only to be stopped by park security. They held everyone back from the attractions until 10:30.

My take: either open, or don't open. Don't do it halfway. I guess it's their business, though.

While waiting for security to stop their tyranny and allow us to ride the rides, we developed a plan. Security had deputized a couple of pre-teen kids, signified with adhesive label badges. We decided that unless word came soon that we could go into the rest of the park, we would point to the ground and say "Look! A toy!", dash past the distracted kids, and quickly take over the park, allowing us to be the first to ride the rides that day. While demponstrating that move, I didn't realize that an older boy was watching me. He looked for the toy. This could work!

But while we were still laughing at the older kid for actually falling for the trick, the guards relented from their oppression, and we dashed to the first ride.

Mr. Freeze: thrilling, but too short. On the other hand, I could sit and watch the takeoff and landing for hours. We rode it twice.

Batman: Good coaster, but even though you're upside down a lot, there's no weightlessness. The line is always too long.

Ninja: Great coaster. No line, so we went through about 6 times. We found it physically tiring, because this older coaster beats you up. Still, there's lots of air time.

Screamin' Eagle
: I was surprised at how much I liked this 30+ year old wooden relic. Once the biggest wooden coaster in the world, this thing is still great. The first time though, a dad was telling his 6- or 7-year-old that the boy was brave enough to ride the Screamin' Eagle. The boy wasn't sure, and whined about Mom not riding. Dad encouraged, saying "You've already been on Ninja and Batman, you can do this one!" I said if he'd been on those, this one would be a piece of cake. I turned to my own son and whispered that I was a big liar, that this was going to kill him. Buuaaa-haah-haah. Especially at the back, you get a lot of floating air time, and the 4000-foot ride is long enough to enjoy. Since it's old, it's not as popular as the newer ones, so we got to go through several times.

(The dad and kid behind us both loved it.)

The Boss: line too long, didn't ride it. Really long wooden coaster, people said it was pretty good.

Tidal Wave: This is a short little water-car ride, the entire object of which is to make a big splash. Yes, you get wet, no matter where you sit. To get really soaked, stand on the bridge overlooking the car as it splashes into the tidal pool. I wrapped my wallet in a little park map, and it stayed dry in my pocket. Wish I'd brought a Zip-lock baggie.

A word about prices: they suck. At Six Flags, everything costs way too much. $7.50 for a turkey thigh seemed like a bargain compared to the $3 bottled water, the $10 32oz sports bottle, and the other overpriced fare. And except for the turkey thigh, which I recommend, the rest of the food was crappy.

We took a bit of a tour of their water park area. Lines, crowds, and everything is $10. Rent an inner tube (required for some attractions) for $10, a locker for $10. At Holiday World / Splashin' Safari in Santa Claus, Indiana, the inner tubes are free.

At Holiday World, the rides are maintained better, the staff is friendlier, and there is free soda all day, every day. It makes for a nicer experience.

Overall, Six Flags has some nice roller coasters, but Holiday World does, too. Given the overall suckiness of Six Flags and their attitude about grabbing every last dime you have, I'll go to Holiday World next time.

(No one paid me to write this, and I'm not affiliated with any theme park or similar competitor)

Saturday, July 14, 2007

The Transformers

This is the first ever, and perhaps only ever, Modern Sourcery Movie Review. Spoiler-free.

I took my son to see The Transformers, a big-budget motion picture version of the television cartoon version of the Hasbro toy figures that changed from trucks and planes into alien robots.

Need I say more?

How about: this was the funniest movie I've seen since Men In Black. It was an amazing artististic success visually, perfectly cast, well-acted, well-directed (as far as I can tell) and hilarious in its overreach. The robot dialogue managed to combine the chill of Darth Vader with the intellectual depth of Mr. T. Buzz Lightyear meets Small Soldiers. We both laughed hysterically.

And I want to see it again.

Tuesday, July 10, 2007

Make a Japanese Beetle Trap

Japanese Beetles are a nuisance for anyone East of the Mississippi River trying to grow roses or other fragrant flowers. They can kill a small rose bush in an afternoon, and they seem to be immune to any season-long insectides you'd want around roses. While I suspect that the Japanese Beetle traps, like bug zappers, may draw as many bugs as they kill, I can't resist the temptation to rid the world of as many of these horrid little beasties as I can.

Several companies sell excellent traps for the pests, including Sterling, SpringStar, and others. And they charge $5 or so for refill bags. Of course, this drops down to 50¢ in the fall, on closeout, which you then have to store the bags all winter. But you already have an endless supply of Plastic Grocery Bags (PGBs), so why should you buy more bags?

By curling the handles and the opening of the PGB inward, you can hook the bag onto the Japanese Beetle trap made by one of the nice companies listed above. Make a loop of a 6-inch piece of wire or twist-tie, girtling the bag with it to give about a 2-inch opening. If you run out of attractant, put a drop of honey (or cut flowers if you have a lot of bees around) in the bottom of the bag. The first bugs will find the nice-smelling honey, and after that the others will be attracted by the smell of other bugs. When the bag gets full (or starts to smell bad), knot it closed and let it sit in the sun to kill all of the bugs.

A Q&A from Gardens Alive doesn't speak highly of traps, but it has some great suggestions for dealing with Japanese Beetles, including ways to attract birds (who apparently eat them) and using beetle juice to repel the bugs. I don't know. We have about a dozen active bird houses around our house, and still every year I get to slaughter Japanese Beetles by the thousands.

And that beetle juice sounds fun to make.
[Update 20070810
This year, I didn't put any traps out. The difference is that the finches who live in our bird houses have found the rose bushes, and patrol them regularly. Finches love to eat Japanese Beetles! Yay!

Whether it's the finches, the lack of traps attracting them, or some downswing in the beetle population, our roses have not been hit by the beetles this year.
]

Friday, July 06, 2007

Stupid Bugs No Match for Ceiling Fan

I just noticed something fun. There's a hole in my window screen, which tomorrow I will fix. But tonight there is a procession of beetles coming in, one every half hour or so, attracted by the ceiling fan light. But they aren't just attracted by the light, but by its reflection in the fan blades.

I suppose the reflection, which flashes about 10 times per second, looks to their pitiful little bug brains to be a really exciting flashy light. It must be near a source for some beetle food, or a sexy beetle. It's sort of a beetle disco ball.

Unfortunately, the reflection also looks like it's on the ceiling, what with depth perception and mirrors and all that. So the bugs ignore the real light bulb, a perfectly usable 60-watt incandescent little number, and go for the reflection ... but they don't get there, as a fan blade knocks them to the floor, where I swat them like bugs, or squash them like bugs under the crushing force of my foam rubber Birken-nots.

Taken a step further, by shielding the real light and only showing the reflection, a nice fan-powered bug killing system could be devised.

Thursday, July 05, 2007

What To Do With Plastic Grocery Bags

Of course we all know about using plastic grocery bags (PGBs) to line small trash cans around the house, so that emptying the bathroom trash becomes child's play -- or child's chore, if you've got a kid needing a chore (which is somewhat redundant). But there are many other uses:
  • Laundry bag - for smelly or damp articles such as gym clothes, as long as you don't leave them there long enough to mildew, which is about six hours, depending on dampness. If you have a watertight bag, consider rinsing your clothes in the shower, and storing them in the bag soapy and wet (for a few hours).
  • Camping in wet or snowy weather, spare socks will stay dry in the bag, and the wet pair can be stored in the same bag (use two bags if you have more than two pairs).
  • Boot liner - if you don't have good boots, put a pair of grocery bags (or bread bags) over your socks. You will be amazed at how much warmer your feet stay. A drawback is that they tend to sweat.
  • Dog raincoat - If you have a stupid little dog that doesn't like cold or wet weather, rip a corner of a bag and stick the dog's head through. Pull its front paws through one handle. It may be necessary to make a hole in the bag for the tail and hind legs, depending on the breed. Pull its back paws and tail through the other hole or handle, tying the handles under the belly. Be sure to leave room at the back for the place of business, should any deposits need to be made.
  • Japanese Beetle trap refill -- see instructions
  • Paint can cover - before opening a can of paint, poke or cut a hole bigger than the size of your brush, but smaller than the opening of your can, in a PGB. Open the can, put the bag over the top, and poke the edges of the hole you cut around inside and under the lip of the can. Used with a brush, you will keep the paint out of the rim. With practice and care, you can even pour the paint without getting any under the bag and into the rim of the can. When finished or taking a break, use up any excess around the rim and put the top back on the can, with the bag still in place. It will seal more easily and also open more easily. Take care not to rip the bag with your can opener, but drying paint will seal small tears.
  • Paint tray liner and brush cover - (at least for latex paint) turn a PGB inside out (to avoid smearing the label) and cover over a paint tray. Wrap the handles around the feet of the tray at the higher end. Pour the paint onto the bag, in the tray, and use with a brush, pad, or roller. It feels a little awkward and messy at first when used with a roller, but it works just fine. The best part: between coats, or if you need to take a break, use up the excess paint and put the wet roller or brush in the painty part. Take the bag off the tray, turning it right side out, and wrap the bag around the handle of your brush or roller. It will keep even overnight if wrapped reasonably. For longer storage, seal with a twist-tie and put it in the freezer, where it will last at least a week, and probably a lot longer. When you're done, discard the bag, or even use the bag for a trash can liner for that "new house" smell.
  • Icing bag - put some icing in a PGB and poke a hole in one corner. Squeeze out a bead of icing. It's not Cordon Bleu, or even Betty Crocker, but you can write "Happy Birthday" on a cake.
  • Mortar/grout bag - use the same technique as for an icing bag ... but be sure to use a different bag.
  • Furniture leg cover - I guess people still shampoo carpets. If you have furniture in the room, cover the legs with PGBs to keep the water and detergents from marring the finish.
  • Doggie Do recovery device - I guess city folk have to pick up after their dogs (out in the sticks we use a sand rake and tray to gather it up to put in the compost). When walking the dog, use a PGB as a glove, picking up Fido's deposit off the sidewalk. Twist the bag to seal in the freshness, and continue. You can several bags for the same walk, or if bags are scarce, our Supertwist technology will allow multiple deposits to be recovered into the same bag.

Wednesday, June 27, 2007

What To Do With Old Carpet

Carpet is not used up once it is no longer good for use in the parlor. There are lots of uses (reuses) for old carpet.
  • Unless it smells like cat:
    • Insulate the dog house
    • Make a cat scratch post
  • Cut into strips and put it on the garden (especially if it smells like cat)
  • Use it as a drop cloth for painting
  • Cover or separate furniture when moving
  • With bicycle hanger hooks, attach it to the eaves of a garage or shed, paint a target such as a baseball strike zone on it, and allow your aspiring young pitcher, golfer, or place kicker to practice in style. (Note: color choice may impact effectiveness.)
  • Pad or protect a pickup truck bed, sides, or rails, tailgate
  • Another site adds:
    • Cut up carpets for use in cars as floor mats or to line the trunk.
    • Cut into small circles and place under the feet of heavy furniture.
    • Take camping for a doormat, or to put under sleeping bags
    • Insulate your compost pile over the winter
  • A commenter at yet another site suggests using it in a greenhouse (which would go as well for any other indoor/outdoor area where function outweighs beauty, such as a garage or barn)

Friday, June 22, 2007

How To Do Anything

As the title suggests, what follows is a strategy for accomplishing any goal, no matter how easy or how hard. Some of the rules may not seem to apply to your goal. Some of it is age-old wisdom, while some is just stuff I've noticed. Which is which will almost certainly be obvious.

I use the terms 'task' and 'project' interchangeably in what follows, except for the connotation that projects are more complex than tasks. A simple task, however, can reveal or become a huge project. A project can also serve as a metaphor for a lifelong dream. The process is recursive: treat each task in a project as a project.

  • Think First, Do Second
    Planning is only necessary if you want to succeed. Before you start work on some project, learn about it. While a novel approach sometimes strikes out of the blue, most of the time your 'novel' approach will be the first one that everyone else who ever tried to do what you're about to do thought of the first time, too. When you are learning about a subject area, don't be too quick to come up with a plan, but let the new information percolate. Time spent thinking, drawing pictures, or asking around will save many multiples in wasted effort, or will avoid the same amount in the paralysis of procrastination. It may also mean the difference between success and failure, or falling prey to threats for which you should have accounted. Periodically on the way to your goal, revisit your plan to make sure external events haven't changed your requirements, and to be sure you haven't gotten away from the plan.

  • Read The Fine Manual
    A lot of things seem impossible until you know how to do them, but are easy once you do. If you don't know how to do something, perhaps someone else does. Few things are really new. In the modern era of search engines and instant communication, getting instructions has never been easier. No matter what the task, by the Green Tennis Shoes Principle, someone probably has a web page describing how to do it — with a printable checklist and a flash movie of the tricky parts, and a forum of users with answers to questions you didn't even know enough to ask. The instructions will generally also tell you how to mitigate any risks.

  • Ask For Help
    People don't know you need help. Ask. Sometimes just asking even someone who has no apparent skills at all to help you will be enough to make you realize what you have to do. There's nothing like teaching a thing to make you learn it. But you most often will be surprised at how a fresh perspective will confront a problem, making what seemed hard before much less so.

  • Divide and Conquer
    Almost by definition, any task worthy of a plan will have component parts which can be handled separately. Take on the largest or most difficult portion you can reasonably achieve while leaving the rest for later.

  • Know What You Have
    Every project has finite resources. Most often this is time, but there may be some other key finite resource such as a raw material, money, distance to be covered, or pounds to be lost, for which you need to account more closely than time. You also need to consider the helpers and groups who will be available to you, and any who may oppose you. The opposition (even if that is only entropy) gets a vote, and so every part of every plan must account for as many kinds of failure as practical.

  • Consider Dependencies Carefully
    One reason a project seems complicated is that one part may depend on other parts being done, or simply started, first.

  • Set Deadlines
    Even if your project has no external deadlines, set them for yourself. Think carefully about these dependencies, and set your deadlines accordingly. Set milestones or benchmarks for each phase or portion of the project, in terms of the key finite resource.

  • Do the Hard Part First
    If there are several independent parts to some project, you have the option to pick off some of the easier portions before tackling what you think will be the hard parts. Other things being equal, it's best to get the hard parts out of the way. This is especially true when "easy" and "hard" are actually euphemisms for "fun" and "not fun", or "rewarding" and "unrewarding". The hard part typically will have the biggest uncertainty in terms of time and resource requirements; doing it first allows you the greatest control over your own deadlines.

  • Measure Twice, Cut Once
    After your plans are made, and you think you know what to do, go over those plans again. Start from what you are sure you know, such as a factory edge, a bank balance, or a spot on a map, and measure your key resource in a different way than you did before. Repeat this process until all measurements match.

  • Do Something Next
    If you don't know what to do next, it usually means you haven't thought or planned enough. But in the middle of a project, it may be inopportune to go back to the drawing board. To avoid indecision paralysis, just pick something. Sometimes it will be a suboptimal choice, but most of the time will be as good as any other, and only rarely will you choose a task order that is harmful.
    Sometimes, just do what you can do. But beware of avoiding things you don't want to do.

  • Don't Bang Your Head
    If you find yourself trying to do the same task repeatedly and having it not work, stop. If you are banging your head on a wall, it either means you need to look for a window, a door, a way around the wall, or you're working on the wrong wall. Perhaps you're just doing it wrong, and need to ask for help. Take a step back and look at the overall project. Is this wall even part of the plan? Is there something else you can do first? Sometimes nibbling at the edge of some other part of a project will make the whole thing easier in ways you didn't understand during initial planning. But most of all, doing something else will allow you to come back at the head-banging problem fresh, perhaps after your subconscious has had a chance to solve the problem.

  • Serialize Parallel Steps
    Some jobs require, or appear to require, doing several things at once. Typically, however, it's possible to take those things one after another, repeatedly switching among them. For people who find it difficult to juggle many tasks at once, taking this serial approach to parallel tasks may make all the difference.

  • Parallelize Serial Steps
    In Divide and Conquer, we saw that sometimes it's possible to accomplish parts of a task independently of one another. If resources permit, taking up several of these independent tasks at the same time, rather than one after another, may make doing them all easier. This is particularly true if there are helpers who can be working on the different pieces.

  • Delegate the Repetitive
    Computers, robots, employees, and tools are helpers. They give you the ability to parallelize, but require time for setup and maintenance, as well as for coordination and inspection of the finished work. Many times a skilled or well-designed helper can perform a task better than you can. Sometimes one of them, especially in the case of humans, really ought to be your boss. Confront (or ignore) such concerns and focus on the project. Delegate, and apply your own ability where it is best used.

  • Invent A Tool
    If you are having difficulty with a particular task, and no one seems to know how to do it, and you've followed all of the other points here, it may be time to step back from the process of doing, and become a toolmaker. Even if you lack the skill to make the actual tool, sometimes you can envision a tool that someone more skilled never thought of making, or never thought to apply to your use. Don't be afraid to invent a tool you will discard after the job. Toolmaking helps especially if you are banging the wall, or if you know you need to delegate a parallel task but don't have any helpers. The hard part will seem easy when you have the right tool.

  • Completeness
    Finish all of the parts, even the ones that don't show. Dependencies lurk everywhere. An incomplete or sloppy job at a minor task here, a corner cut there, and pretty soon you are wasting key resources on reworking tasks that you thought were done, introducing new dependencies and foiling all your plans. Do things right the first time, and do them completely.

Each of the above points could get an entire blog entry, and someday they may. Each of them deserves examples and other justification. Many deserve some scientific at least philosophical underpinning. For all of that, brevity won out.

Wednesday, June 20, 2007

More sed Tricks

Sometimes I think sed(1) is the reason I like Unix. Well, it's one of the quintessentially Unix tools, anyway.

One of my favorite uses for sed is to rename a whole bunch of files all at once. Whether the problem is a spaces or other special characters in filenames, capitalization problems, or whatever, as long as you can see a pattern sed can probably fix it for you.

For instance, I just had to make a whole bunch of symbolic links to some files

audit_user.dir
auto_data.pag
auto_master.dir
exec_attr.pag
....

so that the links had the names:

audit.user.dir
auto.data.pag
auto.master.dir
exec.attr.pag

and so on. Sed to the rescue:

for f in *_* ; do
ln -s $f `echo $f | sed -e 's,_,.,'`
done
(If you try something like that, put an "echo" before the "ln" to test it out)

That's a fairly simple example, and in fact the Unix C-shell has that kind of search-replace built in. I don't use C-shell, because the standard Bourne shell /bin/sh and derivatives (such as the Bourne Again SHell /bin/bash) are better for scripting.

But consider the problem of turning off some, but not all, of the "init scripts" under a particular runlevel in a typical SystemV-style system, such as Solaris or Linux. Red Hat Linux solves this with the chkconfig command, and Red Hat admins may like to use that handy facility.

But for those of us who have heterogenous collections of systems to worry about, and even on Red Hat systems when digging under the hood, it would be nice to have a way to turn off (or on) several services at once.

A "runlevel" is sort of like a system mode, and the levels are not standardized but generally follow a pattern of sorts. The chkconfig link above gives a nice description of runlevels for Linux, but note that while under Linux runlevel 5 means X Window operation, under Solaris it means shut down.

In a System V-style system, the init scripts themselves are stored in /etc/init.d, with some reasonable name like 'apache' for the Apache web server or 'autofs' for the file system automounter.

Each runlevel has its own directory, /etc/rcN.d, which contains symbolic links to the init scripts in /etc/init.d. To control how a particular runlevel uses a given init script, the symbolic link is prepended with an "S" for Start, "K" for Kill, or sometimes another letter, which means to ignore. After the S or K is a number, like 01 or 25, used to sort the names. The init(1) processing runs each S script in alphanumerical order, so that services should get higher numbers than the more basic services on which they depend.

Renaming the files is a bit of a hassle, either from the command line or with a GUI, because each one must be done. From the command line in particular, changing just the first letter requires typing the whole file name, with the numbers.

So what has all of this to do with sed?

This little script renames all the files matching a list of patterns you supply, either from S##name to K##name or the other way. It preserves the numbers, without you having to type the whole name.
#!/bin/sh
#------------------------------
# Script : s2k Copyright 2000,Loren Heal
# Author : lheal
# Created: 20010305
# Known Bugs:
# TODO: only operates on current directory.
#(------------------------------
FROM=S
TO=K
FORCE=""
TEST=""

usage()
{
echo "$1 [-on|-off|-force|-test] expression [...]"
echo ... where "expression" matches one or more of:
ls -F ${FROM}*
exit
}

[ -z ''"${@}" ] && usage "${0}"

while [ -n "$1" ] ; do
# echo "$1"
case ${1} in
"-on" ) FROM="K"; TO="S" ;;
"-off" ) FROM="S"; TO="K" ;;
"-force" ) FORCE="-f" ;;
"-test" ) TEST="echo" ;;
* ) for fname in `ls ${FROM}*${1}*` ; do
tname=`echo ${fname} | sed "s/^${FROM}/${TO}/"`
if [ -n "${tname}" -a -n "${fname}" -f ${fname} ] ; then
&& ${TEST} mv ${FORCE} ${fname} ${tname}
fi
done
;;
esac
shift
done

Friday, June 15, 2007

Tying Shoelaces So They Stay Tied

The bow knot we use to tie our shoes has some good things going for it. It's easy enough to learn, it's as quick as anything else to tie, and as importantly, it's very quick to untie. The trouble is, it comes undone too easily. I use a slight variation on the bow knot, which looks like a nicely tied bow knot but never comes untied until you untie it.

Athletes, children, even business people find it important to keep their shoes tied. Whenever I see some collegiate or professional athlete calling time out so that millions of people can watch him tie his shoes, I think "There's a guy who doesn't know how to tie this shoes!" And there are few things sillier than a man in a $1000 suit walking around with laces dangling from one $200 shoe.

The usual solution, retying the loop ends, looks ugly, doesn't stay as well as it should, and worst of all makes the knot difficult to untie.

Parents and coaches everywhere need to teach their kids the following simple little method. Once it becomes a habit, it's one less worry in life, and one less thing to nag about.

The problem is the ordinary bow knot we traditionally use to tie shoes. I use a slight variation on the bow knot, which looks the same (but neater), and never comes untied. I've used this knot with leather boots, dress shoes, and shoes used in running hundreds of miles.
  1. Cross the strings over to make the usual base, cinching it as tight as desired.
  2. Make a loop with one string.
  3. Wrap the other string around that one TWICE, instead of just once.
  4. Push the remainder of the wrapping string through two wrappings.
  5. Tighten fully.

This works with any shoe lace, whether cotton, synthetic, or leather.

As I typed all of this in, I did a web search to find a picture of shoelaces. It turns out that a guy has a whole site just about shoelaces. The Green Tennis Shoes Principle striketh. His site has pictures of this method, called the Better Bow Knot.



Why does this work?


As the two loops are pulled apart during the final tightening, notice that the two center wrappings cross over one another. That forms a little sub-knot, so that in order for one wrap to slip, the other has to slip first. As a result, neither one does.

Untying is the same as with a standard bow knot. Make sure the ends aren't pulled through the loops, and pull on the loose ends.

I suspect, without any data whatsoever, that this method may even be easier to learn for first-timers. The only hard part about tying a bow knot is in the wrap-and-tuck step. Wrapping twice should make it more clear to young learner how it should be done.

Or maybe knot.

Thursday, June 14, 2007

Robust Systems

Information systems should be robust. A robust system is one which operates correctly and efficiently under a wide range of conditions, even under conditions for which it was not specifically designed. In particular, a robust system resists attempts to make it operate incorrectly. In other words, it is secure.

While the above sounds simple enough, "correct", "efficient", and "secure" as used above are actually terms of art. An information system is a collection of devices or programs organized to change, transmit, or store data. A system can be said to be correct when its output is provable for all given inputs, and efficient when it completes its job with an acceptable and predictable use of resources.

Systems more complicated than shoelaces should be designed in two or more stages. At each stage there is the potential for debugging. The optimal breakdown for the stages of the overall development process can be thought of as finding the maximum amount of progress toward completion that can be effectively debugged, while also maximizing the likelihood of catching a mistake before the next stage.

Along with basic engineering practices, the principles that lead to robust operation are the same ones recognized by security experts:
  1. Economy of Mechanism - this means to keep things simple. Simpler processes are easier to understand and are generally more robust.
  2. Fail Safe Design - Erroneous input should result in the least harmful action.
  3. Open Design - The reliability of the system should not depend on keeping its workings hidden.
  4. Complete Access Control - All access to assets should be allowed only to those authorized.
  5. Least Privilege - Access to assets should be given only as required.
  6. Separation of Privilege - Access to assets should be based on multiple independent criteria.
  7. Least Common Mechanism - Shared means of operations should be minimized.
  8. Psychological Acceptability - If the perceived inconvenience associated with system safeguards is higher than the perceived value they allow, users will tend either to circumvent the safeguards or not to use the system. Therefore, measures should be implemented only if:
    1. They can be built in to the system such that following them will be no harder than avoiding them
    2. They are more likely to mitigate a threat than to cause user frustration
Here are some principles to bear in mind when creating correct, robust systems.
  1. Garbage In, Garbage Out: Input should be validated before it is used
  2. Efficiency: when possible, the resources used by a process should not grow faster than the size of the input. Typically the resource use should be bounded by a function of the size of the input, and for robustness, resource use should not depend on the particular input given.
  3. Correctness: a process cannot be known to be efficient unless it is known to be correct. If some inputs yield spurious results, that is not robust.
  4. Special Cases: the allowance for special cases signals that a design can be improved
  5. Hope is the Enemy of Know: The result doesn't care what you hoped it would be
  6. Expect Failure: Component failure should be an expected part of operation.
  7. Capacity: rooted in efficiency, capacity is a vital part of robustness.
So enough of these generalities. What are some examples of robust system?
  • Handicapped stalls
    Whenever possible, if I have to use a public restroom I use the handicapped stall. These stalls are roomier, and generally better lit.

  • Automatic doors
    Grocery stores have long used automatic doors, which sense the presence of a customer and open without anyone touching them. That works for anyone from small children to the elderly. It also works equally well for anyone, one of the hallmarks of a robust design.

  • 36-inch doors and accessible homes
    Similarly, while 36-inch doors make rooms accessible to those in wheelchairs, they also facilitate moving furniture.
Robustness is not just a matter of handling lots of volume. It's a question of design. A robust system is designed to handle all cases equally well, because it doesn't play favorites. The same algorithm, method, or formula used to handle the most common case handles the unusual ones. That gives the best chance for handling cases we don't even expect to encounter with the same aplomb that we handle the ones we do expect.

Wednesday, June 06, 2007

Google Books and the Big Ten

Google Books and the Committee on Institutional Cooperation (CIC), comprising the Big Ten and the University of Chicago, have announced an agreement with Google to digitize works from its member libraries as part of the Google Book Search project.


In the CIC are 6 of the nation's largest 20 libraries.


In a multi-year project, Google will scan for search millions of public domain and copyrighted items, under Fair Use or by agreement with copyright holders. According to a CIC release,

Public domain materials can be viewed, searched and downloaded in their entirety. For books under copyright protection, a search will result in basic information (such as the book's title and the author's name), and a snippet of text surrounding the search term. Users seeking further information from the text will be directed to avenues for purchase or library access.

The CIC plans to implement a digital archive of research and other content, both for preservation and to enable academic study and collaboration.
This partnership with Google will enable the CIC universities to digitize library content at a scale and scope not possible with the limited means available to individual institutions. And now, with the future promise of a shared digital repository, our universities will enter into an ambitious, groundbreaking collaboration to collectively archive digital public domain materials previously housed within the bricks and mortar of individual libraries.

See the CIC site more information on the CIC and the Google partnership.

Google / CIC Release

Email release from University of Illinois Provost Linda Katehi:

Today the Committee on Institutional Cooperation (CIC), a consortium of 12 world-class research universities, advancing their missions by sharing expertise, leveraging campus resources and collaborating on innovative programs, is announcing an agreement with Google to digitize distinctive collections across all its libraries as part of the Google Book Search project. As a member of the consortium, our university is part of this important initiative.

Over the next several years, Google will scan and make searchable up to 10 million public domain and in-copyright volumes in a way that is consistent with copyright law. Public domain materials can be viewed, searched and downloaded in their entirety. For books under copyright protection, a search will result in basic information (such as the book's title and the author's name), and a snippet of text surrounding the search term. Users seeking further information from the text will be directed to avenues for purchase or library access.

Also, this agreement anticipates the CIC's intention to create a shared digital repository, so that each university can "deposit" its digitized public domain files into a commonly funded and managed data storage system. Over time, the shared digital repository will enable our librarians to archive and organize content collectively for scholarly activity, as well as design services such as customized searches for the academic community. When implemented, students and faculty will have convenient, desktop access to a vast array of public domain materials from across our 12 institutions.

The role of archiving and preserving the vast spectrum of written materials is a critical one for university libraries. Many works become out of print, or deteriorate with age, or are threatened by natural disasters or societal upheavals through the centuries. And as we move to a completely technological and digital environment, materials not available in a digital format will become less and less discoverable. Digitization enables us to preserve our historical collections for all time.

This partnership with Google will enable the CIC universities to digitize library content at a scale and scope not possible with the limited means available to individual institutions. And now, with the future promise of a shared digital repository, our universities will enter into an
ambitious, groundbreaking collaboration to collectively archive digital public domain materials previously housed within the bricks and mortar of individual libraries.

For more information on the CIC and today's announcement, visit:
http://www.cic.uiuc.edu/digitalbooks.

Friday, June 01, 2007

How About Employing an Editor?

If you can't see anything wrong, click here for an explanation.

ht: Daily Telegraph

Tuesday, May 29, 2007

The Network Should Never Be Down

That a whole country could be DOS'd is evidence of someone doing a bad network install. The network should never be down.

Lots of companies have a root-and-branches approach to Internet connectivity, too, thinking that each site (or the whole corporate intranet) needs only one gateway to the outside. It leverages a small investment in Internet connectivity for an entire organization. Put all your eggs in one basket, and watch the basket. For the family baked bean recipe confidentiality that's good, but for availability that's bad.

It takes a lot of effort to protect a single address against a distributed Denial of Service attack, in which thousands of virus-infected machines send relatively small amounts of traffic against a target. When that target is a single gateway for an organization, the connection leverage is used in reverse, causing a lot of disruption for a little effort.

The "right" way to do it is to have multiple redundant shared trunks with neighbors. That word "shared" is scary to network administrators (or rather, to their pencil-pushing mentors). It means they'll have to carry outside traffic on their pipes (that's a metaphor, Senator), and that has risks: it costs money, and it has the potential to allow someone to see inside the network.

It takes a lot more effort on the part of the bad guys to attack multiple addresses, and with a multi-trunked network, keeping one or two gateways up can keep the whole network working.

The rewards for sharing bandwidth are enormous: multiple ISPs mean allowing TCP/IP to do its job, routing traffic to avoid disasters like DOS attacks, hurricanes, and nuclear bombs. The ISPs and other bandwidth partners know they have an interest in helping to protect your network. The technical risks can be mitigated simply by routing and tunneling.

Is the above realistic? Nope. Not in a corporate environment, anyway. I'd be really surprised if anyone outside academia or pure ISP does shared trunking anymore.

But it can also happen at the leaf nodes: you and your neighbors share cable broadband and DSL connections, routing through wifi. That violates most subscriber agreements, but it's the way the protocols were designed to work. Your network should never be down.

Never.

Saturday, May 19, 2007

Adblock List

The Adblock extension is a wonderful little add-on to keep unwanted ads from showing up in to the open source Firefox web browser. Another nice thing about Adblock is that pages load more quickly without the ads, since Firefox never even tries to read the blocked images or access the sites that host them. Blocking ads allows Firefox to get on with loading the rest of the page, which is especially helpful when the site where ads are located is slow or down.

I don't bother to block text-only or small, unobtrusive ads, just the annoying popup, flashy banner, or other annoying disruptions to my online experience.

Sometimes I'll be browsing along and an explicit adult ad will show up. Adblock to the rescue!

You can export and import your Adblock list to or from a text file, to keep your list synchronized from computer to computer, or to import the filters to several computers, such as for a client installation.

You can also add someone else's filters to your own. For example, below is my Adblock filter list, which you can either cut and paste to a text file of your choice, or right-click this link to download.

In Firefox, choose Tools ->Adblock ->[Preferences].

After you have downloaded or created the filter file, from the Adblock Preferences box, choose Adblock Options ->Import, which will bring up a standard File Open box for your system. Select the file, and the filters will be added to your own.

[Adblock]
http://*.adbrite.com/*
http://*.atdmt.com/*
http://*.bfast.com/*
http://*.blogads.com/*
http://*.com.com/*
http://*.doubleclick.net/*
http://*.falkag.net/*
http://*.fastclick.net/*
http://*.liveperson.net/*
http://*.mediaplex.com/*
http://*.mspaceads.com/*
http://*.pointroll.com/*
http://*.questionmarket.com/*
http://*.ru4.com/*
http://*.speedera.net/*
http://*.spyderbyte.com/*
http://*.trafficmp.com/*
http://*.tribalfusion.com/*
http://*.valueclick.net/*
http://*.zedo.com/*
http://adlog.com.com/*
http://ads.ft.com/*
http://ads.osdn.com/*
http://adt.m7z.net*
http://creative.myspace.com/*
http://*.content.ru4.com/images/*
http://i.timeinc.net/*
http://images.radcity.net/*
http://rcm-images.amazon.com/*
http://rcm.amazon.com/*
http://us.a1.yimg.com/us.yimg.com/a/*
http://us.a1.yimg.com/us.yimg.com/us.yimg.com/a/ya/*
http://us.ard.yahoo.com/*
http://www.assoc-amazon.com/s/ads-common.js
http://www.assoc-amazon.com/s/ads.js