Implementing Partials in Python

A colleague of mine was wistfully pining for Haskell-style currying in Python. This sounded like an interesting syntactic feature, so I decided to see if I could toss together something that would at least emulate the behavior of returning functions when a function is called with too few arguments. I've always admired the flexibility of python, so it seemed like an interesting challenge to prove that.

Using a decorator seemed like a bit of a copout due to the additional syntax required, but was otherwise ideal, as it made checking arguments fairly trivial.

def partial(f):
    def wrapper(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except TypeError, t:
            return lambda *_args,**_kwargs:f(*(args+_args), **(dict(kwargs.items()+_kwargs.items())))
    return wrapper

Continue reading "Implementing Partials in Python"

Sensing Magnetic Fields in Android in Very Few Lines!

Overcome with gadget lust, I picked up a HTC Dream from rogers. I had fully expected to need to unlock, root, resolder or otherwise hack this thing to pieces before it could do anything interesting. I was wrong. So wrong.

I'll gush more over the particulars of the phone dreaminess in another post, I hope. It can pretty much do anything I do on my laptop, except with exponentially higher rates of thumb cramping. But I digress. There are magnetic fields to sense.
Continue reading "Sensing Magnetic Fields in Android in Very Few Lines!"

Drawingification in the PhotoChops

Before
Before
Drawingified
Drawingified

Here's a before and after of something that I put together with the photochop webappy thing that I put together.  This one was created by reducing the colors of the image, blurring the result and applying the drawingify filter.

The drawingify filter takes the original image, blurs it, averages the result with the original image, then applies the photocopy filter and blurs that result.  This generally gives a fairly convincing pencil-drawing style effect.

Seeing as this is mainly a test of HTML5's canvas element, it'll die a fiery death on internet explorer, but should work happily on most modern browsers.  Savepoint averaging only works on Firefox 3.5 due to some awkward security settings on other implementations.