Wednesday, November 12, 2014

Drupal7 Installation and Website Development


For installing drupal7 we need to install LAMP(Linux, Apache, MySql, Php) server. I am assuming that you already installed any Debian based Linux(L) OS like Ubuntu. Run the following commands in terminal to install LAMP server.

Installing Apache(A):

To install apache2 run following command.

- sudo apt-get install apache2

To check apache2 installed, type the URL http://localhost/ in web browser.


Installing Php(P):

To install Php5 run following command.

- sudo apt-get install php5 libapache2-mod-php5

- sudo /etc/init.d/apache2 restart

To check php5 installed properly or not, create test.php in /var/www/ with code shown in screenshot.




Now type http://localhost/test.php in web browser, it will display the information of installed Php as shown in following screenshot.























Installing MySql(M):

To install MySql run following command in terminal.

- sudo apt-get install mysql-server

During MySql server installation do not forget to enter root user password.












Run following command to install phpadmin in terminal.

-  sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

During phpadmin installation select apache2 as default to run phpadmin using apache2, by pressing space tab as shown in screenshot.

During phpadmin installation setup required passwords also.

Now LAMP server is installed. Do the following settings also.

- Uncomment extension=msql.so in /etc/php5/apache2/php.ini file as shown in following screenshot.


- Add  ServerName localhost in /etc/apache2/httpd.conf file.

Creating Required MySql Database:

 Log into MySql using following command

- mysql -u root -p

Then create Required database using following command

- create database drupaldb;

Then create a user to access that database using following command

- create user 'user1'@'localhost';

Set password for created user user1

- update mysql.user set password=password('PassWord') where user='user1';

Grant all privileges to user1 on drupaldb using following command

- grant all privileges on drupaldb.* to 'user1'@'localhost';

Then flush all privileges using following command

- flush privileges;

Installing Drupal7:

Download drupal7 using following command

- wget http://ftp.drupal.org/files/projects/drupal-7.23.tar.gz

Now move downloaded drupal-7.23.tar.gz to /var/www/drupalsite folder and extract there itself. You need to create drupalsite folder in /var/www/. Change the owner of drupalsite by running following command.

- chown -r www-data.www-data drupalsite

Now make sure your apache HTTP listens to port 8001 (if you want you can use any other port also). To listen port 8001, enter Listen 8001 in /etc/apache2/ports.conf file as shown in following screenshot.


Now copy the contents of /etc/apache2/sites-available/default to /etc/apache2/sites-available/drupalsite and add the content shown in following screenshot to /etc/apache2/sites-available/drupalsite file.


Now run the following bunch of commands to take affect of made changes / settings.

- sudo a2ensite /etc/apache2/sites-available/drupalsite
- sudo /etc/init.d/apache2 reload
- sudo a2enmod vhost_alias rewrite
- sudo /etc/init.d/apache2 reload

 Now whatever setup needed for installation of drupal7 is ready. Type http://localhost:8001/install.php URL in web browser and you will see the page as shown in following screenshot.



Now click on Save and continue, in the next screen select english as language. After that, in database configuration enter database details, which you have created in mysql as shown in following screenshot.

In the next step enter all the details like site name, site maintenance e-mail and site maintenance account details.

 Once you enter the above details your drupal site is ready.

Now click on Visit your new site to see your site.

Now your basic drupalsite is ready. By using your site maintenance account you can create new content, new modules etc.

http://accessibledesktop.in is an example site developed using drupal7.

Thursday, October 16, 2014

Calibrating Wacom BAMBOO ONE CTE-660 to Particular portion of Screen

I was working on calibrating Wacom tablets (Wacom Bamboo One CTE-660) to particular portion of the desktop screen. Initially I implemented my own mechanism by editing wacom driver configuration files to calibrate but lately I found xsetwacom utility which is very useful to query or change properties on the devices loaded by the wacom driver. The modification of properties happens at runtime and is not persistent through X server restarts.
Wacom Bamboo One CTE-660
  To install xsetwacom, first of all download it from Here and extract the downloaded file & follow the instruction given in INSTALL file.

Once you install xsetwacom utility, to calibrate(map) wacom tablet to left top most portion of 500X500 area of your screen, run the following command.

xsetwacom set "Wacom Bamboo1 5x8 stylus" MapToOutput 500X500+0+0

To calibrate(map) wacom tablet to entire scree run the following command

xsetwacom set "Wacom Bamboo1 5x8 stylus" MapToOutput VGA1

 The following program creates a xwindow & by pressing 'm' key calibrates(map) Wacom Bamboo1 5x8 stylus to the created window and by pressing 'u' calibrates Wacom Bamboo1 5x8 stylus to entire screen.


#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/shape.h>
#define NIL (0)

int main()
{
  char *window_name = (char*)"gem input window";
  Display *dpy = XOpenDisplay(NIL);
  int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
  Window w = XCreateSimpleWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 500, 500, 0, whiteColor, whiteColor);
  XSelectInput(dpy, w, ButtonPressMask| PointerMotionMask| LeaveWindowMask| EnterWindowMask| ButtonReleaseMask );
  XStoreName(dpy, w, window_name);
  XMapWindow(dpy, w);
  for(;;) {
   XEvent e;
   XNextEvent(dpy, &e);
   if(e.xany.window == w)
     {
       switch(e.type)
        {
         case KeyPress: 

        if (e.xkey.keycode == XKeysymToKeycode(dpy, XK_m))
        {
        printf("\n Calibration to 500X500 Done");
        system("xsetwacom set \"Wacom Bamboo1 5x8 stylus\" MapToOutput 500X500+0+0");
        }
        if (e.xkey.keycode == XKeysymToKeycode(dpy, XK_u))
        {
          printf("\n Calibrating to entire screen Done");
          system("xsetwacom set \"Wacom Bamboo1 5x8 stylus\" MapToOutput VGA1");
        }
        if (e.xkey.keycode == XKeysymToKeycode(dpy, XK_e))
        XDestroyWindow(dpy, w);
        break;                  
     }
    }
 }
  return 0;

}

Thursday, September 18, 2014

Replacing Pronunciation Dictionary of Acoustic Model in Sphinx4


Lets say, We are creating a Speech Recognition system for recognising computer related words only.  Now, I will tell you, How to create pronunciation dictionary for computer related words and how to add that dictionary in acoustic model. In this example I am using WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar acoustic model.

CREATING PRONUNCIATION DICTIONARY:

Step 1 :
Create a plain text file "computer.txt", and Write down all words related to computer in that text file.



Step 2 : Now go to this link : http://www.speech.cs.cmu.edu/tools/lmtool.html

Step 3 : After Opening above link, go to "Sentence corpus file" section and then browse "computer.txt" file and then click "Compile Knowledge Base".








Step 4 : Wait for few seconds/Minutes, once the dictionary is created, click on "Dictionary" link and save that .DIC file.

 










Now pronunciation dictionary for computer related words is ready. Now We will see how to include this pronunciation dictionary in acoustic model.

ADDING PRONUNCIATION DICTIONARY TO ACOUSTIC MODEL

Step 5 : Locate WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar file in sphinx4. (Generally can be find at location /sphinx4-1.0beta6-bin/sphinx4-1.0beta6/lib).

Step 6 : Extract WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar

 Step 7 : Open "cmudict.0.6d" which is located in extracted folder /sphinx4-1.0beta6-bin/sphinx4-1.0beta6/lib/ WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/ 

Step 8 : Now copy data from .DIC file created in Step 4 and paste it into "cmudict.0.6d" file and save. 











Step 9 : Now create the JAR file and keep the extracted hierarchy back as it was and the name of JAR file should be WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar.

Now acoustic model with pronunciation dictionary of computer related words is ready.

Now, remove old "WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar" file from Project’s CLASSPATH and add newly created "WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar" file instead of it.

That’s it ! Now We are done.  Now Sphinx will recognize all computer related words which we wrote in "computer.txt" file.

Thursday, July 31, 2014

Unix Shell Programming Basics

Shell Program
A shell program or shell script is a collection of Shell commands to perform a particular task .

Examples:
  • Unix Shell scripts (ksh, csh, bash, sh)
  • Python
  • perl
  • VBScript
  • Java Script
  • Apple Script etc.

Uses of Shell Programming
  • To combine lengthy and repetitive sequences of commands into a single, simple command.
  • To create new commands using combinations of pre-existing commands.
  • To automate the process of setting up and running applications.
Shell Program structure
  • Any text editor can be used to type shell program.
  • #! /bin/sh
    # this is a comment
    body of program
    exit 0 
  • #! /bin/sh indicates to other users to run the script using /bin/sh 
  • #! /bin/sh is called as shebang or hashbang 
  • Comment line starts with #  
  • exit 0 represents the end of script
Steps involved in Shell Script
    Step-1: Type shell program in a text file 
    Step-2: Save file with .sh extension
    Example: FileName.sh 
    Step-3: Make FileName.sh Executable for all users using 'chmod 755 FileName.sh
    Step-4: Run script using ./FileName.sh

Shell Script Examples

#! /bin/sh
#Script Name: Run.sh
#Purpose: to run hello.c file
gcc -o hello hello.c
./hello
exit 0

#! /bin/sh
#Script Name: UpdateUpgrade.sh
#Purpose: To update & upgrade debian #based system
apt-get update
apt-get upgrade
reboot
exit 0

Note: You need super user privileges to run UpdateUpgrade.sh script

Assignments-1
  • Write a shell script to display your name on screen (Time: 1 Min) 
  • Write a shell script to remove CDAC directory, whose absolute path is /home/reniguntla/CDAC (Time: 2 Min) 
  • Write a shell script to display all lines contains “sh” in file UpdateUpgrade.sh (Time: 2 Min)


Shell Script Variables
  • By deafault all variables in shell script are strings.

  • #! /bin/sh
    #Script Name: Variable.sh
    #Purpose: To demonstrate variables
    x=Hello
    echo "$x"
    y="Hi"
    echo "$y"
    z="How are you?"
    echo "$z"
    exit 0
  • Output: Hello
                      Hi
                      How are you?


Quoting of variables

#! /bin/sh
#Script Name: Quote.sh
#Script purpose: To demonstrate variable with #quotations
x=Hello
echo $x
x=”Hello”
echo $x
x=”Hello Mr.L”
echo $x
echo '$x'
exit 0

OutPut: Hello
              Hello
             Hello Mr.L
             $x

Assignments-2
  • Write a shell script to print your name and student id on screen using variables? (1 Mins) 
  • Write a shell script to swap 2 numbers using temporary variable? (2 Mins)

Shell Script Binary Operators 
 

Shell Script Binary Operators Example

#!/bin/sh
#Script Name: BinaryOp.sh
#Purpose: Demonstration of binary operators
a=10
b=20
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a \* $b`
echo "a * b : $val"
val=`expr $b / $a`
echo "b / a : $val"
val=`expr $b % $a`
echo "b % a : $val"
exit 0

OutPut: a+b:30
               a-b:-10
               a*b:200
               b/a:2
               b%a:0

Shell Script Relational Operators


Shell Script Boolean Operators

Note: Explore string operators yourself

Shell Script File Test Operators
 

Reading Input From User

To read input we use read command 
 
#! /bin/sh
#Script Name: InputRead.sh
#Purpose: To demonstrate read command
echo “Enter your name?”
read MyName
echo “Your name is $MyName”
exit 0

OutPut: Enter your name ?
               Reniguntla
               Your name is Reniguntla


Assignments-3

Write a shell script to read your name, roll number, marks in 4 subjects. Display your name, roll number, average of 4 subjects & percentage on screen. (3 Min)

Shell Script Parameters

All command line parameters / arguments of a shell script can be accessed via $1, $2, $3,..., $9, ${10}, ${11}...

$# holds the number of parameters passed

$@ Holds A list of all parameters in a single variable

$* also holds all parameters

$0 holds the name of the script

Shell Script Parameters Example

#!/bin/sh
#Script Name: ScriptParam.sh
#Purpose: Script parameters demo
echo "There are $# parameters"
echo "The parameters are $@"
echo "The script name is $0"
echo "The first parameter is $1"
echo "The second parameter is $2"
exit 0

OutPut: /.ScriptParam.sh reni sam
             There are 2 parameters
             The parameters are reni sam
             The script name is ./ScriptParam.sh
             The first parameter is reni
            The second parameter is sam

Assignments-4


Write a shell script to delete file1.txt & to give RWX permissions to all users on file2.txt. Take file1.txt and file2.txt as shell script parameters. (3 Min)

If-then-fi

Syntax: if [ condition ]
             then
                Statements
            fi

Example:

#! /bin/sh
#Scriptname: ifthenfi.sh
#purpose: To demonstrate if-then-fi
echo "Is it morning? Please answer yes(1) or no(0)"
read response
if [ $response -eq 1 ]
    then
         echo “good morning”
fi
exit 0

if-then-else-if

Syntax: if [ condition ]
             then
                 Statements
            else
                Statements
            fi

Example:
#! /bin/sh
#ScriptName: Ifthenelsefi.sh
#purpose: To demonstrate if-then-else-fi
if [ -d /home/faculty ]
then
    echo “/home/faculty is a directory”
else
    echo “/home/faculty is not a directory”
fi
exit 0

Assignments-5

Write a shell script to check whether read number is even or odd? (Time: 2 Min)
Write a shell script to check given file(take this a script parameter) is plain file or directory. (Time: 2 Min)


Case Statement
Syntax:
case variable in
Pattern ) statements ;;
Pattern ) statements ;;
......
esac

Example:
#! /bin/sh
#ScriptName: Case.sh
#purpose: To demonstrate case statement
echo “is it morning? Please anser yes or no”
read timeofday
case “$timeofday” in
yes | Y | y | YES ) echo “Hi”
echo “good morning” ;;
yo | N | n | NO ) echo “Hi”
echo “Good After Noon” ;;
* ) echo “sorry answer not recognized” ;;
esac
exit 0


For Loop

Syntax: for variable in values
            do
                Statements
           done
Example:
#! /bin/sh
#ScriptName: For.sh
#Purpose: To demonstrate for loop
for file in $(ls *.sh)
do
     echo “$file”
done
exit 0

Note: You can use loop controls break, continue in for loop with a value.

While loop
Syntax: while [ condition ]
             do
                 Statements
            done

Example:
#! /bin/sh
#ScriptName: While.sh
#Purpose: To demonstrate While loop
echo "enter password:"
read password
while [ "$password" != "secret" ]
do
    echo "try again"
    read password
done
exit 0

Note: You can use loop controls break, continue in while loop with a value.
Note: Explore do-while loop for yourself

Arrays in Shell Script

An array variable can hold multiple values at the same time and each value can access using index value.

Example:

#!/bin/sh
#ScriptName: Array.sh
#Purpose: To demonstrate Array in shell script
name[0]="Reni"
name[1]="Sam"
name[2]="Ashok"
name[3]="Mahesh"
#Displaying array item based on index number
echo "First Method: ${name[0]}"
echo "First Method: ${name[2]}"
# Different method to display all items in array
echo "First Method: ${name[*]}"
echo "Second Method: ${name[@]}"
exit 0
 
Function with No parameters & No return 
#!/bin/sh 
#ScriptName:Function1.sh 
#Purpose: To demonstrate function with no #parameters & no return 
# Function Hi definition 
Hipgdst () { 
   echo "Hi PGDST" 
} 
# Invoking function Hi 
Hipgdst 
exit 0

Function with  Parameters & Return Value
#!/bin/sh
#ScriptName:Function2.sh
#Purpose: To demonstrate function with parameters & return val
# Function add definition
add () {
   return `expr $1 + $2`
}
# Reading 2 nums for adding through func
echo "enter first number"
read a
echo "enter second number"
read b

# Invoking function add with a & b as #parameters
add $a $b
# Capture value returned by last command
sumval=$?
echo "Return value is $sumval"
exit 0


Shell Script Assignments
  1. Write a shell script to check read number is prime or not? (use for / while loop) 
  2. Write a shell script to determine whether the given word begins with lower case 
    or upper-case letter or whether it is starting with a special character using case statement. (use case) 
  3. Write a shell script to read contents of a file (which has been provided 
    as a script parameter) line by line and display on screen. (use while loop) 
  4. Write a shell script to read 10 values into an array and print them on screen using array index. 
  5. Write a shell script to read 5 values into array1 and 5 values into array2 and concatenate 
    both arrays store in array3. 
  6.  Write shell script functions to calculate +, -, *, / , % of two numbers which 
    are provided as parameters to the functions and and each function must return result. 
    Call all those functions and print return values. 
  7. Write a single shell script to do the following
    a. Create a file profile.txt 
    b. Change permissions of profile.txt to _rwxr_xr_x 
    c. Read your name, e-mail id, roll number and write them to profile.txt 
    d. Read the contents of profile.txt using a loop and display on screen. 
  8. Write a single shell script to do the following
    a. read a number 
    b. Define a function checkprime() which takes read number as parameter 
    & checks that number is prime or not & return the result. 
    c. Call checkprime() with parameters 12, 97, 111
    d. Display the return values of above function calls on screen 
  9. Write a single shell script to 
    a. read a number N 
    b. read N numbers in to an array called array_all using loop 
    c. Navigate through array_all and check for even & odd numbers. Store 
    all even numbers in array even_array & odd numbers in array odd_array 
    d. display all even numbers then odd numbers on screen.