Fri 16 Feb 2007
This comic from xkcd gave me a laugh.
Fri 16 Feb 2007
This comic from xkcd gave me a laugh.
Mon 1 Jan 2007
My brother-in-law and sister-in-law sent a t-shirt for Nate that made me smile, “Powered by Perl” Toddler T-Shirt with a camel on it. Must get a picture of him wearing it up on the site.
Sat 5 Aug 2006
I’ve been busy with everything else in my life, so I haven’t done much reading. Things have quieted down enough and I’ve picked up:
Sat 1 Oct 2005
Filladapt mode is good but the Perl module Text::Autoformat is better at reflowing text for email. I cobbled together the following elisp to make that easy.
(defun rel-autoformatter (begin end rightmargin)
"Run Text::Autoformat on region"
(shell-command-on-region begin end
(format "perl -MText::Autoformat -e 'autoformat({all=>1,right=>%d})'" rightmargin) t t )
(message "done."))
(defun rel-autoformat (begin end)
Text::Autoformat on region, RFC recommended right margin of 72"
(interactive "r")
(rel-autoformatter begin end 72))
(defun rel-autoformat-quote (begin end)
"Text::Autoformat on region, right margin of 60, suitable for quoting replies"
(interactive "r")
(rel-autoformatter begin end 60))
(global-set-key (kbd "C-c f f") 'rel-autoformat)
(global-set-key (kbd "C-c f q") 'rel-autoformat-quote)
It might be nice to handle parameters other than right margin- and do it in a cleaner way than explicitly specifying them. I doubt I’ll get around to it since Text::Autoformat usually does the right thing for me with just the margin hint.
Thu 29 Sep 2005
At work I have a collection of long-running Perl programs exec-ed by a rc script that have their noise redirected to a single intermingled log. The scripts themselves and the modules they use are littered with carps, warns and print STDERRs depending upon when and by whom they were written. I can differentiate their output (more or less) but I’d like it timestamped for forensic purposes.
My first thought, heaven help me, involving tying filehandles is exampled by this hack:
!/usr/local/bin/perl -w
use Tie::Handle;
use Carp;
use strict;
package TimeStamper;
@ISA = qw(Tie::Handle);
sub wrap {
my $fh = shift;
my $fh_name = $fh;
$fh_name =~ s/^\*//;
local *MYFH;
open(MYFH, ">&$fh_name") or die("Failed to dupe [$fh_name]: $!");
tie($fh,'TimeStamper',*MYFH);
}
sub TIEHANDLE {
my ($class,$fh) = @_;
my $obj = bless [$fh],$class;
return $obj;
}
sub PRINT {
my $self = shift;
my $fh = $self->[0];
my @t = localtime();
print sprintf("[%4d/%02d/%02d %02d:%02d:%02d] ",
$t[5]+1900,@t[4,3,2,1,0]),@_;
}
package main;
TimeStamper::wrap(*STDERR);
print STDERR "This is timestamped.\n";
warn('This is timestamped.');
carp('This is timestamped.');
print "This is not timestamped.\n";
Neat. Even half clever. But I’m not sure it’s a good idea.