EuroPython 2011 Notes

These are some of my notes from EuroPython 2011. I mostly collect projects and tools that are of immediate interest to me in my own work. If you’re interested in the complete list of talks and would like to download the slides or watch the talks on video, you can find those on the EuroPython talks page. Also, Julie Pichon has summaries of some interesting talks on her site.

EuroPython Bag

Python Environment

At our company, we deploy non-interactive Python tools to our internal users. So far, we deploy these tools into the users’ local Python installations. Problems arise when the package versions that our tools require are different from the versions that the user has installed, or when updates to our tools require new dependencies to be installed. To avoid such problems, the “virtualenv” package allows you to keep separate Python environments for different tools. The “pip” package can then be used to automatically install dependencies into these environments. Alex Clemesha has an article up on his blog about the Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip.

Another useful addition to the Python toolbox is the “nose” unit-testing package, which extends the Python “unittest” module. It has advanced support for test fixtures, generated test cases, running test batteries, and more. More at the “nose” project homepage.

. . . → Read More

Continued Fractions for Representing Real Numbers

This is something I learned at EuroPython 2011. I think it came up in a lightning talk by Alex Martelli, but I don’t recall exactly.

Continued fractions are a representation of real numbers that allows for arbitrary-precision arithmetic.

If you’ve worked with floating-point numbers in Python (or most any other programming language, for that matter), you are aware of precision problems like this:

x = 1.0 / 3.0
total = 0.0
for i in range(300):
    total += x
print repr(total)
print total == 100.0

This prints 99.99999999999966, not 100.0. The reason is that the IEEE 754 floating-point representation of 1/3 isn’t exact, and this (initially small) error accumulates 300 times.

. . . → Read More

Live Desktop Streaming via DLNA on GNU/Linux

TWiT and the Ubuntu terminal on a TV set via DLNA

Many modern TVs (and set-top boxes, gaming consoles, etc.) support DLNA streaming. Suppose you have a PC that stores all your music, downloaded podcasts, video podcasts, photos, and so on. You can run some DLNA media server software on your PC and stream your entire media collection to your TV over your home network. No more carrying around USB sticks, it’s all in your home cloud.

On GNU/Linux, I am using MediaTomb as my DLNA server. It’s nothing fancy (it’s a file server, after all), and it just works.

Okay, this takes care of media files stored on your PC. But can we do more? Is it possible to stream a live capture of your desktop to the TV?

Let’s say you’re watching a Flash video in your browser, and there’s no way to download the video file. Or, you’re watching a live event being streamed via Flash or whatever. It would be kinda cool to be able to stream that to your TV via DLNA. And it’s possible—not trivial, mind you, but I’ve seen it working at least once…

. . . → Read More

Quick Review: “The Master Switch: The Rise and Fall of Information Empires”

I finished reading “The Master Switch: The Rise and Fall of Information Empires” by Timothy Wu. Here’s my short review in more than 140 characters. ;-)

Timothy Wu describes how, historically, information industries have tended to cycle from the freedom and openness that follows a disruptive invention to monopoly. About two thirds of the book are devoted to retelling the history of four such industries: Telephone, radio, movies, television. These are intriguing and eye-opening stories: How Hollywood started out as a bunch of “IP pirates”; how the FCC came about and what they were up to; how the Bell System delayed technologies like magnetic storage media and the answering machine for decades; etc.

. . . → Read More

SSL Certificate Error With Gwibber And identi.ca on Ubuntu

UPDATE: The problem has been fixed on identi.ca’s side. Maybe the workaround will be useful to others in some other context at some other time. I will also remove the certificate mentioned below from my system. It won’t be needed any longer, and who knows what nasty side effects it might have going forward…

I ran into this problem today where Gwibber (the micro-blogging client) on Ubuntu would not work with identi.ca anymore. The bug report referred to the log file ~/.xsession-errors, which contained this message:

Traceback (most recent call last):
File “/usr/lib/python2.6/dist-packages/gwibber/microblog/network.py”, line 53, in __init__
self.curl.perform()
error: (60, ‘server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none’)

. . . → Read More

Tutorial: Scaling Processing for Android Apps to Different Screens

In my previous article, I gave an introduction to the built-in features of the Android platform for supporting screens of various sizes and densities. In this article, I am going to expand on this and show you actual code for achieving screen-independence in an app. My example will be a Processing app (as that’s my own primary use case), but the ideas should apply equally well to any game or graphics-centric app.

"Chimpzilla Attacks!" mockup (no, I'm not serious)

Let’s use the game “Chimpzilla Attacks!” as an example. I made up this game specifically for the purpose of this tutorial—and already spent way too much time on the mockup. I have no idea what the game mechanics are, but judging from the cheesy graphics, it’s got to be some kind of “Punch The Monkey” knock-off. Anyway, back to the tutorial…

. . . → Read More

WordPress Database Errors

Some combination of adding and deleting images too fast broke it...

While editing my previous post, my WordPress installation suddenly started acting up on me. The problems had to do with uploading and deleting images using the post editor. I think what I did was upload an image, then click the “Delete” link right in the upload dialog—probably while WordPress was still updating the tables or something.

Anyway, suddenly the Media Library would not show any items anymore, and soon after that, the Posts were gone as well (both in the Admin interface and on the real site).

I checked the server logs* and found a number of relevant error messages:

*) I’m on Yahoo hosting. The relevant file was scripts.log in the logs directory of my site, accessible either through FTP or at http://yourdomain/logs.

[21-Dec-2010 11:26:48] WordPress database error Duplicate entry ’289′ for key 1 for query INSERT INTO `wp_postmeta` …
[21-Dec-2010 11:35:34] WordPress database error Incorrect key file for table ‘wp_posts’; try to repair it for query UPDATE `wp_posts` …
[21-Dec-2010 11:42:30] WordPress database error Can’t open file: ‘wp_posts.MYI’ (errno: 145) for query SELECT post_modified_gmt FROM wp_posts …

. . . → Read More

Multiple Screen Sizes With Processing for Android

Samsung Galaxy Tab (Android Virtual Device)

In my ongoing effort to port a desktop Processing application to Android, I am now trying to add support for multiple screen sizes. The goal is that the same .apk works on, say, a 3.7″ Milestone equally well as on a 7″ Galaxy Tab and on a multitude of other screens. The Android Dev Guide has a comprehensive page that explains the platform features for supporting different screens. I did my own tests and experiments to better understand the concepts. This article explains my findings and hopefully saves you some time and work.

. . . → Read More

Sound Playback in Processing for Android

I added sound playback to the Processing app that I’m currently porting to Android. On the desktop, I used the Minim sound library, which is not supported on Android (although there is some discussion about alternatives and a possible port). All I really need from a sound library is a way to play several .ogg (or .mp3 or .wav) files simultaneously and asynchronously, query their playback durations, maybe set the playback volume of individual sounds, and stop playing sounds at any time.

The android.media.MediaPlayer class is just fine for that.

In general, a sound can be played using the following code:

snd = new MediaPlayer();
snd.setDataSource(path_or_url_of_sound_to_play);
snd.prepare();
snd.start()

My own app is a game that contains only a handful of .ogg files. I keep a HashMap of the MediaPlayer instances for all sounds in the game, with prepare() already called on them. Then I simply call start() whenever an event triggers the sound in the game.

. . . → Read More

Operating System Usage Statistics

Graziano Sorbaioli pointed out a link to the w3schools.com OS Platform Statistics. The data from their web server access logs shows which operating systems visitors to w3schools.com use.

I wanted to look at the data graphically, so I created two OpenOffice.org charts.

OS Platform Statistics

Operating System Shares

OS Platform Statistics - Yearly Averages

OS Platform Statistics - Yearly averages

Not surprisingly, around 90% of visitors run Windows. But Windows usage is declining slowly, from 93% in 2003 down to 88% in 2010. Mac and Linux* are both growing slowly but steadily (Mac faster than Linux). All other operating systems account for only 0.67%.

. . . → Read More

My Buzz