Archive for February, 2009
Getting to it
Started seriously getting the ball rolling on my thesis this week, outlines and everything. I found a really great app for writing called Scrivener (non free, OS X only). Notice that I said writing, not publishing. For my purposes, it does rather poorly as a publishing platform, but I have that end of things worked out rather well (
represent!). 1000 words in the first day. Granted, they are the easy words (background and lit review), but hopefully I can keep up a moderate pace so I can defend this summer. Once I start finishing sections and moving my draft into LaTeX, I’ll start publishing them somewhere here. Probably not in this blog, but maybe a directory for a Latex2HTML dump.
In other news, we got a Nikon d80. All the recent pics in my Flickr stream are taken with it (minimal post-processing).
It’s nice to be writing again.
Python unit testing super fun time
There’s a weird thing that happens after a long night of mind-blowing back-breaking coding. Well, hacking in this case. Every time I stay up late working really hard on something, I feel compelled to blog/tweet/emote about my experience so others might feel sympathy/compassion for me. Even though I’m dizzyingly tired, and have to get up in ~5 hours, I cannot deny this urge to massage my ego.
So tonight I bring to you the joy of unit testing in Python. I’ve been using py.test, and loving it. It extends the basic functionality of Python’s built-in module, unittest (which is really not that bad). The main improvements are in the simplicity of writing the tests. Py.test supports unit testing on methods, classes, even whole modules.
Here’s your first test
def test_iszero():
assert 1==0
If you haven’t guessed, this test will fail (1 does not equal 0). A cool thing about py.test is that you just prefix the method name with “test_” and that becomes a test. If it’s in a class or module, you need setup and teardown methods, but beyond that just write methods starting with “test_”. There’s lots more fancy stuff you can do, I suggest checking out the docs (link above).
However, by my favorite thing py.test does is support generative testing. By using generators, a test can spawn “sub” tests with a yield statement. Let’s say I want to test if a bunch of numbers are even.
def isEven(x):
assert x%2==0
def test_evenNumbers():
n = [1,2,3,4,5,6]
for x in n:
yield isEven,x
This can be tremendously helpful when you need to do a repetitive test on many input parameters. Enjoy!
-David
Mad scientist in my trash
While I was taking out the trash today, I noticed something peculiar about an old computer monitor left out by my trash can. It had been smashed open and a component was taken out of it. The missing component was in fact the electron gun – perhaps the coolest part of a cathode ray tube (CRT).
An electron gun is essentially a mini particle accelerator used to speed up and focus electrons into a teeny tiny beam that hits phosphorous atoms on the back of the class of your favorite CRT and causes them to fluoresce (make color). In a physics lab back in undergrad, I was playing with a smaller version of one of these that was running at 600V (low amps). My lab partner zapped himself and was all shaky for the rest of the afternoon. I imagine the volts running through these commercial grade electron guns must be pretty serious.
My best guess is that one of the bums in my area is aspiring to be an evil genius – constructing some sort of death ray I’m sure. My hunch was bolstered upon further investigation of a photo I took of the CRT. As you can see, it’s clearly missing the electron gun as a whole (notice the large hole in the tube). However, I also noticed that a piece of the gun remained – the electron source itself (to the right of the hole). So whoever Frankensteined my monitor was after the accelerator component of the electron gun – the magnet array. What sort of dastardly particles could he or she be planning to accelerate?!? Photons? Positrons?!
I’m going to install a Faraday cage around my bedroom – just to be safe.
-David