Android vs iOS

Over the weekend, I tried to do some multi-touch stuff in Javascript, for smartphones. This, it turns out, is a huge pain in the butt.

Unless you’re just targeting iOS. Not only has iOS had multi-touch support in its native browser since the dawn of time, they also have good documentation for web application developers.

If you want multi-touch events in Android’s native browser, it doesn’t exist until 3.0, which means less than 1% of mobile users and less than 2% of Android users. Adding insult to injury, the documentation for developers targeting Android’s native browser is basically a footnote.

Posted in Programming, Technology | Leave a comment

Change of State

Today, I noticed a common pattern between Chinese and Spanish. When something changes state, you can express this as “the current state is X” + special-word-that-means-changed-state. That special word is ya in Spanish and 了 in Chinese. Here are three sentences, all meaning the same thing:

I don’t have money any more.
Ya no tengo dinero.
我没有钱

Obviously, this is not a one-to-one correlation. The Spanish “ya” is mainly used to mean “already,” while the Chinese 了 is more specifically a time particle (papers are written on the finer points of 了).

Posted in Language | Leave a comment

My first open-source contribution

Well, I forked piggyphoto (mentioned here) on GitHub and did a lot of work to get it to play nice with libgphoto2 version 2.4.8, plus I added some functionality that I needed for my project. When I had something I was happy with, I contacted Alex (the piggyphoto author) and asked him if he would like to merge my code back into his original repository, and he did!

piggyphoto still isn’t complete, but at least it’s better than when I found it.

If my mother had any idea how cool it is to contribute to an already-established open source project, she would be so proud!

piggyphoto network graph

Posted in Uncategorized | 2 Comments

Distributed revision control systems

I finally understand how Git and Mercurial work. I really wish I had figured this out a long time ago; it isn’t hard. I had two or three “ah-ha moments” while reading these two documents. If you’re still using SVN then please take a moment:

Hg Init: a Mercurial tutorial Joel Spolsky’s usual clarity+wit
Git Reference Organized similar to the first, but for Git

Posted in Programming | Leave a comment

Python and libgphoto2

It took a lot of work to figure out that there is no *totally* complete Python binding for libgphoto2.

I finally did figure out that piggyphoto is active, but is compatible only with the SVN version of libgphoto2. What held me up was a little example script included with piggyphoto called autodetect.py, which fails unless libgphoto2 is the SVN version (2.4.x doesn’t include gp_camera_autodetect() ). If there were a little bit of documentation for piggyphoto, I’d have a much easier time. It looks like it’s a complete ctype front-end for libgphoto2, so maybe docs would be sort of redundant…

The clearest help for getting up-and-running with piggyphoto:  http://magiclantern.wikia.com/wiki/Remote_control_with_PTP_and_Python

Posted in Uncategorized | 3 Comments

BeautifulSoup Performance

I’ve always been happy with the results of BeautifulSoup 3.0.x (has anyone tried 3.2.x yet?). It’s one of those chunks of code that yields significant productivity increases.

However, today I’m using BeautifulSoup in a place where performance is an issue (Google App Engine). Here are two lines of code which take ~1.1 seconds to run given ~90 kilobytes of HTML on my (slow) workstation:

soup = BeautifulSoup(html)
price = soup.find('td', {'class': 'price'}).text

I tried SoupStrainer two or three different ways, which gave moderate performance improvement. Adding SoupStrainer reduced run time to ~0.65 seconds (50% improvement):

soup = BeautifulSoup(html, SoupStrainer('table', {'class': 'product_prices'}))
price = soup.find('td', {'class': 'price'}).text

So, before sitting down for a couple of hours to write some good ol’ regular expressions, I tried one more idea, and it’s working great! The idea depends on BeautifulSoup’s very high tolerance for poorly-formatted HTML. By using a simpler method (string.find() for example) to find something close to the information you’re looking for, you can just get a slice of the HTML string that should include the information of interest and send that to BeautifulSoup.

price_index = html.find('class="price"')
soup = BeautifulSoup(html[price_index-100:price_index+100])
price = soup.find('td', {'class': 'price'}).text

I realize that html.find() wouldn’t work for everyone; using a regular expression would be more reliable. This takes ~0.010 seconds:

price_index = re.search('class\s*=\s*"price"', html, re.I)
soup = BeautifulSoup(html[price_index-100:price_index+100])
price = soup.find('td', {'class': 'price'}).text

Posted in Google App Engine, Programming, Python | Leave a comment

Asynchronous URLFetch in Google App Engine (Python)

Google App Engine has this cool feature that lets you fetch up to ten URLs simultaneously, asynchronously. You can fetch more, but to do that you have to queue ten, then wait for the first one to complete, then queue one more, rinse, repeat.

This thing even has a callback feature that is about as awkward as the best callback interfaces. While the GAE Dev Guide is quite good, I wasn’t looking forward to hacking together something to manage more than 10 URLFetch’s plus callbacks.

Well, thanks to David Underhill, I don’t have to hack anything. David wrote a nice little class that takes care of both problems: more than ten URLs and a much easier callback interface. Thanks David!

Posted in Google App Engine, Programming, Python | Leave a comment