nix, shell, perl, php, mysql and mac os x tips and tricks

Tuesday, May 20, 2008

Use perl on the command line with modules

perl -e 'use POSIX qw(strftime ceil floor); my $ts = strftime( "%Y%m%d%H%M%S",localtime(time)); my $t = substr($ts,0,12); print "TIME: $ts $t\n"';

Wednesday, May 14, 2008

Use mod_rewrite to create "fake sites" (with subdomains) on a single apache vhost

Note: the subdomains need to be server aliases on the vhost
RewriteCond %{HTTP_HOST} ^(subdomain1|subdomain2)\.yoursite\.com [NC]
RewriteRule ^(.*){REQUEST_URI} [L,P]
Apparantly this also works:
RewriteCond %{HTTP_HOST} ^(sub1|sub2)\.yoursite\.com [NC]
RewriteRule (.*)$1 [R=301,L]

Thursday, May 8, 2008

MySQL Select random integer between 0 and 82

SELECT FLOOR(0 + (RAND() * 82))

Monday, May 5, 2008

Change case on file extensions in a directory

for f in *.JPG; do mv $f `basename $f .JPG`.jpg; done;