Maker Faire 2008 Highlights

May 4th, 2008

компютри втора употреба weekend I attended my first Maker Faire and was amazed at the variety of cool stuff to be seen. I’m sure every attendee has their own list of highlights, but here’s mine:

TechShop: The TechShop provides access to tools beyond the reach of the average hobbyist. Welding, CNC plasma cutters, later etching, and machine tools are all available after a short training class and payment of a modest use fee. I can’t even explain how excited I am to check this place out - I’ll be taking the TIG welding class at the end of May.

Electric Unicycle: The was probably the coolest single thing I saw. It sounds deceptively simple: a unicycle with an electric motor. The neat thing is that, like a Segway, it (sort of) self balances and is controlled by the operator leaning forward and backwards.

Orb Swarm: A 3′ diameter hollow sphere that can roll along the ground under autonomous control. A motor is suspended in side the sphere, and it changes direction by tilting the batteries to act as a counterweight.

Michael Cooper’s Chair: This item was sort of out of place at the fair in that, as far as I could tell, it didn’t actually do anything. Even so it was easily the most beautiful and polished piece I saw. The chair is made of curved wood laminate and is set in the middle of a spider/helicopter/hydraulic lift device right out of science fiction.

Unfortunately Mr. Cooper’s website follows the common artistic failing of using unlinkable Flash applets to display their portfolio so I can’t link directly to the piece. The item I saw is shown in the upper-right hand corner on the main page of his website.

Pretty colors: Syntax Highlighting in Mercurial

November 18th, 2007

I recently switched my personal revision control system from subversion to mercurial. One of the great things about mercurial is the built-in web interface, but I missed the syntax highlighting that’s available in interfaces such as ViewVC.

I’ve written a mercurial extension that applies pygments

view. This extension is now available in the main mercurial repo.

To enable it, install pygments and add the following entry to hgrc:

[extension]
hgext.highlight =

An example of the output.

Thanks to micha who wrote an initial patch. black jack betting strategyfree online video pokerbackgammon gambling,online backgammon gamblinghow to play video pokervideo poker practicefree baccarat game,baccarat game,baccarat casino gametournament backgammoninternet casino gamefull pay video pokerno deposit bonus online casinofree slots,free slots game,free on line slotsbaccarat rulefree black jack gamecraps online gamevirtual casino gamblingfree video poker downloadsblackjack gambling game,blackjack gambling,online blackjack gamblingblackjack casino gameno deposit free money casinocasino link online suggestreal money backgammonplay free casino slotshow to play backgammon,instructions to play backgammon,play backgammon online freevideo poker tournamentfree on line slotsblack jack downloadon line casino wageringfree cash casinoplay free online slotslearn to play crapsdouble bonus video pokerbest online casino bonusinternet casino gambling game,internet casino gambling,internet casino gambling ukonline casino gambling,gambling casino online bonus,online casino online gamblingfree backgammon downloaddownload casino gamevideo poker doublejacks or better video pokerno download video pokeronline black jack gameonline casino gambling sitebaccarat the internet casino game,casino baccarat,virtual online casino gambling baccaratfree online black jack gameonline baccarathow to win at roulettedeuces wild video pokerfind online casinole casinoblack jack regolenouveau casino bonus sans depot

Python λ Shorthand

November 10th, 2007

In Python a lambda expression (anonymous function) is created with the lambda keyword:

map(lambda x: x+1, [1,2,3])

Some Scheme interpreters such as Dr. Scheme allow the λ symbol (U+03BB) as a shorthand for lambda. I started wondering what this would look like in Python. For example:

map(λ x: x+1, [1,2,3])

Or for a slightly more gratuitously complex example, a recursive factorial with the Y combinator:

Y = (λ X:
         (λ p:
              X(λ arg: p(p)(arg)))
     ((λ p:
           X(λ arg: p(p)(arg)))))

F = (λ f: (λ x: (x*f(x-1) if x > 0 else 1)))

fact = Y(F)
fact(5) => 120

The interpreter changes to make this work this are quite simple. All it requires is small change to the grammar, an update to the syntax checker, and a hack in the parser generator to treat characters with the high-bit set as though they were in the alpha class.

There are a few cases where the shorthand is beneficial. For example, compare:

[i for i in lst if i > 42]

to:

filter(λ x: x > 42, lst)

While list comprehensions are the standard python way to accomplish this, I do like how the predicate comes first in the latter version.

Also, pretty much all of the functions in the itertools module could work nicely with the shorthand form:

itertools.groupby(lst, λ x: x.somevalue)

Even so this is probably isn’t something that would be worth adding to the language. Lambda expressions are rarely useful in Python so a shorthand form is not going at add much benefit compared to the added language complexity. Not to mention the need for a UTF-8 aware editor and terminal.

Using It

Since λ probably doesn’t appear on your keyboard a certain amount of editor configuration is required. The easiest way in emacs is to define a key binding that inserts the character:

(global-set-key "\C-c\C-l" (lambda () (interactive) (insert "λ")) )

Alternatively, abbrev-mode can insert this character whenever the word lambda is typed:

(define-abbrev-table 'global-abbrev-table
  '(("lambda" "λ" nil 0)))

To build an interpreter with this enabled you’ll need this patch applied to a recentish checkout of python 3k. I don’t know if it would work on earlier versions.

Update: On reddit, gwern pointed out that it’s better to translate from lambda -> λ in the editor display rather than embed this symbol in the text. There is (of course) elisp to do this.

One more time: BK Trees in Haskell

November 2nd, 2007

After the Python BK-tree implementation I decided to try my hand at a Haskell version. Here it is.

videos of drunk girls peeing outside: free squirting video. free teen incest sex videos free incest hentai manga movies. free rape forced sex exploitation movie sites extreme rape porn movies.

Burkhard-Keller (BK) Trees In Python

October 28th, 2007

I recently came across a description of an interesting data structure called a Burkhard-Keller tree (BK tree). BK trees provide efficient lookup of the set of words that lie within a certain distance of a query word. For example, this could used to suggest corrections in a spell checker.

To play around with this I’ve written up a Python implementation of the tree. For example:

>>> tree = BKTree(levenshtein, dictionary_words)
>>> tree.query("ricohet", 2)
[(1, 'ricochet'), (2, 'richer'), (2, 'riches'), 
 (2, 'richest'), (2, 'ricochets')]
>>>

In the above example ‘levenshtein’ is a function that implements the Levenshtein Distance. This is commonly used to determine the distance between a word and its misspellings.

How much faster is a bk-tree than the brute force approach? Here are a few example queries compared with the brute-force time:

word, distanceBK TreeBrute Force
amphibious, 23s15s
ricochet, 23s11s
the, 20.2s6s

You can see the BK tree is much faster for small distances. As the query distance increases the BK tree query time approaches that of the brute force method.

Of course, there’s no free lunch. Creating this tree of 57,024 words takes 94s on my system.

The source for this module is available here. Enjoy!

Serving mercurial with mod_wsgi

September 17th, 2007

Here’s a quick and easy recipe for serving a mercurial repository with mod_wsgi.

  1. Create a file called hgwebdir.wsgi with these contents:

    from mercurial.hgweb.request import wsgiapplication
    from mercurial.hgweb.hgwebdir_mod import hgwebdir
    
    def make_web_app():
        return hgwebdir("/path/to/hgweb.config")
    
    application = wsgiapplication(make_web_app)
    
  2. Add it to the apache configuration:

    WSGIScriptAlias /hg /path/to/hgwebdir.wsgi

  3. [optional] To make sure nobody modifies your repository via the http interface, add ‘deny_push = *’ to the ‘[web]’ group of hgweb.config.

Hopefully this page will save the next person a few minutes of searching.

etframes: Applying the ideas of Edward Tufte to matplotlib

September 3rd, 2007

Edward Tufte is a professor and author known for his excellent (and beautiful!) books on the visual display of statistical information. Last year I had the opportunity to attend one of his courses and was inspired to apply his ideas to my favorite plotting library, matplotlib.

The result is etfames, a python module that operates on matplotlib plots. So far I’ve implemented two graph types described in the The Visual Display of Quantitative Information (VDQI): the dash-dot-plot and range frames.

Dash Dot Plot

A dash-dot-plot places a tick mark on the axis for each value in a scatter plot. When there are many values in the graph this can be a more effective way to understand their distribution than looking at the raw data. For example:

Example of a dash-dot-plot

See demo_ddp.py for a working example.

Range Frames

The range frame re-uses the frame (edge) of a graph to display useful information. Instead of drawing a full frame around the graph the frame is only drawn from the minimum to the maximum value along that axis. For example:

Example of a range frame

See demo_range.py for a working example.

Other Work

There are several other graph types described in VDQI that would be nice to implement, particularly the extension of range frames that turns them into a box plot.

A related project is sparkplot which uses the matplotlib library to create sparklines.

26.2

July 30th, 2007

Yesterday I completed the San Francisco Marathon (my first) with a time of 3:50:09. Here’s the stats. My goal was a flat 4:00 so I’m pretty pleased with the time. Most of my family came down to run the half marathon or 5K, and my wife also ran the half.

This being my first race I learned a few things along the way.

  1. Several people told me take it easy for the first half of the run, but I think it’s actually better to keep a consistent pace the whole time. There’s no way you’re going to make up the time later on and at least for me the most wear is caused by the distance, not speed.

  2. When I registered for the race I put down an expected finishing time of 4:15. It didn’t occur to me that this was important, but it turns out to be. Once we got to the Golden Gate Bridge the course became narrow and I lost some time trying to pass people. I’ll underestimate next time.

  3. I thought I was good at running down hills, but I was wrong. When I’m tired I tend to lean back against the hill instead of leaning downhill and as a result my knees were in bad shape by the end. I’ll definitely pay more attention to this next time.

The most amusing moment was the beer station at mile 15. I suspect the Hash House Harriers were involved in that.

It was a great experience and I’m looking forward to my next race. Not too soon though.

dsc.py: Automated Warnings for Debian Security Updates

June 21st, 2007

dsc.py (Debian Security Check) is a Python script that automatically notifies a machine’s administrator when installed packages require a security upgrade.

Why this is useful

This week there were 9 Debian security advisories released, and I don’t always know which ones apply to my server. This is especially hard in the case of libraries (think fast: do any of your services depend on freetype?). dsc.py will only notify you of packages that actually require upgrades.

The alternative is to put an ‘apt-get upgrade’ directly in crontab, but I’d prefer to do upgrades by hand.

How does it work?

Necessary upgrades are determined by comparing the packages listed in the security advisories RSS feed with the set of upgradeable packages. When a match is found a summary of the issue is written to stdout. This script is run via cron nightly, with output (if any) mailed to the administrator. Note that an ‘apt-get update’ will need to be run first. My crontab entry looks like this:

0 3 * * * apt-get -qq update && /usr/local/bin/dsc.py

dsc.py depends on these packages: python, python-apt, dctrl-tools, and python-feedparser

It can be downloaded here

Go West, Young Man!

June 1st, 2007

Erin and I have arrived in Berkeley, completing our NC to CA cross-country road trip. We’ll be staying here this summer for Erin’s internship in the Bay Area. The drive out was great, with stops in Wisconsin, Minnesota, Badlands National Park (SD), Colorado, Arches National Park (UT), Mono Lake (CA) and Yosemite National Park.

Pictures are up here.