Blog

Trust & Nigeria: Our unborn children need us

January 1st, 2012. Nigerians got a gift. The PPPRA’s announcement of government’s removal of its subsidy on Premium Motor Spirit (PMS / Petrol). Prompting an immediate hike in pump price.

Sudden, yet not sudden. Since October 2011, Our President, Jonathan Goodluck and his cabinet have tried via several means to get Nigerians to say “yes” to the removal. They failed. Even the National House of Assembly disagreed. The removal was enforced by executive order.

I will attempt to bring three things to light here:

  • My understanding (without any numbers) of why subsidy should be removed
  • The impact of the removal on Nigerians’ everyday lives
  • The singular reason we cannot entrust more funds to our government – Trust!

Nigeria needs to stop subsidizing PMS. This is mostly because a large percentage of the money given as subsidy to marketers cannot be justified. Even audit firms called to verify the monies the marketers request have been compromised. Trust is lacking. Another reason is the source of oil subsidy. That our government subsidizes PMS by obtaining foreign loans is concerning. If this continues, foreign debt will mount and as Governor Oshiomhole of Edo state puts it, Nigeria will go bankrupt in no time.

Poverty will take a quantum leap in a few weeks. Jobs will be lost. Companies will go under. Farm produce will go to waste. Citizens (and not-so-citizens) will flee. Why is this? The Nigerian economy, until December 31st 2011, sat shakily on power generated from numerous petrol generators. More than three-quarter of Nigeria’s transportation is by road, in petrol-burning vehicles. A commodity on which two most vital aspects of our livelihood depends has just doubled (tripled in some areas) in price.

In response, Nigerians have taken to the streets – protesting and registering their anger at the inconsiderate action taken by our rulers. Note that I am careful not to refer to the government as leaders. A leader will be the first to take a plunge before asking followers to step on the edge. Our rulers ask us to adjust to a life of greater hardship but are unwilling to live less luxuriously.

Our government has done nothing to make us trust their judgment, words or actions for a long time now. We need LEADERS we can TRUST, who will work selflessly to make Nigeria an enabling society that allows all citizens flourish.

Stand up. Make the “ruling class” understand that we won’t accept their way of handling things anymore.

A word though before you join in: can you TRUST yourself to be forever true to the cause, to never falter?

Thanks. Future generations will thank you.

Written on January 3rd, 2012. 0 Comments

Secure Solution System Website

Secure Solution System Website

The website for Secure Solution System limited. 

http://www.securesolutionsystem.com

 

 

 

 

Written on September 7th, 2011. 0 Comments

Salat Clock

Salat Clock

Salat Clock: Get mentioned on twitter 5 to 10 minutes before salat in your city.

Written on August 1st, 2011. 1 Comment

Class Base-36 (alphabets and numbers as digits) conversion

Recently I find me writing code that requires having a “code” for each item saved. To make my tasks easier and portable, I have created a PHP class called base36 to automate the task of converting to and from base10 (integer). The class is included below. A second class base26 is included in case you’d prefer to use just alphabets.

How do I mean?

Say you create a shopping cart and need to have order codes for each order on the site, using numbers can be very clumsy. Or you have a database of customers. Your customers will mostly get a numeric code assigned to them. Very few can remember the code easily.

Now for the scenarios depicted above, imagine that you could assign an alphanumeric non-case-sensitive code. It takes away the stress of having to remember very long numbers. A customer with order code “AGOOD1″ is less likely to forget or even get it wrong than if the order code were say “632686933″ (That’s the equivalent in base36).

However, note that with the class included below, the biggest code you can get is “ZIK0ZJ”. This is due to the integer limit of PHP being 2147483647. I had to copy and paste that even after knowng it for over 8 years! ZIK0ZJ, on the other hand I just knew yesterday and could type by hand. #justsaying. And the highest for base26 is “GYTISYX”.

Here are the classes:

Base 36:

class base36{
  public static function from10($base10){
   // $base10 stores a value in base 10
   // solution will have digits in an array

   if (!is_numeric($base10)){
      return '0';
      //if this were python I'da thrown an exception
      //but this is PHP #SMH
   }
   if ($base10>2147483647){
      return '0';
      //same excuse as above
   }

   $stringrep='';
   $index = 0 ;
   while ( $base10 > 0 )
    {
       $remainder = $base10 % 36 ;
       $base10       = (int) ($base10 / 36) ;  // integer division
       $stringrep =  base36::mychr($remainder) . $stringrep;
       $index ++ ;
    }

    if ( $stringrep==''){
      return '0';
    }

    return $stringrep;
  }

  public static function to10($base36){
    //only upper case, unless we'd like to do a base 62!
    $base36 = strtoupper($base36);

    //i'da loved to do thorough check for strictly alpha
    //and numeric digits here but
    //too lazy to do that right now
    $decval=0;
    $len=strlen($base36);

    for($i=0;$i<$len;$i++)
    {
      $digval = base36::myord($base36{$i});
      $digpower = $len-$i-1;
      $decval += (pow(36,$digpower)*$digval);
    }

    return $decval;
  }

  public static function mychr($ordinal){
    if($ordinal>=10){
      return chr(55+$ordinal);
    } else if($ordinal>=0){
      return $ordinal;
    } else return 0;
  }

  public static function myord($character){
    if(is_numeric($character)){
      return (int) $character;
    } else {
      return ord($character)-55;
    }
  }
}

and Base 26

class base26{
  public static function from10($base10){
   // $base10 stores a value in base 10
   // solution will have digits in an array

   if (!is_numeric($base10)){
      return 'A';
      //if this were python I'da thrown an exception
      //but this is PHP #SMH
   }
   if ($base10>2147483647){
      return 'A';
      //same excuse as above
   }

   $stringrep='';
   $index = 0 ;
   while ( $base10 > 0 )
    {
       $remainder = $base10 % 26 ;
       $base10       = (int) ($base10 / 26) ;  // integer division
       $stringrep =  chr($remainder+65) . $stringrep;
       $index ++ ;
    }

    if ( $stringrep==''){
      return 'A';
    }

    return $stringrep;
  }

  public static function to10($base26){
    //only upper case, unless we'd like to do a base 62!
    $base26 = strtoupper($base26);

    //i'da loved to do thorough check for strictly alpha
    //digits here but...
    //too lazy to do that right now
    $decval=0;
    $len=strlen($base26);

    for($i=0;$i<$len;$i++)
    {
      $digval = ord($base26{$i})-65;
      $digpower = $len-$i-1;
      $decval += (pow(26,$digpower)*$digval);
    }

    return $decval;
  }
}

Usage:

$mycode = base36::from10($anumber);
$mynumber = base36::to10($code);

//$mycode now contains the base36 equivalent of $anumber
//$mynumber now contains the base36 equivalent of $acode

Download code here: base36.class.php.zip

Written on July 14th, 2011. 0 Comments

Easy Automated cPanel BackUp

Hi there,

After attempting a manual backup of 75 sites, i got tired and tried to google an answer to my issue i found this: http://forums.cpanel.net/f49/script-backup-only-sql-only-homedir-139881.html except this meant a cron job, and probably creating a file per domain. for 75 domains i felt too lazy to try that. so I extended it and encapsulated it in a class. Here’s the script I use now:

<?php

// Class that does cPanel backups automatically to a remote FTP server.
// This script will contain passwords.  

/***** KEEP ACCESS TO THIS FILE SECURE! *****/

//(place it in your home dir, not /www/)

class BackUp{

  // Info required for cPanel access
  public $cpuser; // Username used to login to CPanel
  public $cppass; // Password used to login to CPanel
  public $domain; // Domain name where CPanel is run

  public $skin="x3"; // Set to cPanel skin you use (script won't work if it doesn't match).
                     // Most people run the default x3 theme

  // Info required for FTP host
  public $ftpuser = "ftpuser"; // Username for FTP account
  public $ftppass = "ftppass"; // Password for FTP account
  public $ftphost = "ftphost"; // Full hostname or IP address for FTP host
  public $ftpmode = "ftp";     // FTP mode ("ftp" for active, "passiveftp" for passive)

  //in case the domain you need to back up is currently not live (expired or any other reason)
  //specify a domain that is live and is on the same server as the one you are attemting to backup
  //e.g your reseller domain
  public $livedomain="";

  //what email should be notified after the backup is complete?
  public $notifyemail="you@yourdomain.com";

 //what directory should the backup be saved on teh remote server
 //you may need to create this
 public $remotedir="/";

  public function __construct($cpuser,$cppass,$domain,$livedomain="",
                              $skin="", $ftpuser = "", $ftppass = "",
                              $ftphost = "", $ftpmode = "" )
 {
    $this->cpuser = $cpuser;
    $this->cppass = $cppass;
    $this->domain = $domain;
    $this->livedomain = $livedomain;

    //skin,ftppass,ftpuser,ftphost,ftpmode override default when specified via constructor
    if($skin){$this->skin = $skin;}

    if($ftpuser){$this->ftpuser = $ftpuser;}
    if($ftppass){$this->ftppass = $ftppass;}
    if($ftphost){$this->ftphost = $ftphost;}
    if($ftpmode){$this->ftpmode = $ftpmode;}

  }

  function createBackup() {

    $cpuser = $this->cpuser;
    $cppass = $this->cppass;
    //use the live domain if specified
    if($this->livedomain){
      $domain = $this->livedomain;
    } else {
      $domain = $this->domain;
    }
    $skin = $this->skin;

    $ftpuser = $this->ftpuser;
    $ftppass = $this->ftppass;
    $ftphost = $this->ftphost;
    $ftpmode = $this->ftpmode;

    // Notification information
    $notifyemail = $this->notifyemail; // Email address to send results

    // Secure or non-secure mode
    $secure = 0; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP

    // Set to 1 to have web page result appear in your cron log
    $debug = 1;

    // *********** NO CONFIGURATION ITEMS BELOW THIS LINE *********

    if ($secure) {
       $url = "ssl://".$domain;
       $port = 2083;
    } else {
       $url = $domain;
       $port = 2082;
    }

    $socket = fsockopen($url,$port);
    if (!$socket) { echo "Failed to open socket connection... !\n"; return; }

    // Encode authentication string
    $authstr = $cpuser.":".$cppass;
    $pass = base64_encode($authstr);

    $params = "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&email_radio=1&port=21&rdir=$remotedir&submit=Generate Backup";

    // Make POST to cPanel
    fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n");
    fputs($socket,"Host: $domain\r\n");
    fputs($socket,"Authorization: Basic $pass\r\n");
    fputs($socket,"Connection: Close\r\n");
    fputs($socket,"\r\n");

    // Grab response even if we don't do anything with it.
    while (!feof($socket)) {
      $response = fgets($socket,4096);
      if ($debug) echo $response;
    }

    fclose($socket);
  }

  static function runForArray($sites){

    foreach($sites as $tmp_arr){

      $tmp = new BackUp(
        $tmp_arr[0],
        $tmp_arr[1],
        $tmp_arr[2]
      );

      //except for the "$tmp->createBackup()" command,
      //all lines below are just so that we have distinct reports
      echo "<hr />";
      echo "<h1>".$tmp->domain."</h1>";
      echo "<hr />";
      echo '<div style="overflow:hidden; height:300px;">';
      $tmp->createBackup();
      echo "</div>";
      echo '<div style="clear:both; height:20px; background:red;">';
    }
  }
}

?>

Download code: backup.class.php.zip

And this can be called in any of three ways after importing the class file. Use the line below to import the class file:

include 'backup.class.php';

1. Create a new BackUp object and call the backup function thus:

$tmp = new BackUp("cpuser","cppass","domain","livedomain","x3","ftpuser","ftppass","ftphost","ftpmode");

$tmp->createBackup();

Note that except for the first three, you may leave the rest as default and set a generic ftp server to dump your backup files. You can as well set a generic live domain. In case all are under the same reseller account this comes in handy for sites that need backing up but are down for some reason.

2. Create an array and loop through the login details calling backup each time thus:

$sites=array(
  array("site2","passme","site1.com"),
  array("site2","passyou","site2.com"),
  array("site3","one$"."acent","site3.com"),
);

foreach($sites as $tmp_arr){

  $tmp = new BackUp(
    $tmp_arr[0],
    $tmp_arr[1],
    $tmp_arr[2]
  );

  $tmp->createBackup();
}

AND

3. You may just create an array and use the built-in “runForArray” function thus:

$sites=array(
  array("site2","passme","site1.com"),
  array("site2","passyou","site2.com"),
  array("site3","one$"."acent","site3.com"),
);

Backup::runForArray($sites);

And your site backup is complete!

Written on June 9th, 2011. 1 Comment

Ecolab Consult

Ecolab Consult

Built using jquery and a powerful suckerfish menu, this is a stunning website.

Written on April 24th, 2011. 0 Comments

JCI Nigeria Database

JCI Nigeria Database

Built with Django on python, The JCI NIgeria database website allows members to submit their profiles for verification by Exco members. Profile details are only visible to verified members.

Written on April 24th, 2011. 1 Comment

Ludnid Designs

Ludnid Designs

A sizzling website for Ludnid Designs Nigeria: http://ludnid.com

Written on April 24th, 2011. 0 Comments

Search Terms for Twitter

Operator Finds tweets…
twitter search containing both “twitter” and “search”. This is the default operator.
happy hour containing the exact phrase “happy hour”.
love OR hate containing either “love” or “hate” (or both).
beer -root containing “beer” but not “root”.
#haiku containing the hashtag “haiku”.
from:alexiskold sent from person “alexiskold”.
to:techcrunch sent to person “techcrunch”.
@mashable referencing person “mashable”.
“happy hour” near:“san francisco” containing the exact phrase “happy hour” and sent near “san francisco”.
near:NYC within:15mi sent within 15 miles of “NYC”.
superhero since:2010-12-27 containing “superhero” and sent since date “2010-12-27″ (year-month-day).
ftw until:2010-12-27 containing “ftw” and sent up to date “2010-12-27″.
movie -scary :) containing “movie”, but not “scary”, and with a positive attitude.
flight :( containing “flight” and with a negative attitude.
traffic ? containing “traffic” and asking a question.
hilarious filter:links containing “hilarious” and linking to URLs.
news source:twitterfeed containing “news” and entered via TwitterFeed

Written on April 9th, 2011. 1 Comment

Hide proprietary div, p or a using CSS pseudo-classes

DISCLAIMER!! IT’S GOOD TO ALLOW YOU BLOG OR SITE LINK TO A PROVIDER’S SITE ESPECIALLY IF YOU GOT FREE STUFF FROM THEM. USING THIS HACK TO REMOVE LINKS IS NOT EXPRESSLY SUPPORTED BY THE AUTHOR.

Ever downloaded a lot of proprietary software and found it annoying that every page on your site has: Powered by… blah at the bottom. After reading this piece you should have learnt to use pseudo-classes in CSS to remove such.

You can remove these easily if the block were surrounded by a div, p or a element with a class attribute. e.g. if when you inspect the “powered by” element in the page and have something like this:

 

 

<div class="blah_powered_by">
   Powered by: <a href="http://blah.blah">blah</a>
</div>

 

 

This can easily be hidden by including the following in your stylesheet:

p.blah_powered_by{
    display:none;
}

But how do you hide:

<div style="text-variant: capitalize; font-size: xx-small;">
Powered by: <a href="http://blah.blah">blah</a>
</div>

or

<div>
    Powered by: <a href="http://blah.blah">blah</a>
</div>

This requires making use of pseudo-classing for the two samples above.

For the first the pseudo class that will hide it is:


div[style="text-variant: capitalize; font-size: xx-small;"]{
display:none;
}

And the second?:


a[href="http://blah.blah"]{
display:none;
}

Unfortunately, CSS does not allow selecting of the parent element. so for the second option, we only get to hide the link. Using the more advanced XPath selector scheme is the only way we get to hide the whole block. Unless you are willing to do:


div{
display:none;
}

div.displayed{
block;
}

then add a class="displayed" to every div in your pages.

There are a lot more things one can achieve by using the CSS pseudo-class selector. Do share what you have done with them.

Written on March 13th, 2011. 0 Comments

Latest Work

Secure Solution System Website
Salat Clock
Ecolab Consult
JCI Nigeria Database

Latest Blog Posts

My Yahoo Pingbox

Translate

Google +

GTalk

Be Happy! Thats all you need to be!!