WEB 2.0 In NY

Posted by root Wed, 09 Jul 2008 20:08:00 GMT

Posted in  | Tags  | no comments

TRAC - change SVN repository

Posted by root Tue, 08 Jul 2008 00:26:00 GMT

Go to your TRAC project dir and issue the following commands:
1. cd to_your_trac_project_dir
2. ruby -i -pe ’$_.sub! /(repository_dir\s=\s).+/, “repository_dir = NEW_repository_PATH”’ trac.ini
3. trac-admin . resync

Posted in  | Tags  | no comments

regexp on String object

Posted by root Sun, 06 Jul 2008 11:04:00 GMT

Some of the more rarely used string methods:

str = "the tester"

str["tester"]        #true, the String contains "tester"
str[/\w+\s\w+/] #true, the String matches the regexp
emulates capitalize!
str[/(\w+)/] = ($1[0] - 32).chr

RDoc Documentation

Posted in  | Tags  | no comments

Google calculator response to "once in a blue moon"

Posted by root Fri, 04 Jul 2008 13:46:00 GMT

Results in the following:

once in a blue moon = 1.16699016 × 10-8 hertz

Can be tested here

Tags  | no comments

Google Chart API

Posted by root Mon, 30 Jun 2008 07:33:00 GMT

Charts for a map (in this example I’ve included Spain, France, Italy and Norway):



more about this API

Posted in  | Tags  | no comments

mkdir && cd to it

Posted by root Mon, 16 Jun 2008 12:49:00 GMT

# negative - spawning a new shell
mkdir -p $1 && cd $1 && $SHELL

Posted in  | Tags  | no comments

Getting an indication of the number of arguments accepted by a method

Posted by root Mon, 16 Jun 2008 08:57:00 GMT

class Object
  def arguments?(*methods)
    methods.each do |method|
      begin
        rval = self.method(method).arity
        if rval > 0
          puts "'#{method}' takes fixed (#{rval}) number of argument"
        elsif rval < 0
          puts "'#{method}' takes variable number of arguments"
        elsif rval == 0
          puts "'#{method}' takes no arguments"
        end
      rescue
       puts $!
      end
    end
  end
end

String.new.arguments?(:size, :to_i, :scan, :flatten)

www.ruby-doc.org arity

Posted in  | Tags  | no comments

Fun with String class methods

Posted by root Sat, 14 Jun 2008 13:45:00 GMT

class MyString < String
  # not really useful
  alias + concat

  # emulates Array '*' method
  def *(string)
    self.split('').inject('') do |s1,c|
      s1 + c + string
    end
  end

  # emulates Array '-' method
  def /(string)
    (self.split('') - string.split('')).to_s
  end

  # chars' delimiter
  def delimiter(string)
    self.*(string).sub /.$/, ''
  end

end

a = MyString.new("abcdef")
b = MyString.new("ABCDEF")

puts a * ':'
puts a / (b + "a")
puts a.delimiter(":")

#a:b:c:d:e:f:
#bcdef
#a:b:c:d:e:f

Posted in  | Tags ,  | no comments

downloader

Posted by root Mon, 09 Jun 2008 08:09:00 GMT

#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize;
use LWP::Simple;
use Data::Dumper;
use Time::HiRes qw( usleep tv_interval gettimeofday );
$|++;
my $url  = shift || die "no url given!\n";
my $ext  = shift || 'mp3'; #die "no file extention given!\n";
my $mech = WWW::Mechanize->new(agent=>"Mozilla/5.0");
my $ua   = LWP::UserAgent->new;
my %seen;

$mech->get($url);
$ua->timeout(5);

my $links = $mech->links;

no warnings;
my $c = 0;
for my $link ( @{$links} ) {
        my $url  = $link->url_abs;
        my $res  = $ua->head($url);
        my $http_res   = HTTP::Response->new($res);
        my $abs_name   = $http_res ->{'_rc'}->{'_previous'}->{'_headers'}->{'location'};
        my ($rel_name) = $abs_name =~ /.+\/(.+)$/;
        my $local_name = $rel_name;

        $seen{$local_name}++ and next;

        if( $rel_name =~ /\Q$ext\E$/i ){
                $rel_name =~ s/\%\d+/ /g;
                $rel_name =~ s/(.{35}).+/$1.../;
                print(pack('A45', "[$rel_name]"), "  is being downloaded ... ");
                my $s_time = q{};
                my $e_time = q{};
                my $flag = [];

                for( 1..5 ){
                        local $SIG{ALRM} = sub { die("timeout") };
                        eval {
                           alarm(10);
                           $flag = [head($abs_name)];
                           alarm(0);
                        };
                        next if $@ =~ m|timeout|;
                        last if $@ !~ m|timeout|;
                }

                if( $flag->[0] ){
                        $c++;
                        $s_time = [gettimeofday];
                        getstore($abs_name, $c."-".$local_name);
                        $e_time = tv_interval ($s_time, [gettimeofday]);
                }

                $e_time =  $e_time ? $e_time . " seconds" : 'less than 1 milisecond';
                print "timeout failure in $e_time seconds :(\n" and next if $@;
                print "done in $e_time\n";
        }
}

`ruby -e 'Dir["*"].each{|f| File.rename f, f.sub(/^\d+-/, "")}'`;
`ruby -e 'Dir["*"].each{|f| File.rename f, f.gsub(/%20/, "_")}'`;

Posted in  | Tags  | no comments

cheat sheets

Posted by root Fri, 30 May 2008 00:06:00 GMT

command-line cheat sheets

279 cheat sheets:
$cheat sheets
$cheat unix_text

One of Unix’s most useful features is its large number of text/data manipulations programs. Some of the more propular include:

cat - concatenate and display files
cut - remove selected fields from each line of a file
sort - sort and collate lines
uniq - remove or report adjacent duplicate lines
awk - pattern scanning and processing language
sed - stream editor
tr - translate characters
diff - display line-by-line differences between pairs of text files
grep, egrep, fgrep - search a file for a string or regular expression
paste - join corresponding lines of several files, or subsequent lines of one
file
colrm - remove characters from specified columns within each line
expand, unexpand - expand TAB characters to SPACE characters, and vice versa

Posted in  | Tags  | no comments

Older posts: 1 ... 3 4 5 6 7 ... 10