Archive for the ‘code’ Category

Backing up a mysql Database to your email

Saturday, October 17th, 2009

I needed to backup a mysql database on a computer different from the one on which it was running and I set a cron task executing the commands below:


mysqldump -ce --user=username --password=password dbname | gzip | uuencode dbbackup_e.gz | mail email@address.com

The backup file in compressed .gz format will be mailed to the email that you specify and will always have a small size as a result of the enconding and compression.

Enjoy as you backup your data!

Displaying commas in php

Sunday, March 1st, 2009

For long, whenever I needed to format my figures (.. am talking of bucks), I had to write a new UDF to handle that. Just today when I was running through the php manual that I came across this neat function. — number_format()
Usage:
Supposing my variable that displays the currency where I need the thousand separator to be commas is $amount,

What I needed to do is to pass the variable as an argument, to the function and here is the code snippet that worked for me.

//other code lines

$amount =number_format($amount);

//other code lines
?>

It did the magic for me and when the amount was One million it was displayed like : 1,000,000

Have fun and enjoy as well!

Setting up ns2 on your linux box

Monday, February 23rd, 2009

It was just this normal day and a friend asks me to lend a hand and setup ns2 on his laptop which was running susse linux.

After some 5 attempts, i finally found some post on the web by some guy and it really helped a lot and at the end of the sixth attempt, i had already started simulating networks.

The procedure is shown below:

NS2 Installation for Starters
How to install NS 2 on Linux, The step by Step Procedure

Step 1:Get NS2 All in one package from the below link or by clicking here

Step 2:Copy the tar file in /home/

Step 3:Extract the tar file located in /home/ #tar -zxvf File name

Step 4:#cd

Step 5:#./install
/* This will run the install Script, wait for the output */

Step 6:Now it is the time for setting environment variable, Copy the message displayed after running the above commmand to a text file else copy and paste this in a new text file ===================================
PATH=$PATH:/home/ns-allinone-2.31/bin:/home/ns-allinone-2.31/tcl8.4.14/unix:/home/ns-allinone-2.31/tk8.4.14/unix
LD_LIBRARY_PATH=/home/ns-allinone-2.31/otcl-1.13:/home/ns-allinone-2.31/lib

TCL_LIBRARY=/home/ns-allinone-2.31/tcl8.4.14/library
export PATH
export LD_LIBRARY_PATH
export TCL_LIBRARY
================================
Step 7:save the file as ns2.sh

Step 8:copy the file into /etc/profile.d/

Step 9: either restart the machine or relogin

Step 10:Now run these commands
#cd ns-2.31/
#./configure
#make
#make clean
#./validate

Step 11: all done , just type ns at terminal
e.g. #ns
%

and it is ready !
Enjoy simulating networks, protocols whatever you like, All the Best !