1/10/2010: 11:43 pm: RobertDjango, Python

Django includes a Bash shell completion script, which can save a lot of time. The tutorial recommends installing it, but doesn’t explain how. Fortunately, its the same as for any other Bash shell completion script. Here’s how I did it for Django.

  • Add an environment variable for the location where you installed Django. For example, add the following line to ~/.bash_profile:
    export DJANGO_HOME=/Users/rstewart/code/Django-1.1.1
  • Add a line after this one in ~/.bash_profile to read the script, e.g.,
    source $DJANGO_HOME/extras/django_bash_completion
  • After saving .bash_profile, open a new terminal or run source ~/.bash_profile

Now, you can press tab to complete commands. Below, I pressed tab after entering “manage.py”.

$ python manage.py
compilemessages   diffsettings      loaddata          runserver         sqlclear          sqlreset          syncdb
createcachetable  dumpdata          makemessages      shell             sqlcustom         sqlsequencereset  test
createsuperuser   flush             reset             sql               sqlflush          startapp          validate
dbshell           inspectdb         runfcgi           sqlall            sqlindexes        startproject
12/29/2009: 5:17 pm: RobertMac, MySQL, Python

I just updated an old post on using Python with MySQL on OS X. The good news is that you don’t need to create an extra directory of symbolic links anymore. The not really bad news is that you have to be careful about 32-bit versus 64-bit.

Ideally, you’ll first upgrade to a 64-bit version of MySQL 5.1 or later, unless you already have. Then, follow Geert’s simple instructions for building the MySQL Python connector.

12/20/2009: 10:40 pm: RobertFood and Drink

Note for my vegetarian and vegan friends. Nothing to see here. Move along.

We endured the spiral sliced ham shaped line at Blue Bottle Coffee this morning to buy 10 pounds of heritage-breed pork. Despite the chaos and lack of signs explaining how to pay or pick up your pork, everyone seemed to eventually figure it out, and no Walmart Black Friday incidents broke out. The free coffee, sausage and bacon after the long wait were pretty awesome, especially the sausage. I can hardly wait to cook the sausage we got in our bag. It was crazy good.

Chris Cosentino of Incanto was there, waiting in line with everyone else to score some pork. Although he obviously has a direct source for his restaurant, it was cool to see him there, relishing the experience with the rest of us.

We got a 1/4 rack of chops from an apple-fed Berkshire, some pork belly from an apple-fed cross between a Mangalitsa and a Berkshire, a ham hock from an apple-fed Mangalitsa and two bags of sausage.

For dinner tonight, we tried to make schweinshaxe from the ham hock. While an interesting experiment, it was a bit disappointing in the end. The next time a recipe calls for what sounds like too much cloves, I’m going to go with my gut and use much less. The meat came out a little too tough. I think we went way, way too light on the salt. That will teach us next time to use a real German and not a random recipe on the Internet next time we come face to face with a trotter. At least it looked great when it came out of the oven.

Schweinshaxe

11/21/2009: 1:08 pm: RobertJava, Scala

A few weeks ago I decided to learn Scala in order to develop the website for my latest side project. This led me down the road of trying to learn Google App Engine/Java, Lift, Maven, Git, ScalaTest, Spec and much more, so it’s been pretty slow going. Especially due to diversions into Cassandra, MongoDB, Tokyo Cabinet, Hadoop and HBase.

I’m a huge fan of JUnit for unit testing Java code, so I was happy when Bil Venners announced the release of ScalaTest 1.0 at a BASE meeting at Twitter. I really like being able to quickly run tests in Eclipse, but it wasn’t obvious to me how to do this with ScalaTest, especially when using the BDD styles of testing, like Spec. Creating test runners manually for each class was a deal killer. I finally found some info that mostly clarified things.

A simple example is helpful, so here you go:

import org.scalatest.Spec
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
 
@RunWith(classOf[JUnitRunner])
class MinimalSpec extends Spec {
   describe("My class") {
     it("should have testable behavior like...") {
       assert(true)
     }
   }
}

After creating the class, do one of the following:

  • Right click on file in tree and select Run As -> JUnit Test
  • Select file in tree and press Alt-Command-X + T on OS X or Alt-Shift-X + T on other OSs

After the test completes, the JUnit view should display something like:

Screenshot of JUnit view after running MinimalSpec with ScalaTest

11/12/2009: 2:41 pm: RobertMySQL

After upgrading to the newest version Maatkit, the invaluable toolkit for MySQL, I was no longer able to run any of the Maatkit tools. The problem turned out to be caused by my update to MacPorts after upgrading to Snow Leopard.

By default, Apple provides perl 5.10, which is built in 64-bit mode, though backwards compatible with 32-bit binaries. However, I was seeing a different version.

$ perl --version
 
This is perl, v5.8.9 built for darwin-2level

Trying to run mk-archiver resulted in the following error (again, wrapping some lines for readability):

$ mk-archiver --version
Can't load '/opt/local/lib/perl5/site_perl/5.8.8//darwin-2level/auto/Data/Dumper/Dumper.bundle'
for module Data::Dumper:
dlopen(/opt/local/lib/perl5/site_perl/5.8.8//darwin-2level/auto/Data/Dumper/Dumper.bundle, 1):
no suitable image found.  Did find:
/opt/local/lib/perl5/site_perl/5.8.8//darwin-2level/auto/Data/Dumper/Dumper.bundle:
mach-o, but wrong architecture at
/opt/local/lib/perl5/5.8.9/darwin-2level/XSLoader.pm line 73.
 at /opt/local/lib/perl5/site_perl/5.8.8//darwin-2level/Data/Dumper.pm line 27
Compilation failed in require at /opt/local/bin/mk-archiver line 874.
BEGIN failed--compilation aborted at /opt/local/bin/mk-archiver line 874.

The “wrong architecture” note in the error message led me to eventually find the cause of my troubles. MacPorts added the following to my ~/.bash_profile (I wrapped a line to make it easier to read:

# MacPorts Installer addition on 2009-10-31_at_23:33:12:
# adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

This caused the 32-bit perl 5.8.9 from MacPorts to be used instead of the 64-bit perl 5.10 provided with Snow Leopard. Commenting out the export line above was the first step to fixing the problem.

I also noticed that I wasn’t adding /usr/bin to my path before I added the MacPorts paths. So, I made the following change to my .bash_profile (leaving out some of the path components for clarity).

PATH_PREFIX=/usr/local/bin:/usr/bin:$JDK_HOME/bin:/opt/local/bin:/opt/local/sbin
PATH_SUFFIX=$ANT_HOME/bin:$MYSQL_HOME/bin:$SCALA_HOME/bin:$GIT_HOME/bin
export PATH=$PATH_PREFIX:$PATH:$PATH_SUFFIX

Using source .bash_profile won’t update the PATH variable properly because of the way it is being constructed above. So, start a new console to get a corrected value for the PATH. Then you should get:

$ perl --version
 
This is perl, v5.10.0 built for darwin-thread-multi-2level

and something like

$ mk-archiver --version
mk-archiver  Ver 1.0.20 Distrib 5014 Changeset 5004
10/26/2009: 12:44 pm: RobertMySQL

OpenSQL Camp 2009 in Portland, OR

I’ll be in Portland on November 13, 14 and 15 for OpenSQL Camp, an unconference covering open source databases. In addition to learning more about MySQL and Drizzle internals, I’m looking forward to learning a bit about Postgres and some of the NoSQL database alternatives. They aren’t just your father’s high performance key-value stores, anymore.

10/22/2009: 9:21 am: RobertEverything Else

Wombat Day badgeThanks to my ever alert colleague, Rob, I’m celebrating Wombat Day today. I’ll be taking in my stuffed wombat that was handmade in Australia with what almost appears to be actual wombat hair, but I’m thinking is actually dyed wool.

10/12/2009: 12:18 am: RobertFood and Drink

After tasting my way through many beers, though a fraction of the total, at Dimond Oaktoberfest in my hood, I made my way over to Cal for 99 Bottles of Beer, a beer symposium, fair, workshop and exhibit.

After getting the lay of the land at the beer fair, I started at the back with an Eel River Acai Berry Wheat Ale. Very light wheat ale with a (surprise) subtle berry flavor. Not my favorite, but maybe good for weaning someone off American industrial light lagers.

While I missed the workshop on beer packaging, I’m sure that the person from 21st Amendment was talking about their canned beers. Proper canned beers these days use an inert liner that does not impart a metallic taste to the beer. The aluminum cans’ opacity obviously is even better than brown bottles for preventing reactions between isohumulones in the beer and blue light that produce skunky flavored mercaptans. Okay, I’ll put the book down, now.

My next taste was about half a can of 21st Amendment Brewery Hell or High Watermelon Wheat. The watermelon taste was not subtle. Being a Southerner, I looked around for salt. I would absolutely drink this on a hot summer day. Unfortunately for 21st Amendment, their hometown of San Francisco has about four of those a year. I bet they could sell a lot of this in Texas.

Dan was drinking his IPA at the Bison Brewing booth, so I decided to follow his lead. Great aroma hops perfectly balancing the malt. Just what my palate needed.

Symposium Time. First up was Charlie Bamforth, a malting and brewing science prof at UC Davis. He was a fantastic speaker, combining a high speed history of beer with hilarious anecdotes and comments. I could listen to him for hours. I now wish I had purchased his book Grape vs. Grain while he was signing books before the symposium.

Fritz Maytag of Anchor Brewing then spoke mostly about the effort in 1989 to produce a beer very much in the brewing style in ancient Sumeria over 5000 years ago. Clearly, he loves his work. They’re cooking up a big new project at Anchor, but Fritz wasn’t ready to reveal what it is. Fritz was also a great speaker.

Bruce Paton spoke briefly about food and beer pairings. The Cathedral Hill hotel is closing very soon, so there is only one more food & beer dinner on schedule with Rob Tod from Allagash. He said he will be a “free agent” after that. Bruce said he refers often to Garret Oliver’s book The Brewmaster’s Table, which I have been busily reading along with Randy Mosher’s Tasting Beer. I was hoping Bruce would talk more about how he chooses beer for food, but he mostly works in the opposite direction. I guess that makes a lot of sense when the beer dinners often feature the beers of a particular brewer. I asked him more about this during the Q&A at the end. He had talked about complement, contrast & cut (cut as in clearing the palate) when choosing pairings. I asked if he favors one approach over the other. He replied that he first looks to complement food with beer, but if he can’t find a good complement, he looks for contrast. I think that’s very useful advice.

Finally, Christine Hastorf from Cal talked about the archaeology of beer, mostly in Egypt, the Middle East and the Andes. Her talk tied together very nicely with Maytag’s talk. She showed off a small kero that is typical of the tumblers used to drink chicha, a corn-based beer, in the Andes. My father-in-law gave us a carved wooden kero that he acquired while they lived in Bolivia and he was going on digs at Tiwanaku with Ponce. Christine guessed that it was from the Colonial period based on the photos I showed her. We really should get it dated. The wood has a really well-worn patina that makes it look fairly old.

I caught the tail end of the tour at the Hearst Museum. Ira Jacknis was telling interesting and amusing about some of the 130 or so beer-related artifacts on display. I’ll have to go back when I have more time, because,…

… it was porter and stout time for me during the closing minutes of the Beer Fair. First up was the Triple Rock Stonehenge Stout. Very dark and chocolately, but perhaps only faintly druidic.

I also had what I think was a porter from Butte Creek. I wasn’t taking any notes, so after a day of tasting, my memory may be a bit off, though I definitely liked it. Damn, next time I bring a notebook, or walk around with a voice recorder saying “Note to self, …”

A fine day of beer tasting came to an end with the Bison Brewing Chocolate Stout. Loved the cocoa flavor and the rich mouth feel of the beer. I’d put it somewhere in mocha-land.

10/11/2009: 9:52 pm: RobertFood and Drink, Oakland

The second annual Dimond Oaktoberfest was even bigger than last year’s event. Unfortunately, I could stay only for a few hours, because I was also planning to attend the 99 Bottles of Beer beer symposium and beer fair at Hearst Museum at UC Berkeley. More on that later. Of course, a lot worse things could happen than having multiple major beer celebrations on the same day.

The Dimond District had quite a few German Biergartens back around the turn of the century. The closest thing we have today in our neighborhood is Oaktoberfest. However, a fantastic group of businesses have opened in the past few years and the heavy retail traffic will hopefully bring us a brewpub like establishment.

The Oktoberfest event itself was free and very well organized. There were the traditional booths filled by non-profits, school groups, commercial sponsors and local businesses. The Bill Brand Memorial Biergarten was a lot bigger than last year’s biergarten, with a lot more participating brewers. The Mad Zymurgists showed up and handed out free samples of homebrew, as well as ran a homebrew contest.

I decided to spend $20 on a souvenir stein with 10 tastes and 2 full beers, instead of 4 full beers. This turned out to be a very savvy move, as the alleged 2 ounce tastes ended up being anywhere from 4 ounces (the mark on the glass) to 6 ounces. I think none of the people pouring wanted to look cheap by offering just a tiny taste. I salute them.

I started with a Bison Brewing (not listed on the t-shirt, but definitely there) Reunion Double Wheat. It’s a pretty powerful wheat ale with a lot of carbonation and a distinct lemon flavor with subtler coriander and orange aroma. I would definitely drink it again.

Then I went for the Orange Kush Wit Beer from Ale Industries. A little googling on the beer’s name suggests an, uhh, unusual possible ingredient. I just tasted hops, though. And, my god, the surprisingly orangelicious flavor. I’m thinking they didn’t just stop at an orange peel or two. Florida called and they want their crop back.

Next was the Iron Springs Oktoberfest. I didn’t like this quite as much I expected I would, though it was a pretty straightforward Märzen. I’ll try it again another time to make sure it wasn’t me with crazy expectations for the first Märzen of the day. It was probably me.

I probably went for the Linden Street Brewery Urban People’s Lager too early, as I wasn’t quite ready for the hop bite, which was stronger than I remembered. Maybe it was the food I was finishing off that wasn’t working, because by the last swallow of beer, I was really enjoying the lager. My glass was once again empty, but my palate felt crisp and clean.

The Beach Chalet Ocean Beach Oktoberfest seemed more like an amber ale than a Märzen. It was a little sweeter and less spicy than I was expecting. This was my wife’s favorite. It was pouring with huge carbonation, but not as much as Drake’s tap, which sprang a leak and nearly sprayed our backs. So sad to watch so much beer spray pour onto the ground. I thought about doing a Homer and diving (in slow motion, of course) with mouth wide open below the cooler. If I had been out of beer tickets, that would absolutely have been me.

I headed over to the corner of the tent for a Thirsty Bear stout. I’ve had the Kozlov stout at the brewery a few times, but this tasted different. Of course, maybe that’s the five previous beers talking. Seemed a little bitter for an Irish stout. Otherwise, silky smooth with a very creamy head.

On the way out I scored a Rubicon Amber. Very sweet malt with tons of caramel. If they told me they juiced the fermenter with a couple bags of those cubic caramel candies that I seem to see only at Halloween, I would totally believe them.

But it wasn’t just about the beer. I had parts of two delicious, soft pretzels with mustard from La Farine Bakery, part of a ground beef meat pie my wife picked up from some vendor and a boar sausage. I would have gone for the La Farine apfelstrudel, but I was feeling a little full by the end.

8/16/2009: 10:17 am: RobertPrivacy and Security

The EFF has posted a very interesting and sensible article on locational privacy. The solutions to the problems are not trivial, but they do exist, at some cost.

Locational privacy (also known as “location privacy”) is the ability of an individual to move in public space with the expectation that under normal circumstances their location will not be systematically and secretly recorded for later use.

The first example the article details is road tolls. Every system in use I know of uniquely identifies the car by a transponder, and thus tracks a location. If the car goes through multiple toll sites, the monitoring system can begin to put together a detailed history of your travels, as well as make inferences about where you might have or couldn’t have been. Or even issue you a ticket if you traveled between two sites faster than the speed limit would allow.

Of course, these systems are tracking the transponder and not you, but they also photograph the license plate(s) of the car. What if the camera up front just happens to be positioned so it also photographs the driver?

The article proposes an alternative that uses cryptography to anonymize the transponder. One catch is that the proposal requires you connect your transponder to your computer so it can communicate with the company’s systems to calculate what you owe. Obviously, it would be simpler if it could do this wirelessly, but that brings up other locational privacy issues.

The biggest problem I see goes back to the photographs. Some drivers will go through the toll site without a transponder, either because they never had one or because they thought they had it when they didn’t (perhaps they took it into their house to connect to the computer to anonymously pay their tolls and then forgot to put it back in the car). Also, in a case that has happened to me, the transponder was on the dashboard, but not detected. When that happens, the system falls back on photos of license plates and optical character recognition software.

I don’t think the toll taking companies are going to give up those images easily. Perhaps they could be convinced to delete them if a valid transponder was detected. However, I think they will still want them, even in that scenario, for non-repudiation. Until they get paid, they are likely to retain the images. As long as the images exist, they are subject to abuse. The EFF article acknowledges and explores this issue.

The EFF article brings up several other important areas where your location info can be pervasively tracked and easily abused. A big challenge is that the proposed anonymizing solutions involve additional effort and cost for the provider. In many cases, this is a double whammy, since the provider must shoulder more implementation and maintenance cost and no longer has as much marketing data to sell. This can be offset if the service is valuable enough to consumers to pay more for. Unfortunately, though, I’ve read about a couple of studies that have shown that most consumers don’t value privacy very highly when it comes to paying for it. I think that often this is due to a lack of awareness of how their data can and is being used. Hopefully, the EFF’s very important work will change this.

The only electronic cash system that seems to have had much success is Hong Kong’s Octopus Card system, which is run by a private company. However, according to the Wikipedia article it seems to have succeeded by forced migration (to transit systems gave users only 3 months to switch over from old cards), misconception (residents thought older coins were becoming more valuable than face value, so they stockpiled them) and forced inconvenience (buses began requiring exact change). The popular On-Loan cards are anonymous. A Personalized card has additional uses beyond electronic cash. Although some coercion was involved, the fact that convenient, anonymous solutions succeeded at a large scale is very promising.