Author: scruss

  • 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

    DATE(year,month+1,1)-WEEKDAY(DATE(year,month+1,1),1)

    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
    # second_last_friday.pl - show date of 2nd last friday
    use strict;
    use Date::Calc qw(Today
      Nth_Weekday_of_Month_Year
      Add_Delta_YMD);
    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 ) =
                Nth_Weekday_of_Month_Year(
                    $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++
    }
    exit;
    

    and this gives

    
    2009/11/20
    2009/12/18
    2010/01/22
    2010/02/19
    2010/03/19
    2010/04/23
    2010/05/21
    
    ...
    
    

    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 …

  • cheap databases for Mac

    Apparently they all use the wonderful SQLite, too.

  • wordpress visual editor not working?

    If it always doesn’t work, go to Users -> Edit Profile, then check ‘Disable the visual editor when writing’, then update profile. Now go back and uncheck ‘Disable the visual editor when writing’, and resave your settings.

    This worked for Catherine under 2.8.5. I’ve never had this problem myself.

  • big-ass spider

    This is one of the last surviving garden spiders. It’s huge – perspective makes it look smaller than my thumb, but it’s about the same size.

    It looks weary and arthritic. May not see november.

  • brontosaurus in my window

    I have a crane looming very close to my office.

  • The Drones of Scarborough Superstore

    I’ve mentioned the beautiful drone in the Loblaw Superstore before, but only last night did I actually get around to recording it:

    1. meats, fish – 2009/10/24 19:24:36
    2. chill – 2009/10/24 19:34:38
    3. ice cream – 2009/10/24 19:36:56
    4. organic dairy – 2009/10/24 19:40:52
    5. frozen veg – 2009/10/24 19:45:38
    6. ice cream 2 – 2009/10/24 19:52:04

    You should probably listen through headphones or decent speakers – there’s some bass in there. If you can, try to experience it for yourself. The store is at 1775 Brimley Road, just south of the 401.

  • 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.

  • foo

    I am in oakwood village library, trying WordPress for BlackBerry.

  • Save Chambers Harrap in Edinburgh

    Harry writes:

    As you may have heard, the historic dictionary firm of Chambers in
    Edinburgh is threatened with closure by the parent company Hachette
    Livre
    .

    They intend moving the English dictionaries to London and the
    bilingual Harrap titles to Paris, involving not just the loss of 27
    jobs in Edinburgh but the end of a publishing tradition going back
    nearly two centuries.  Chambers is a Scottish and British institution
    dear to the hearts of word-lovers.

    Yes, the advent of free resources on the internet has changed the
    world of reference publishing, but it is far from clear whether all
    options for the future of Chambers Harrap have been properly
    considered in what appears to be a very drastic and possibly even
    underhand move by Hachette.  I feel strongly we shouldn’t just accept
    this as inevitable.  Hachette should be forced at the very least to
    undertake a properly full and open review of the situation first, in
    due consultation with the NUJ.  If you wish to join with others in
    urging them to think again, you may like to sign the online petition
    at http://www.ipetitions.com/petition/chambers-in-edinburgh/.  It only
    takes a few seconds.

    More at http://sn.im/chambersharrap and http://harrycampbell.blogspot.com.

  • she says I’m boring her camera

    pentax mx + 40mm f/2.8 pancake

    I missed my old Pentax MX. Of all of the cameras I’ve ever owned, it was probably the one with the most charm – and I don’t mean that in the same way that former Eastern bloc cameras were “charmingly” unreliable.

    The MX doesn’t do much, but does all you need. It is tiny, but it’s a very solid chunk of metal. The shutter/mirror makes a very civilized little klipp! when fired. All the controls are where you’d expect them. The pancake 40mm lens gives my MX a snub-nosed appearance. I used to have the bigger and heavier 50mm f/1.4, which some lens nerds consider to be one of the finest lenses ever made.

    Sure, it has its faults. The advance lever will poke you in the eye if you change shutter speed on the fly. And, well, y’know, film.

  • like 8-bit on a green screen

    Saw a forces type wearing CADPAT on the subway. He looked like old-school 8-bit, so I thought I could improve on the design:

    mario camouflage

  • some interesting doinks

    An empty whisky bottle tube struck hard against the tiled floor: interesting doinks [wav].

  • Gothpops: frozen treats for the doomed

    gothpop

    Yes, it’s a black ice lolly/popsicle. Wei-Chuan Black Sesame, to be exact. They’re a bit, well, seedy for my taste.

  • My Name is not Alvin

    When I first heard of Alvin Lucier‘s “I Am Sitting in a Room” I thought it would be interesting to attempt a recreation with the tools I had on hand. Rather than shuffling tapes around, I recorded on my iPod Touch, and then e-mailed the file to my laptop to play back. I repeated this sixteen times. This is what I ended up with: my name is not alvin [mp3].

    "My Name is not Alvin" recording rig

    I’m pretty sure all I ended up recording was the hard drive and the backlight on my MacBook. By the final iteration, the cricket-like chirping is centred pretty close to 5400 and 16000 Hz.