A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

How to get your subdomains to resolve

Mac:
  • The wrong way: Edit /etc/hosts
  • The right way: Add subdomains to your network preferences 'Search domains' (in TCP/IP tab)

Windows:
  • No idea - someone please tell me

Burning .gbi files to CD

In Windows:
  • MagicISO
  • gBurner

In Linux:
  • K3B - doesn't seem to work
  • You can't burn .gbi files natively in Linux, you can only burn .iso files
  • There is daa2iso (gbi to iso), but it may need to be compiled for Linux.
  • Or use the Windows version like this: wine daa2iso.exe name.gbi name.iso

POST contents of a file

#!/usr/bin/perl

use strict;
use warnings;
require LWP::UserAgent;

use HTTP::Request;

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;

my $url = $ARGV[0];
my $file = $ARGV[1];
my $head = $ARGV[2];

my $text = do { local( @ARGV, $/ ) = $file or die $!; <> } ;

my $headers;
if ($head) {
$headers = HTTP::Headers->new(Accept=> $head);
}

my $req = HTTP::Request->new('POST', $url, $headers);
$req->content($text);
my $response = $ua->request($req);

print $response->content;

Convert a string to UTF8

If the string is in iso-8859-1 encoding:

my $string_iso_8859_1 = decode("iso-8859-1", $string);
my $string_utf8 = encode("utf8", $string_iso_8859_1);

Text file endings

Mac OS: \r
Unix: \n
Windows: \r\n

parser error : Start tag expected, '<' not found

What this error means:
You're not giving the parser the XML you think you are.

Check for non-ascii characters

perl -lne'until (! $_) { s/^(.)//; $c = $1; print $_ if ord($c) > 127 }' file.html

Roll an 'if' statement into a single line in vim

Ctrl-V
s/\n\t\+/ /g

or

type JJJ