Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Fletch (75)

Fletch
  (email not shown publicly)
http://phydeaux.org/
AOL IM: lemurnomicon (Add Buddy, Send Message)

Frink? Frink? Phtang!

Journal of Fletch (75)

Wednesday May 05, 2004
04:12 PM

Class::DBI::Pg and multi-column primary keys

This will let Class::DBI::Pg deal with tables which have a primary key consisting of more than one column (e.g. CREATE TABLE foo ( a integer, b integer, PRIMARY KEY ( a, b ) ))

Patch sent to author as well, but just in case anyone else is interested . . .

--- /usr/lib/perl5/site_perl/5.8.0/Class/DBI/Pg.pm      2003-09-10 03:59:40.000000000 -0400
+++ Class/DBI/Pg.pm     2004-05-05 13:53:57.000000000 -0400
@@ -23,7 +23,7 @@
WHERE relname = ?)
SQL
     $sth->execute($table);
-    my $prinum = $sth->fetchrow_array;
+    my @prinums = split( /\s+/, ( $sth->fetchrow_array )[0] );
     $sth->finish;

     # find all columns
@@ -50,17 +50,17 @@
     $sth->finish;
     my($sequence) = $nextval_str =~ m/^nextval\('"?([^"']+)"?'::text\)/;

-    my(@cols, $primary);
+    my(@cols, @primary);
     foreach my $col(@$columns) {
        # skip dropped column.
        next if $col->[0] =~ /^\.+pg\.dropped\.\d+\.+$/;
        push @cols, $col->[0];
-       next unless $prinum && $col->[1] eq $prinum;
-       $primary = $col->[0];
+       next unless @prinums && grep $col->[1] eq $_, @prinums;
+       push @primary, $col->[0];
     }
-    _croak("$table has no primary key") unless $primary;
+    _croak("$table has no primary key") unless @primary;
     $class->table($table);
-    $class->columns(Primary => $primary);
+    $class->columns(Primary => @primary);
     $class->columns(All => @cols);
     $class->sequence($sequence) if $sequence;
}

Friday March 26, 2004
08:58 AM

Changing OS X Location from the command line

Found out about scselect yesterday from here. A couple of minutes effort on the train and I now can change from a shell without having to mouse up to the apple menu.

zsh ++

##
## _scselect -- Completion for OS X Network Location utility
##
_scselect () {
    local locs
    locs=( $( scselect |& \
              perl -lne 'next if/^\S/;/\(([^)]+)\)/&&print qq{"$1"}' ) )
    _arguments -C "*:Network Location Set:($locs)"
}

Saturday January 17, 2004
12:18 AM

iLife 04 first impressions

  • GarageBand – Consumer grade Reason; looks interesting.
  • iPhoto – Much more responsive (loading pictures, rotating).
  • iDVD – Neat new themes, the new slideshow transitions look neat (haven't burned to look on TV yet but . . .), and the map/overview looks like it'll be useful.
  • iMovie – Didn't really poke at this yet. Pulling in the holiday video's the weekend project.
Monday October 27, 2003
01:34 PM

Mac::Carbon on Panther

Just to save some other person some googling:

You need to undef I_POLL

Friday October 24, 2003
07:27 PM

Waiting for Panther

Memo to myself: Next OS release bring chair. Mall tile floor is not the most comfortable.

Monday September 08, 2003
11:16 AM

nosleep 'till Brooklyn

Or at least until that long running wget completes. This will temporarily set the OS X energy saver sleep timer to `never', run the specified command, and then restore the sleep time.

#!/usr/bin/perl
##
## nosleep -- Disable sleep while command runs (OS X)
##
use warnings;
use strict;

my @pm_set_cmd = qw( pmset sleep );

unshift @pm_set_cmd, 'sudo' unless $> == 0; ## Setting needs root privs

## Figure out what sleep's set to
my $old_sleep = undef;

open( GET, "pmset -g live |" ) or die "Can't open pipe from pmset -g: $!\n";

while( <GET> ) {
  if( /sleep\s+(\d+)/ ) {
    $old_sleep = $1;
    last;
  }
}

close( GET );

die "Couldn't determine current sleep setting.\n" unless defined $old_sleep;

my $ret;

## Set sleep to 0 (never)
$ret = system( @pm_set_cmd, 0 );
die "Problem setting sleep: @{[ $? >> 8 ]}\n" unless $ret == 0;

## Run command passed as argument
$ret = system( @ARGV );
warn "Problem running command: @{[ $? >> 8 ]}\n" unless $ret == 0;

## Revert to old sleep value
$ret = system( @pm_set_cmd, $old_sleep );
die "Problem setting sleep: @{[ $? >> 8 ]}\n" unless $ret == 0;

exit 0;

__END__
You may wish to add something along these lines to your /etc/sudoers:

Cmnd_Alias      PMSET = /usr/bin/pmset sleep [0-9]*
%admin  ALL=(ALL) ALL, NOPASSWD: PMSET

Friday March 07, 2003
12:00 PM

Handy SSL CA Articles

Two handy ORA onlamp.com articles you may not have seen:

Now I don't have to remember what box I book marked those on . . . :)

Friday January 10, 2003
10:43 AM

Socks

Last night I bought some socks at a warehouse store because the wife has been complaining about the lack of structural integrity of my present hosiery.

At any rate; 12 pair, 9$US, in a plastic bag. A plastic bag with a recloseable zipper seal.

Socks. In a ziplock bag. This means something. Possibly that ziplock bags are available off the shelf and were the most convenient way to package 12 socks. Or that I should be keeping my socks in the vegetable crisper in the fridge.

Tuesday November 05, 2002
02:53 PM

Interesting Web Services Application

All Consuming grobbles throughthe sites listed in weblogs.com for links to books on Amazon and then makes lists of the most blog'd about ones.

See the site for a more complete explanation.

Wednesday October 30, 2002
10:51 AM

My mind is going, Dave . . .

I've now forgotten my headphones at home for the third day in a row. Usually they stay at work, but last week someone was using my office and I was working from home so I took them home. I keep remembering that I've forgotten them when I'm sitting in the car or when I've already gotten to the office.