Archive for January, 2010

Euler tour of Manhattan

Sunday, January 31st, 2010

I’ve had a mind to do an Euler tour of the bridges of New York, specifically those in and out of Manhattan. Yesterday a few friends and I made our attempt.
Our tour was an Euler tour in the historical sense, not quite the mathematical sense (I guess a valid Euler tour would start and finish in the same place). The graph illustrating the bridges (at least those traversable on bicycle) looks something like this:
manhattan euler tour graph
The basic idea of an Euler tour is to traverse each edge (bridge) exactly once. Notice this can only happen in the above graph if you start in New Jersey and end in Manhattan.
In order to cross all the bridges of Manhattan, we originally thought we’d take the Path to the New Jersey side of the George Washington Bridge, but we were dismayed that Hoboken (the highest stop on the path) wasn’t so close to the bridge. Also my girlfriend and I had decided to rent a tandem bike:
tandem bike drawing
The rental shop was on W 104 st in Manhattan so we conceded to cross the GW twice, essentially invalidating or at least delaying our Euler tour.
Here’s the map we used to find our way from bridge to bridge:
euler tour of manhattan map
The ordering of the bridges was to be as follows:

  1. George Washington
  2. Broadway Ave
  3. 207 St
  4. 181 St
  5. Macombs Dam
  6. 145 St
  7. 138 St
  8. 3 Ave
  9. Willis Ave
  10. Triborough
  11. Ward’s Island Pedestrian
  12. Queensborough
  13. Williamsburg
  14. Manhattan
  15. Brooklyn

…which is almost how it was executed.
Unfortunately the pedestrian walkway from Ward’s Island to Manhattan is not open in the winter and we didn’t find this out until we saw it statically gaping from Randall’s Island. Thus we had to also cross the Triborough bridge twice.
My girlfriend and I, on the tandem bike, crossed 11 of the 15 bridges above. We covered about 42.5 kilometers (≈26.4 miles ≈ 1 marathon) in total before we were getting too nervous about returning our rental in time. Here’s a rough sketch of our route on the map:
euler tour of manhattan map with route
The rest of our group made it over 14 of the 15 (all but that pedestrian walkway).

New York City Teaching Fellows Candidate for Elementary School Science Department

Wednesday, January 20th, 2010

My friend recently attended an interview with the New York City Teaching Fellows program (NYCTF). It was a group interview and each candidate had to prepare a 5 minute lesson plan to present to the others. My friend told me that one of the candidates presented a lesson plan for an second grade science class. The subject was gravity and the lesson was about why a book falls faster than a feather. Why heavier objects fall faster than lighter objects. Here’s a scan of the handout the candidate wrote up:
new york city teaching fellows gravity front
new york city teaching fellows gravity back
If you don’t understand why this it’s not just funny but scary, you could review about gravity on wikipedia.

I’m thinking of drafting a letter to NYCTF. But I’m at a loss of words what it should say. Obviously they shouldn’t have to account for an applicant’s ignorance, but how can I feel comfortable that this candidate won’t be in front of a second grade science classroom next year?

Robo-poetry

Monday, January 18th, 2010

I challenge the internet to start a new genre of robot poetry. It can be humans reading robot generated poetry, robots reading human poetry, robots reading robots poetry or even just human poetry about robots and the reading there involved.

Here’s a little something to get the ball rolling as they say:



By the way, I generated the above on my Mac (10.5) using this command:


say -v Alex -o row-your-boat.aiff "Row, row, row your boat. Gently, down the stream. Merrily, Merrily? Merrily. Life, is but a dream"

Set mp3 tags of all files in a directory using current file name

Sunday, January 17th, 2010

This could probably get more elaborate and use the containing directories to set album and artist tags. For now here is a bash script to set the titles based on the current file name. This uses a program called tagmp3.


artist="Artist"
album="Ablum"
for filename in *.mp3; 
  do title=`echo $filename | sed 's/.mp3$//g'`; 
  tagmp3 set "%A:$arrtist %a:$album %t:$title" $filename; 
done

Log in to nytimes.com download crossword puzzle and convert to pdf script

Tuesday, January 12th, 2010

I have given my girlfriend a subscription to the New York Times crossword puzzle which she (graciously?) allows me to use. Using the help of the decode_crossword.pl perl script, I have made a bash script to log in to nytimes.com, grab today’s puzzle in .puz format and convert it to pdf so I can easily print and view it. Here’s the script (replace userid and password with your own):


#!/bin/bash

if test -z $1 ; then
  date=`date +%b%d%y`
else
  date="$1"
fi

#
# log in to nytimes and save cookies
wget --post-data \
  "USERID=youremail%40gmail.com&PASSWORD=yourpassword&is_continue=true" \
  --save-cookies=cookies.txt --keep-session-cookies \
  -O /dev/null\
  http://www.nytimes.com/auth/login &>/dev/null

# download puzzle
wget --load-cookies=cookies.txt \
  http://select.nytimes.com/premium/xword/$date.puz &>/dev/null

# get rid of cookies
rm cookies.txt

# convert to pdf
./decode_crossword -P $date.puz | ps2pdf - $date.pdf &>/dev/null

# get rid of .puz version
rm $date.puz

Update: NYTimes changed their login routine so now you should use something like:


#!/bin/bash

if test -z $1 ; then
  date=`date +%b%d%y`
else
  date="$1"
fi

wget \
  --no-check-certificate \
  https://myaccount.nytimes.com/auth/login \
  -O login.html \
  &>/dev/null
 
token=`grep token login.html | sed -e "s/^.*value=\"\([A-z0-9]*\)\".*$/\\1/g"`
expires=`grep expires login.html | sed -e "s/^.*value=\"\([A-z0-9]*\)\".*$/\\1/g"`

# log in as annie, should get rid of her password from this
wget --post-data \
  "userid=youremail%40gmail.com&password=yourpassword&is_continue=false&remember=true&token=$token&expires=$expires" \
  --save-cookies=cookies.txt --keep-session-cookies \
  --no-check-certificate \
  -O /dev/null \
  https://myaccount.nytimes.com/auth/login \
  &>/dev/null

# download puzzle
wget --load-cookies=cookies.txt \
  http://select.nytimes.com/premium/xword/$date.puz &>/dev/null

# get rid of cookies
rm cookies.txt
# get rid of login cache
rm login.html

# convert to pdf
./decode_crossword -P $date.puz | ps2pdf - $date.pdf &>/dev/null

# get rid of .puz version
rm $date.puz

Music clock

Monday, January 11th, 2010

The music clock is an invisible clock. It tells the time through musical
tones. For now, it reads the hour and the minutes mod 12. Hopefully I will be
able to explore this idea and come up with a universally understandable and
recognizable system.

I use ajax requests and ruby and sox on the backend to make this work.

Getting python to print 5 digits of accuracy in the current time in seconds

Monday, January 11th, 2010

In the python shell if I type:


import time
time.time()

I get the current time in seconds with 5 digits past the decimal place of accuracy:


1263245893.382139

If I want to use this as a unique ID then I need to have this value as a string. Namely I need to be able to print it. But if I issue:


print time.time()

I only get 2 digits of accuracy past the decimal place:


1263245893.38

This seems to be because print when converting the time to a string is rounding its float value someplace. To solve this I use instead:


print "%f" %  time.time()

Which again returns all of the accuracy places I original had:


1263245893.382139

Finally to save this value as a string I just remove the print and instead have a variable on the left hand side of an equals sign:


current_time = "%f" %  time.time()

Mac OS X 10.5 “Don’t save” keyboard shortcut

Monday, January 11th, 2010

On OS X 10.4 I used to be able to “tab through” the options of the “Don’t save, Cancel, Save…” dialog. On 10.5 the glowing tab tracer does not show up, but finally I’ve found the keyboard shortcuts to each.

Option Keyboard shortcut
Don’t save D
Cancel esc
Save… return or enter

Clock design take 2

Saturday, January 9th, 2010

After a friend showed me the Raphaël javascript library, I immediately wanted to rewrite my
old java geometric clock prototype applet into a new javascript version.

Here it is:



Hack infinite scroll javascript with infinite auto-scroll to bottom of page

Thursday, January 7th, 2010

This is a hack to have your browser load all search results when a page is using jQuery’s infinite scroll feature, like this site: http://instantwatcher.com/titles/all?infinite=1.
Here’s the client side javascript to keep auto-scrolling this page to the bottom, thus triggering infinite scroll to load more results. It runs until there are no more results to load:

    function scrollToBottom(){
      bottom = document.body.scrollHeight;
      current = window.innerHeight+ document.body.scrollTop;
      if((bottom-current) >0){
        window.scrollTo(0, bottom);
        setTimeout ( 'scrollToBottom()', 1000 );
      }
    };
    scrollToBottom();

I run this on Safari using this short applescript:


tell application "Safari"
  set doc to front document
  set this_url to URL of doc
  do JavaScript "
    function scrollToBottom(){
      bottom = document.body.scrollHeight;
      current = window.innerHeight+ document.body.scrollTop;
      if((bottom-current) >0){
        window.scrollTo(0, bottom);
        setTimeout ( 'scrollToBottom()', 1000 );
      }
    };
    scrollToBottom();
    " in doc
end tell

Try it!