2011 in review


The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

A San Francisco cable car holds 60 people. This blog was viewed about 2,300 times in 2011. If it were a cable car, it would take about 38 trips to carry that many people.

Click here to see the complete report.

Advertisements

Create new mysql user with grant option


Login in mysql using:

$ mysql -u root -p

First create a database using:

mysql> create database dbname;
Query OK, 1 row affected (0.00 sec)

Then in mysql shell create new user using:


mysql> create user 'username'@'localhost' IDENTiFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on dbname.* to 'username'@'localhost' with grant option;
Query OK, 0 rows affected (0.00 sec)

Or you can use ‘%’ wildcard if you want to connect mysql from any host:

mysql> create user 'username'@'%' IDENTiFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on dbname.* to 'username'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

For more details visit mysql manual.

Create and Import dumpfile or SQL datafile into mysql database


Here are few commands to easily create and import MySQL data.

To create dumpfile:
mysqldump -u USER -p PASSWORD DATABASE > filename.sql

To import dumpfile:
mysql -u USER -p PASSWORD DATABASE < filename.sql

Export MySQL database structure only:
mysqldump -u USER -p PASSWORD --no-data DATABASE > filename.sql

Export data of MySQL database only:
mysqldump -u USER -p PASSWORD --no-create-info DATABASE > filename.sql

To create dumpfile of all databases:
mysqldump -u USER -p PASSWORD --all-databases > filename.sql

To import dumpfile when either database name is not known or dump has database info:
mysql -u USER -p PASSWORD < filename.sql

USER : database username
PASSWORD : password
DATABASE : database name to which datafile is to be imported

cls: command not found


I used ‘cls’ for it does clear screen and ls.
After I upgraded my ubuntu, i can’t use that any more. It showed:

cls: command not found

Finally I have found the solution.

You have to create a alias for the command you want to use.
For example, for cls

$ alias cls='clear;ls'

You can make more aliases,

$ alias cll='clear;ls -lh'

These aliases will vanish on your next login. So to make the change permanent you can add it to your ~/.bashrc or ~/.bash_profile. Just add the whole alias line as these files are executed (as bash scripts) on login.

Install network simulator on ubuntu


This blog post is regarding installing network simulator on Ubuntu.

Make sure you have the following packages installed:

build-essential autoconf automake libxt-dev libx11-dev libxmu-dev

Download ns-allinone-2.34.tar.gz. Then execute the following using command prompt:

tar -xzf ns-allinone-2.34.tar.gz 
cd ns-allinone-2.34
./install

For Ubuntu 9.10 (karmic), you may encounter this error in the linking of otcl:

otcl.o: In function `OTclDispatch':
  /your/path/ns-allinone-2.34/otcl/otcl.c:495: undefined reference to
`__stack_chk_fail_local'
  otcl.o: In function `Otcl_Init':
  /your/path/ns-allinone-2.34/otcl/otcl.c:2284: undefined reference to
`__stack_chk_fail_local'
  ld: libotcl.so: hidden symbol `__stack_chk_fail_local' isn't defined
  ld: final link failed: Nonrepresentable section on output
  make: *** [libotcl.so] Error 1

This error is because the linker being used is “ld -shared” instead of “gcc -shared”. If you edit one line in otcl-1.13/configure, and rerun install, it should work:

--- configure.orig      2009-11-02 12:14:52.556167945 -0800
 +++ configure   2009-11-02 12:17:28.966706099 -0800
 @@ -6301,7 +6301,7 @@
          ;;
      Linux*)
          SHLIB_CFLAGS="-fpic"
 -        SHLIB_LD="ld -shared"
 +        SHLIB_LD="gcc -shared"
          SHLIB_SUFFIX=".so"
          DL_LIBS="-ldl"
          SHLD_FLAGS=""

After a long wait and a whole lot of text, you should see the installation finish up with text like the following:

Nam has been installed successfully.
Ns-allinone package has been installed successfully.
Here are the installation places:
tcl8.4.11:      /your/path/ns-allinone-2.34/{bin,include,lib}
tk8.4.11:               /your/path/ns-allinone-2.34/{bin,include,lib}
otcl:           /your/path/ns-allinone-2.34/otcl-1.13
tclcl:          /your/path/ns-allinone-2.34/tclcl-1.19
ns:             /your/path/ns-allinone-2.34/ns-2.34/ns
nam:    /your/path/ns-allinone-2.34/nam-1.14/nam
xgraph: /your/path/ns-allinone-2.34/xgraph-12.1
gt-itm:   /your/path/ns-allinone-2.34/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns


Please put /your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.19/unix:/your/path/ns-allinone-2.29/tk8.4.18/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.

IMPORTANT NOTICES:

(1) You MUST put /your/path/ns-allinone-2.34/otcl-1.13, /your/path/ns-allinone-2.34/lib, 
    into your LD_LIBRARY_PATH environment variable.
    If it complains about X libraries, add path to your X libraries 
    into LD_LIBRARY_PATH.
    If you are using csh, you can set it like:
                setenv LD_LIBRARY_PATH 
    If you are using sh, you can set it like:
                export LD_LIBRARY_PATH=

(2) You MUST put /your/path/ns-allinone-2.34/tcl8.4.19/library into your TCL_LIBRARY environmental
    variable. Otherwise ns/nam will complain during startup.

(3) [OPTIONAL] To save disk space, you can now delete directories tcl8.4.18 
    and tk8.4.18. They are now installed under /your/path/ns-allinone-2.34/{bin,include,lib}

After these steps, you can now run the ns validation suite with
cd ns-2.34; ./validate

For trouble shooting, please first read ns problems page 
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive
for related posts.

If your ubuntu version is 9.10, you must change the variable of environment CC if not set

$ export CC=gcc-4.3

Now, You have to set environment variables

$ gedit ~/.bashrc 

Replace /your/path with the path to parent directory of ns-allinone-2.34.

# LD_LIBRARY_PATH
OTCL_LIB=/your/path/ns-allinone-2.34/otcl-1.13
NS2_LIB=/your/path/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB

# TCL_LIBRARY
TCL_LIB=/your/path/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.18/unix:/your/path/ns-allinone-2.34/tk8.4.18/unix
NS=/your/path/ns-allinone-2.34/ns-2.34/
NAM=/your/path/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM

Ensure that it immediately takes effect:

$ source ~/.bashrc

Validation of the installation can be tested by:

$ cd ns-2.34
$ ./validate

Now, installation of network simulator is done. Enjoy coding.

How to delete useless file in Ubuntu


Using gedit creates lot of temp files of pattern “*~”. And if you are working in multiple directories its really hard to get to all these directories and delete these files.
Also, people want to delete “Thumbs.db” from windows directories but don’t know how.

Here is a solution:

This will find all the files,

find /path_to_directory -type f -name "file_pattern"

To delete these files, you can use

find /path_to_directory -type f -name "file_pattern" -exec rm -f {} \;

where /path_to_directory is path to directory from which you want to delete the files having pattern or name file_pattern recursively.

For example, to remove files like program.cpp~ created by gedit you can use

find /home/user -type f -name "*~" -exec rm -f {} \;

and to remove Thumbs.db from windows directories you need to do

find /media -type f -name "Thumbs.db" -exec rm -f {} \;

If you want to examine the files that are going to be deleted before doing it, you should execute the same command, changing ‘rm’ for ‘ls’, like this:

find /path_to_directory -type f -name "file_pattern" -exec ls -f {} \;

In this way you may control the list of files to delete.

PS: \; is necessary.
I hope this helps.

Mathmania Report


On 13th Mar, Codefest was proud to have world’s top coders and mathematical geeks as participants in first of the three live contests, MathMania,
mathematical puzzle contest.

Overall 954 participants across 54 countries competed in the gruelling battle. It was a 6 hour contest with 10 mathematical puzzles for which participants were required to only provide the answers.

KoenR from Netherlands won the contest and was the only person to solve all the 10 problems correctly.
DrKorbin and Silence both from Russia bagged 2nd and 3rd positions with 185 and 150 points respectively.
Complete ranklist is available at http://itbhu.ac.in/codefest/mm-full-scoreboard.php. There are only 5 indians ( 2 from IT-BHU) in top 30 and that includes 4 professionals also.

The intensity of the competition can be imagined by the fact that ACRush (Google CodeJam 2008 and 2009 winner) solved the first problem in 8 mins and KoenR solved Problem 7 in the very last minute to snatch the first prize from DrKorbin. It was indeed a pleasure for the event administrators to see the actual scoreboard fluctuating almost every minute of the contest.

It was great for all of us to have positive feedbacks regarding the level of problems and the organization of the event from the various participants.