Back in Business

This Monday morning, I started up my laptop to check the weather report like usual. Although it booted, it quickly crashed. I tried again, and it froze again. I tried memtest86, and that froze too. And so began My Time Without Half My Brain. Something in my thinkpad’s motherboard fried so I had to send it in to IBM to get repaired. Although they assured me the average turnaround is 5-7 days, I knew from experience that, with shipping time, this would be more like two weeks.

This really sucked because after 6 straight weeks of finishing shows and this week being my last, 20th show of the year, I was planning to take much-needed next week off and do some hacking on the OLPC version of PenguinTV. Without my laptop it would be next to impossible to find another linux machine and get it to the point where I’d feed productive on it.

On Tuesday, I got the ez-ship box from DHL and shipped off the poor little laptop Taking care, of course, to remove my not-officially-supported-harddrive with not-officially-supported-OS and insert my original-low-capacity harddrive for them to reimage. DHL: you rock for calling ahead and confirming my address which IBM had wrong.

With my minidock naked and empty, I salvaged some tomboy notes and bookmarks from my backup drive and uploaded them to a VMWare Fusion instance on the mac on my desk By the way, VMWare Fusion is totally awesome and I recommend it highly. I had a fully-functional Ubuntu desktop in the time it takes to download the pre-made image. You can even drag and drop files from the host OS to the guest OS desktop!. This gave me a workable solution for checking email and such, but I still felt slow and stupid without my various array of calendars, bookmarks, and email archives.

Today, I was presented with a package from DHL. My laptop is completely fixed and working again. This is the fastest turnaround time I’ve ever experienced for a laptop repair, and after popping back in my own harddrive everything is just as I left it. And because I got a three-year warranty, it was free.

Now, my hacking plans for next week are back on, and even better I also got an email that I’ve been accepted into the Nokia n810 developer program, so I’m soon going to have two separate mobile platforms for which to develop PenguinTV.

IBM / lenovo / whoever it was: you rock. I’m sorry I ever thought about getting my next laptop from HP.

iphone analogies

Mark Pilgrim has written a now-dugg post on the iphone, and how people should learn to stop buying products from Apple in the hopes that they will get a clue and truly open them up.

Although the blog post is nice, I prefer the simplicity of his delicious comment:
“Doctor, it hurts when I buy Apple products.”

The punchline, for those that don’t recognize the joke: “Then don’t do that.”

Or take the digg comments when Steve Jobs took X+200$ from people for an iphone, then gave them 100$ back so they can spend it at the Apple store. Commenters were falling over themselves praising Apple for doing the right thing, even though customers have still spent X+200$ at Apple, and the only thing Apple loses is the equivalent of a few months iphone subscription revenue. My response: “Thank you sir may I have another!”

Similarly, I often describe buying a Mac as a deal with the devil. You get the best-available computing experience money can buy, but you’ll have to put up with Steven P. Jobs’ odd whims — some of which cost money18-month 129$ charges for OS upgrades, plus money for simple utilities that should be free, others of which just make you mad“Why do I have to buy the expensive laptop to get it in black?”, some of which screw you over“you mean this device that worked with my ipod two days ago doesn’t work now because it doesn’t have a chip from apple?”.

But I think the most apt analogy for Apple and its users is the abusive relationship. Apple will slap you around and beat you up, but it’ll always come back with a bouquet of flowers and promise that this time things’ll be different.

Update:

Now apparently Apple is saying “I’ll buy you a bouquet of flowers, and you can choose the flowers, but only if I think they go with the drapes.”

Audioscrobbler support in Sonata

As I’ve mentioned before, Sonata is my favorite music player. One shortcoming, however, is that it lacks support for last.fm’s audioscrobbler, which allows music players to automatically submit songs to the service and help build one’s musical profile.

No more: sonata-audioscrobbler.diff

I whipped this up in a couple hours, so be on the lookout for bugs. It’s not so good at reporting bad passwords, so you have to look at the console output for that information. Either you see “BADAUTH” (bad) or “Uploaded 1 tracks successfully” (good). If the Sonata author adds feedback for mpd authentication problems, I’ll hook up to that.

I’ll also update my sonata olpc package to include this patch.

Update: Added a check to ignore songs that don’t have all the metadata that audioscrobbler wants.

March Madness — nerd style

My work is doing a silly contest around the whole NCAA thing. Back in high school kids used to run around comparing their brackets and arguing over every detail, and I hated it. I don’t follow basketball at all, and other than knowing that Duke ususally does well I have no basis upon which to make any choices except the seeds.

So I decided to write a bracket-generating algorithm that uses the seeds to generate weights for a random function and pick teams that way. The algorithm works as such:

  • for a pair of teams, take their seeds and invert them (make small numbers big)
  • divide each seed by the total of the two seeds to get values 0 < = x <= 1
  • get a random number 0 < = r <= 1. If team a’s chance is >= that value, they win

The actual code isn’t as nice as that explanation, but it should be mathematically equivalent. Any errors in programming only make these results more my own. I took the results from the first run that (a) worked, and (b) had Wisconsin (my alma mater) not getting knocked out in the first round.

Based on brackets.py, the final four will be: Arizona, Kansas, Texas, and Ohio St.

Kansas will win.

Source code after the break:
Continue reading “March Madness — nerd style”

OLPC as a music player

One side project I’ve been having fun with is creating an activity to allow the olpc to play music. At first I was just going to port a MusicPD (mpd) client over to olpc to allow me to use the laptop as a remote control at parties. Mpd runs as a system-level service that plays music, and then users can connect to it with many dozens of available clients to tell it to play music. It turned out that porting over a client was so easy that I decided to create a bundle that had its own mpd daemon builtin as well.

The client I chose is Sonata. I’ve used a lot of music players, including xmms, rhythmbox, amarok, banshee, and muine, but the combination of Sonata+mpd is the best way to enjoy music on Linux. It’s really, really good, and it’s worth the slight headache of setting up mpd.conf to get it working on your machine.

Sonata is also written in Python and only took maybe 20 lines of alteration to sugar-ize it. The author, Scott Horowitz, was even nice enough to incorporate my alterations into the main codebase, meaning that my bundle isn’t a fork of his project.

The bundle also contains a specially-compiled and configured version of the mpd daemon. And since I hate freedom, I’ve bundled an mp3 library along with it (But it also plays ogg). Music should be stored in /home/olpc/.mpd/Music, which could be symlinked to a mounted mmc device or USB key for greater storage. When the activity is started, the daemon is automagically started as well.

By default the client will connect to the olpc’s mpd daemon, but one can right-click on the main window and change the preferences to connect to any other mpd daemon on the network.

While I don’t know if this bundle will be useful to the kids, it’s useful to me and it shows the power of the bundle architecture. It really is plug and play 🙂

Sonata OLPC bundle (v7)

Adventures in virtualization

I’ve been adapting PenguinTV for use on the olpc, which is not entirely easy. For an all-python application it’s not too hard, but I have precompiled libraries that I need to distribute with PenguinTV because the olpc doesn’t provide pycurl. Since I run Ubuntu Edgy and the olpc is based on Fedora Core 6, I need to do some sort of virtualization to test my activity.

The recommended practice is to download an OLPC OS Image and run it with qemu. Unfortunately, the image is broken for Debian-based distributions like mine.

The next option is to download the OS image and chroot inside it and run sugar-emulator from there. That also doesn’t work for me.

My solution is really complicated: Run Fedora Core 6 in VMWare, and then chroot inside the OS image from there. Success!

So here’s a picture of PenguinTV, running inside olpc build 142, chrooted on FC6, running inside VMWare Workstation, on Ubuntu. It’s not a pretty way to do software development, but it seems to work.

inefficient_ptv.jpg

PenguinTV optimization

I’ve been going through the crufty and scary ptvDB.py looking for ways to improve performance. Armed with the trust profile and pstats modules, I cut polling time in half by removing redundant and unnecessary database hits.

I then got the idea of generating a print statement every time I hit the DB, so I can see exactly what the database is doing during regular operation.

The result is not always pretty:

Basic article read:

SELECT title, creator, link, description, feed_id, date FROM entries WHERE id=? (69443,) ok
SELECT id,entry_id,url,file,download_status,viewed,length,mimetype FROM media WHERE entry_id = ? (69443,) ok
SELECT read FROM entries WHERE id=? (69443,) ok

Ok that’s fine, we get the entry, any associated media, and then the read state.

What about an unread entry?
SELECT title, creator, link, description, feed_id, date FROM entries WHERE id=? (67523,) ok
SELECT id,entry_id,url,file,download_status,viewed,length,mimetype FROM media WHERE entry_id = ? (67523,) ok
SELECT read FROM entries WHERE id=? (67523,) ok
UPDATE entries SET read=? WHERE id=? (1, 67523) ok
UPDATE media SET viewed=? WHERE entry_id=? (1, 67523) ok
SELECT read FROM entries WHERE id=? (67523,) ok
SELECT id,entry_id,url,file,download_status,viewed,length,mimetype FROM media WHERE entry_id = ? (67523,) ok
SELECT title, creator, link, description, feed_id, date FROM entries WHERE id=? (67523,) ok
SELECT id,entry_id,url,file,download_status,viewed,length,mimetype FROM media WHERE entry_id = ? (67523,) ok
SELECT read FROM entries WHERE id=? (67523,) ok
SELECT feed_pointer,description FROM feeds WHERE id=? (233,) ok
SELECT id,title,fakedate FROM entries WHERE feed_id=? ORDER BY fakedate DESC (233,) ok
SELECT id FROM entries WHERE feed_id=? (233,) ok
SELECT feed_pointer FROM feeds WHERE id=? (233,) ok
SELECT pollfail FROM feeds WHERE id=? (233,) ok
SELECT feed_pointer FROM feeds WHERE id=? (233,) ok
SELECT read FROM entries WHERE feed_id=? (233,) ok
SELECT id FROM feeds WHERE feed_pointer=? (233,) ok

Oops. It’s whacking the database three times for the entry data, and updates the whole feed as well. Time to figure out what I’m doing wrong!

Bicycle GPS navigation on the cheap

Necessity may be the mother of invention, but being cheap is the mother of glorious hacks.

My friend Mike and I went bike riding two weeks ago using a route from a book. This was awkward because each of us could only retain three or four instructions at a time (“right? left? Mountain? Peach Orchard?”). We had to check the map so often that progress was slow and uncontinuous. Ah, but for a handlebar-mounted gps with mapping!

Vista -- pricy!

Ouch! Ok, nevermind.

So I did some googling, and discovered that someone had made some Garmin-specific files of Boston area bike rides. Char and I own the cheapest Garmin, the eTrex. No mapping, no magnetic compass, no altitude, just location data and route information. I got it at target thinking we might do some Geocaching, but we haven’t done any yet. The problem was, how to get the maps into the GPS?

serial cable

Cheap-ass serial cable! I learned that the data port on the Garmin is simply a serial port: Rx, Tx, Ground. Wire those terminals to a 9 pin serial connector (everyone has a 9 pin serial cable lying around in a drawer somewhere of course!), and you’ve saved yourself $38.00. My cable isn’t very well made and could use a little solder to improve the connections, but right now it works well enough.

While it’s nice to use other people’s maps, I really wanted to create my own. As you can see by my previous post, the solution was handed to me on a silver platter, as was the problem of format conversion and linux-based uploading. This weekend I created a short map on the website, uploaded it to the GPS, and Char and I followed the path around the neighborhood. The problems I noted after that walk led to the development of the python script I wrote.

The last problem was the one I had been avoiding thinking about: mounting the GPS on my thick handlebars. The sanctioned mounting kit fits handlebars of one-inch, but mine are larger. After some fiddling, it appeared that I might be able to attach the device to the stem of the bike. Maybe zip-ties could do it?

GPS hack

Yes! And in the event of catastrophic zip-tie failure, the lanyard is secured to the stem so the GPS doesn’t go careening to the ground.

Had I gone the “legit” route, I would have paid:

Garmin Etrex GPS 100$
Data Cable 38$
Bicycle Mount 18$
Software 30$
Total 186$

And that’s not counting the price of windows! (:P)

If I had gotten the Vista, it would have been 250$ for the device plus the same 18$ and 38$ for the mount and cable, plus an optional 117$ for a national map (which, by the way, I can’t get for any price with my eTrex) for a total of $423. That’s a lot to pay for directions.

Instead I paid:

Garmin Etrex GPS 100$
Serial Cable free (from drawer or old mouse)
Out of Date Credit Card free
Zip Ties free (from work)
Total 100$

Which I think is a better deal, even if I have an ugly cable and worry-inducing mount. I bet the map-creation interface is better, though :). You could go even cheaper by getting a used eTrex on ebay or craigslist. I hope to take the whole contraption on the road this weekend. The one big feature I might miss is the “beep on upcoming waypoint,” but the screen is large and clear so that shouldn’t be an issue.

Happy Hacking!