Wednesday, December 13, 2006

Week #2, a code snippet, and Dana mysteriously silent

So -- week #2, eh?

The target for this week was suggested on the Software Jedi forum (thanks to everybody who's vented their fertile imaginations over there and in comments on this blog -- as long as there's enough grist for one week's mill, I'll be happy). It is, and I quote, "some kind of file tagger app".

The idea is pretty simple: del.icio.us (and Flickr, and lots of places now) lets you organize your links by tag. The tags are arbitrary and you can get a groovy tag cloud to let you see what's most important. So the suggestion on the forum was: wouldn't it be neat if you could do that with the files on your own drive? Or maybe on a corporate shared drive or something? Well -- it doesn't really matter what you do with it, the idea is that it would be neat.

So that's the app for this week, 'cause it's easy, and I'm all about easy.

This naturally breaks down into three pieces:
  1. The drop part (or some other way of identifying files for inclusion)
  2. The file manager -- a simple document management function.
  3. The tag cloud generator and some means of selecting lists, etc., from the cloud.
When I first started on this, I thought it'd be fun to create a generic drop handler as an Explorer extension -- then I saw how un-fricking-believably difficult Microsoft has made that seemingly simple task. So forget that -- instead, I'll simply set up a link under SendTo, which is equivalent, and much easier. And anyway, while the file manager component is actually open, it will still be possible to drop files into it, because that's simple to code.

And I've written a little Perl prototype code to do the tag cloud formatting in HTML:
sub keyword_tagger {
my $ct = shift @_;

my $weight;
my $font;
my $sm = 70;
my $lg = 200;
my $del = $lg - $sm;
my $ret = '';
foreach my $k (sort keys %kw_count) {
$weight = $kw_count{$k} / $max_count;
$font = sprintf ("%d", $sm + $del * $weight);
$ret .= "<a href=\"wherever\"
style=\"font-size: $font%;\">$k</a>\n";
}

return $ret;
}
This code assumes that all the tags are the keys of a hash %kw_count, and the values in that are the number of posts or files or whatever for that tag. The parameter to the function is simply the maximum count value (already determined in an earlier pass, in this prototype).

Pretty straightforward stuff -- this is a quote from the code I'm now using for the keyword cloud for my own blog. So for app #2, I'll be translating it into Python (natch) for use on the desktop.

So that's a little progress. And in other news, Dana's been awfully quiet since I started posting actual challenges and code and stuff. Could it possibly be that he's a little intimidated by seeing a non-Microsofty being too Jedi-like for his comfort? Time will tell.... But the gauntlet is definitely thrown, Dana. We're waiting!

0 Comments:

Post a Comment

<< Home