The Occasional Occurence

Political Plug

November 29, 2007 at 04:43 PM | categories: work, General

Here's an article from the Economist on foreign policy and the race for the White House.

Foreign policy and the presidential race.

It's an interesting article, but even more interesting is that the data in the poll came from the organization that I work for. Ok, maybe more interesting is a bit of a stretch. ;-)

So there you go - the fruits of my (and many others') labor.

cw

Those Useful Iterators

November 27, 2007 at 10:14 AM | categories: Python, work, General

I've really been enjoying working with Python iterators lately. They make working with iterative tasks so flexible. Lately I've been working on adding progress tracking to an application so that we can give our users some feedback on where the application is at in various long-running tasks.

Since the long-running tasks in question are coded as iterators, I'm thinking about using something like the following:

def progtracker(iterator, name, store, workunits, step=1):
    """Store the progress of a named iterator in a dictionary-like store."""
    count = 0
    workunits = float(workunits)
    for part in iterator:
        yield part
        count += 1
        if count % step == 0:
            store[name] = count/workunits

That iterator can be used to track the progress of any bounded iterator. I guess it has to be more than a bounded iterator - you have to know the upper bound as well. Here's a semi-complete example:

progress = {} # some dict-like store
total = len(records) + 1 # account for all the rows plus the header row
docgen = create_document(records, schema)
p_docgen = progtracker(docgen, "docgen-task-x", progress, total, 5)
f = open('outfile.fmt', 'w')
for line in p_docgen():
    f.write(line)
    update_progress_display(progress)
f.close()

I've got another iterator recipe that uses the processing package to offload the processing of an iterator to a subprocess. I'll see if I can get that posted here soon.

cw

UPDATE: corrected error in example (didn't pass the store to the progtracker - thanks Michael)

Safari Gotchas

August 16, 2007 at 09:56 PM | categories: work, Software, computing, General

In the spirit of sharing knowledge that will save someone from the sort of tedious pain I went through the past couple days, here are a few Safari (2.0.4) bugs that I had to work around:

1. No Global Javascript eval() That's right. You can't eval() in the global (window) context. Safari doesn't allow it. A lot of places mention the fact that you can do a window.setTimeout, but that runs asynchronously (which I did not want). Thankfully, there is one place on the web that gives the secret sauce on how to implement something that will accomplish basically the same thing as eval() in any other browser. Wrap that up in a nice little function of your own, and you are good to go.

2. CSS: background-position and Container Size If you want to control the position of a background-image in a DIV, make sure that the DIV is at least one pixel larger than the background-image. Otherwise, your attempts to position it might drive you to the brink of insanity. Not that I would know.

3. Calling click() on a Checkbox If you think you can just grab a checkbox type INPUT element from the DOM and call click() on it, you are sorely mistaken! You must explicitly check that bad boy by doing something like checkElem.checked = true.

4. Reinitializing jQuery Interface Plugin Sortables This is probably the most esoteric gotcha of the bunch, as it involves a third-party library (jQuery). All of the other major browsers (Firefox 2, IE6/7, Opera 9) simply let you reinitialize as many Sortables as you want. You just call .Sortable(config) on any element each time you want to make it sortable. This does not work in Safari. Before you reinitialize the Sortable, you need to call .SortableDestroy() on it.

In the application I am working on, this is important because we load each new state via an XMLHTTPRequest. Now, when a Sortable is initialized, a callback is registered to handle the .SortableDestroy() before a new state is initialized.

That's That Hopefully this info will save some of you a little trouble.

cw

Ion

July 21, 2007 at 11:51 PM | categories: work, Software, computing, General

So an article about user interfaces on Coding Horror prompted me to say a short piece about Ion*.

When doing serious work on the computer, I always find myself tiling my windows. Overlapping windows are so annoying. And tiling them in an organized manner is even more annoying.

From the article:

Manipulating windows is pure excise-- extra work that stands between the user and completing their task. The more windows you have to deal with, the less work you get done, and the more time you spend sizing them, moving them, bringing them to the top, and dragging them around so they aren't overlapping.

Enter Ion.

It tiles them for you. And lets you move around from window-to-window using the keyboard.

Sure, it doesn't have wobbly windows or pretty wallpaper. But if you need some more visual or tactile feedback while computing, I suggest getting up and taking a short walk - not shaking a window around on your screen or gazing at your hipster wallpaper.

cw

* Sorry, Linux only. Try Ubuntu.

Why I am a Software Developer

June 29, 2007 at 10:15 AM | categories: Python, Software, work, computing, General

I think that this blog entry at Coding Horror pretty much nails why I enjoy programming.

At my previous job we took this personality test of sorts called StrengthsFinder that is supposed to help reveal your top 5 strengths. I took it twice and while some of the results varied, I had Learner in my list both times.

Programming is a real outlet for that constant desire to learn something new. There is always a new problem to be solved, a new tool to be created.

Fun stuff!

cw

« Previous Page -- Next Page »