Coding Projects

Coding Projects

Things, what I have made.

A few of the little projects I've been working on, may be useful to someone else. I use Perl for almost everything these days.

All Perl code has been tested on both Linux and Mac OS X systems. Most require the Term::ANSIColor module. It's installed as standard on most modern systems.

All my work belongs to me and anyone can use it under the terms of the GPL. So if you find it handy, let me know. If you find some problems, or if you fix some obvious ones, please do let me know.

Libraries
Any libraries, that is shared code, required by the programs are listed along with them. Just keep them in the same folder/directory as the program.

-DOWNLOAD
Some of the files you download will now have -DOWNLOAD at the end of the filename, this is to stop the web server from trying to execute them and let you have the source code. To use the files just delete the -DOWNLOAD from the end of the filename.

I'll try and find a more elegant solution soon.


iPlayer

Thu, 25 Sep 2008 19:01:51 GMT

Update: cleaned up the output, slimmed down the code.

I've been fiddling with a bit more Perl code and built two versions of a quite useful tool for searching the BBC iPlayer.

There is no system for subscribing to shows so I can see when new episodes appear.

So I made one.

It's very simple, runs as a cron job and sends me an e-mail when episodes of of shows I'm interested in appear.

As I have a few tools that search the iPlayer and tell me about it in different ways, I moved the actual searching subroutine into a shared file.

So first up, here is the simple iPlayer search tool modified to use this.

iplayer-search
This presents the results in a nicely colour coded way, like this:

BBC iPlayer search results search term: Wrong Door The Wrong Door: The Train Pirates http://www.bbc.co.uk/iplayer/episode/b00djdrd/

While this looks nice, I needed a version that is silent when there is no hits, iplayer-search always returns the header and the search term, also the ANSIColor details make no difference when viewed with a mail client, so I can leave them out too.

iplayer-notify
The quiet and plain version is called iplayer-notify.

This I add as cron jobs, using:

crontab -e

Like this:

# BBC iPlayer notifications, searches run every day # m h dom mon dow command 00 05 * * * /home/gav/bin/iplayer-notify Doctor Who 03 05 * * * /home/gav/bin/iplayer-notify Spooks 06 05 * * * /home/gav/bin/iplayer-notify Waking the Dead 09 05 * * * /home/gav/bin/iplayer-notify QI 12 05 * * * /home/gav/bin/iplayer-notify Timewatch 15 05 * * * /home/gav/bin/iplayer-notify Torchwood 18 05 * * * /home/gav/bin/iplayer-notify Have I Got News for You

So each morning I get e-mails about any available episodes of shows I may like to see.

Make sure you set your actual email address in the crontab file, like this:

MAILTO="revford@blueyonder.co.uk"

Obviously use your own address not mine. You need it to tell you when your shows are on, not me. :)

Hopefully that will be a bit helpful to someone.


Libraries
lib-rf-iplayer.pl

Download
iplayer-search
iplayer-notify


All these tools require LWP::Simple, which Ubuntu/Debian users can install from the console with:

sudo aptitude install libwww-perl

Everyone else can use CPAN.

perl -MCPAN -e 'install LWP::Simple'

RSS Feed System

Thu, 04 Sep 2008 18:49:35 GMT

Update: The code has been updated to only take the last 20 posts for the RSS file. The file was getting too big to be useful as one large file.

Also the HTML generation was adjusted to create separate pages with 20 posts per page.

An RSS feed generation system, the RSS feed generation is generic enough to be useful, the HTML generating code could be handy but it would take some adaptation to make any real use of it.

I wanted to add an RSS feed to the site. Mostly as I find them so handy elsewhere. Of course I wanted it integrated nicely into my pages, also as this web host doesn't provide CGI bin it had to work offline and upload the pages from here.

So, simple enough. First I looked up the spec of RSS on Wikipedia, which lead me to the RSS Advisory Board. Also very handy was feedvalidator.org.

Next I created an RSS feed for this site by hand. Once I had it validating okay I moved on to the next stage.

All the update posts are stored as individual files in a directory called posts. The files are very simple, the first line is the title, second the date, third the category and the rest of the file is the article text.

The script (sitebuild-update-rss) opens the RSS file, writes a standard header, then reads each post, pulling the first three lines off to create the item header then writes the item to the file.

Once that's done, it writes the foot to the page and it's done.

Similar scripts create the front page (sitebuild-update-index) and a set of pages of previous blog posts (sitebuild-update-html).

The shell script (sitebuild-update) runs each script in turn and then uploads the whole lot using ncftp.


Download
sitebuild-update-rss
sitebuild-update-html
sitebuild-update-index
sitebuild-update

Libraries
lib-rf-sitebuild.pl
lib-rf-babble.pl
lib-rf-date.pl


mydate

Thu, 04 Sep 2008 15:31:36 GMT

A simple tool for generating a date string in the format needed for RSS feeds. This replaces a shell script that called the GNU date tool.

The shell script was very, very simple. Like this:

#!/bin/sh date +"%a, %d %b %Y %T %Z"

I used the same command as this in the sitebuild-update-rss script. But a pure Perl solution is faster that starting a shell, running an external command and capturing that output.

So I wanted a Perl version. And here it is.

sub rssdate { $daysago = $_[0]; $longdate = gmtime(time() - ( 24 * 60 * 60 * $daysago)); $longdate =~ s/\ \ /\ /; ($day, $month, $mday, $fullTime, $year) = split(/ /, $longdate); $mday = sprintf "%02d", "$mday"; return ("$day, $mday $month $year $fullTime GMT"); }

Download
mydate

Libraries
lib-rf-date.pl


Roleplay Tools in Perl

Thu, 04 Sep 2008 14:22:26 GMT

I've been collecting together the Perl versions of my various random stuff for roleplay programs, collecting the arrays and subroutines into a shared library of code so I can combine the effects in new ways.

I started this a while back, but the last few days I've got all the old code moved over.

As a first step, here are the old programs, tavern, dishoftheday, names-male and names-female converted to use the combined library.

As an example, here is the new version of tavern:

#!/usr/bin/perl # tavern # by Gav Ford # revford@blueyonder.co.uk # http://revford.pwp.blueyonder.co.uk # 2008 early # Tavern Name Generator use FindBin '$RealBin'; require "$RealBin/lib-rf-roleplay.pl"; print tavern() ."\n";

The $RealBin finds the directory where you've put the program and finds the library there.

Then it's simple calling the tavern() function from library and printing the result.

To install all this stuff, just dump it in a directory together and run the programs from a terminal.

If terminals aren't you're thing, there are still the web based Javascript versions here:

Roleplay Menu


As well as these roleplay tools, I've converted the technobabble generator in the same way. The sitebuild tools that create this page now use the babble library for the blog pages.

The plan is to create more kinds of technobabble and add them to the babble library soon.


Download
tavern
dishoftheday
names-female
names-male
babble

Libraries
lib-rf-babble.pl
lib-rf-roleplay.pl


Wealth

A simple tool for the d20 Modern roleplay game. Converts a value in dollars to the abstract wealth check value used in the game. Also works in reverse.

Usage:

wealth dc 15 $ 500
wealth cash 40,000 DC 30

Download
wealth


Technobabble Generator

A simple script for randomly generating some technobabble, it pulls a random element from three arrays and prints the result.

Usually I'd do this sort of thing in Perl, I've done similar things for random name generators in the past. However this was for the Tuesday nights group to use during our games and I wanted to host it here on my webspace. This free webspace doesn't provide CGI for me so I had to do something client-side, to put this together with a little JavaScript.

This was my first Javascript project for over ten years. I may just start using it more.

As an update I rewrote the technobabbler as a function, this allows me to pull random technobabble into other pages more easily, such as the subtitle for this part of the page. Refresh the page to see it change, view the source to see how it works.

As that was so handy I wrote random thing generators for our D&D games too, creating NPCs and Taverns. These two are still under development but you can see the progress with the code here.


Download
babble.js
npc.js
tavern.js


Open the Technobabbler.


clear-mailbox

My Wife's POP3 mailbox was jammed up with 6000 junk mails, so I went and wrote this little tool to clear the thing out. I didn't fancy typing "dele" 6000 times. It uses the module Net::Telnet you can get from CPAN or your distro.

Update: Added a version that just checks, not clears the mailbox, check-mailbox.

Usage:

clear-mailbox mailhost username password

Download
clear-mailbox
check-mailbox


toolz.exe

When s/s/z/g was cool.

Part of a project I did at Uni, a free floating toolbox of commonly used HTML, handy alongside any text editor.

This was done back on Windows 3.1 and requires the Visual Basic 3 libraries available from Microsoft.com. Works with WINE too.

Usage: Just run the Executable.


Download
toolz.exe

OK HTML
OK CSS
OK RSS
CC
2011-11-25