Fuel Economy
In the sixteen years since it was manufactured, my truck has travelled some 190000 miles. Supposing an average fuel economy of 14 miles per gallon, the truck has burned about 13571 gallons of fuel. That’s a lot.
A Boeing 777-200, smallest of the 777s, has a maximum fuel capacity of 31000 gallons. That’s more than twice as much as a lot. The 777-200’s maximum range is listed as 5235 nautical miles, or some 6024 miles. Disregarding other factors, and the possible irrelevance of such limits to typical operation, these maximums suggest a fuel economy between 0.19 and 0.2 miles per gallon.
These calculations are contrived, but it should be clear that a transcontinental flight consumes more than peanuts.
Nevertheless, this comparison should not be construed as an indictment of air travel. There are millions of trucks like mine but only a handful of airliners. Furthermore, airplanes carry many passengers, and cars do not. Last but not least, cars cannot fly. Flight is intrinsically cool.
So, I leave it as an exercise for the reader to figure out how many people a 777-200 would have to carry from NY to LA to use less fuel than those people would use if they each drove a truck like mine the same distance.
Posted on Tuesday, May 13th, 2008.
Fox Kits
Here’s a video clip my mom took of some little foxes frolicking around their den.
Posted on Monday, May 12th, 2008.
Note Poster
Here’s a script to create a new post in MarsEdit from a note selected in Yojimbo. Why use a script when it’s already as easy as copy and paste? Well, maybe your computer is running out of paste.
tell application "Yojimbo" set _items to selected items of browser window 1 if (_items is {}) or (_items is missing value) then return set _note to item 1 of _items if class of _note is not note item then return end tell tell application "MarsEdit" set _post to make new document set body of _post to contents of contents of _note set title of _post to name of _note activate end tell
Click here to open the script directly in Script Editor. Save it in ~/Library/Scripts/Applications/Yojimbo
and you’re ready to run.
Posted on Sunday, May 11th, 2008.
LDTrim
LDTrim is a simple program that condenses or formats LDraw code by trimming extraneous characters like spaces – or inserting them to align values in columns.
LDTrim was developed to help “pretty-print” examples for documentation or discussion, but it could also be used to reduce file size or to standardize the format of many models.
Much of what LDTrim does is already possible with LDraw Design Pad. For example, see “Trim Lines” and “Auto Round Selection” under the “Tools” menu.
Usage
Here is the output of ldtrim -help
:
LDTrim 1.1 Usage: ldtrim Default: [-in FILE] | [-in FILE FILE...] stdin (use -ing to glob wildcards) [-out FILE] | [-out DIRECTORY] stdout [-precision DIGITS] all significant digits preserved [-trim zeros|none] zeros (trims redundant trailing zeros) [-justify left|right|none] none (alignment of values in field) [-invalid omit|keep] omit (keep retains unrecognized lines) [-width CHARACTERS|max] variable (minimum width of all fields) [-1..15 CHARACTERS] variable (override width for one field) [-h|--h|-help|--help] display this usage summary If multiple input files are specified without -out, they are modified in place. If -out is given with multiple input files, output is saved to that directory. The -precision option causes values to be rounded down and may append zeros to reach the specified precision unless -trim zeros is explicitly specified. Whitespace between fields is condensed to a single space. The -width option pads values with spaces to reach the specified field width. If -width max is given, the widest value is used as the width for all fields. (Sub-part names are ignored for this comparison.) If a field value exists that is wider than the requested width, that width is used as the field width. Right justification is used if -width or -1..15 is specified without -justify. If none of -width, -1..15, or -justify is specified, fields are unaligned. If environment variable GATEWAY_INTERFACE is defined, LDTrim is a CGI script.
Example
Suppose you have saved this LDraw code as sample.ldr
:
1 0 20.000000 0.000000 20.000000 0.000000 -1.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 4085c.dat 1 1 28.000000 7.000000 27.000000 0.000000 -1.000000 0.000000 0.500000 0.000000 -0.866025 0.866025 0.000000 0.500000 3023.dat 1 25 36.000000 -5.000000 11.000000 0.000000 -1.000000 0.000000 0.707106 0.000000 -0.707106 0.707106 0.000000 0.707106 2412b.dat
Running ldtrim -in sample.ldr -out trimmed.ldr
will save the following as trimmed.ldr
:
1 0 20 0 20 0 -1 0 1 0 0 0 0 1 4085c.dat 1 1 28 7 27 0 -1 0 0.5 0 -0.866025 0.866025 0 0.5 3023.dat 1 25 36 -5 11 0 -1 0 0.707106 0 -0.707106 0.707106 0 0.707106 2412b.dat
The default behavior is to condense the code as much as possible without modifying the model. Alternatively, you can use LDTrim to reformat code. For instance, ldtrim -precision 2 -width 5 -1 1 -2 3 -in trimmed.ldr -out aligned.ldr
outputs the following as aligned.ldr
:
1 0 20.00 0.00 20.00 0.00 -1.00 0.00 1.00 0.00 0.00 0.00 0.00 1.00 4085c.dat 1 1 28.00 7.00 27.00 0.00 -1.00 0.00 0.50 0.00 -0.87 0.87 0.00 0.50 3023.dat 1 25 36.00 -5.00 11.00 0.00 -1.00 0.00 0.71 0.00 -0.71 0.71 0.00 0.71 2412b.dat
Giving a minimum field -width
argument implies -justify right
. Similarly, decimal -precision
implies -trim none
, leaving trailing zeros intact. The -1
and -2
options override the minimum width for the first two columns.
Batch Mode
If LDTrim is given multiple input files, it will process them all, saving the results to files of the same name in the directory given by -out
or overwriting the input files if no output folder is given.
ldtrim -in $LDRAWDIR/parts/*.dat -out /trimmed/parts/
Note that with a single -in
file, -out
is interpreted as a single output file, but with multiple -in
files, -out
is interpreted as a directory to contain the results.
Web Interface
LDTrim has a rudimentary web interface built in. If the GATEWAY_INTERFACE
environment variable is detected, LDTrim will behave like a CGI script. Specifically, it will print an HTML form with controls that roughly correspond to its command-line options. LDraw code posted via this form (to itself, as the action ldtrim
) is processed according to the selected options. The results are returned in the same form.
Download
LDTrim is also available as a platform-independent Starkit (50 KB) which requires an 8.5 Tclkit.
- Mac OS X 2.4 MB
- Linux (x86) 1.5 MB
- Windows 686 KB
The current version of LDTrim is 1.1; it fixes a bug that caused malformed line endings to be output on Windows.
Posted on Saturday, May 10th, 2008.
Candid Sketches
Drawing people in public is a fun challenge because you’ve only got a few seconds to nail their form before they walk past or shift position. I think the figures that result are more convincing than many I’ve drawn from photographs because they’re based on natural poses rather than those affected for the camera or the studio.
It’s refreshing to leave faces blank for a change.
I colored this picture on the computer. Give it a click to look at a few other recent sketches.
Posted on Wednesday, May 7th, 2008.
Hobbies
I’ve often said that I have many hobbies. I draw, I write little computer programs, I play with Legos. I work on my truck and in summer I kayak. I’ve run a hundred miles in the past month, and sometimes I even try to play the piano.
Am I an expert at any of these things? Decidedly not. But my expertise develops in step with my entertainment, and perhaps some aspect of these endeavors will someday assist or inspire someone else. (Hell, maybe someday it’ll even earn me an income.)
So it was with great interest and optimism that I watched Clay Shirky’s recent “Gin, Television, and Social Surplus” speech (via Gus Mueller, who also linked to a transcript).
The gist of Clay’s talk is that television has been an entertaining but unproductive use of the relatively plentiful spare time enjoyed by members of modern society. More importantly, he argues that ambitious projects like Wikipedia represent a total investment of personal time that is negligible in comparison to the time people spend watching TV. He calls this recreational time our “cognitive surplus”, and regards it—rightly, in my opinion—as an incredible resource that has only begun to be tapped.
I am enthusiastic about what can be accomplished as more slivers of spare time are spent on pet projects and the mischievous misadventures that beckon from beyond the sofa. Serendipity, meet spontaneity! Curiosity and collaboration are already here.
Anyway, I admit television is a popular scapegoat. It’s not all bad, but there should be more to life than a daily cycle of drudgery and reruns. We improve each other’s lives by pursuing the interests that enrich our personalities and abilities, be at it work, in the back yard, or even on the tube. I am pleased to say that this holds true for every person I know; everyone has some hobby or calling or quirk that contributes to what I know and appreciate about the world. Thank you!
Posted on Wednesday, April 30th, 2008.
Toggling Line Numbers and Soft Wrap in TextWrangler
As with most text editors, TextWrangler provides many options that allow you to customize the editing interface. Two settings I sometimes change are accessible only as preference options or as toolbar menu items. As I would prefer to toggle these features with a single keystroke, I wrote a pair of scripts to do the job. Two associated keyboard shortcuts later, there’s no need to display the toolbar or visit the preferences.
Toggle Line Numbers
This script toggles the show line numbers
property of the frontmost text window.
Toggle Soft Wrap
This script toggles the soft wrap text
property of the frontmost text window.
Download
- Toggle Line Numbers 1.3 KB
- Toggle Soft Wrap 1.3 KB
The color scheme seen in the screenshots is Gruber Dark.
Installation
Unzip the scripts and put them in ~/Library/Application Support/TextWrangler/Scripts
. Keyboard shortcuts can be assigned with the Set Key
button in the Scripts
palette, found under Palettes
in the Window
menu.
Posted on Monday, April 28th, 2008.
List splicing with foreach
Tcl’s foreach command is commonly used to iterate through items in a list. However, I had not realized that it can step through more than one list at once. Here’s a handy application of this property based on an example from the documentation:
proc splice {l1 l2} {
set s {}
foreach i $l1 j $l2 {
lappend s $i $j
}
return $s
}
This procedure combines two lists into a new list comprised of alternating items from each input:
% splice {a b c} {1 2 3}
a 1 b 2 c 3
One use for this is to join a list of keys to a list of values to establish a dictionary or an array:
% set dimensions [splice {length width height} {10 16 33}]
length 10 width 16 height 33
% dict get $dimensions height
33
% array set d $dimensions
% set d(width)
16
So if you’ve got an ordered list of values you’d like to access as named fields, you can combine it with a list of field names using foreach
and be on your way.
Posted on Monday, April 28th, 2008.
Sigma Notation
The for
loop is a useful control structure common to many programming languages. It repeats some code for each value of a variable in a given range. In C, a for
loop might look like this:
for (x=1; x<=10; x=x+1)
{
/* do something ten times */
}
The initial parameter, x=1
, starts a counter at one. The second parameter, x<=10
, means the loop repeats until the counter reaches ten. The last parameter, x=x+1
(sometimes written x++
), explains how to do the counting: add one to the counter each time through the loop.
In math, sometimes it may be necessary to add up a bunch of a related terms. For example, rather than write out 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, the problem can be expressed with sigma notation as a sort of loop:
The x=1
below the big sigma starts the counter at one. The number 10
above the Σ specifies the final value of the counter. The Σ itself means to add up multiple copies of whatever follows, using integer values of x
ranging from the initial 1
to the maximum 10
for each copy.
(The sum is 55.)
For simple arithmetic, this notation is hardly a simplification. However, if the terms to add are complicated, or if there are many instances of them, you’ll find this is clearly a compact and convenient way to express the sum. Plus, the Σ symbol is wicked fun to write.
The dweebs at Wikipedia have beat the programming-a-sum example to death.
Posted on Wednesday, April 16th, 2008.
What we choose to do with freedom
On the way home from my evening class, the bus stops to pick up visitors from the county jail. At the prison I can see a few rows of small barred windows uniformly lit by yellow light. The people behind those windows have no choice but to remain in their cells.
The bus drops me off a few blocks from my apartment. As I walk home, I pass rows of houses whose curtained windows are inevitably lit by the flickering blue light of television screens. The people behind those windows remain seated in their homes by choice.
So I celebrate the vagrant youths and fading elderly who live in transit on the sidewalks and buses between prison, school, and home. Theirs may be a sorry lot, but at least they have somewhere to go.
Posted on Wednesday, April 16th, 2008.