1. 2010
    Aug
    07

    More Python voodoo: optional-argument decorators

    I’ve just been doing something that probably should never be done in Python (again), and I figured it might be useful to record this little snippet for posterity. Many Python programmers are probably familiar with decorators, which modify functions by wrapping them with other functions. For example, if you want to print ‘entering’ and ‘exiting’ to trace when a function’s execution begins and ends, you could do that with a decorator:

    def trace(func):
        def wrapper(*args, **kwargs):
            print 'entering'
            func(*args, **kwargs)
            print 'exiting'
        return wrapper
    
    @trace
    def f(a,b):
         print 'in f: ' + str(a) + ',' + str(b)
    

    Note that in practice there are better ways to do this, but it’s just an example.

    Anyway, it’s also possible to customize the behavior of decorator itself by providing arguments, for instance if you wanted to print different strings instead of ‘entering’ and ‘exiting’. But in that case, your “decorator” function is actually a wrapper that creates the real decorator and returns it:

    def trace(enter_string, exit_string):
        def _trace(func):
            def wrapper(*args, **kwargs):
                print enter_string
                func(*args, **kwargs)
                print exit_string
            return wrapper
        return _trace
    
    @trace('calling f', 'returning')
    def f(a,b):
         print 'in f: ' + str …
  2. 2010
    Aug
    03

    Hall Pong: The sport of grad students

    Born out of a combination of ping-pong, racquetball, hockey, and sheer boredom, hall pong is a perfect way to procrastinate (and pretend to get some exercise) when you’re stuck in a basement office. It’s played in a hallway, with a goal line on the floor at each end, using a ping-pong ball and two paddles. The Official Rules are simple:

  3. 2010
    Jul
    26

    Linkless URLs in Facebook statuses

    Facebook doesn’t seem to distinguish between posted links and status updates anymore, which means that whenever you try to post a status with a URL in it, it automatically turns it into a posted link. Granted, they are mostly equivalent, but a link won’t show up as your current status or in the status update RSS feed, which I find annoying. But there is a solution! In retrospect, this should have been pretty obvious, but when you put a URL in your status, in the top right corner of the info box that pops up, there is a blue X which you can click to prevent Facebook from including meta-information about the URL. This has the side effect of making Facebook treat your update as a regular status, rather than a link.

  4. 2010
    Jul
    25

    Facebook does bug reports right

    There are a lot of complaints you could make about Facebook, many of them legitimate, but the bug reporting process is one thing I think they really do well.

    A while ago I had occasion to report a problem with the message inbox showing up as a blank page. As the first step in the process, Facebook presents you with a grouped list of categories corresponding to the different features of the site. Each one is tagged with the same icon used on other menus, so it’s easy to identify, and the images really help to visually distinguish the different categories. I much prefer that to the standard bug reporting interface, where all you get is a combo box with a long list of different products or categories (text-only of course), some of which you may not even be familiar with.

    On Facebook, when you click the category that matches your bug, you get a list of the common reports that have already been filed under that category. But unlike a typical bug listing which uses the (often non-descriptive) bug report titles submitted by users, the titles are written by members of the Facebook team, and they’re all …

  5. 2010
    Jul
    24

    RSS Graffiti

    I decided it’s about time to start syncing the posts I make here with Facebook to get some exposure for this site. Not because I think anyone will really care about my content, but everyone else seems to be doing it. I guess it puts pressure on me to write more interesting stuff, that’s probably good.

    Anyway, to test out the system and also as sort of an unsolicited “kickback” to what seems like it might be a good program, I wanted to mention RSS Graffiti. I picked up on it from a mention on the Webapps Stack Exchange site. Basically it’s an RSS/Atom feed aggregator: you configure it with the URLs of any number of feeds, and specify which ones should show up on your profile and the profiles of any groups, events, or pages you administer. The app checks periodically for new entries and posts them up to the destinations you specified. Nice and simple, which is actually just what I’ve been looking for in a Facebook RSS aggregator for a while. Here’s hoping it works as well as it looks!

  6. 2010
    Jul
    09

    Bad science on The Daily Show

    Normally I love The Daily Show. (Especially in HD) But Jon Stewart's interview with Marilynne Robinson last night really fell short of the usual standard. And not just because she wasn't funny. At 2:52 in:

    The more you delve into science, the more it appears to rely on faith.

    You know, when they start to speak about the universe, they say, well, it's actually, "Most of the universe is antimatter." "Oh really? Where's that?" "Well, you can't see it." "Well, where is it?" "It's there." "Can you measure it?" "We're working on it..."

    The Daily Show With Jon StewartMon - Thurs 11p / 10c
    Marilynne Robinson
    www.thedailyshow.com
    Daily Show Full EpisodesPolitical HumorTea Party

    No. Sorry. That's not science. For one thing, nobody with a clue really thinks most of the universe is antimatter. But the more important point is that observation is the core of science. If you can't see something, can't measure it, can't even produce any observable evidence that it exists, you can't pass it off as scientific fact.

    I have to wonder where Jon Stewart is getting this idea that scientists are relying on faith, claiming that things are true without having the …

  7. 2010
    Jul
    09

    Navicat for MySQL

    I’m used to using PHPMyAdmin (PMA) for managing my MySQL databases. It works fine for normal maintenance, like getting rid of the spam comments that sneak through my checks (of which there are, or rather were, none), but while setting up the new version of this site, I found myself wanting to transfer the entire contents of the database to my home computer so I could tinker with it and try to figure out how to convert it to the new format I needed. PMA doesn’t really do that. Sure, it can manage multiple servers, but it treats each one separately; as far as I know the only option for transferring data is to export it to a text file and import it into the new database. I’ve never had particularly great luck with PMA’s export function, and besides, since the whole structure was changing, I needed to take the information in each table of the existing database and split it up among different tables in the new database. I briefly considered processing SQL dump files with a Perl script but it quickly became evident that that would be a mess.

    So I went to my …

  8. 2010
    Jun
    24

    Environment variables and sudo

    A discovery I made: apparently sudo does not pass through environment variables you set in the shell. So if I’m trying to install git with the GUI, I need to do this:

    sudo USE=gtk emerge git
    

    instead of

    USE=gtk sudo emerge git
    

    The former starts a root shell and then sets the environment variable USE=gtk, whereas the latter sets the variable and then starts a root shell, but the new shell doesn’t inherit the value of USE.

  9. 2010
    Jun
    14

    Global USE=debug

    Don’t do it.

    A warning to any fellow Gentoo users: don’t put debug in your USE flags in make.conf, because there are many, many packages that produce copious amounts of debugging output and you can’t possibly care about them all. I think I’ve been getting about a thousand lines from PAM every time I su to root.