Archives for: January 2009
Work in progress
January 16th, 2009
Looking for work
January 15th, 2009JJ Behrens is looking for work. Smart guy. You should hire him.
After you hire him, have a look at my resume and hire me too.
2009 Linnaeus Awards
January 13th, 2009The Linnaeus Awards
I'm starting a new category here: the Linnaeus Awards. Candidates must be examplars of Linnaean Taxonomy:
The method, the soul of science, designates at first sight any body in nature in such a way that the body in question expresses the name that is proper to it, and that this name recalls all the knowledge that may, in the course of time, have been acquired about the body thus named: so that in the midst of extreme confusion there is revealed the sovereign order of nature.
So, if you encounter a trout in the wild, you don't call it a "trout". You call it an "Oncorhynchus (mykiss) aguabonita masculinus trescenti-septi-squamatic duodecim-annus-natis...", stuffing every conceivable attribute of the object into its name.
Categories
- Longest Name. Names which are mashed together because of formalLanguageIdentifierRestrictions or natürlichsprachemodifizierdiarrhöe might get bonus points.
- Most Dimensions. Names which incorporate knowledge from varied axes, the more the better.
- Most Abstract. Placing the number-of-scales-on-a-fish into its name is fun, but for real "sovereign order" you need to incorporate the vocabulary of the taxonomy itself into the name. For example, a function in a spreadsheet program named, "SpreadsheetProgramAdditionFunction". Bonus points for including terms from ontology, taximetrics, or metaphysics.
Feel free to nominate additional candidates here or email: linnaeus@aminus.org.
Today's nomination:
RequestProcessorFactoryFactory
Factory-factories are not new. But this one goes a step further with some of its "implementing classes":
- RequestProcessorFactoryFactory.RequestSpecificProcessorFactoryFactory
- RequestProcessorFactoryFactory.StatelessProcessorFactoryFactory
...and genuflective attributes like:
- RequestProcessorFactoryFactory.RequestProcessorFactory.getRequestProcessor(XmlRpcRequest)
But it doesn't stop there; the copy nominates itself:
There is nothing magic about the request processor: It may very well be a POJO. The RequestProcessorFactoryFactory is passed to the AbstractReflectiveHandlerMapping at startup...
Passing a factory-factory to an abstract-anything makes this a good candidate. Using the phrase "nothing magic" with a straight face catapults it to the top.
assertNoDiff
January 9th, 2009I recently had to test output that consisted of a long list of dicts against an expected set. After too many long debugging sessions with copious print statements and lots of hand-comparison, I finally got smart and switched to using Python's builtin difflib to give me just the parts I was interested in (the wrong parts).
With difflib and a little pprint magic, a failing test now looks like this:
Traceback (most recent call last):
File "C:\Python25\lib\site-packages\app\test\util.py", line 237, in tearDown
self.assertNoDiff(a, b, "Expected", "Received")
File "C:\Python25\lib\site-packages\app\test\util.py", line 382, in failIfDiff
raise self.failureException, msg
AssertionError:
--- Expected
+++ Received
@@ -13,4 +13,3 @@
{'call': 'getuser101',
'output': {'first_name': 'Georg',
'gender': u'Male',
'last_name': 'Handel',
...}}
{'call': 'getuser1',
'output': None}
{'call': 'getuser101',
'output': {'first_name': 'Georg',
'gender': u'Male',
'last_name': 'Handel',
...}}
-{'call': 'getuser101',
'output': {'first_name': 'Georg',
'gender': u'Male',
'last_name': 'Handel',
...}}
...and I can now easily see that the "Received" data is missing the last dict in the "Expected" list. Here's the code (not exactly what I committed at work, but I think this is even better):
import difflib
from pprint import pformat
class DiffTestCaseMixin(object):
def get_diff_msg(self, first, second,
fromfile='First', tofile='Second'):
"""Return a unified diff between first and second."""
# Force inputs to iterables for diffing.
# use pformat instead of str or repr to output dicts and such
# in a stable order for comparison.
if isinstance(first, (tuple, list, dict)):
first = [pformat(d) for d in first]
else:
first = [pformat(first)]
if isinstance(second, (tuple, list, dict)):
second = [pformat(d) for d in second]
else:
second = [pformat(second)]
diff = difflib.unified_diff(
first, second, fromfile=fromfile, tofile=tofile)
# Add line endings.
return ''.join([d + '\n' for d in diff])
def failIfDiff(self, first, second, fromfile='First', tofile='Second'):
"""If not first == second, fail with a unified diff."""
if not first == second:
msg = self.get_diff_msg(first, second, fromfile, tofile)
raise self.failureException, msg
assertNoDiff = failIfDiff
The get_diff_msg function is broken out to allow a test method to call self.fail(msg), where 'msg' might be the join'ed output of several diffs.
Happy testing!
99 Bottles...
January 5th, 20091) Copy this list into your blog, with instructions.
2) Bold all the drinks you’ve imbibed.
3) Cross out any items that you won’t touch
4) Post a comment here and link to your results.
OR
If you don’t have a blog, just count the ones you’ve tried and post the number in the comments section.
- Manhattan Cocktail
- Kopi Luwak (Weasle Coffee)
- French / Swiss Absinthe
- Rootbeer
- Gin Martini
- Sauternes
- Whole Milk
- Tequila (100% Agave)
- XO Cognac
- Espresso
- Spring Water (directly from the spring) Soda water, too!
- Gin & Tonic
- Mead
- Westvleteren 12 (Yellow Cap) Trappist Ale
- Chateau d’Yquem
Budweiser- Maraschino Liqueur
- Mojito
- Orgeat
- Grand Marnier
- Mai Tai (original)
- Ice Wine (Canadian)
Red Bull- Fresh Squeezed Orange Juice Once a week!
- Bubble Tea
- Tokaji
- Chicory
- Islay Scotch
- Pusser’s Navy Rum shudder
- Fernet Branca
- Fresh Pressed Apple Cider
- Bourbon
- Australian Shiraz
- Buckley’s Cough Syrup
- Orange Bitters
- Margarita (classic recipe)
- Molasses & Milk
- Chimay Blue
- Wine of Pines (Tepache)
- Green Tea
- Daiginjo Sake Of course
- From the department of redundancy department: Chai Tea
- Vodka (chilled, straight)
- Coca-Cola
- Zombie (Beachcomber recipe)
- Barley Wine
- Brewed Chocolate (Xocolatl) Does Abuelita count?
- Pisco Sour
- Lemonade
- Speyside Single Malt
- Jamaican Blue Mountain Coffee
- Champagne (Vintage)
- Rosé (French)
- Bellini
- Caipirinha
- White Zinfandel (Blush)
- Coconut Water
- Cerveza Corona es lo mejor...
- Cafe au Lait
- Ice Tea
- Pedro Ximenez Sherry
- Vintage Port
- Hot Chocolate
- German Riesling
- Pina Colada
- El Dorado 15 Year Rum
- Chartreuse
- Greek Wine
- Negroni
Jägermeister- Chicha
- Guinness
- Rhum Agricole
- Palm Wine
- Soju
- Ceylon Tea (High Grown)
- Belgian Lambic
- Mongolian Airag
- Doogh, Lassi or Ayran
- Sugarcane Juice
- Ramos Gin Fizz
- Singapore Sling
- Mint Julep
- Old Fashioned
- Perique
- Jenever (Holland Gin)
- Chocolate Milkshake
- Traditional Italian Barolo
- Pulque
- Natural Sparkling Water
- Cuban Rum
- Asti Spumante
- Irish Whiskey
- Château Margaux
- Two Buck Chuck
- Screech
- Akvavit
- Rye Whisky
- German Weissbier
- Daiquiri (classic)
and I'll add: - Rompope