SmartDict - a smart 'dict' wrapper

July 14, 2005
9 comments Python

For a work project we needed a convenient way to wrap our SQL recordset, instance objects and dictionary variables to share the same interface. The result is SmartDict which makes it possible to assert that access can be made in any which way you want; something that is very useful when you write templates and don't want to have to know if what you're working with is a dict or a recordset.

This doesn't work:


>>> d= {'name':"Peter"}
>>> print d.get('name') # fine
>>> print d.name # Error!!!

Likewise with some instance objects or record sets, this doesn't work:


>>> d = getRecordsetObject()
>>> print d.name # fine
>>> print d.get('name') # Error!!!

Truncated! Read the rest by clicking the link below.

Rent a chest

July 12, 2005
0 comments Misc. links

Rent a chest This entrepreneurial bloke called Chris (from North Carolina, USA) takes requests for messages to be written on his chest for $20. Then he paints the message on his chest and shows the images online. Clever!

Have a look at this flickr album. Why didn't I think of that??

Drop down selects that learn

July 10, 2005
4 comments Web development

Drop down selects that learn A very common thing on the web with forms is that you have a drop down with lots of options that gets used often. It's a very convenient little widget that is used a lot on the web.

I've been thinking about a possible way to make these a big more user friendly by pushing the most popular options towards the top. By doing so, most selects will require little scrolling. Obviously the implementation depends a lot on the application. As a good example, look at the two drop downs on http://www.xe.com/ucc/ where the most common choices (EUR and USD) appear at the very top of the list.

In many cases you can't reorder the options within the drop down because the order might be alphabetic or something like "Not at all, Not very, Fairly, Very". Suppose most people select "Fairly", it would still not make sense to reorder the options to be "Fairly, Not very, Not at all, Very". But, let's instead focus on those that can be reordered to help the user.

Truncated! Read the rest by clicking the link below.

Unaffected by the London blasts

July 7, 2005
1 comment

I live very near Liverpool Street station where some of the blasts happened but I'm fortuntely totally unaffected by the blasts.

When I cycled to work I calmly went past the vast amounts of people, police and ambulances. I wish all people the best of luck with handling the situation.

Lisp compared to Python

July 7, 2005
1 comment Python

I was reading a thread about "Lisp development with macros faster than Python development?" on comp.lang.python when I stumbled across a little statement by Raymond Hettinger, a core Python developer:

"With Lisp or Forth, a master programmer has unlimited power and expressiveness. With Python, even a regular guy can reach for the stars."

Falling mannequin animation

July 4, 2005
1 comment Misc. links

Falling mannequin animation Probably the coolest Flash animation I've seen in weeks. Not a lot happens but I warn you because it's dangerously addictive. The body keeps falling down and sometimes get stuck. When she gets stuck you have to pick her up and get her to fall down in some other place instead.

Don't miss that you can pick her up and throw her upwards so that she falls harder the next time. Got this link via boingboing.

Module dependencies of IssueTracker.py

July 2, 2005
0 comments IssueTrackerProduct

Dependency graph of IssueTracker.py A rather impressive yet useless dependency graph of IssueTracker.py I created this graph simply by downloading py2depgraph.py and depgraph2dot.py from this website

The result is a big ass picture with little boxes that describe each little module that is connected to IssueTracker.py in some way. This image becomes rather useless to me because it digs down into python libs that the code never really goes near. To make this genuinely useful one would have to intercept the .dot file and remove references to libs that aren't interesting.

ztar - my wrapper on tar -z

June 29, 2005
8 comments Python, Linux

Something I find myself doing very often is to download a .tar.gz or .tgz file that I want to unpack, but only in a subfolder. Some rather annoying gzips aren't collected in one folder so that when you unpack it lots of files are created in the current directory. Do you find yourself often doing this:


$ tar -ztvf Some-0.x.tar.gz
Some/file1.txt
Some/file2.txt
...
Some/file100.txt
$ tar -zxvf Some-0.x.tar.gz
Some/file1.txt
Some/file2.txt
...
Some/file100.txt

Or, in case they the gzip is badly organised:


$ tar -ztvf Foo-0.y.tar.gz
file1.txt
file2.txt
...
file100.txt
$ mkdir Foo; mv Foo-0.y.tar.gz Foo/; cd Foo/
$ tar -zxvf Foo-0.y.tar.gz
file1.txt
file2.txt
...
file100.txt
$ cd ..

Truncated! Read the rest by clicking the link below.

Zope in DevelopmentMode

June 26, 2005
0 comments Zope

Imagine if you, in your code, want to find out if Zope is running in debug mode or not, then how do you do that? Here's my take on it that I learned today:


from Globals import DevelopmentMode

class MyProduct(Folder):
   def save(self, file):
       if DevelopmentMode:
           print "Saving the file now"
       self._save(file)

The example doesn't do much justice because your product code should perhaps use its own "debug mode parameter" to get greater control.

Truncated! Read the rest by clicking the link below.

AJAX accelerated web widgets

June 23, 2005
5 comments IssueTrackerProduct

To me, AJAX (Asyncrounous Javascript And XML) patterns are only interesting if they work as a bonus rather than a must. I've written before about autosaving web forms whereby a form with a big textarea is autosaved on the server every 8 seconds. That feature took existing form functionality and used it in Javascript instead of user actions.

Now I've done it again (actually it was a couple of days ago but I've had time to write about it until now). When you on the IssueTrackerProduct, list issues you'll see a little button that makes it possible to enable "filter options". If you press that button it sets off a GET request to the server to re-request the same page but this time with ShowFilterOptions=true as a parameter. Here's some simplified code:


<div id="filteroptions">
  <form action="ListIssues">
    <input type="hidden" name="ShowFilterOptions" value="1" />
    <input type="submit" value="Show filter options" />
  </form>
</div>

How can we load the filter options widget on the List Issue page without having to refresh the whole page?

Truncated! Read the rest by clicking the link below.