Monday, December 7, 2009

Python debugging trick

A personal project of mine is in python and littered with some heavy debugging statements. 'Heavy' as in there are many of them, and even more so in that they're costly to execute. My debugging method was:


def noop(*args):
pass

def debug(string):
print("##DEBUG >>> {0}".format(string))

debug=noop

def foo(...):
...
debug("blah blah " + repr(baz))
...


Debugging is then enabled by commenting out the debug=noop line, or disabled by uncommenting it.
The downside is that the repr() is executed whether or not debugging is enabled; so if they turn out to be large or expensive to calculate, they hurt performance in all cases.

In the car on the way to lunch today with a colleague, I was bemoaning this state of affairs and wishing python had some kind of macros. His suggested solution was to eval a string; my mildly better counterproposal was to use python's excuse for a closure:


def noop(*args):
pass

def debug(stringfunc):
for line in stringfunc():
print("##DEBUG >>> {0}".format(line))

debug=noop

def foo(...):
...
debug(lambda : "blah blah " + repr(baz))
...


This saves the evaluation of the repr() until the lambda is eval'd... which may be never. The more conventional way of doing this is:



DEBUG=false

def debug(string):
print("##DEBUG >>> {0}".format(string))

def foo(...):
...
if DEBUG: debug("blah blah" + repr(baz))
...


which always seemed much more... redundant, I guess... to me. Either one is a solution to the problem of extra debug overhead, however.

Friday, October 9, 2009

Must-have Thunderbird Addons

Since I've got a G1 that syncs between it and Google Contacts, I figured I should have Thunderbird sync too, which apparently means Zindus.

And IWBNI more messaging was in one place, so SamePlace means I don't need to fire up Pidgin as well as Thunderbird.

And finally, most of what I do is file stuff as 'done', so Archive This will save me a bunch of mouse-time.

Tuesday, September 8, 2009

Dear Lazyweb, here's an idea:

Talking to some friends about wanting safer logins, it seems that a cellphone with a camera could be a good challenge/response device, like so:

1) sit down to log into your desktop as normal
2) enter your username
- the response is a 2D barcode 'challenge' with an entry field for the response
3) use your cellphone to take a picture or 'scan' in the barcode.
- cellphone generates the correct response (presumably your key is in the cellphone software already)
4) type in the code that your cellphone generates as the response

Kind of like OPIE stuff or those RSA keyfobs, but slightly more general since the above is mostly an I/O method and says nothing about the encryption used.

Monday, July 20, 2009

Free of the FreeRunner

I've given up on trying to use the FreeRunner as an "every-day phone". There aren't enough buttons to support Android properly. Suspect/Resume support (vital on a power-limited device like a cellphone!) was always touchy. It was just all a bit too unfriendly.

So I bought a G1 from a friend-of-a-friend for cheap and unlocked it to work on my current provider. It's been fun! ConnectBot gives me an 80x22 ssh session anywhere - that's only 3 lines from the size of the standard PC text console that I spent so many of my teenage years in front of. The dev environment is open enough that I experimented with writing my own game - a falling-blocks game called Polyfallminoes. Contacts sync with google, the browser is fine to read ebooks on (I read html ebooks that I buy from webscriptions.net and host on my own server), and in general it acts like a nice polished platform. Not that things aren't missing, because they are... but I'm going to see what I can do about fixing that :)

Thursday, June 11, 2009

Android

I've gotten more and more interested in Android lately. My FreeRunner is running it thanks to a guy named panicking. I've got an app in the App Store... er, pardon me, 'Android Market' for it. And I think in general it's a Good Thing.