選擇

December 23, 2009 Posted by vanyell

作詞:陳大力 作曲:陳大力/陳秀男 
編曲:Ricky Ho 女聲:葉蒨文 男聲:林子祥

男:風起的日子 笑看落花
女:雪舞的時節 舉杯向月
男:這樣的心情
女:這樣的路
合:我們一起走過

女:希望你能愛我 到地老 到天荒
男:希望妳能陪我 到海角 到天涯
合:就算一切重來 我也不會改變決定
合:我選擇了你
合:你選擇了我 哦…

女:我一定會愛你 到地久 到天長
男:我一定會陪妳 到海枯 到石爛

合:就算回到從前 這仍是我唯一決定
女:我選擇了你
男:你選擇了我
合:這是我們的選擇

男:走過了春天 走過秋天
女:送走了今天 又是明天
男:一天又一天
女:月月年年
合:我們的心不變

My first perl script…

November 23, 2009 Posted by vanyell

As a technical support engineer,  I would need to send multiple spam samples through our product for detection rate.  I initially used a bash script to send the samples through via telnet command.  The drawback was that the processing was sequential (slow).  I was already thinking of how to use threading to send the samples through in large batches which finishes the job a lot faster and at the same time enables me to tune the performance of our product when handling multiple connections.  Finally, after a great deal of procastrination, I finally hacked together a perl script to do the job, after googling and modifying some ther perl scripts.  I used the script from http://pentestit.com/2009/05/20/source-code-perl-multithreaded-scanner-webdavenabled-servers/ as basis for my script.


#!/usr/bin/perl -w

$|++;
use strict;
use 5.008;
use threads;
use threads::shared;
use Thread::Queue;
use Net::SMTP;

our $thrnum:shared=100;
our $q:shared;
our @threads;

sub smtp_send {

    my $target='192.168.50.135';
    my $filename;
    my $line;
    my @message;

    my $dir = shift;

    if ($dir =~ m/\/$/) { } else { $dir = $dir."/";};

    $filename  = shift;
#   print "Opening connection to target : ".$target."\n";
#   print "Filename: ".$dir.$filename."\n";
    $filename=$dir.$filename;

    open FILE, $filename or die $!;
    @message=
    close FILE;

    if (my $smtp = Net::SMTP->new($target,Hello=>'peters.eatsc.ts',Timeout=>30,Debug=>0)) {;
        $smtp->mail('test@test.bng');
        $smtp->to('peters@eatsc.ts');
        $smtp->data(@message);
        $smtp->quit;
        } else {
            die;
               };
}

sub main {
    my $dir;
		my $spamfile;
		my $running;

		$q = new Thread::Queue;
		$dir = shift;

		opendir (DH, $dir);
		while (defined ($spamfile=readdir(DH))) {
				unless ($spamfile =~ /^.{1,2}$/) {
						$q->enqueue($spamfile);
				}
		}
		closedir(DH);

		while (1){

				@threads = threads->list;
				if ($q->pending > 0) {
#       		print "Pending items: ".$q->pending." \n";
						if ($#threads <= $thrnum+1) {
								threads->new(\&spam_send,$dir,$q->dequeue);
#            		print "Adding new thread ".$#threads." \n";
						} else {
								foreach $running(@threads) {
										$running->join;
#                   print "Freeing thread: ".$#threads." \n";
								};
						};
				} else {
						if ($#threads >= 0) {
								foreach $running(@threads) {
										$running->join;
#                   print "Freeing thread: ".$#threads." \n";
								};
        		exit;
				    };
    };
#    print "\nThread count:" .$#threads;
}

&main($ARGV[0]); #input directory name as command-line parameter.

I will be recoding this script in python and ruby to check which one will run faster (not that I expect that there will be a huge change in performance, but a programming exercise for me).

State of calamity and oil price hike

October 30, 2009 Posted by vanyell

Just these past few days, the Big Three raised pump prices by 2 pesos at most.  The government, legislators and militant groups immediately raised their ferocious objections against this insensitive move.  The Palace even passed an Executive Order mandating the immediate rollback of the price increase.   This, IMHO, is just a short term solution to beef up the sagging reputation of the current administrator, and at the same time, serves as a trumpet call by those politicians hankering for public limelight.

Oil price increase is inevitable.  Oil is a decreasing commodity.  In time, market forces will demand the price increase.  What our politicos should do is explore renewable sources of energy and ways to lessen our consumption of petroleum products.  This is a far more effective way of combating the incessant oil price increase.  But I doubt if they will ever seriously consider taking these needed steps, since they are known more for blowing hot air than doing things.

Streamline the public transport system.  We have too many buses and jeepneys, which are not even fuel-efficient.  Worse yet, they are among the top contributors of air pollution.  Water and rail transport are feasible alternatives only if our national and local government officials would stop pandering to other stuff for their own advantage.

Tidal generators to generate electricity.  We are an archipelago, for crying out loud.  Too costly, they say?  Stop corruption, then we will have enough money to implement these.