Skip to main content

Posts

Showing posts from May, 2008

Relearning Java

The last time I wrote Java code was my freshman and sophomore year of college. Six years later, Java has had 2 "minor" revisions and the nutshell book has tripled in size. Java in a Nutshell is the kind of nut only an African swallow could carry. But, I'll try to keep an open mind.
Read more

Bike Ride Through Paderborn, Germany

I used Nokia Sports Tracker to track our ride through Paderborn last weekend. The Sports Tracker website lets you export KML, so it's easy to build up a Google map that includes both halves of the trip. Now I wish I could set geographic limits on my Picasa Web Albums maps so that I could include any of my pictures that were taken in the vicinity.
Read more

SSH Tunnel to Router Settings

I always forget how to do this and it's extremely useful. If you have SSH access to your box behind your router, you can use a double SSH tunnel to connect to the router and adjust your settings. localhost$ ssh -L 8888:remotehost:8888 remotehost remotehost$ ssh -L 8888:router:443 localhost Now just point your localhost browser to https://localhost:8888/.
Read more

My Train Orb (also Scraping Munich Train Schedules)

In an effort to optimize my commute, I wanted a glowing orb whose color indicated when I should start walking to the train stop. My train comes fairly frequently (every 10 minutes). The glowing orb lets me tell at a glance if I should be getting my stuff together, walking out the door, or running. The glowing orb part is easy. Arduino Tri-color LED Ping Pong ball Mix with Python appropriately. I'll post the code for the orb some other time. The hard part was actually getting the train schedule information. MVV (the mass transit authority in Munich) only provides PDFs for train schedules. To parse those, I used pdftohtml. pdftohtml can generate XML which provides the absolute position of all the text elements on the schedule. Since they're in a grid, it wasn't too hard to parse that into something useful. from BeautifulSoup import BeautifulSoup import datetime import re _DIGITS_RE = re.compile(r'^\d+$') # Schedule paramaters (page, hour column bounds, minute column b
Read more

Python Decorators and SimpleXMLRPCServer

While working on an XML-RPC server for App Engine , I came across an interesting problem. I wanted to add a way to get performance measurements for my calls, so I wrote a simple decorator that returns a tuple of the result and the time it took to complete. from SimpleXMLRPCServer import CGIXMLRPCRequestHandler import time import functools def timed(func): @functools.wraps(func) def decorator(*args, **kwargs): start = time.time() result = func(*args, **kwargs) return result, time.time() - start return decorator @timed def mypow(*args): return pow(*args) if __name__ == '__main__': handler = CGIXMLRPCRequestHandler() handler.register_function(mypow) handler.handle_request() The key to making this work is functools .wraps(). Without it, the function returned by the decorator no longer has the same name as the original function. So, when I register the function, the call fails. You can fix this by hand (or pre 2.5) by changing your decorator like so: def ti
Read more

FriendFeed Getting Better

Now that I've managed to hide all Twitter, Jaiku, Delicious, and my own entires from my feed, I'm much happier. Still seems noisy though. I think I'd prefer a daily summary.
Read more

Save The Date (also, fun with historical weather data)

Laura and I would like to have the wedding outdoors. Naturally, this means that weather will play a significant factor. To get some idea of what the weather will be like on the big day, I whipped up some Python to calculate local average temperature, rainfall, and wind speed for the time surrounding April 5th. import csv import urllib2 STATION_ID = 'KNCOAKIS1' WEATHER_URL = \ 'http://www.wunderground.com/weatherstation/WXDailyHistory.asp?' REQUEST_DATA = { 'ID': STATION_ID, 'format': 1, 'year': None, 'month': None, 'day': None, } def _GetRequestData(year, month, day): request_data = REQUEST_DATA.copy() request_data['year'] = year request_data['month'] = month request_data['day'] = day return request_data def GetDayStats(year, month, day): request_data = _GetRequestData(year, month, day) get_data = '&'.join('%s=%s' % (k, v) for k, v in request_data.items()) u
Read more

Django on Google App Engine

My article on Running Django on Google App Engine had a few bugs at launch. I've since fixed those and just wanted to write a shameless plug for it. App Engine really makes Django fun again. No databases or web servers to worry about. Just upload your code and enjoy the ride. I built Twiddlee using Django on App Engine and really enjoyed it. It was trivial to write a session engine that used the Datastore API and the integrated support for Python logging in the Admin Console makes it easy to keep track of exceptions. I definitely plan to look to App Engine first for all my future web apps.
Read more

Review of O'Reilly's "Programming Collective Intelligence"

Programming Collective Intelligence by Toby Segaran covers the basics of machine learning and in an easy and enjoyable read. All of the examples are in Python and leave nasty, symbol-ridden equations for the appendix. The samples cover real world scenarios such as movie or product recommendations, spam filtering, dating, housing markets, web search, the stock market, etc. In the two days I spent reading the book, I definitely feel like I've learned more than enough to be dangerous. I was also pleasantly surprised to see time spent on code to visualize the results of the algorithms discussed. There's code to draw dendrograms, networks, multidimensional scaling (2D clusters from n-dimensional data), and decision trees. There's even a discussion of how to use machine learning to improve the quality of network diagrams. Very cool stuff. Overall, I highly recommend Programming Collective Intelligence for anyone that's ever wondered "how'd they do that?"
Read more