Calculating the second last Friday of the month

My boss, bless ‘im (no really, do; he’s a sound bloke, great guy to work for, and is just getting through some serious health problems), needs a monthly status report on the second last Friday of every month. I live by my calendar applications reminding me to do things, so I thought it’d be no problem getting Outlook to set up a reminder.

No dice; it will only set up appointments on the 1st, 2nd, 3rd etc., starting from the beginning of the month. I did a web search, and really thought I’d found a solution for iCal. It was not to be; this was for a Unix program called ICal; dratted case-insensitive search. Curiously, it appears that the ics spec might support a second-from-last syntax, but Outlook and iCal (and Google Calendar) can’t create them. Phooey.

So I tried excel; and really thought I’d found the basis of an answer: Last Friday of the month. And indeed, most of their assumptions are right; the code


really does give you the date of the last Saturday in the month. But you can’t assume that the day before the last Saturday is the last Friday – it is the second last, if the month ends on a Friday (April 2010 is a test case).

So I tried the Swiss Army chainsaw of brute-force date calculation: Perl with Date::Calc. What I do here is create an array of every Friday in the month, then print the second last member; never known to fail:

#!/usr/bin/perl -w
# - show date of 2nd last friday
use strict;
use Date::Calc qw(Today
my ( $new_year, $new_month ) = 0;

my ( $year, $month, $day ) = Today;
foreach ( 1 .. 24 ) {
    my @fridays = ();   # for every friday in this month
    foreach my $week ( 1 .. 5 ) {
        if (
            ( $new_year, $new_month, $day ) =
                $year, $month, 5, $week
        {               # day of week 5 is Friday
            push @fridays, $day;
        else {
            last;       # not a valid Friday
    printf( "%4d/%02d/%02d\n",
        $year, $month, $fridays[-2] );
    ( $year, $month, $day ) =
      Add_Delta_YMD( $year, $month, 1, 0, 1, 0 )
      ;                 # month++

and this gives



See, notice the tricksy 23 April 2010, which – considering thirty days hath April et al – ends on a Friday and threw that simple Excel calculation off.

I’m disappointed that all these new applications like Outlook and iCal don’t seem to handle dates as elegantly as the old unix programs I used to use. pcal, in particular, could generate incredibly complex date formulae. I must dig around to solve this problem – and for now, actually have to remember to write that report on the second last Friday of this month …

renaming files to include datestamp

My Marantz PMD-620 has a reliable internal clock, and stamps the files with the time that recording stopped. File times are remarkably fragile, so I wanted to make sure that the times were preserved in the file name. Perl’s rename utility does this rather well, as it allows you to use arbitrary code in a rename operation. So:

rename -n 'use POSIX qw(strftime); my $mtime=(stat($_))[9]; s/.WAV$//; $_ .= strftime("-%Y%m%d%H%M%S",localtime($mtime)); s/$/.WAV/;' *.WAV

which, for files 1007.WAV and 1008.WAV recorded last night, results in:

1007.WAV renamed as 1007-20091024192436.WAV
1008.WAV renamed as 1008-20091024193438.WAV

To actually rename the files, remove the -n from the command line. I left it in so you couldn’t blame me for b0rking up your files if you typed first, thought later.

There are probably smarter ways to handle the file extension. This works for me. Perfection comes later.

more on WordPress dates

I got sick of the annoying date display bug, and so dug through the default theme files looking for specific references to date formats. And there were many …

I found that, instead of using the WordPress the_date() function, there were many calls to the_time('l, F jS, Y'), which forces a specific date format. If you replace instances of the_time('l, F jS, Y') with the_date(), your date and time format set in the Options panel will work as expected.

How hard was that? Not very. How easy would it be to be modified in the default template?

The Apples in Stereo – Lee’s Palace, Toronto – 20 February 2007

In haste: The Apples in Stereo – Lee’s Palace, Toronto – 20 February 2007
(now updated to include better MP3s)

  1. (intro)
  2. Go
  3. Please
  4. Can You Feel It?
  5. The Rainbow
  6. Energy
  7. Strawberryfire
  8. Radiation
  9. Do You Understand?
  10. Open Eyes
  11. I Can’t Believe
  12. (apples in stereo mini-theme)
  13. Skyway
  14. (mini theme/tuning)
  15. Motorcar
  16. Tin Pan Alley
  17. Sun Is Out
  18. Same Old Drag
  19. (theme interlude)
  20. What’s the #?
  21. Ruby
  22. (encore intro)
  23. Play Tough
  24. Baroque

wordpress dates

I’m a bit peeved that even in WordPress 2.1, they haven’t fixed a very long-standing bug: all templates (especially the default one) should respect the user’s date format. It seems that moderators on the forums see this as a non-issue, and zealously close (or ignore, if such a passive thing can be done zealously) any discussion on the topic, as has happened here. I don’t need or want to edit PHP to make this work; it’s supposed to work.

Today’s date is 28 Jan 02007. I want you to see it that way. WordPress doesn’t.

you go, Glen!

Congratulations are due to Glen Estill, who got his two Vestas V82s on the Bruce Peninsula running today. Glen is a pioneer of wind energy in Ontario, and we’re all grateful to him for his tireless work for the industry.

Update: further to my wind turbines from space obsession, I found Glen’s original V80 turbine at 44° 56′ 46.42″ N, 81° 15′ 47.12″ W.

pear shaped plan

I fear my plan to have the T21 as a home server has gone wrong. Looks like the mini-PCI network card has blown, leaving it invisible to the network. Since the screen backlight is dead, I can read no diagnostics … ;-(

Update: Aha! The backlight gods must’ve heard me, for the T21 actually graced me with a visible screen for a few hours. It was down to:

  • A bad line in my fstab which was trying to mount an unattached USB drive. This drops OpenBSD into single-user mode.
  • no dhclient configuration, so the machine would not automatically appear on the network. Since I swapped out the purportedly faulty mini-PCI network card for a spare (what?! you mean you don’t have spare mini-PCI network cards about the house? Tsk.) I had to tell the system that this was the new card to get a DHCP address.

So all works now, and I’m happy. Now to attack the LaserJet 4 duplexer, and swap it onto my refurbed printer …

gone with the wind

I see that Americas Wind Energy updated their website to replace the site I wrote for them a couple of years back. It’s purty, but:

  • The page URL sometimes inexplicably switches to from
  • The product page for the AWE 52-750 shows a bunch of non-operational turbines.
  • The AWE 52-900 page also has a picture of a parked turbine, and it looks a lot like Tallon Energy’s 52-750 at Pincher Creek.
  • More parked turbines on the 54-900 page, and occasionally a completely different machine is shown.

Oh wait, I get it – it’s a random turbine image for each page. Hmm.

Standard Offer is Go – March 21

From OSEA:

The moment we have all been waiting for has arrived! The Ministry of Energy, the Premier, David Suzuki and OSEA will be announcing the Standard Offer Program on March 21st. We are organizing a celebration and press event in partnership with the Ministry of Energy that will take place at 3 pm at Exhibition Place, Toronto, home to Ontario’s first community wind turbine.

Please mark this date in your calendar and watch for further notices (via email and at on details regarding location, speakers and entertainment.

This is a celebratory event – please everyone, let us celebrate the positive role the Standard Offer Contract program will play in Ontario for renewables, for community power, for cost effective power, and for our air quality and health!

Thanks to everyone for their efforts!

If the province has got this right, we really will see a lot more wind power in Ontario.

manitoulin sunset

There was supposed to be a picture of a nice — if low-res and a bit squinty — sunset over McLean’s Mountain on Manitoulin Island here, but 1&1’s webmail isn’t too good on attachments.

Update: Here it is:—
manitoulin sunset
(The vertical lines are guy wires, btw)

timely quotation

Anent George W. Bush’s “God Told Me To Do It …” revelation, was it purely coincidence that the week’s quotation in Catherine‘s Women Artists Datebook is:

I distrust those people who know so well what God wants them to do because I notice it always coincides with their own desires.

 — Susan B. Anthony

Mozilla Update :: Extensions: New Tab Homepage

Ah, New Tab Homepage brings happiness to this Firefox user. I rather got to like the lightweight Epiphany browser during my mini-itx odyssey. When you opened a new browser tab in Epiphany, it loaded your home page. The supposedly more advance Firefox never did this.

New Tab Homepage fixes this, and doesn’t add any other tab-related cruft that I couldn’t use.

1/9/XX, and the smell of new pencils

Although school in late August for us I always derived the tiniest bit of pleasure from writing the date today, and seeing that it was the same as the year. This shows I was educated in the last century.

As it was the start of the schools year, I was writing with new pencils, and summer holidays were long enough for me to forget their wooden smell. So I remember writing the date, and simultaneously, the smell of new pencils.