2009-08-31

 

Amazing stuff...

Here's an interesting product called "d3o" that provide amazing impact protection.

Some movies:

First, the official d3o movie:



And here's a Discovery channel clip:



Can't wait to play with it myself :-)

2009-08-28

 

The story of the Seacom cable

Found this video on the SEACOM site. Interesting background.


2009-08-18

 

FNB Connect Speed Test


Ah... This is how ADSL should be :-)

2009-08-17

 

Disrict 9 Trailer and some related info

Trailer



And here is a look at two other short clips:

"Alive in Joburg" on which District 9 was based:



And"Tetra Vaal":


2009-08-06

 

[Perl] Check if DB table exists

Building on the script of yesterday, I have created a subroutine that will create a table if it doesn't exist. It also uses a DB connect retry for up to an hour in cases where the DB is not available.

The input arg's of the sub:

  1. The table name
  2. The table create definition
Here is the script:

sub CheckTables {

my( $tblname, $tbldef ) = @_;

# Connect to DB
my $cont = 0;
my $tries = 0;
my $dbh1;
while( not $cont ) {

$tries++;
eval {

$dbh1 = DBI->connect( "dbi:mysql:database=$dbdb;host=$dbhost;port=$dbport", "$dbuser", "$dbpass" );

};

if( $@ ) {

sleep( 1 );

} else {

$cont++;

}

if( $tries > 3600 ) {

# We have been trying for an hour - give up
print "CheckTables_GIVE_UP\t1\n";
exit;

}

}

my $sql = "show tables like '$tblname'";
my $sth = $dbh1->prepare( $sql );
my $exists = 0;
if( $sth->execute() ) {

while( my $t = $sth->fetchrow_array() ) {

if( $t =~ /^$tblname$/ ) { $exists = 1; }

}

}

# If table didn't exist, create it
if( not $exists ) {

# Attempt to create table
$dbh1->do( $tbldef );

# Check again
$sth = $dbh1->prepare( $sql );
if( $sth->execute() ) {

while( my $t = $sth->fetchrow_array() ) {

if( $t =~ /^$tblname$/ ) { $exists = 1; }

}

}

}

$dbh1->disconnect;

return $exists;

}


2009-08-05

 

[Perl] Waiting for a DB connection to become available

While working on Hadoop, I found that connecting to a DB to get or insert data presented a problem as you often need more connections then what's available. My solution right now is to "wait" for a connection to become available - without using any fancy queuing mechanisms:
# Connect to DB
my $cont = 0;
my $tries = 0;
my $dbh1;
while( not $cont ) {

$tries++;
eval {

$dbh1 = DBI->connect( "dbi:mysql:database=$dbdb;host=$dbhost;port=$dbport", "$dbuser", "$dbpass" );

};

if( $@ ) { sleep( 1 ); } else { $cont++; }

if( $tries > 3600 ) {

# We have been trying for an hour - give up
print "GIVE_UP\t1\n";
exit;

}

}


And that's it. When the while loop finally exists, you have a DB handle to use. In the above example we retry for more then an hour - which should be sufficient for most scenarios.

Hope some one else find it useful as well.

Labels: , , ,


This page is powered by Blogger. Isn't yours?