Software | Secret Software | Writing
Software
So at the Friends of O'Reilly camp, Danny O'Brien ran a session on secret software - the stuff that lives in your ~/bin (or your /usr/local/bin if you're really brave) and never sees the light of day, or the crufy hacks in your various .rc files.
"Why does nobody release this stuff?" asks Danny. Well, some people do. But why don't I? Well, here it is.
blog
blog is a simple script which goes nicely with Bryar. It create a new blog post ID and fires up an editor. I like this particularly because of the clever use of Cantor's diagonal theorem. Oh, and you can give it a path to a sub-blog off your main blog directory, and it'll do the right thing there.
chk_pending
chk_pending looks in the mbox/home/simon/mail/pending (you may need to customise that if
you're not called Simon) and reports on the messages in there. (This is
where I file stuff that I need to reply to eventually.) It's cute
because it produces friendly output like this:
Mail received 50 days and 20 hours ago from Stray Toaster
Subject: Re: Phone
classview
classview tells you where a method is defined in a Perl
class hierarchy.
% classview 'Mail::Message->new' Mail::Reporter->new
coll
Why the hell isn't coll a standard Unix utility?coll works a little like diff
except that it tracks additions between files, not changes: it tries
to make the largest file possible based on the input. I use it for
collating signature files between various machines:
ssh remotehost -c "cat sigfile" | coll -s '\n%\n' sigfile > sigfile.merged
get-balance
This uses myFinance::Bank::LloydsTSB module to check the balance
on all of my accounts. Feed it your username, memorable information
string, and password. With a first argument of "-s" it'll give you a
statement.
mygrepmail
mygrepmail was the precursor toMail::Miner
. Still, mygrepmail is
still useful and incredibly fast.
oxdate
This cannot be concievably useful to anyone who doesn't have it already, and it's so short I can insert it here:#!/usr/bin/perl use Oxford::Calendar; print "Today is ", Oxford::Calendar::ToOx(reverse Date::Calc::Today);If you don't know what that means, you don't need it. (Tuesday, 2nd week, Michaelmas 2003, as I write this.)
transcode
Perl 5.8.x comes with a module called Encode, which has support for moving data between character sets.transcode is a
simple front end to this so I can quickly convert a (usually Japanese)
text between various encodings. Again, it's really short:
#!/usr/bin/perl -p
BEGIN {
binmode(STDIN, ":encoding(".shift(@ARGV).")");
binmode(STDOUT, ":encoding(".shift(@ARGV).")");
}
Three for Perforce
Although I use CVS for all my modules, there are some instances where I use Perforce. There are two scripts I picked up from other people, p4d2p and p4genpatch (from, I believe, the Perl porters directory in the Perl source kit) which turn p4 changes into patches. I also started writing but never really finished an improved interface to perforce called p5 which tells you the details of the latest change, can generate patches, and, hopefully sometime in the future, will be able to retract changes by change number.Two for POP3
I hate POP3, and have mail delivered directly to my box where possible,
but sometimes my box goes down, and I have to resort to my ISP's POP services.
And then what am I going to use? fetchmail? I think not. popread
is a command which ships with Mail::Audit, the (deprecated)
mail filtering library I wrote a while back, and does the fetchmail job.
But there are other jobs; before bothering to download a ton of mail, you might want to check whether or not there's anything there: popcheck will report on how many messages there are in each of your POP boxes, plus who they're from and the subject; it'll also check for duplicate messages, and slim down your mailbox before you download it by deleting all the messages it's seen before. And then, once you've got a list of who sent what, you can work out which of those messages on the POP sever are spam. Of course, you don't want to bother downloading spam, so you can use popkill to delete messages (by number) which you've seen before, or know to be bogus.
tardis
This is a little related to blog above. I write a lot of my
blog entries offline on the laptop, and my blogging software uses the
mtime of the entry as the time it was written; of course, if I copy
stuff from the laptop to the blog server, then the mtime is all screwed
and things appear at the wrong time. tardis takes a description of a
date/time and a filename, and opens an editor on that file, and when
you're done editing it, winds the mtime back to the time specified. For
instance:
tardis 'Tue Sep 30 22:34:49 BST 2003' 20030930.txt
will allow me to make changes to the file 20030930.txt
without changing its mtime.
Shell hacks
So that's all my secret software in ~/bin. But there are
other, smaller hacks I use to make my working experience more pleasant.
For instance:
google () { lynx 'http://www.google.com/search?client=googlet&q='"$1" }
is a handy shell function to google for a given term, while
article () { lynx "news:$1" }
is considerably easier than telneting to your news server and talking
NNTP.
My answer to the perennial question "how do you delete a file starting with (some metacharacter)" is this:
unlink () { perl -le "unlink q/$1/" }
And two very useful hacks for Perl programmers - first, to open an editor on the installed source of a given Perl module:
vipm () { vi `perldoc -l $1 | sed -e 's/pod$/pm/'` }
and second to find out the version of an installed Perl module:
version () { perl -MUNIVERSAL::require -e "$1->require; print $1->VERSION" }
mutt hacks
I like archiving my mail by month. Did you know you can do this?
set mbox=+read-mail-`date +'%Y%m'` set record=+outbox-`date +'%Y%m'`