14 May 2008

word count plugins for habari

November's still five three months away, but I'm thinking ahead. I've written two simple plugins for Habari that will let me easily see how many words I've written* toward the 50,000 word goal of National Novel Writing Month. These plugins provide a quick and easy tally of words used in individual posts and all posts with a given tag.

Requirements

version 0.5 of Habari or later

Download

These will always link to the most recent versions:
Word Count by Tag
Post Word Count

Installation and use

Word Count by Tag

Unzip wordcountbytag.zip in /user/plugins. Then activate and configure it in the Plugins Admin page. If you leave the 'tags to include' box empty it will count all words from published posts with all tags. The words in the posts' titles can optionally be added to the total.

Here how to add it to your theme (no need to echo):

$theme->word_count;

Post Word Count

Unzip postwordcount.zip in /user/plugins. Then activate it in the Plugins Admin page. It will count all of the words from the post, and the words in the post's title can optionally be added to the total.

Here is the template tag for adding to your theme, inside the posts loop:

echo $post->word_count;

Comments and questions should be left below. Subsequent updates and releases will likely appear on the plugin page, not here.


* Or rather, how far behind I am, if my typical progress from the last several years progress is any indication.

13 May 2008

geotags plugin for habari

I've written a simple plugin for Habari to add geographical information to a blog. I've used geotags for years* with websites like GeoURL by manually-editing my page headers, but this geotags plugin automatically inserts the correct tags in every generated header.

Requirements

Using version 0.5 of Habari or later, all you need is this line somewhere in the <head> block of your theme.

$theme->header();

If you are using one of Habari's default themes, then you are already set.

Download

This will always link to the most recent version: geotags.zip

Installation and use

Unzip geotags.zip in /user/plugins. Then activate and configure it in the Plugins Admin page - you will need to know your latitude and longitude in decimal. To find them you can use My Geo Position.

Once the plugin is installed and configured, you're done. Your headers will now display your position like this (the location of my site):

<meta name="DC.title" content="mikelietz:fine whine">
<meta name="ICBM" content="40.076665, -82.95996">
<meta name="geo.position" content="40.076665, -82.95996">

Comments and questions should be left below. Subsequent updates and releases will likely appear on the plugin page, not here.


* Whether or not they've ever been useful is, I suppose, a question I've never really asked. They've certainly got potential to become something interesting, or at least useful.

21 January 2008

a creativecommons-licensed interesting photo findr for flickr

The more I play with making fake CD covers from flickr photos, the more I get frustrated by the sheer number of interesting photos that are unusable because of their creators' chosen license. I realize that if I emailed them, many wouldn't mind me using their photos for something like this, but that seemed like it would be so much trouble.

So instead I programmed a little script to find only the usable shots, and made a page for it. Took me a couple hours, give or take, to get it working.

To be more specific, here's what you might want to know about what I did.

Flickr photos can be licensed in a number of ways, either through the default "© All rights reserved" that regular copyright protection grants, or through the more flexible and friendly creative commons licensing with its many permutations, including requirements for attribution, non-commercial and commercial use, and even the licensing of derivative works. So what I needed to do was take the five hundred photos flickr picks each day for their "interestingness", and filter out anything that was marked "all rights reserved" or "no derivative works". Fortunately those happened to map to the integers 0,3, and 6, which meant filtering them out was a simple modulus test*. Calculations aside, the rest was a matter of a few hours' work and the phpFlickr documentation to get a working script that wouldn't hammer my server, nor get me banned from flickr's.

So all it does is check 3,500 of the last seven days of interesting photos, and from those, screens out the usable ones. From my quick observations, the percentage of correctly-licensed photos chosen for their interestingness is under ten percent. Which means that hopefully I can save people some time. The one that it picks, at random, is ready to use.

Click here to try it for yourself.

Go ahead and put your comments and questions below. I'm releasing this as a 0.1 version - I know there is much more I'd like to do with it, but since it works, I figured I'd get it out there for people to play with. My source code is messy, but eventually I'll get the relevant bits of it posted too.


* At the risk of sounding too nerdy, modulus is, and has been, one of my favorite mathematical operations. It's just a fancy name for "the remainder", but since that sounds like something out of elementary school, I think everybody calls it the much more impressive "modulus". It's wildly useful (or at least, I've used it a lot), and, well, I've used it a lot, probably more than multiplication and division combined, in my programs over the years.

12 March 2006

more with the madness

I'm not finished with my bracket programming by a long stretch. There's no way to save the page, it's still gigantic, and frankly I'd much rather play with it than fix it.

I find interesting connections between the contenders. Sometimes the two share stars (I've battled over both Tim Robbins and Dustin Hoffman*, among others) or themes, or sometimes just the year they were released, but no matter which two are randomly picked, it's still fun to pick one over the other.

With that, I can add this to my ever-expanding list of programming projects I've begun and abandoned. The script that grabs the first titles, even, is among them. I've intended for some time to have all sorts of interesting lists and polls and links created from the movies I've seen and want to see, but so far have only been able to grab the raw data and effectively sit on it.

But I don't intend to give up on this yet. Maybe I'll dub it the 'bracketeer' and devote a directory of my site for it, for anyone to come and pick from the movies I've seen, or even enter a new list to rank--basketball teams, crayon colors, anything. It's just a matter of further cleaning up the code, and making it easier to use.

Hmmm, the bracketeer. I like the ring of that, I think.


* Wag the dog beat Stray dogs.

11 March 2006

madness, madness

So an idea struck me for an interesting programming project and a fun diversion: a single-elimination bracket for ranking the movies I've watched, 64 random ones at a time.

You see, it's March, and with that month comes the annual basketball tournament, and while I enjoy making the brackets I don't know about or care about the teams involved. So movies it is.

The logistics of entering and displaying the data made for an interesting challenge, and it's taken me a week to clean up my code. It worked fine for me the second day, but the code was horrible and disorganized and very, very bad.

I've rewritten it twice already, and with the magic of regular expressions* I've condensed some eighty or ninety cut-and-pasted lines down to around ten, and now I can make brackets of more arbitrary sizes (well, powers of two, unless I introduce some sort of 'bye' functionality) filled with whatever I want to tourney-ize.

So enough talk. Take a look at this example of the final output.

Yes, it's huge. Yes, it's difficult to read. I'm still working on making it legible at smaller sizes, but that's another project for another day.

Let me walk you trhough some of the more interesting match ups of that particular bracket. You may notice that The Shawshank redemption beat The Godfather, and here you can see my opinions in action. I know Godfather is probably the better movie, but I also know that any time I'd see any bit of Shawshank, from any point in the movie, on TV I'd watch the rest of it all the way through. I've ranked the winners by how much I enjoyed watching them, not necessarily how good they really are.

Moving back to round 1 (the one with 64 titles), we have some interesting bouts:

  • Local hero vs. Terminator 2: This isn't the first choice that would probably get me drummed out of the armchair film school. While the former is a fantastic movie, T2 is even more fun to watch, if not one-tenth as intelligent.
  • The living daylights vs. Mr. Deeds: This was not a choice to be made lightly: I didn't really enjoy either film all that much, and neither will be held up on a pedestal anytime soon. In the end Deeds got the nod because the copy I watched had Malaysian subtitles that were as informative as they were entertaining.
  • The conversation vs. The last action hero: Actually this isn't that interesting. It's a blowout.
  • Soylent green vs. Cube: I thought about this one longer than many others. I enjoyed both films, but in the end I liked Cube that little bit more. It's not nearly as dated as Soylent green, and nowhere near as parodied.

Later notable matchups include these:

  • The Blues brothers vs. The conversation: Both of these films are the sort that should appear in the final four; I was sad to eliminate either of them so early on. Other times I've run brackets each one has 'won' at least once, but the advantage goes to the SNL movie since it's so much fun in every way that Coppola's film is serious. They both so darn great, though.
  • M*A*S*H vs. The tall blonde man with one red shoe: I doubt these shared any marquees in 1972, unless Altman's film got stuck in the art houses. The latter is a small French picture made into a rollicking remake with pre-Forrest Tom Hanks, and it's a good movie too, but like most foreign movies remade here, it loses just a little in the translation. M*A*S*H, on the other hand, is too loose, too unstructured, too disorganized to grab onto without watching it five or fifteen times. I may like it more someday, but I've only watched it once so far and I'm in no hurry to see it again.

I've found this method for picking the movies I liked far better than picking favorites. I could never pick the one (or five, even) movie I enjoyed the most to yoke myself to it as a favorite. Grabbing sixty-four at once means I can subjectively pick the ones I liked most, on something of an equal playing field.

Of course, something like pitting Scary movie 3 against The Empire strikes back isn't exactly a meeting of equals, but I'm pretty sure that's how these things work out with the athletes, too.


* Regular expressions are cryptic strings of letters, numbers and other characters that make matching patterns inside text much, much easier. I wish I'd learned them in grade school, or at least high school. Read more about them here; at least, that's what I do every time I need to use them.

1 December 2005

making progress

Even since Carina wrote about 43 Things I've wanted to make a list of my own on the site. It offers people a very simple interface for making a 43-item to-do list of sorts*, and easy access to items and lists from other members. It took me some effort and thought, but I too have written my 43 things.

I've even begun working on some of them. This one is rather specific but still one that I want to do. The 43things site lets me add updates and even pictures to show what I've done.

What I'm doing, I should explain, is making the wishlist feature of online DVD retailer DeepDiscountDVD more usable. The way it works on the site is this: you add discs to your wishlist and then email the list to the people you hope will buy them for you. Other wishlists, such as the ones Amazon offers, are pages available online that link back to the site and can be accessed and updated easily without spamming people with more emails.

So the script I've created so far takes the email from DDD (which is sent to a mailbox I've created just for this), scans through the titles and links, and grabs DDD's cover art image links, and links those to the pages to buy the discs. My next steps are to cache links, so that I'm not hitting DDD's servers many times to get the same data, and to create some sort of presentation better than just the cover images.

Then again, it does look neat with just the pictures. Check it out.


* Other 43-item list sites provided by the creators are 43 Placess and 43 People. They are all linked together by userid and equally easy and fun to use.