September 9th, 2009
I gave a talk at PDX Python last night on Python Packaging. It’s just an overview and introduction completely lacking in any practical examples.
Let me know if the ODP source is messed up. OpenOffice.org liked randomly losing background images and forgetting other formatting.
So as penance I quick hacked up a silly little command line utility and uploaded it to PyPI to serve as a simple packaging example:
It’d be nice to add some more advanced features like test running, including package data, and building C extensions. If you feel adventurous please fork it and send me a pull request on BitBucket.
Thanks to everyone who came to PDX Python last night! Especially Armin Ronacher who was able to clarify and elaborate on a number of different distutils/setuptools topics!
Update: Just spotted an excellent post on distutils and setuptools by Tarek Ziadé. Make sure to read his blog if you’re interested in packaging in Python.
Tags: distribute, distutils, packaging, pdxpython, pip, setuptools, slides, whereampy
Posted in Open Source, Python, Technology | No Comments »
August 10th, 2009
Small update on my toy tc-rest project: I switched to using WebOb for creating HTTP Request and Response objects. Cleaned up the code a bit, but a real dispatcher is what’s needed to really remove the cruft.
I’m anxious to extend the API and add features, but I have no clue when I’ll have time to touch it again. In the mean time I’ve pushed tc-rest to bitbucket.org if you want to take a look.
Tags: bitbucket, fapws3, Python, tc-rest, tokyo cabinet
Posted in Open Source, Python, Technology | 2 Comments »
August 8th, 2009
Have you ever wondered how hard it would be to tack a RESTful HTTP interface on top of a fast key/value database like TokyoCabinet?
Probably not, but I did: tc-rest.tar.gz
Components:
- TokyoCabinet – my favorite persistent key/value database
- pytc – a wonderful Python wrapper for TC
- fapws3 – a fast libev based HTTP/WSGI server
- simpleson – (or Python >= 2.6) for encapsulating HTTP responses
- okapi – a fantastic little static HTML page for testing HTTP APIs
Getting TokyoCabinet+pytc to work inside a virtualenv was a bit tricky, so check out my run.sh script if you’re having trouble getting it to start.
Once you get it started, load okapi in your browser:
http://localhost:8080/static/okapi.html
And then create a database by doing a POST like:
http://localhost:8080/foo/
And finally store/get keys and values using GET and POST requests like:
http://localhost:8080/foo/bar/
http://localhost:8080/foo/baz/
Doing a GET request to a database URL lists keys.
At any rate, I had big dreams for building a system where you would store JSON, specify indexes on certain keys, and the server would maintain those indexes for you by creating ad hoc TokyoCabinet databases.
Instead I ended up wasting most of my time learning how to write a low-level WSGI app. I should have just used CherryPy or Django from the beginning, but I had never written a pure WSGI app before. It was a good lesson even if it meant not getting some of my features implemented.
I’ll probably keep playing with this idea, but the next version will probably be based on some existing framework. Parsing environ['PATH_INFO'] and running start_response(...) manually gets old fast.
fapws3 is pretty neat, but had lots of annoying rough edges. I had to manually create a README file because its setup.py expects one to exist. Then I had to manually allow DELETE HTTP methods in fapws/base.py, otherwise it would return an HTML error message for me! That was a bit shocking since I was working under the assumption fapws3 is just a low-level HTTP/WSGI server.
Update
- If you’re new to TokyoCabinet, I posted my presentation on it that I did at Portland Python meetup.
- Someone want to benchmark this for me? Might be interesting since its made with the fastest libs available in Python for their respective tasks. I’m just feeling lazy at this point.
Tags: fapws3, Python, tc-rest, tokyo cabinet
Posted in Open Source, Python, Technology | No Comments »
August 7th, 2009
Finally made it up to biking to work 3 times this week! Had only been averaging about once every 2 weeks for the past couple months. Sam & I recently moved to North Portland which is flat. We had been living in the very hilly Southwest area of town, and biking to work from there was killer.
I really didn’t realize how much my situation had improved until my friend, Aaron Colflesh, pointed me to HeyWhatsThat.com which generates elevation change profiles for you based on coordinates:
My current route from home to work:

It has a good 100′ hill in it. Not fun on the way home, but it doesn’t last too long.
Now compare that to my old route from home to work:

No wonder I never did it more than once a week! It was brutal coming home.
We’re much happier in North Portland in general, but finding these diagrams made me feel much better about struggling to get on bike at the old place.
Tags: cycling, fb, Portland
Posted in Personal | 1 Comment »
July 14th, 2009
Here are 3 helper jQuery functions from my ever-mutating util.js file.
jQuery.check(); – Checks or unchecks a checkbox input field based on the boolean you pass it. Very simple, but a handy shortcut. Does not trigger any events like click or change by design.
jQuery.enable()/jQuery.disable() – Does 3 things:
- Adds or removes the “disabled” class on all matched elements.
- Sets the disabled HTML DOM property on elements which support it (input and select).
- Adds or removes the “disabled” class for any labels whose
for attribute matches the ID of an affected input.
That last little side effect is what makes these 2 helper functions so handy. I like to subtly theme label.disabled to indicate when a field is disabled.
(function(){
jQuery.fn.extend({
check: function(on) { return this.each(function() {
this.checked = true ? on !== false : false;
});},
enable: function() {
this.removeClass('disabled');
return this.each(function() {
if (this.disabled !== undefined) {
// Only disable elements that support it
this.disabled = false;
// Affect labels as well
$("label[for="+this.id+"]").removeClass("disabled");
}
});
},
disable: function() {
this.addClass('disabled');
return this.each(function() {
if (this.disabled !== undefined) {
// Only disable elements that support it
this.disabled = true;
// Affect labels as well
$("label[for="+this.id+"]").addClass("disabled");
}
});
}
});
})();
Would love to hear feedback.
Posted in Open Source, Technology | 2 Comments »
July 9th, 2009
Next week I’ll be leaving Lo-Fi Art to start working for YouGov Polimetrix (aka PMX). For the past couple of years I’ve been consulting with Chris Pitzer mostly as a Python web developer specializing in Django. It will be sad to stop working for a company I own with a friend, but I’ve been working part time for PMX and am excited to work for them full time.
There are many reasons for my decision, but I should make it clear that it has nothing to do with Chris! It has been great working with him, and I’m glad we get to continue to share office space even if we’re working on different things. There is plenty of client work stacking up for him to do as well, so I’m not bailing on a sinking ship.
So why am I leaving Lo-Fi Art?
The biggest reason is probably stress. I’ve just stopped enjoying client work because if I’m not stressed about getting the current client done on time, I’m stressed about finding the next client. If its not one of those two things, I’m probably stressed about when the next check is coming in. How much was it for again? Wait, did I already get that one? Argh! On top of that I’m terrible at managing money. While Chris does a great job with the company books, that doesn’t keep me from screwing up my own (don’t even ask me about how my tax return went this year).
On top of that, contracting gigs just have a lot of overhead. For me overhead is anything that keeps me from writing code. I really don’t enjoy writing proposals and meeting with clients to discuss (or often: haggle over) implementation details. Its not that I don’t like people. I love people! But I like working with a team more than a client.
Some people really thrive in the consulting world. I think its just taken me years to realize I’m not one of those people. I could see returning to consulting someday, but I can’t imagine it would ever be back to the 2-4 week projects I currently spend most of my time on.
Why am I joining YouGov Polimetrix?
I’ve been a consultant for PMX working on the BrandIndex project for over a year now, and it was getting to the point where I needed to either commit or focus purely on Lo-Fi work. It was a really hard decision, but in the end PMX just gives me the opportunity to do what I love. I work in a fantastic team* with lots of fun technology in an organization that places high value on their IT resources. What more could I ask for? Oh yeah, a steady paycheck. That was a plus too.
* Some of the dev team at PMX: Jamie Turner (@jamwt), Christian Wyglendowski (@dowskimania), Eric Larson (@ionrock), and Robert Brewer (fumanchu on irc.oftc.net).
Tags: brandindex, fb, lofiart, polimetrix
Posted in Personal | 1 Comment »