Monday, December 17, 2007

We WON the match....!!!!!

I think you'll not believe this, HR team of my company was organized Cricket Tournament(hSenid Happy Cricket Tournament). They asked for teams which having 6 members including one female member, but we played without female member. My team was CRUSADERS, Actually I didn't wish to win this tournament, but fortunately we could won the tournament. Most important thing is here, I was the captan and I did not have good picture about cricket.



Some pictures are I added to the my picasa space. click here to visit there.

Monday, November 19, 2007

A Turbo C++ Program, which uses Strategy Pattern to select sorting algorithm.
This program selecting sorting algorithm from merge sort, insertion sort, quick sort and bubble sort using strategy pattern. If here having any mistakes comments are welcome....
:-)
click here to download

Tuesday, September 11, 2007

How to make a sheared memory segment in UNIX environment using C language
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<sys/types.h>
#include<sys/msg.h>
#define MAX_SEND_SIZE 80
struct mymsgbuf{
long mtype;
char mtext[MAX_SEND_SIZE];
};

void send_message(int qid, struct mymsgbuf *qbuf, long type, char *text);
void read_message(int qid, struct mymsgbuf *qbuf, long type);
void remove_queue(int qid);
void change_queue_mode(int qid, char *mode);
void usage(void);

int main(int argc, char *argv[])
{
key_t key;
int msgqueue_id;
struct mymsgbuf qbuf;

if(argc == 1)
usage();

key=ftok(".",'m');

if((msgqueue_id = msgget(key, IPC_CREAT | 0660)) == -1){
perror("msgget");
exit(1);
}
switch(tolower(argv[1][0])){
case 's': send_message(msgqueue_id,(struct mymsgbuf *)&qbuf, atol(argv[2]),argv[3]);
break;
case 'r': read_message(msgqueue_id, &qbuf, atol(argv[2]));
break;
case 'd': remove_queue(msgqueue_id);
break;
case 'm': change_queue_mode(msgqueue_id,argv[2]);
break;
default: usage();
}
return(0);
}

void send_message(int qid,struct mymsgbuf *qbuf, long type, char *text){
printf("Sending a message.. \n");
qbuf->mtype=type;
strcpy(qbuf->mtext,text);

if((msgsnd(qid,(struct msgbuf *)qbuf,strlen(qbuf->mtext)+1,0)) == -1){
perror("msgsnd");
exit(1);
}
}

void read_message(int qid,struct mymsgbuf *qbuf,long type){
printf("Reading a message.. \n");
qbuf->mtype = type;
msgrcv(qid, (struct msgbuf *)qbuf, MAX_SEND_SIZE, type, 0);
printf("Type %ld Text: %s\n", qbuf->mtype, qbuf->mtext);
}

void remove_queue(int qid){
msgctl(qid, IPC_RMID, 0);
}

void change_queue_mode(int qid, char *mode){
struct msqid_ds myqueue_ds;
msgctl(qid, IPC_STAT, &myqueue_ds);
sscanf(mode, "%ho", &myqueue_ds.msg_perm.mode);
msgctl(qid, IPC_SET, &myqueue_ds);
}

void usage(void){
fprintf(stderr, "A utility for message queues\n");
fprintf(stderr, "\n USAGE: (s)end \n");
fprintf(stderr, "(r)ecv \n");
fprintf(stderr, "(d)elete\n");
fprintf(stderr, "(m)ode \n");
exit(1);
}


Monday, August 13, 2007

How to create a MySQL table using Perl Script.
Following way is the method which can create MySQL table using perl script.
It uses DBI perl module. You can get more information about DBI module by visiting
http://www.cpan.org
Changing the variables, try and see how is it easier.

#!/usr/bin/perl

use DBI;
use strict;

my $DB_NAME = 'nipuna';
my $USER_NAME = 'root';
my $PASSWORD = '';

my $dbh = DBI->connect('DBI:mysql:$DB_NAME','$USER_NAME','$PASSWORD',{RaiseError => 1});

if($dbh){
print "Sccessfully connected to the database! \n";
}
my $sql = "CREATE TABLE tblTest(fname varchar(30), age int(2))";
my $query = $dbh->do($sql);
if ($query == 0){
print "Table was created\n";
}else{
print "Not created\n";
}
$dbh->disconnect;

Following script explain how to execute a MySQL query using perl script.

#!/usr/bin/perl

use DBI;
use strict;

my $DB_NAME = 'nipuna';
my $USER_NAME = 'root';
my $PASSWORD = '';

my $dbh = DBI->connect('DBI:mysql:$DB_NAME','$USER_NAME','$PASSWORD',{RaiseError => 1});

if($dbh){
print "Sccessfully connected to the database! \n";
}
$query = $dbh->prepare("SELECT * FROM tblTest");
if (defined($query)){
$query->execute();
}else{
print "Could not execute the query! \n";
}
my @row;
while (@row = $query->fetchrow_array()){
print "$row[2]\n";
}
$dbh->disconnect;

Friday, August 10, 2007

Working with hSenid
This is my second month in hSenid. Actually working with hSenid is great experiance. More things to understand and have to do much new works. Here people are very friendy and helpfull. Other than that I can not get understand about works which I have to do here.
This company is growing world wild.
visit http://www.hsenid.com

Wednesday, July 11, 2007

File moving shell script according to unix time stamp

change the variables given inside comments. TimeValue should be in HH:MM:SS time format

#!/bin/bash
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++Variables++++++++++++++++++++++++++++++++++++
Source=/home/nipuna/first/
Destination=/home/nipuna/second/
TimeValue=00:05:00
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
#Getting date to variable
CheckTime=`date cut -d" " -f4`
#Split Time Value
tHour=`echo $TimeValue cut -f1 -d:`
tMin=`echo $TimeValue cut -f2 -d:`
tSec=`echo $TimeValue cut -f3 -d:`
#Split Date Value
cHour=`echo $CheckTime cut -f1 -d:`
cMin=`echo $CheckTime cut -f2 -d:`
cSec=`echo $CheckTime cut -f3 -d:`
#Sub. by TimeValue
cHour=`expr $cHour - $tHour`
cMin=`expr $cMin - $tMin`
cSec=`expr $cSec - $tSec`
#echo $cHour "." $cMin "." $cSec
#getting file list with time
File_List=`ls --full-time --time-style=full-iso -t $Source awk '{print $7 "%" $9}'`
for i in $File_List;
do
if [ '%' != $i ]; then #remove bulk values
#split file time values
fHour=`echo $i cut -f1 -d:`
fMin=`echo $i cut -f2 -d:`
fSec=`echo $i cut -f3 -d: cut -f1 -d.`
if [ $cHour -gt 0 ]; then
tHour=`expr $fHour - $cHour`
tMin=`expr $fMin - $cMin`
tSec=`expr $fSec - $cSec`
else
tHour=`expr $cHour - $fHour`
tMin=`expr $cMin - $fMin`
tSec=`expr $cSec - $fSec`
fi
if [ $tHour -lt 0 ]; then
fileName=`echo $i cut -f2 -d%`
mv $Source/$fileName $Destination
echo "$fileName moved"
fi
fi
done

Tuesday, July 10, 2007

Good Bye CeIT
Last wednesday(5th) I was leaved from ITC of UOP permanently because I got a job from h'Senid mobile software company as an Imlementation Engineer.

ITC is a good place to work and study. Mainly I could done so meny experiments under UNIX environment.It was a funny times which I had in my life. When I was there I could learned about people and friends and their characteristics.

Tuesday, July 03, 2007

Home Business through Internet
Do you have heard about home businesses via internet? One of my friend was done it nicely so you can visit there.

www.homebizpal.com

Friday, June 29, 2007

Nice Poem
This poem said to be the nominated poem of 2005 for the best
poem , written by an African kid......... (this is an e-mail)
amazing thought!!!
When I born, I Black,
When I grow up, I Black,
When I go in Sun, I Black,
When I scared, I Black,
When I sick, I Black
And when I die, I still black.
And you White fellow,
When you born, you Pink
When you grow up, you White,
When you go in Sun, you Red,
When you cold, you Blue
When you scared, you Yellow
When you sick, you Green
And when you die, you Gray
And you calling me colored?

Monday, June 18, 2007

Working with ITC of UOP
Today is the my first day working with Information Technology Center of University of Peradeniya. It's nice, Last year also I worked here as a assistant instructor but now I'm working as a full time instructor. This center has three labs and more than 300 workstations. More than 12000 users are using this network.
visit :http://www.ceit.pdn.ac.lk

Wednesday, April 04, 2007

Google Adsense

Google AdSense is a fast and easy way for website publishers of all sizes to display relevant Google ads on their website's content pages and earn money. Because the ads are related to what your visitors are looking for on your site — or matched to the characteristics and interests of the visitors your content attracts — you'll finally have a way to both monetize and enhance your content pages.

It's also a way for website publishers to provide Google web and site search to their visitors, and to earn money by displaying Google ads on the search results pages. Visit Following Link http://adsense.google.com

Saturday, March 24, 2007

My Second Science Camp

Last 16th , 17th and 18th I was in Hambanthota Weeraketiya Rajapaksha Central College because of the my second science camp which was organized by faculty of Science, University of Peradeniya. Here I have attached some of the photographs which I took there. We did some physics, chemistry, biology and zoology practicals and lectures for students from rural areas near Hambanthota District.

for more photographs visit

http://picasaweb.google.com/nipunap/Science_camp


Wednesday, March 14, 2007

Beryl Intel and debian Linux

I installed the beryl on deban linux system in the following way. It's the easiest way that ever I found.
my graphic card drivers is Intel Corporation 82915G/GV/910GL Integrated Graphics Controller. First you should install the kernel header file to your computer using

apt-get update
apt-get install linux-headers-2.6.*-*-*

* Should be replaced by your kernel version, (take it using uname -r)

After that using modprobe command select your driver modules or go to the http://www.intel.com and find the Linux driver for your graphic card, it is a must, otherwise Beryl is not working. Xgl and other OpenGL libraries are prerequisites.

Then install Beryl using apt-get, put following in /etc/apt/source.list file and configure the xorg.conf file
deb http://debian.beryl-project.org etch main
deb-src http://debian.beryl-project.org etch main


Here is my xorg.conf

Section "Files"
FontPath "/usr/share/fonts/X11/misc"
FontPath "/usr/X11R6/lib/X11/fonts/misc"
FontPath "/usr/share/fonts/X11/cyrillic"
FontPath "/usr/X11R6/lib/X11/fonts/cyrillic"
FontPath "/usr/share/fonts/X11/100dpi/:unscaled"
FontPath "/usr/X11R6/lib/X11/fonts/100dpi/:unscaled"
FontPath "/usr/share/fonts/X11/75dpi/:unscaled"
FontPath "/usr/X11R6/lib/X11/fonts/75dpi/:unscaled"
FontPath "/usr/share/fonts/X11/Type1"
FontPath "/usr/X11R6/lib/X11/fonts/Type1"
FontPath "/usr/share/fonts/X11/100dpi"
FontPath "/usr/X11R6/lib/X11/fonts/100dpi"
FontPath "/usr/share/fonts/X11/75dpi"
FontPath "/usr/X11R6/lib/X11/fonts/75dpi"
# path to defoma fonts
FontPath "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
EndSection

Section "Module"
Load "dbe"
Load "glcore"
Load "type1"
Load "v4l"
Load "i2c"
Load "bitmap"
Load "ddc"
Load "dri"
Load "extmod"
Load "freetype"
Load "glx"
Load "int10"
Load "vbe"
EndSection

Section "InputDevice"
Identifier "Generic Keyboard"
Driver "kbd"
Option "CoreKeyboard"
Option "XkbRules" "xorg"
Option "XkbModel" "pc104"
Option "XkbLayout" "us"
EndSection

Section "InputDevice"
Identifier "Configured Mouse"
Driver "mouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "Protocol" "ImPS/2"
Option "Emulate3Buttons" "true"
EndSection

Section "Device"
Identifier "Intel Corporation 82915G/GV/910GL Integrated Graphics Controller"
Driver "i810"
BusID "PCI:0:2:0"
Option "RenderAccel" "true"
Option "backingstore" "true"
Option "EnablePageFlip" "true"
Option "AGPMode" "8"
Option "AGPFastWrite" "true"
Option "XAANoOffscreenPixmaps" "true"
Option "AllowGLXWithComposite" "true"
EndSection

Section "Monitor"
Identifier "Generic Monitor"
Option "DPMS"
HorizSync 28-64
VertRefresh 43-60
EndSection

Section "Screen"
Identifier "Default Screen"
Device "Intel Corporation 82915G/GV/910GL Integrated Graphics Controller"
Monitor "Generic Monitor"
DefaultDepth 24
SubSection "Display"
Depth 1
Modes "1280x1024" "1280x960" "1280x854" "1280x800" "1280x768" "1200x800" "1152x864" "1152x768" "1024x768" "800x600" "640x480"
EndSubSection
SubSection "Display"
Depth 4
Modes "1280x1024" "1280x960" "1280x854" "1280x800" "1280x768" "1200x800" "1152x864" "1152x768" "1024x768" "800x600" "640x480"
EndSubSection
SubSection "Display"
Depth 8
Modes "1280x1024" "1280x960" "1280x854" "1280x800" "1280x768" "1200x800" "1152x864" "1152x768" "1024x768" "800x600" "640x480"
EndSubSection
SubSection "Display"
Depth 15
Modes "1280x1024" "1280x960" "1280x854" "1280x800" "1280x768" "1200x800" "1152x864" "1152x768" "1024x768" "800x600" "640x480"
EndSubSection
SubSection "Display"
Depth 16
Modes "1280x1024" "1280x960" "1280x854" "1280x800" "1280x768" "1200x800" "1152x864" "1152x768" "1024x768" "800x600" "640x480"
EndSubSection
SubSection "Display"
Depth 24
Modes "1280x1024" "1280x960" "1280x854" "1280x800" "1280x768" "1200x800" "1152x864" "1152x768" "1024x768" "800x600" "640x480"
EndSubSection
Option "AddARGBGLXVisuals" "True"
Option "DisableGLXRootClipping" "True"
EndSection

Section "ServerLayout"
Identifier "Default Layout"
Screen "Default Screen"
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
EndSection

Section "DRI"
Mode 0666
EndSection

Section "Extensions"
Option "Composite" "true"
EndSection


Then you can download and install beryl or get using apt-get
finally you will get following window until that you must work hard.....
;-)



good luck....

some screen shots are here visit http://www.flickr.com/photos/nipuna/
References: http://en.wikipedia.org/wiki/Beryl_%28window_manager%29

Saturday, February 10, 2007

Science Camp
Last January 20th I went to the Science Camp that held on Ginigathhena M.M.W., which was organized by Faculty of Science University of Pradeniya.

There were so many Students from rural areas near Ginigathhena. Here I have attached some photographs.