Archive for the ‘code’ Category

Inspired by Alex King’s recent post on backups, I hacked together this short Perl script that will backup MySQL databases to Amazon’s excellent S3 storage system.

You can download it here. You will need to edit a few configuration items at the top of the script, to include your Amazon Web Services IDs and MySQL details. You will also need the Amazon::S3 and DBI perl modules. You can get them from CPAN.

$ wget -Omysql_s3.pl http://dparrish.com/files/mysql_s3.pl
$ vi mysql_s3.pl (enter your details)
$ chmod 755 mysql_s3.pl
$ ./mysql_s3.pl

It’s probably best to add it to cron so it will run daily. Something like this works nicely:

0 3 * * * perl /home/dparrish/mysql_s3.pl

I’d also suggest using S3 Firefox Organizer to manage your S3 account. It’s a Firefox plugin.

I’ve been mucking around with Comet, and ran into a situation which I couldn’t seem to find a solution on the lazyweb for. The problem was that none of the streamed JavaScript code blocks would be executed until the entire page was loaded.

I tracked it down to the gzip encoding module, which waits for all the data to be output, compresses it and sends it on to the browser.

You can disable gzip encoding for a particular directory in a .htaccess file (with Apache) like this:

RemoveOutputFilter DEFLATE
SetEnv no-gzip

Obfuscated Perl

14th Jun
PERL:
  1. $S=int(rand(time))*9;while($S>=10){$t=0;$t+=$_ foreach split//,$S;$S=$t}
  2. @s=(296,1837,2403,2798,3343,3458,4021,4586,5242,5548,5573,5850,6042,6240
  3. ,6860,6967,7754,8439,8984,9239,9249,9310,10385,10655,10661,10817);srand$S
  4. ;$s=shift@s;while($s){$_=rand$S**3;push@n,chr($_)and$s=shift(@s)if++$count
  5. ==$s}map{print}@n

Who doesn't love obfuscated Perl code? This is one I wrote, and it's very simple.

-->