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:
- The drop part (or some other way of identifying files for inclusion)
- The file manager -- a simple document management function.
- The tag cloud generator and some means of selecting lists, etc., from the cloud.
And I've written a little Perl prototype code to do the tag cloud formatting in HTML:
sub keyword_tagger {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).
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;
}
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