anoved.net: April 2008anoved.net logo

Posted on Wednesday, April 30, 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!

2:19 PM Comment (0)

Posted on Monday, April 28, 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.

Line Numbers Off Line Numbers On

Toggle Soft Wrap

This script toggles the soft wrap text property of the frontmost text window.

Soft Wrap Off Soft Wrap On

Download

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.

12:36 PM Comment (0)

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.

11:14 AM Comment (0)

Posted on Wednesday, April 16, 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:

\sum_{x=1}^{10}{x}

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.

9:57 PM Comment (0)

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.

8:36 PM Comment (0)