Saturday, March 30, 2013

Are good solutions always expensive?

Almost every day I'm confronted with dilemma's and problems that need an adequate solution. Many people inside my company ask me advice about how solving problems or finding the best solutions for. Sometimes finding solutions means make investments or spend money to buy goods or services for the company. Expensive solutions seems almost always to be the best but… is that true? Before I take a decision on a matter I keep always a story in my mind about the NASA and the Russians; I don't know if this story is true, but I think it's a great example how sometimes things work. Read… "When NASA first started sending up astronauts in the cold space, they quickly discovered that ballpoint pens would not work in zero gravity. To solve this the problem, NASA scientists spent a decade and $12 millions to develop a pen that writes in zero gravity, upside down, underwater, on almost any surface including glass and at temperatures ranging from below freezing to 300 C. The Russians used just a normal pencil." What can we learn from this story? I guess… if you are looking for a solution, clear your mind and think simple, but most of all… THINK!

Saturday, March 23, 2013

Mysql backup shell script

This is a shell script that allows you to backup your MySql databases and mail a compressed file to you. Of course if the backup becomes huge, you can better set the mail option off.
In the script you can give the database(s) you want to back up in an array. The script iterates the array and select the tables to back up.

In the given folder there are 4 sub folders for back up rotation. Every day is the new back up dumped in folder 01. 

Here below the script:



  # modify the destination directory to suit your environment
  export DB_BACKUP="/var/www/backup"

  # rotation ######################
  # remove day 4
  rm -rf $DB_BACKUP/04
  # moves day 3 to day 4
  mv $DB_BACKUP/03 $DB_BACKUP/04
  # moves day 2 to day 3
  mv $DB_BACKUP/02 $DB_BACKUP/03
  # moves day 1 to day 2
  mv $DB_BACKUP/01 $DB_BACKUP/02
  # makes dir 01 for day 1
  mkdir $DB_BACKUP/01
  # end rotation commands #########

  # define array of the database to bak up
  array=( db1 db2 )

  # loop through the array (each database to bak up)
  for db in "${array[@]}"

    # loop through the tables of the database
   for i in `echo "show tables" | mysql -u UserNameHere -pYourPasswordHere $db | grep -v Tables_in_`;
     # dumps the sql of the table to a compressed file with a database name prefix to hold the tables together
      mysqldump --add-drop-table --allow-keywords -q -a -c -u UserNameHere -pYourPasswordHere $db $i | gzip -9 > $DB_BACKUP/01/${db}_$i.sql.gz


  # makes a single compressed file of the backups
  tar -cvzf $DB_BACKUP/db_backup.tar.gz $DB_BACKUP

  # sends the file to your emailbox (you have to have sharutils and mailutils installed)
  uuencode  $DB_BACKUP/db_backup.tar.gz db_backup.tar.gz | mailx


Wednesday, March 13, 2013

How to get a Mustek 600 CP scanner working in Ubuntu

I have an old scanner Lifetek that I bought years ago at the Aldi market. It is an old scanner I know, but I do not need some spectacular job, just sometimes a simple scanning job. The scanner does not work over USB, as I said it's a 'grand fa'. I faced the problem to get it working in Ubuntu under 'sane'. After some research I came to know that Lifetek is a sub brand that Mustek made for Aldi.

With the following i was able to shake it alive:

1. Edit /etc/sane.d/mustek_pp.conf, by uncommenting the right line:
# Uncomment/customize to your needs ... mine was the first one
# scanner Mustek-600CP 0�378 cis600
#scanner Mustek-1200CP 0�378 cis1200
# scanner Mustek-1200CP+ 0�378 cis1200+
# scanner Mustek-600-IIIEP 0�378 ccd300

2. Edit /etc/sane.d/dll.conf by uncommenting mustek_pp:

3. Save the following script as /etc/init.d/mustek:
chmod 777 /dev/lp0 # Does it hurt?
chmod 777 /dev/parport0

4. Execute the following commands:
sudo chmod a+x /etc/init.d/mustek
sudo update-rc.d mustek defaults


Sunday, March 10, 2013

Broadcom wireless on Unbuntu

I got a lot of headache when I had to reconfigure the wireless of my wife's laptop after installing xubuntu. My wife's laptop is a Dell Vostro 1000 with a Broadcom card (BCM4311). This is a issue because it is not supported out of the box. After a lot of trial and error (a lot of) I found the way of getting it work. Here below the commands:

open a shell box and digit:

sudo apt-get update
sudo apt-get remove --purge bcmwl-kernel-source
sudo apt-get install linux-firmware-nonfree
sudo modprobe b43
sudo reboot
After these commands the pc should reboot and you should have your wireless up and running. Do not forget to check that the laptop hardware wireless is ON.

If it doesn't work... please do not shoot on the pianist!

Secure GET

This class can generate and validate URLs to prevent tampering.

It takes an associative array of parameters to pass in a link.

The class assembles the link parameter keys and values and adds an extra parameter which is the SHA1 value of all parameters adding a secret prefix and a suffix salt values.

The class can also verify if the parameter values are correct in a page of the previously generated URL checking against the passed SHA1 value.

Download the package at

The class:


class secure_get {
    var $arr_get;
    var $salt1;
    var $salt2;
    var $sha1;
    var $link;
    function __construct(){
       $this->salt1 = 'e5dg6hyt7u8fgigg802s';
       $this->salt2 = '4nfgs5asdd320dkjh7kd';
    public function secure_make($arr=array()){
        $this->sha1 = $this->salt1;
        $this->link = '?';
        foreach($arr as $key => $val){
            $this->sha1 .= $key.$val;
            $this->link .= "&".$key."=".urlencode($val);
        $this->sha1 .= $this->salt2;
        $this->sha1 = sha1($this->sha1);
        $this->link .= "&sha1=".$this->sha1;
    public function secure_check($arr=array()){
        $this->sha1 = $this->salt1;
        foreach($arr as $key => $val){
            if($key != 'sha1') $this->sha1 .= urldecode($key.$val);
        $this->sha1 .= $this->salt2;
        $this->sha1 = sha1($this->sha1);
        if($this->sha1 == $arr['sha1']) return(TRUE);


and how to use it:


$arrValues = array('city'=>'Amsterdam', 'name'=>'J. Rambo', 'age'=>'45');

$sg = new secure_get;

$link = $sg->secure_make($arrValues); 

 * checks if the data is sent properly
   echo($sg->secure_check($_GET)) ? 'SENT PROPERLY' : 'SENT WITH MANUPULATION';


About "Real scripting"

Hi everyone; I'm a rich internet applications developer and I will publish in this blog everything I think is useful to avoid you some headache. Useful scripts in php, shell, vbs and JavaScript. I will publish other info too that maybe will help you in your search journey on the web. If you need professional developing you can reach me also on my website

Today I was implementing the Gapi Google analytics php interface and I struggled in a issue in the account settings.

This is the url of the class:

In order to get you data from Google you have to fill your account data (see below):

define('ga_password','your password');
define('ga_profile_id','your profile id');

Right, everything OK till the ga_profile_id; this id seems to me almost impossible to find in your dashboard. I tried the id's of the tracking code that you have to insert in the tracked page, but without success.

After almost an hour of research I was able to find my code. The code is the number that you find in the URL of your Google analytics page after the p character

Here an example:

Use that code as ga_profile_id and you will be able to authenticate and get your data.