baconrank.com Powered by Turbogears 2

The baconrank.com website was written with the Turbogears 2 web application framework. It is pretty lightly modified from the quickstart project.

In the UI front the quickstart project used a lot of images to make rounded corners and so on to make everything look good in cross-platform way. I dislike this practice, so I decided to see if I could take the basic layout and not use any images for corners and backgrounds and the like. I think the result looks pretty good in modern browsers, including the default browser in Android 2.1. border-radius and -moz-linear-gradient did the bulk of the work. Which reminds me that I forgot to look for the equivalent of -moz-linear-gradient for other browsers…

The template language I used was Genshi, both because it is the default that comes with TG2 and the quickstart project, but also because I wanted to try out another template language as well. The thing I like about Genshi is that it guarantees I get well-formed output. However, its use of XPath can be a pretty steep learning curve to someone who doesn’t know XPath (like me). I did not see how to control the whitespace around elements: in some cases I have elements one on each row, other times they end up on the same row. I think I also could not get a comment to appear at the end of the document (to put in page rendering time, for example, although it turned out you’d need to hack tg2 itself to get the rendering time – unfortunately I lost the link).

I originally had bigger plans for the application, including forum, password recovery and so on, but canned those plans for now because I realized I could not find enough time to do all those and ship something before the summer. Part of that I did get in, although it is only exposed to the admin user. Being the security-minded geek that I am, I hacked the auth code to use bcrypt. I also learned about doing password comparison in a way that does not leak information due to timing.

I designed the small protocol that the Android client uses to communicate with the server. Most operations are covered by the following:

Initial sync:

>>>request<<<
POST /users
@JSON@

>>>response<<<
201
Location: /users/123

>>>request<<<
GET /users/123

>>>request<<<
200
@JSON@

Add bacon:

>>>request<<<
POST /users/123
@JSON@

>>>response<<<
200
@JSON@

Incidentally, if you'd like to write another client (iPhone anyone?), let me know...

I wanted to wrap the client API in its own class, but could not get that to work as a separate class so had to just settle with a method that does way too too much. Something I hope I can visit later.

I really wanted to like Turbogears 2 since it is based on my favorite, Pylons, but I actually felt that TG2 was getting in my way almost as often as it was helping me. I am happy that I did not have to write the auth code from scratch, and having the admin area almost as easy as in Django were big wins, but since I did not yet implement the forum (where I think I could really have used more of tg2's strengths) I would probably have been better off with plain Pylons. The documentation has been in flux the whole time I've been working on my app, some things working, some broken, and I had to resort to comments at the end of docs and doing web searches to try and figure things out. There were periods of time when the dependent packages were out of sync, and you could not even get a working quickstart project without setting version limits. I think that the controller methods not returning the actual string to render can be potentially big headache (for me, I just could not get the timing information output into the end of the returned HTML). I'd say TG2 has potential to be great, but right now things feel a little bit too unfinished. I know 2.1 will fix some of the issues I run into, but I don't know if anyone is looking at checking and cleaning up the documentation.

Bacon Rank Released

I am pleased to release Bacon Rank, the application you have been waiting for to count your bacon! (You may not have realized this, of course. I forgive you.)

I’ve been working on this application combo since last November, a few hours here and there. The server piece is a Turbogears 2 application, while the client piece is an Android application. As a whole, they form the Bacon Rank application ecosystem. The idea is that whenever you eat bacon, you submit the number of strips of bacon you ate, using the Android client, to the server. The server returns your statistics, including your rank compared to other users of the system. It is clearly a not very serious application, but it presented some interesting programming challenges.

I’ve been going through various Python web frameworks, and this time I wanted to learn about Turbogears 2. There isn’t anything especially groundbreaking about it, but I think it marks the first time I am actually running a real service. Of course it is also tied to the Android application, which makes it interesting.

The Android application is a bit more ambitious from engineering point of view. In the UI the trickiest piece was a customized SeekBar: uncooked bacon that becomes cooked as you move a skillet over it. I was also able to finally figure out how to make a background network request survive screen orientation change gracefully.

I am also experimenting with Twitter for the first time as a communications channel for the project.

In the next two posts I will explore the server and client pieces in more detail.

New Adventures

This news is a couple of weeks old, but I thought better late than never… For the past couple of years I was working at SpikeSource, on a variety of things ranging from Pylons and CherryPy applications to designing RESTful APIs and client libraries and even CakePHP and Java web applications (horror of horrors ;) ). It was never a good fit culturally, though, so just before my two year anniversary came around I decided I needed a change.

I decided to be very focused on my search: Python web application development, startups, and ideally located from Sunnyvale to Palo Alto. I used mostly craigslist.org and startuply.com for my search, with a couple of hints from friends. I applied to eight jobs, and got five interviews. I was quite surprised that there were so many companies matching my preferences within such a small area hiring at the time when I was looking! I was also pleasantly surprised that I got into as many interviews as I did; last time around I had a bit worse success rate. Hint: requirements aren’t necessarily requirements in job postings.

Unfortunately I learned I am bad at interviews aimed at Python web application developers. For some reason I find coding questions a lot easier to answer when they are in C. I was also badly prepared to answer a few questions related to web development; having not thought about something for a while makes a bad interview impression. Note to my future self: start practicing at least a week before interviews, practice in Python on problems designed to be solved in Python (maybe Python challenges, Facebook programming puzzles and the like), and check with friends for some common web developer questions. Assuming I were to look for that kind of job next time around, of course.

To make long story short, I decided to join Aahz at Egnyte. Egnyte provides cloud storage, backup and sharing services. My first task involves integrating new UI design to a CherryPy application using Cheetah templates. I am also working on a Mac after many years on Linux.

Nexus One Radio Follow-up

As you have probably gathered by now, my earlier announcement was an April Fools’ prank. Unfortunately I had forgotten to adjust my blog settings for Daylight Saving Time, so the URL and time on the post refer to the previous day, even thought it was posted a few minutes into April 1st.

I got the idea for the prank out of the blue around 11 pm, and had the application ready a few minutes before midnight, so I waited for that to pass to create the .apk and post it to Android Market. Most of the development time went into finding a suitable image of a radio and scaling and cropping it (as you can guess, Gimp gives me trouble). I used the Creative Commons search engine to find the image.

I was pretty satisfied with the results. According to Android Market statistics, the application was installed 10741245 times (although the real number is somewhat higher since the statistics don’t update in real time), has 7787 ratings with average around 3.5. Not bad for less than 24 hours of exposure. Some of my favorite comments were from people who were fully on board with the prank:

  • Pretty good. Can’t seem to tune below 88.9
    anakin78z
  • OMG this best radio player ever. Pandora and Slacker don’t even come close.
    freddie
  • nice hack :) Will pre-sets be available in the future? :-p
    dbrowne
  • would be a 5 if the dialer was more accurate. great job dev! :)
    semeon

There were also others who seemed to have fully fallen for it without liking it ;) :

  • Wasted about 2 minutes of my life. . Don’t bother, feeble prank !
    Ian
  • I hate you.
    Tom

Of course there were also a number of spoilsports who just gave one star and mentioned it was a prank app. Shame on you.

I got one support email asking if it would work on HTC Touch. Also the comment in the original blog post about collaborating on a droid project makes me wonder if I fooled that person or if they were in on it.

Seems like I also fooled some people on reddit.com.

Since this was a joke app just for today, I’ve unpublished the app from Android Market. So if you are one of the 300+ people who still got the app installed, you are suddenly the owner of a rarity :)

Nexus One Radio

If you have been wondering why I haven’t posted in a while, it is because I have been hard at work on my most ambitious Android project to date. When Google came out with the Nexus One phone I was quick to grab one. But one thing about the hardware has always bugged me. The Nexus One contains an FM radio, but there wasn’t any way to use it from software. Until now! I have painstakingly tracked down the hardware details and reverse engineered the API needed to get the radio to appear. The UI is pretty primitive. Go grab yourself an early build of Nexus One Radio (see ratings on Cyrket). Search for it in the Android Market!

Update: Please see the follow-up!

GPS Still on After LocationManager.removeUpdates?

My most recent Caltroid update added map view with two location listeners: one coarse (=network) and one fine (=GPS) location listener. Or so I thought. Even though I was calling LocationManager.removeUpdates() for both location listeners, I could still see the GPS icon active at the top, and logcat showed GPS activity still going on. Users were reporting drained batteries. Not good.

It took me a few false starts until it occurred to me that I was also using MyLocationOverlay to automatically put the user’s location on the map. Well, this obviously requires location updates. I had somehow falsely assumed that as soon as the map view went away, MyLocationOverlay would stop listening to location updates. That is not the case. You must explicitly call MyLocationOverlay.enableMyLocation() to start updates, and MyLocationOverlay.disableMyLocation() to stop updates.

After figuring this out the fix was easy. In my map view’s onResume() I request location updates for my two location listeners and enable MyLocationOverlay, and in onPause() I do the opposite. No more drained batteries!

Caltroid with Map

My latest update to Caltroid added two notable new features: the next available train is highlighted and scrolled into view automatically, and the simple locate function was replaced with a custom Google Map view. The map has Caltrain stations as an overlay, and the map starts out centered and zoomed so that all stations should be visible. While the map is active, it will update the users current position (using GPS and/or network location), and showing the nearest Caltrain station (as the crow flies). It is possible to select this station as the starting station from the map. Additionally, it is possible to tap the directions button on the map to get driving directions to the nearest station.

Working on the map feature was a pleasure now that I actually have an Android device.

If you look at the map view carefully, you will notice the text is written in transparent grey boxes with rounded corners. A stackoverflow question showed me how to do this with custom shape resource. I also based the map overlay largely on this blog post.

I had agonized for the longest time about how to get highlighting for the the list view. Then I stumbled into a couple of stackoverflow questions that showed me the way. In the end the best example I found was the List14 sample in Android API demos. I just need to call convertView.setBackgroundDrawable() with the right drawable, and make sure to add the following attribute for the list view: android:cacheColorHint="#00000000"

A Month of Nexus One

My first Android phone is the Nexus One. I tried to wait for an AT&T one, but the battery in my 8525 wasn’t so good anymore so I decided I could wait no longer. So far I am pretty happy with the phone.

I ordered the unsubsidized phone, which leaves me an option to go with T-Mobile or staying with AT&T. Time will tell which one I choose. T-Mobile coverage is my main concern. If I knew roaming would work well in the US without obnoxious costs, I might switch. On the other hand, I have been reasonably happy even with AT&T’s EDGE speeds. It is fast enough for checking email, do light browsing, and navigation works as well. Most of the time when I need the higher speeds I am in some location where I can use wifi.

Setting up the phone turned out to be a breeze. I just went through all the settings on first boot and everything worked. I was initially somewhat concerned about being able to put in the settings for AT&T network, but I didn’t really need to do anything fancy, just looking in the wireless options and selecting the only carrier it found (AT&T).

Since this is my first actual Android device, I put my Android apps through some tests on actual hardware. Everything worked! I’ve also been able to work on some new features (namely location related) that I didn’t much attempt with just the emulator. Some updates will roll out shortly.

Getting adp working with Nexus One turned out to be a little more work. First I updated the SDKs and the Eclipse ADT plugin, but even after this the phone was just showing with question marks in the launch dialog and would not let me copy the apk and run it. I found a thread on xda-developers which gave me the answer. I am on Ubuntu 8.04 and this is what I did:

  1. Create file /etc/udev/51-android.rules with contents SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
  2. Restart adp: adb kill-server && adb start-server
  3. Turn on USB Debugging on the phone in Application > Development settings
  4. Connect the phone with USB cable to the computer

I get great battery life on the Nexus One. And what I mean by that is that I can go for two full days before I need to recharge with my normal usage. I keep wifi, bluetooth and GPS off unless I am actually using them. I talk less than five minutes on the phone per day, browse a handful of websites for a few minutes, and read email several times a day. Surprisingly I also find myself playing some games, probably half and hour to an hour a day. You could say on most days I am not using the phone for anything that’d require a smartphone.

During my first week the phone had some stability issues, crashing several times when I had left it in the charger overnight. But once I uninstalled some applications that kept services running (SIPDroid, Fring and some other IM clients), I haven’t had a single crash. Best uptime when I remembered to check was over 300 hours.

I’ve encountered some annoying bugs as well. During my first week the phone got into a state where tapping the messaging icon always launched the browser. The only way I could recover was to reboot. This hasn’t happened since. Far more common problem is the soft keyboard not registering taps, or thinking I pressed one of the four buttons at the bottom (back, menu, home or search, with accompanied vibration feedback). Switching back and forth between apps fixes this eventually. I also seem to have situations when I don’t seem to get any GPS information. Some people have reported that this might require a reboot, but I haven’t been trying persistently enough to confirm if this is the only cure.

Voice recognition generally works great. There have been a few bizarre mistakes, like once I did a voice search saying “swype for android” and voice recognition thought I said “life on crack”. I find I miss a physical key I could press and do arbitrary voice commands, though.

One of my major issues with the phone, besides it not working on AT&T’s 3G network, is the inability to call out with Bluetooth without handling the phone. With my 8525 running Windows Mobile 5 and 6 I was able to tap my Bluetooth headset and say a name in my addressbook, and it would make the call. With Android nothing happens when I tap the headset, and I need to find my contact by handling the phone. This seems bizarre to me, since as far as I know California law requires hands free calling, and Google is based in California. Answering calls does work as I expect.

I haven’t been thrilled with voice quality on calls, which has been a surprise. I seem to get a fair bit of static. Also the earplugs and microphone that shipped with the phone have been practically useless; the other party can hardly hear anything when I try to use them.

I haven’t bought any apps yet, although I was tempted to get Locale. However, Locale author(s?) seem to have pissed off their potential customers by silently removing the free beta when they introduced their relatively expensive paid version while at the same time apparently making the paid version worse than the free version was. I’d also be interested in being able to buy Swype, since I don’t seem to be a very good typist with the builtin soft keyboard. Unfortunately Swype is not (yet?) available on the Android Market.

I don’t want to sync my data with Google, so I am looking for some way to sync with my PC. So far I haven’t had much luck. There are apparently paid solutions for Windows, and maybe Mac, but haven’t found anything for Linux. The most promising effort to me seems to be the Funambol Android Sync Client. AFAIK you could run your own Funambol server, which would solve my sync needs nicely. Except that at this point only contact sync is supported. If my phone loses data now, I am going to be sad…

I installed the Google update which added multitouch to Google apps, and I really like it in the browser.

I haven’t found the need to root my phone yet, but I will probably do that down the line to get some of the features that are not available otherwise.