sungate.co.uk

sungate.co.uk

Ramblings about stuff

Fighter Command 1940 and Daily Random Numbers

I’ve been meaning to write this up for a while, so here goes. In addition to my own personal Twitter account, I run two others as ‘projects’. The first one is called Fighter Command 1940 and it traces the history of Spring and Summer 1940 from the British point of view in World War II on this day in 1940. There is one tweet per day from this account which currently has 450 followers and, at “present”, the Dunkirk evacuation is in full swing. Some recent tweets:

22 May: British and French troops in the North retreating towards Dunkirk. The RAF’s last airfield in France (Merville) is over-run.
23 May: Germans advancing on Calais and Boulogne, and towards Dunkirk. Bad weather prevents Luftwaffe attacks on troops around Dunkirk.
24 May: Hitler personally orders advance on Dunkirk to be halted, a surprise giving Allies time to begin carrying out their evacuation.
25 May: Allied resistance at Boulogne ends as Germans capture the citadel. Defence of Calais is ongoing but Germans are still advancing.
26 May: While Allied troops retreating towards Dunkirk, owners of small boats are contacted by the Admiralty to assist.
27 May: Evacuation of troops from Dunkirk begins with co-operation of Royal Navy vessels, the assorted Little Ships and cover from RAF.
28 May: King Leopold of Belgium surrenders to the Germans as the evacuation at Dunkirk proceeds.

I’m sure you get the idea. Behind the scenes, I prepare the content in advance with an automated trigger to send the tweets each day.

My other project is rather more low key: Daily Random Numbers – this does as its title suggests. It posts random numbers each day. You can use them for any purpose you choose. For example, this morning’s post is:

Today’s random numbers: 2508 6927 2875 8334 9093 5291 4317 5422 7002 5643; today’s random dice rolls: 4 4 1 4 1 6 4 3 2 5

Behind the scenes, this one is a short Perl script which I’ll include here for interest’s sake:

#!/usr/bin/perl 

use strict;
use warnings;

use Net::Twitter;

# In following block, 'KEYHERE' represents an authentication 
# string/secret obtained from the Twitter development area
my $nt = Net::Twitter->new(
    traits              => [qw/API::REST OAuth/],
    consumer_key        => 'KEYHERE',
    consumer_secret     => 'KEYHERE',
    access_token        => 'KEYHERE',
    access_token_secret => 'KEYHERE',
    ssl                 => 1,
);

my $update = "Today's random numbers:";
for ( 1 .. 10 ) {
    my $rand = int rand 10_000;
    $update = "$update " . sprintf "%4.4d", $rand;
}

$update = "$update; today's random dice rolls:";

for ( 1 .. 10 ) {
    my $rand = 1 + int rand 6;
    $update = "$update " . sprintf "%1d", $rand;
}

my $result = eval { $nt->update($update) };

warn "$@\n" if $@;

And there you have it.