How to find free domain name

Posted by root Fri, 22 Feb 2008 21:23:00 GMT

#!/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

Posted in ,  | Tags  | no comments

Scalar || List context

Posted by root Tue, 12 Feb 2008 20:12:00 GMT

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"

Posted in , ,  | no comments

Lotto checking script

Posted by root Tue, 12 Feb 2008 19:16:00 GMT

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

Posted in ,  | Tags  | no comments

Perl script opening (vim variant)

Posted by root Mon, 04 Feb 2008 21:57:00 GMT

#!/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

Posted in ,  | Tags  | no comments

JAPH with AUTOLOAD

Posted by root Sun, 03 Feb 2008 14:20:00 GMT


#!/usr/bin/perl

JAPH->Just->Another->Perl->Hacker;

package JAPH;

sub AUTOLOAD { bless [print+($AUTOLOAD=~/::(.+)/)[0], q/ /] } sub DESTROY {}
 

Posted in  | Tags  | no comments

find command (practical books' dir copy)

Posted by root Sun, 03 Feb 2008 11:26:00 GMT


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

Posted in  | Tags  | no comments

Sample .irbrc (with autocomplete)

Posted by root Sat, 02 Feb 2008 19:39:00 GMT

Usage: 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

Posted in  | Tags  | no comments

HTML To WIKI converter

Posted by root Sat, 02 Feb 2008 12:59:00 GMT

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

Posted in ,  | Tags ,  | no comments