Lambda lambda lambda

It can help ya help ya help ya.

It’s Python’s lambda function1! Pesky urllib2 not allowing you to construct a DELETE request? Environment Overlords not letting you install a sane http module like Requests2? Don’t like what a module you have no control over is doing for you?

Lambda the damn thing!

For example urllib2 has a method called .get_method(). It returns the type of HTML request being made. In their infinite wisdom, the writers of urllib2 thought there were only two useful types of request anyone would ever want to make using their module, GET and PUT. The method looks at the URL and if it sees post data it returns “POST”. Otherwise it returns “GET”.

But it’s a modern Web we live in and we want to do modern things like make calls against a RESTful api provided by a vendor. Sometimes that vendor uses the kind of request being sent to determine the kind of action to take. Makes sense, no? But urllib2 spits on us and makes us write bad checks. What shall we do?

In this case we just hack the bejesus out of the .get_method() method and force it to return “DELETE” every time.


import urllib2
req = urllib2.Request( "http://www.example.com" )
req.get_method = lambda: "DELETE"

Now we can run DELETE requests against the RESTful API all damn day long. And then, later, when we want to do a “GET” all we have to do is lambda the damn thing again and make it return “GET”. Yay for us!

Yay for lambdas!

This is my rose for the day.

1http://www.secnetix.de/olli/Python/lambda_functions.hawk
2http://docs.python-requests.org/en/latest/

The binary scale

My manager type person just asked me if I though a proposed story was something I could bang out. To which I replied thought it was bangable. Which makes is a “1” on the binary scale. Which, if you get right down to it, is the scale that matters way more than the traditional 1 – 10 scale.

The new phonebooks are here!

To say I’ve enjoyed the Wool1 saga by Hugh Howey is an understatement. It’s probably the best long-arc dystopian fiction I’ve ever read. For a kid coming of age in Reagan’s America, I had nightmares of how living in fallout shelters might work. The numbers of generations needed to outlive the half life of nuclear fallout was incomprehensible. At some point the math just doesn’t hold and everything has to collapse.

In the Wool saga, Howey puts a story and framework around these childhood fears and lets his characters play out in this world. It is gripping stuff and I devoured everything published. I came to the party relatively late so having most of the series already available was great. Waiting for these last few books to drop have been interminable.

Dust2 is the very last book in the series and it was made available this last weekend. If you’re short of reading material, like dystopian fiction, and have a little coin to throw around, you could do a lot worse than pick these up.

I should also add, Hugh Howey is a model for self publishing. It doesn’t work for everyone, but he managed to turnkey Amazon direct-to-Kindle printing into a multi-six-figure payout.

1 http://en.wikipedia.org/wiki/Wool_%28series%29
2 http://www.amazon.com/Dust-Silo-Saga-ebook/dp/B00CYNGPTG