This blog is now hosted at

Friday, March 28, 2008

Blackberry SDK, Modifying messages

In an earlier article, I stated that I liked the BlackBerry SDK, and one of the things that I liked that the SDK seemed complete, in that it supported and documented how to do things that are "hard to do" (e.g. Bluetooth support).

I decided that a thought experiment was in order: could I modify email messages as they are sent?

The BlackBerry SDK makes this fairly straightforward: implement the net.rim.blackberry.api.mail.SendListener interface, which has a single method:

public boolean sendMessage(Message message)

By implementing this method, you can modify the message as you see fit (Message is what you think it is!), and even block the message by returning false from the method.

Now, based on things that Apple has said, I don't believe that the iPhone will support this type of development-- modifying the default behavior of the built-in applications.

Based on what I have seen in Android, it does look like this would be possible there (I haven't looked extensively, however).

Wednesday, March 26, 2008

ReportLab ImageAndFlowables + drawing

So, I've been doing a lot of work with ReportLab lately, and I discovered something that is under-documented, and something that works, but seems like it might be contra-indicated. Hit the link for a description.

The under-documented bit is that the Drawing class is a Flowable. What this means: you can use all the graphics libraries (including all the chart creation) directly within platypus formatted documents. This is great, and here's why:

I'm trying to create charts to include in my report, and up until figuring this out, I've been using matplotlib, exporting to PNG, and importing into my document as an Image object. This works acceptably, but seems a little balky when the images get scaled.

I went looking for a way to embed vector graphics into my document (no scaling issues!), and happened upon the above. Then I decided to take it to another level entirely, and see if the Drawing could be embedded in an ImageAndFlowable (as the image). In short, the following works:

drawing = Drawing(400, 200)
bc = VerticalBarChart()
p = Paragraph("spam " * 200, style['Normal'])
fi = ImageAndFlowables(drawing, p)

Which happens to be exactly what I needed, and I'm psyched.


Monday, March 24, 2008

Singletons in Python

Since the project that I'm working on has a whole lot of nasty, boil the oceans, SQL queries, I thought it'd be best to cache information. Caching is great, but what I really need is an application-wide cache (not tied to a specific instance object).

Normally I use Singletons (from _Design Patterns_) to provide this functionality. Here's how to implement them in Python:

from (in the comments):

class Singleton(object):
def __new__(cls, *p, **k):
if not '_the_instance' in cls.__dict__:
cls._the_instance = object.__new__(cls)
return cls._the_instance

all you have to do then is inherit from Singleton, and it just works. This is actually cleaner than some other languages I've implemented Singletons in.

The real bonus, however, is the actual article that the posting above was about:

class Borg(object):
_state = {}
def __new__(cls, *p, **k):
self = object.__new__(cls, *p, **k)
self.__dict__ = cls._state
return self

That will share the state of the object across instances. No thinking about it.

Alembic Pictures

We had a spot of sun this weekend, so I decided to take a break from work, and take some pictures.

Hit the link to see pictures of my 6-string Alembic Series II Balance K.


New Classes vs. Old Classes in Python

I found a bit of daftness in Python today:

class A:
def __init__(self):
print "Rutabaga!"

class B(A):
def __init__(self):
super(B, self)


TypeError: super() argument 1 must be type, not classobj

Changing the first line to:

class A(object):

fixes it.

Now, forgive me if I think that's completely stunted. You could have at least said:

TypeError: to use super(), the superclass must have one of the built-in base classes in its inheritance path.


Friday, March 21, 2008

Guest Blogging at Archiving 101

I'm guest blogging over at Archiving 101. Jump on over to view some of my thoughts on the need for proactive email categorization.

This will be a two part series: look for a follow on article next week. Read more...

Thursday, March 20, 2008

More Python

Some more thoughts on Python...

The fact that there don't seem to be any adjectives in the language is a bit wierd: as a Perl programmer, I'd expect to be able to declare a variable as local (I go back to Perl 4) or my, but nothing equivalent in python.

Declaring static methods is wonky, but at least they are there, so I can make Singletons.

For those of you who haven't read Design Patterns, a Singleton is a way to implement classes that you only load once. For instance, when the startup costs for the object are very expensive. In my case I'm doing a dozen or so nasty, full table-scan (on hundreds of thousands or millions of rows) SQL queries. You might guess I want to do this as few times as possible. :)

Anyhow, the lambda expressions and first class functions more than make up for it. Very nice.

Tuesday, March 18, 2008

Game Programmers

My brother is an accountant in Silicon Valley, and this email from him nearly made me fountain Diet Dr. Pepper:

So I've serviced several of the players in Silicon Valley, from semi-conductors to networking to software. Along the way there have most certainly been some interesting characters, but none as interesting as today when I arrived at a well known gaming software company.

Gaming programmers take the cake, from thug looking kids to your classic unkempt, pale pony-tailed man that you envision casting "intimidating shout" in a battle playing World of Warcraft. I wanted to cry out "Leeeeeeeerrooooooooy Jeeeenkiiiiiiiiiiiiins" just walking into this place.

Learning Python

I've avoided it for at least 10 years, but I finally bit the bullet.

I am developing an application in Python.

Read on for my take on what I like about Python, and what I didn't like so much.

Great stuff:

  • Functions are first class

  • Great support for object oriented programming

  • Basic feature parity with Perl

  • Great library support (I'll cover some of these in a later post)

  • Closures (all the cool kids have them)

Not so great stuff:
  • Scoping is wierd, but maybe I just need to get used to it

  • Feels wrong to not close blocks explicitly

  • Wierd __foo__ special functions, etc. (although I don't have much room to talk since I like Perl)

  • No autovivification

Random thoughts:
  • Anyone who says it has "cleaner" object orientation than Perl probably just doesn't "get" Perl.

  • Somehow, it reminds me strongly of Javascript. They are just somehow similar.


Google Desktop as a crude forensics tool

Raise your hand if you've become de-facto tech support for your family.

I certainly have.

One of the questions I am periodically asked is: how can I get to files that have been deleted/check web browsing history/check deleted emails?

And I have the answer: Google Desktop Search (GDS)!

Read on for how it works.

You see, GDS actually keeps copies of basically everything that you do.

Your emails
Your web browsing history
Your files

And it can even present these in a timeline view.

Pretty amazing, although it might create some surprises if you, say, "thought you deleted that email".