Posted by root
Fri, 22 Feb 2008 21:23:00 GMT
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";
Posted in Perl, scripts | Tags money | no comments
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, b, c = ["a", "b", "c"]
Posted in programming, Ruby, Perl | no comments
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 programming, Ruby | Tags senseless | no comments
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 Perl, scripts | Tags UNIX | no comments
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 Perl | Tags japh | no comments
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 scripts | Tags UNIX | no comments
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 Ruby | Tags config | no comments
Posted by root
Sat, 02 Feb 2008 12:59:00 GMT
Perl script (thanks to the author of HTML::WikiConverter):
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);
Posted in Perl, scripts | Tags converter, wiki | no comments