How to find free domain name

Feb 22
2008
#!/usr/bin/perl
 
use strict;
use warnings;
 
my $dom = shift || die "missing name\n";
my $res = qx{whois $dom};
 
die $1 . "for '$dom'\n" if $res =~ /(no\s+whois\s+server\s+)/i;
die "$dom is free\n"    if $res =~ /no\s+match|does\s+not\s+exist/i;
die "$dom is reserved\n";
 
__END__
_whois 123456.com
123456.com is reserved
 
_whois _123456_.com
_123456_.com is free

Scalar || List context

Feb 12
2008

Perl

 $a  = ("a", "b", "c"); # $a is "c" - the last element
($a) = ("a", "b", "c"); # $a is "a" - the first element

Ruby

 obj        = ["a", "b", "c"] # obj is Array - ["a", "b", "c"]
 obj, b, c = ["a", "b", "c"] # obj is String - "a"

Lotto checking script

Feb 12
2008

The idea comes from http://www.waider.ie/hacks/workshop/perl/lotto.pl script.

Should I be so wasteful? No:

irb

my_numbers       = [1,2,3,4,5,6]
winning_numbers = [1,2,3,41,42,43]
 
result = 6 - (winning_numbers - my_numbers).size
 
puts "#{result} " +
  if not result.eql? 0
    "hits"
  else
    "hit"
  end

Perl script opening (vim variant)

Feb 04
2008
#!/bin/bash
 
file=$1
 
if [ -e $file ]
then
        vim $file
else
        touch $file
        echo '#!/usr/bin/perl' > $file
        echo '' >> $file
        echo 'use strict;' >> $file
        echo 'use warnings;' >> $file
        echo 'use diagnostics;' >> $file
        echo '' >> $file
        chmod +x $file
        vim $file
fi

JAPH with AUTOLOAD

Feb 03
2008
#!/usr/bin/perl
 
JAPH->Just->Another->Perl->Hacker;
 
package JAPH;
 
sub AUTOLOAD { bless [print+($AUTOLOAD=~/::(.+)/)[0], q/ /] } sub DESTROY {}

find command (practical books’ dir copy)

Feb 03
2008

Copy all those formats (pdf|chm|txt|html) from $HOME/Desktop to the current working directory:

find  ~/Desktop/ -iname "*.pdf" \
  -o -iname "*.chm" \
  -o -iname "*.txt" \
  -o -iname "*.html" \
-exec cp -v {} . \;

more about find command

Sample .irbrc (with autocomplete)

Feb 02
2008
cp .irbrc $HOME; irb
require "irb/completion"
 
IRB.conf[:PROMPT_MODE] = :SIMPLE
 
def ri(*arg)
  system("ri #{arg.join" "}")
end
 
class Object
  def __find_method(reg=Regexp.new)
     self.methods.sort.grep reg
  end
 
  alias :fm :__find_method
end

HTML To WIKI converter

Feb 02
2008

Perl script (thanks to the author of HTML::WikiConverter):

#!/usr/bin/perl
 
use strict;
use warnings;
use HTML::WikiConverter;
use Perl6::Slurp;
 
my $file_name = shift;
 
-f $file_name or die "No file given!\n";
 
my $wiki = new HTML::WikiConverter(dialect=>'MediaWiki');
 
print $wiki->html2wiki(slurp $file_name);
 
__END__
 
  Supported dialects:
 
  DokuWiki
  Kwiki
  MediaWiki
  MoinMoin
  Oddmuse
  PbWiki
  PhpWiki
  PmWiki
  SlipSlap
  TikiWiki
  UseMod
  WakkaWiki
  WikkaWiki

Calendar

February 2008
M T W T F S S
« Jan   Mar »
 123
45678910
11121314151617
18192021222324
2526272829  

Tags