Archive

Archive for the ‘geekery’ Category

Atomisator Configuration for Unified Python Planet

May 9th, 2009

Robert Kern asked me to share my Atomisator configuration for the Unified Python Planet. So, here it is:

[atomisator]
 
# sources
sources = 
    rss http://www.planetpython.org/rss20.xml 
    rss http://planet.python.org/rss10.xml
 
# filters
# "doublons" is French for "duplicates" --  this is what de-dups the feed
filters =
	doublons
 
# enhancers
# I'm not using any, just leave this blank (default)
enhancers =
 
# outputs
outputs =
    rss /home2/mpirnat/webapps/pirnatwp/static/unified_python_planet.xml "http://feeds2.feedburner.com/UnifiedPythonPlanet" "Unified Python Planet" "A uniqued union of the Official and Unofficial Python planet feeds.  Generated by Atomisator FTW!" 
 
# database
database = sqlite:///atomisator/unified_python_planet.db

The example configuration files that come with Atomisator are really good at illustrating how you would use them; I’ve omitted the explanatory comments from my example, but they’re in the examples and will point you in the right direction. Thanks again to Tarek for this very handy tool!

geekery, python , , , , ,

The Diaper Pattern Stinks

May 9th, 2009

I mentioned the “Diaper Pattern” in a recent post and got some comments asking what the term meant. I had hoped to just link to an explanation, thinking it was a well-known antipattern, but several minutes of frustrated Googling have left me convinced that there’s actually a tiny knowledge gap to be filled here.

“Diaper Pattern” is a term that I picked up from working with Matt Wilson and David Stanek. It’s an anti-pattern about naively over-broad exception catching. A very basic example in Python might be:

try:
    do_something_that_might_throw_various_exceptions()
except Exception:
    pass

If anything at all goes wrong in do_something, the except will catch and silence it–but we know that errors should never pass silently (unless explicitly silenced). It’s called a Diaper because it catches all the shit.

In practice, unless you have a good reason to catch everything, it’s a lot better to only catch the specific exceptions that need special handling, so that you’ll know right away about any runtime surprises and where they came from:

try:
    do_something_that_might_throw_various_exceptions()
except IOError, e:
    # handle just IOErrors; let everything else make noise

Maybe it’s just a coincidence, but I’ve heard the term used more by developers who have young children than by those without kids.

geekery, naughty-words, python , , , ,

The Zen of Doing It Wrong

May 6th, 2009

A coworker unearthed this little treasure today… I think it’s a vestigial structure to assist Diaper (anti)Pattern treatment during testing or debugging, but it’s still gross to see it in real, live production code. (Oddly enough, I couldn’t find a good “Diaper Pattern” link whilst Googling about–surely I’m not the only one who uses this term?) Anyway, without further ado:

        try:
            os.remove(filename)
        except:
            raise
            pass
        try:
            os.remove(os.path.join(TMP,'out-%s' % base_filename))
        except:
            raise
            pass
        try:
            os.remove(os.path.join(TMP,'properties_%s.lock' % brandid_human))
        except:
            raise
            pass

If an exception is raised, raise an exception… It has a certain zenlike beauty to its awfulness. The use of the Diaper Pattern is bad enough, but this guarantees blowouts!

geekery, python, wtf , , , ,

A More Excellent Unified Python Planet

March 28th, 2009

Good news, everyone!

After a couple days of playing Twitter tag with Tarek Ziade, we finally met up for lunch at PyCon, where, in addition to having a lovely conversation, he was kind enough to give me a personal tour of his Atomisator framework for data aggregation.

Atomisator is much savvier than Yahoo Pipes at things like removing duplicates and not mangling content, so I’ve kicked Pipes to the curb and hooked up the Unified Python Planet feed to my Atomisator output.

What this means for you, lucky reader, is that everyone who subscribes to the Unified Python Planet should not only stop getting duplicates, but, more importantly, have legible code samples directly in the feed. (It’s okay if you need to take a moment to process this joyous news. It makes me pretty damn happy.)

Please let me know if you experience any flakiness with the new, improved feed.

I want to give major, major thanks to Tarek! Atomisator is really well suited to this purpose, as well as some other stuff I’m now curious to tinker with.

geekery, pycon, python , , ,

Well That Was No Fun

December 29th, 2008

Thought I’d be all spiffy and upgrade to the shiniest new Wordpress tonight. I did my little svn switch/bzr add/bzr merge trick to get all the new files in the right place, upgraded the database, and felt pretty awesome… Then my blog started throwing miles upon miles of “transport errors” and 500s, as did a couple others that I hadn’t even touched with upgrades. The common factor seemed to be WP instances that were nested off of subdirectories of one of my domains, rather than WP instances at the root level of the domain. That smells like some kind of configuration problem in Webfaction panel-land, but I was too impatient to open a ticket (and trying to focus on something, anything other than Mama Mia that my wife was watching), so I ended up doing a mysql dump, blew away my old blog instance, dropped a new one into place (which magically worked, thanks a lot, universe), and restored from my backup.

So… Upgrade done (good) but not how I planned it (bad).

On the plus side, I was kind of getting sick of the theme anyway. :-P

geekery, wordpress

Python: You’re Doing It Wrong

November 25th, 2008

A coworker just showed me this little gem–a maintenance script that’s got no author attribution and isn’t in source control, so whoever has perpetrated this crime against all that’s good and holy remains anonymous and (for the moment) safe from our wrath. I’m so completely taken aback by this–I… I don’t know what to say. I just have to share.

#!/usr/bin/env python
import os,sys
C=os.chdir
S=os.system
M=os.mkdir
J=os.path.join
A=os.path.abspath
D=os.path.dirname
E=os.path.exists
W=sys.stdout.write
V=sys.argv
X=sys.exit
ERR=lambda m:W(m+"\n")
PRNT=lambda m:W(m+"\n")
assert len(V)==2,"you must provide a sandbox name"
SB=V[1]
H=A(D(__file__))
SBD=J(D(H),SB)
C(SBD)
PST=J(SBD,'bin/paster')
VAR=J(SBD,'var')
ETC=J(SBD,'etc')
S("mkdir -p "+VAR)
PRNT("restarting "+SB)
CMD=";".join(['source %s'%J(SBD,'bin/activate'),PST+" serve --daemon --pid-file=%s/sandbox.pid --log-file=%s/sandbox.log %s/sandbox.ini start"%(VAR,VAR,ETC)])
PRNT(CMD)
S(CMD)
PRNT("All done!")
X(0)

Weep for us.

geekery, python, wtf , , ,

A Unified Python Planet

November 2nd, 2008

I subscribe to both the official and unofficial Python planet feeds because they’ve each got some content that’s unique to one or the other, but the overlap and duplication has really been bugging me lately. So I suddenly remembered the joy that is Yahoo Pipes and glued both of them together with a unique-ifying filter to eliminate duplicates, and, feeling generous, I stuck a friendlier Feedburner URL around it–you can get it at http://feeds.feedburner.com/UnifiedPythonPlanet.

It makes me pretty happy so far, except that somewhere in Pipes land I seem to be losing newlines in pre elements (which appears to be a bug in Pipes itself, argh), which is a little (very) annoying when trying to read people’s code samples. I may end up replacing the Pipes side with a little bit of Python (a little Feedparser and PyRSS2Gen ought to do the trick) if I get the time later today.

Anyway. I figured I should share it, on the offchance it makes anyone else’s life better. (Or if such a creature already exists, let me know and I’ll gladly use that instead.)

geekery, python, rss , , ,

He Who Rocks and Puts Away Lives to Rock Another Day

October 27th, 2008

The kiddo has had a pretty strong musical interest for a while now, but in the last week or so she’s gotten really excited by my Rock Band controllers, which have been hanging out in the corner of the family room, right where they’re easy for her to get at if she wanted to. I’m content (thrilled, in fact!) to have her noodling around with my original Rock Band 1 controller (of the woefully busted whammy bar), but I’d like to keep my pair of RB2 controllers in good shape for as long as possible.

So, off we went to Guitar Center to pick up a couple of guitar hooks to hang the controllers on the wall, safely out of reach from curious little hands.

I’m not sure if I’m more embarrassed by buying guitar hooks for my fake guitars, or by the fact that we’d worked up an elaborate tale of how I’d recently inherited a (fictional) ukulele collection (to explain my concerns about whether the hook would be narrow enough to hold the guitar head). Sadly, no questions were asked about my purchase, so we never got to try out the story.

So, here you go–photographic evidence that I am, in fact, pretty much a total dork. Enjoy.

children, claire, geekery, music, retail-therapy, video-games

You Nuked My Battlestar!

July 13th, 2008

Pretty much out of nowhere, I suddenly decided that what the world really needs is a Battlestar Galactica-themed version of the classic Battleship game. Besides the obvious cool factor of having a board full of miniature BSG ships, I think there’s a lot of depth to be added by tweaking the rules a little bit:

  • The human player can choose to “jump the fleet” rather than firing a shot, allowing the player to rearrange the locations of all of their ships.
  • The Cylon player can return any destroyed ship to the board per turn until the destruction of their resurrection ship, in addition to their normal “take a shot” action. If the Cylon player doesn’t have any destroyed ships, they can instead opt to repair one “hit” from a non-resurrection ship per turn in addition to firing a shot, so long as the resurrection ship is still in play.
  • Both sides have a limited number of nuclear weapons which, rather than targeting a single point on the game grid, will have a several-coordinate blast radius. Nukes are only available to their respective players so long as there are battlestars or basestars in play.
  • The Cylon player has a number of sleeper agents in the human fleet; the Cylon player can opt to activate a sleeper instead of firing, which will result in one hit against a human ship of the human player’s choosing.
  • The human player may sacrifice a battlestar to destroy a Cylon basestar.
  • After some as-yet-undertermined number of turns, the human player can produce a stealth Viper, which can be relocated on the grid every turn or which can be sacrificed to learn the location of the Cylon resurrection ship.
  • After some as-yet-undetermined number of turns, the human player gets a second battlestar.
  • And, if you’re not afraid of Season 4 spoilers, if the human and Cylon player get tired of endlessly killing each other, they can opt to partner up and “go find Earth,” at which point the game is over and they both lose.

Cylon raiders and heavy raiders seem like one- and two-hit vessels to me, while the Colonial Vipers and Raptors are probably single-hit ships. Basestars should be relatively large (suggesting a much larger field of play than the standard Battleship grid) and maintain a six-pronged X shape target profile. Battlestars would probably need to be three spaces wide so that the flight pods can take hits too. Obvious choices for other Colonial ships include Colonial One, Cloud 9, Demetrius, the Astral Queen, Daru Mozu (the tylium refinery ship), mining ships, Space Park (the “spinny ship”), and numerous others. Clearly, getting the balance right on both Colonial and Cylon sides would be important to proper gameplay.

The reaction from my coworkers who are also fans has been very positive, so I suspect that if the appropriate corporate behemoths could work out the licensing, they’d at least sell a few units to us. In the mean time, if you feel like giving it a whirl, go for it! The rules definitely need some fine-tuning to make sure gameplay is properly balanced, but they should be at least a good start. If you do end up trying it out, I’d love to hear how it went.

So say we all!


[Edit 7/14/2008 @ 23:19] The collective unconscious appears to have reared its ugly head–turns out I’m not the first to have this idea.

galactica, games, geekery, sci-fi, science-fiction

Reconciling Leopard and the Brother 5070N Laser Printer

May 8th, 2008

Once upon a time, I upgraded to Leopard on my Mac Pro, and, though I did not mention it at the time, something in upgrade land totally pissed off my Brother 5070N laser printer.

I’d bought the printer in the first place because it was one of the first to support Bonjour (née Rendezvous, née Zeroconf) networking. With good ol’ Tiger, it Just WorkedTM, and all was milk and honey as far as printing went in my home. But noooo, it didn’t like the hoity-toity, super-duper-greatest-thing-since-sliced-bread Leopard attitude, and just spat out endless reams of cryptic stack dumps instead of, say, directions to wherever I was in a hurry to leave for. I poked around a little, checking for new drivers and all that sort of common sense stuff, and found that even Brother’s website claimed that the drivers were bundled with Leopard and that there was nothing for me to download.

I never did get around to figuring out the problem at the time, and being a sleep-deprived and very busy new dad it unfortunately hasn’t been much of a priority. Somehow I’ve learned to live with six months (!!!) of not being able to print a damn thing. And worse, I’ve had to hold off on upgrading my wife’s machine, which has kept her from being able to enjoy the goodness of automated Time Machine backups.

I finally got fed up with it today and decided to finally sort things out once and for all. I even indulged my inner noob and followed Brother’s directions, even though it meant assigning a static IP to my printer and dropping it back from the awesomeness of Bonjour to the semi-awesomeness of old-school IP printing. It turns out that, even though no one says it anywhere, that was the key. So, here’s a bit of advice for future Googlers: the 5070N will not print correctly using Bonjour under 10.5. You want the CUPS driver and the “HP Jetdirect – Socket” protocol. Then poof! It’s all happy again.

Now to go about breaking upgrading Liz’s laptop…

computers, geekery, macintosh