Tools: January 2008 Archives
Oh no, hourly smoke test failures in my inbox today! Looks like I put some bad HTML on work's website's home page, and every hour one of the automated tests, via Test::HTML::Lint, told me once an hour that
# HTML::Lint errors for http://devserver.example.com/ # (72:53) <a> at (61:53) is never closed
Well, phooey, it's a PHP-driven website, so I can't open index.php and check lines 72 and 61. I can use GET, installed with LWP, to fetch the website and save the source:
$ GET http://devserver.example.com/ > foo.html $ vim foo.html +61
but since I'm a Perl programmer, I want to be as lazy as possible by using the tools at my disposal. In this case, it's ack, and ack has the --line option to display ranges of lines instead of results of a regex. (Thanks to Torsten Blix for implementing this!)
$ GET http://devserver.example.com/ | ack --lines=61-72
So much nicer that way! and look at it in an editor, but how much easier to not have to do that.
There is no project so small, so trivial, that it is not worth you putting it into a Subversion repository. If it's worth your time to work on it, it's worth saving. Putting it in Subversion is a matter of a few statements, and you don't have to do any big fancy-shmancy server setup.
Let's assume you're working on Linux/Unix, and you have svn installed, which is pretty standard these days. Say you're working on a game called bongo, and you've just been keeping it in ~/bongo. Do this:
# Create the Subversion repo $ mkdir /svn # Create the bongo repo $ svnadmin create /svn/bongo # Import bongo into its project $ cd ~/bongo $ svn import file:///svn/bongo -m'First import of bongo into Subversion' # Move the original bongo directory out of the way, # in case something goes wrong $ mv ~/bongo ~/bongo-original # Check out bongo from Subversion svn co file:///svn/bongo
At this point, you'll have a checked-out version of bongo in ~/bongo, and you can make commits against it.
Ricardo Signes points out that Git makes it even easier.
# Go to the bongo directory $ cd ~/bongo # Import bongo $ git init
With Git, everything is put in your ~/.git directory, and you don't have to check out anything from the project.
Whatever route you choose, version control is so simple these days there's just no excuse not to do it. Your programming life will never be the same.
This thread on use.perl.org points to some cool vim support for Perl. I'm not sure I like all the doodads in perl-support.vim, but I did add this to my .vimrc:
autocmd FileType perl :noremap K :!perldoc <cword>
\ <bar><bar> perldoc -f <cword><cr>
Now hitting K in vim runs perldoc or perldoc -f on the word under the cursor.
Ricardo Signes' marvelous module CPAN::Mini just got an update today, and it reminds me to tell you all how great it is to be able to have a small version of the CPAN on your local hard drive, especially on a laptop. The included minicpan program makes it trivial to update your local archive.
First, I make a little ~/.minicpanrc that looks like this:
local: ~/minicpan/ remote: http://cpan.pair.com/pub/CPAN/ also_mirror: indices/ls-lR.gz
And then I run minicpan every so often. This pulls in the latest version of each distribution, and deletes ones that are obsoleted by newer versions. When I run minicpan, it looks like this:
$ minicpan authors/01mailrc.txt.gz ... updated modules/02packages.details.txt.gz ... updated modules/03modlist.data.gz ... updated mkdir /tmp/Woq_DHsWsN/indices indices/ls-lR.gz ... updated indices/ls-lR.gz ... updated mkdir /home/andy/minicpan/authors/id/G/GR/GROMMIER authors/id/G/GR/GROMMIER/Text-Editor-Easy-0.01.tar.gz ... updated authors/id/G/GR/GROMMIER/CHECKSUMS ... updated mkdir /home/andy/minicpan/authors/id/Z/ZO/ZOFFIX authors/id/Z/ZO/ZOFFIX/Acme-BabyEater-0.01.tar.gz ... updated authors/id/Z/ZO/ZOFFIX/CHECKSUMS ... updated ... cleaning /home/andy/minicpan/authors/id/L/LU/LUKEROSS/DBIx-StORM-0.04.tar.gz ...done cleaning /home/andy/minicpan/authors/id/L/LU/LUKEC/Test-WWW-Selenium-1.13.tar.gz ...done cleaning /home/andy/minicpan/authors/id/L/LU/LUKEC/mocked-0.07.tar.gz ...done cleaning /home/andy/minicpan/authors/id/L/LO/LOCATION/Geo-IP2Location-2.00.tar.gz ...done cleaning /home/andy/minicpan/authors/id/L/LO/LODIN/Regexp-Exhaustive-0.03.tar.gz ...done
Currently the repository is only 846M of disk space. Who doesn't have an extra gig lying around these days?
uniqua:~/minicpan $ du -sh 846M .
I also point my CPAN shell configuration to use the mini CPAN as its source of modules by prepending file:///home/andy/minicpan to the list of URLs it checks.
Thanks to Ricardo for putting out this great tool, and Randal Schwartz for the original column on which it was based.
Rafael Garcia-Suarez has posted his modifications for vim to support Perl 5.10. His are a good deal more complete than the simple modification I posted last month that just covers the say keyword.