Garbage Bag

All my Garbage talks and junk codes

Month: February, 2010

lock and unlock gnome with gsm

tested with :

i) ubuntu 8.10

ii)gnokii

iii) mysql 5

iv) lg kp 199

functionalities :

i) just message “lock” to your server mobile to lock the screen

ii)   “unlock” to release the screen

iii) you can even change the pidgin status by messaging “status:your status here

iv )  execute any shell commands that take return value  below 160  characters

procedure:

step 1)

set the memory for sms to sim and run the smsd daemon as

sudoo /usr/sbin/smsd -u root -d smsgw -c localhost -m mysql -u root –password=password -b SM -f /var/log/smsdaemon.log

step 2)

run this python script  and minimize the shell

#!/usr/bin/python

#    before running this program you must configured gnokii-smsd and it must be up and running
#     @Author:    Karthik selvakumar
#    Name :     Dictionary Server

# install python-MySQLdb  before importing this module

import MySQLdb

# imported inorder to perform shell operations

import os

processed=1;
# run as a daemon and never exit this thread

while(True):

#defines the database parameter change according to your configuration

host=”localhost”

user=”root”

passwd=”123456″

db=”smsgw”

# Optionally get input from user

#    print ” Enter Host :”

#    host=raw_input()

#    print ” Enter Password :”

#    passwd=raw_input()

#    print ” Enter database :”

#    db=raw_input()

#creates a database object for corresponding config

db=MySQLdb.connect(host,user,passwd,db)

cursor=db.cursor()

#performs pruning of inbox table which may contain null entities

cursor.execute(“delete from inbox where text=\”\”")

#gets the latest entered SMS from Mysql server

cursor.execute(” select number,text,id,processed from inbox where id=(select max(id) from inbox)”)

record=cursor.fetchall()

for result in record:

# gets the word to find meaning

word=result[1]

# get the number bcoz u have to reply the meaning to this number later ;)

number=result[0]

row=result[2]

processed=result[3]

if(processed==0):

# script to get meaning of a word from google server
if(word==”lock”):
up=”gnome-screensaver-command –lock”;
elif(word==”unlock”):
up=”xset dpms force on && gnome-screensaver-command -d”;

elif(word.startswith(“status:”)):
up=” purple-remote \”setstatus?status=available&message=”+str(word.replace(“status:”,”"))+”\”";

else:
up=word+” >meaning.txt”;

print up;

#set the entity to be processed when taken out

cursor.execute(” update inbox  set processed=1 where id=”+str(row));

# run the command in shell and write it to file named meaning.txt

os.system(up)

# open the file in read only mode

filehandle=open(‘meaning.txt’,'r’)

# load the meaning in the string text

text=filehandle.read()

print ” text is “+text;

# we no more need this

filehandle.close()

if(text!=”"):
cursor.execute(“insert into outbox(number,text) values(%s,%s)”,(number,text))

# close all active connections :)

cursor.close()

db.close()

#thank you !

step 3)

your done with now message to the mobile you have connected like lock or unlock or status:status to see the magic happen :)

A simple start to SVN

SVN is a version control system used to track your various versions of your software over various levels called Revisions.

Basically every software will be stored in SVN as REPO called Repositories .

Step1 :

First before starting with your coding create a repo name in SVN as :

svnadmin create<your-repo-name>

e.g) svnadmin create mediaplayer

now you have created a repo named mediaplayer

this copy is the master copy for all clients

this will be a directory with some system defined files in it

note the directory you have  created a repositiory

Step 2:

now you cannot directly do modify on master copy

you have to checkout this repo to some workspace and start working

let it be a directory called workspace

mkdir workspace

cd workspace

now you can checkout the master copy and start your coding process

svn co file:///home/<user-name>/<repo-name>

eg:)  svn co file:///home/karthik/mediaplayer

now you will have a directory named mediaplayer

go into the directory  by

cd mediaplayer

then start a code name it as myfile.java

now save it in this directory  . To add this into your master copy do

svn add  <file-name>

eg) svn add myfile.java

Step 3:

you can optionally use these commands

i) svn commit – to  commit the current modification to the master copy ( Do this whenever you do minor changes to you files)

ii) svn status – to check the status of files in working copy

here ? means unknown  A means added M means modified but not added

iii) svn update – to update to the latest revision of the master copy ( this will be usefull when more than one client has modified the master copy without your knowledge )

for more details refere here

Thank you :)

Running SMS Dictionary server in your Home

Do you want to run a dictionary server that messages you the actual meaning

Requirments :

i)  A GSM mobile phone

ii)  Linux  with python

iii) Mysql Database

iv)  Gnokii-SMSD

You must be sure that gnokii-smsd is up and running and database is available

if not refer to my previous post here

Code :

This code simply connects to dictionary.org and gets the meaning for the word that is latest in INBOX table and writes the meaning to OUTBOX table which will be sent to user later .May have bugs in it please report me at earliest :)

copy and paste the code to a file . let it be dict_server.py . code is below :

#!/usr/bin/python

#    before running this program you must configured gnokii-smsd and it must be up and running
#     @Author:    Karthik selvakumar
#    Name :     Dictionary Server

# install python-MySQLdb  before importing this module

import MySQLdb

# imported inorder to perform shell operations

import os

# run as a daemon and never exit this thread

while(True):

#defines the database parameter change according to your configuration

host=”localhost”

user=”root”

passwd=”password”

db=”smsgw”

#creates a database object for corresponding config

db=MySQLdb.connect(host,user,passwd,db)

cursor=db.cursor()

#performs pruning of inbox table which may contain null entities

cursor.execute(“delete from inbox where text=\”\”")

#gets the latest entered SMS from Mysql server

cursor.execute(” select number,text,id from inbox where id=(select max(id) from inbox)”);

record=cursor.fetchall()

for result in record:

# gets the word to find meaning

word=result[1]

# get the number bcoz u have to reply the meaning to this number later ;)

number=result[0]

row=result[2]

# script to get meaning of a word from google server

up=’/usr/bin/curl -s -A \’Mozilla/4.0\’ \’http://www.google.com/search?q=define%3A\”

low=’| html2text -ascii -nobs -style compact -width 500 | grep “*” | head -n 1 -q | tail -n 1 > meaning.txt’

# run the command in shell and write it to file named meaning.txt

os.system(up+word+low)

# open the file in read only mode

filehandle=open(‘meaning.txt’,'r’)

# load the meaning in the string text

text=filehandle.read()

# we no more need this

filehandle.close()

# insert into outbox table which will send the meaning of the word to the phone number later

cursor.execute(“insert into outbox(number,text) values(%s,%s)”,(number,text))

# close all active connections :)

cursor.close()

db.close()

#thank you !

now run the dictionary daemon by running python dict_server.py in terminal

whenever a message is received to your mobile it will be read by dict_server.py and meaning of that word will be in outbox table

to see run select * from outbox ; in mysql console

Enjoy :)

Installing Network Simulator 2 in Ubuntu

Are you baffled by random errands saying “  ns2 doesn’t work on ubuntu ” and so ?

Are you a linux geek don’t wanna boot to windows for network simulator software ?

did your lab admin made a mess with your system in the name of installing ns2 :D ?

then you are in a right place :)

You can make NS working in your system by putting little effort  on your ubuntu :)

Step 1:

Download network simulator software from here

if you prefer other old versions you can swich by viewing files in that page

the file will be of almost 57 MB

Step 2:

Extract the files to your own desired directory

I did in /home/karthik/Desktop/

step 3:

now go to your working directory of ns2 by

cd /home/karthik/Desktop/ns-allinone-2.34

step 4:

Run this command to check any unresolved dependencies existing between installation

sudo apt-get install build-essential autoconf automake libxmu-dev

run the command ./install in terminal

it will take around 5 minutes

step 5:

Well Thats were your installation of ns2 exits :)

now you have to configure to make it alive

you have to edit in the shell

run gedit ~./bashrc

add at end of the file this lines

remember change  /home/karthik/Desktop/ to your file path say /home/host-name/


# LD_LIBRARY_PATH
OTCL_LIB=/home/karthik/Desktop/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/karthik/Desktop/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=/home/karthik/Desktop/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

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

now save the file and close it

run source ~/.bashrc

ignore if any errors ;)

then run ./validate

this is the longest step it takes 30-45 minutes hence you can have a meal during the course of time ;)

step 6:

this  is editing thing ( optional )

just make  links to the files in /home/karthik/Desktop/ns-allinone-2.34/bin by right click on all files and choose make link

copy  all and paste to /usr/bin/ directory  by running

sudo nautilus

then rename the file name for eg) link to ns to ns and so on . do this till all files are renamed .

step 7:

Sample code

now u can check out a demo to test you ns 2 by writing a sample code as below :

#Create a simulator object
set ns [new Simulator]

#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#Define a ‘finish’ procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}

#Create two nodes
set n0 [$ns node]
set n1 [$ns node]

#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail

#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 “finish”

#Run the simulation
$ns run

now copy this code and paste to a file say  myfirstprogram.tcl

then run ns myfirstprogram.tcl

you must see a window like this :

my ubuntu screen running NS2

and  …   You did it , Enjoy   :)

Follow

Get every new post delivered to your Inbox.