sjh - mountain biking running linux vegan geek spice - mtb / vegan / running / linux / canberra / cycling / etc

Steven Hanley hackergotchi picture Steven




Other online diaries:

Aaron Broughton,
Andrew Pollock,
Anthony Towns,
Chris Yeoh,
Martijn van Oosterhout,
Michael Davies,
Michael Still,
Tony Breeds,


Linux Weekly News,
Girl Genius,
Planet Linux Australia,

Canberra Weather: forecast, radar.

Subscribe: rss, rss2.0, atom

Mon Tue Wed Thu Fri Sat Sun



Archive by month:

Tue, 03 May 2005

Random Ani sig thing - 15:13
I previously mentioned a plan to have random signatures in my email using quotes I selected from all Ani Difranco songs. As lca is now over and I do not feel the need to advertise the conference in my signature I thought it was time to finish implementing this. (after all only about one hour was required to finish it)

The perl code may be found here and the source data is this files of quotes. It is not particularly difficult to change the code to use a different data source and different thing to print. As for the code, it would be pretty easy to implement a random selection of a quote every time the program runs. My ideal implementation however uses each quote from the file once until it runs out then starts over again, the same quote can not appear twice in a row.

To do the easy only random implementation I would only need the read_quote_file, serialise_quotes and remove_random_quote functions (it could in fact be simplified far more than this too). So I added command line options (give it an alternate data source, and alternate cache file, an alternate static sig content file, a unique option and a help option). Run as is it uses the default filenames that I set in the code and sits out a random quote.

For my usage the unique option maintains a cache of quotes that diminishes every time the program is run with the -u option. I used Data::Dumper to store the cache, messy and hackish but really easy to do. Anyway pretty basic code, did not take long to implement, and sure it can be simplified a lot (lets hope it does not get out of hand (on the recursive mkdir case, Tony removed a few more characters from Jeremy's example, maybe he should blog about it)) but it works and passes the test case I created for it (small files, missing files, running a thousand times, using various options, etc) though I did not bother making it handle bad input data correctly, oh well no matter.

Getting back into geeky things lightly.

[/comp/email] link

home, email, rss, rss2.0, atom