Google

Wednesday, March 11, 2009

LAN - static IP on fedora 10

It is pretty easy task to set a static ip on LAN in fedora 10 machine. 
First go to network (System -> Administration -> Network) and double click on the device listed in it. Select "Statically set IP address" and enter required fields. In my machine I have used,
Address : 192.168.1.XX
Subnet mask:255.255.255.0
Default gateway address:192.168.1.1

At this point I was unable to connect to internet. By setting fields in DNS tab I was able to connect to internet, but reset them when machine reboots. So I enter those fields in /etc/sysconfig/network-scripts/ifcfg-eth0. It is as follows,
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=XX.XX.XX.XX
DNS2=XX.XX.XX.XX

Finally, I was able to set a static ip and connect to internet.

Sunday, February 22, 2009

Binary Search Algorithm

Over the weekend I read some chapters of Beautiful Code book. It is really interesting and I am seeing the beauty in programming :). I read the Beautiful Test chapter and impressed with the example it has introduced. It is Binary Search algorithm. It says that this algorithm was published in 1946 but took 12 years for the first binary search without bugs to be published. It is amazing!!!
You can refer the most common bug here.

Further it shows that the algorithm may not returns the first position of the target value. But for the binary search algorithm, only pre-condition is to have a sorted array[1]. A sorted array can have duplicate values. If so algorithm should return the first position, as I guess. But the algorithm published in most sites(in wikipedia too) do not consider this point.
Here is the changed algorithm to handle duplicate values,

public static int binarySearch(int[] array, int target){
int low = 0;
int high = array.length - 1;
while(low <= high){
int mid = calculateMidPoint(low, high);
int midValue = array[mid];

if(midValue < target)
low = mid + 1;
else if(midValue > target)
high = mid -1;
else{
while(mid!=0 && target == array[mid-1]) //loop backward to check whether duplicate values present
mid -= 1;
return mid;
}
}
return -1;
}

Here is my java implementation of this algorithm and test classes. My reference is Beautiful Code book.

[1] http://en.wikipedia.org/wiki/Binary_search

Tuesday, February 17, 2009

Limit the number of rows in Oracle and MySql

Say we want to select 10 records for a perticular query, we can use the following syntax

// mysql 

select column from table limit 10;

// Oracle 

select column from table where rownum <= 10;

 

If we want to select number of records from the results set in Oracle,

// Oracle 

select * from (select a.*, rownum rnum from (select column from table) a where rownum <=10) where rnum >= 5;

Thursday, February 12, 2009

Enable wireless on fedora 10

This article guided me to connect to wireless network from fedora 10
http://forums.fedoraforum.org/showthread.php?t=193555

Install vlc player in fedora 10

I installed vlc player in my fedora partition. It consumes time to search plugins for other players like totem.
Use this link to install vlc player using yum
http://www.videolan.org/vlc/download-fedora.html

Tuesday, January 13, 2009

A Python Sidebar for Mozilla

When I was doing my Google summer of code in python I had so google search for many times to complete the project. Since, I did it in Python language and I was not familiar, I learn the basics through the Internet. But I couldn't find a place where I could gather all the information. Today I found a handy sidebar for python resources for Mozilla.

Monday, January 12, 2009

Trac WebAdmin Plugin

I was able to enable trac webadmin plugin to the trac system. Here are the simple steps,

first need to install easy_install utility
  • wget http://peak.telecommunity.com/dist/ez_setup.py
  • python ez_setup.py
I got the following error when I try to install it,
unable to open /usr/lib/python2.5/config/Makefile
then I install python-devel using yum
yum install python-devel
then I install webadmin trac plugin,
  • svn co http://svn.edgewall.com/repos/trac/sandbox/webadmin/
  • cd webadmin
  • python setup.py egg_info
  • python setup.py bdist_egg
  • cd dist
  • easy_install *.egg
then edit the trac.ini file which is in ${trac_home}/conf/trac.ini
[components] webadmin.* = enabled
install AccountManager Plugin,
  • svn co http://trac-hacks.org/svn/accountmanagerplugin/0.10 accountmanagerplugin
  • cd accountmanagerplugin
  • python setup.py bdist_egg
  • cd dist
  • easy_install *.egg
add following lines to trac.ini
[components] trac.web.auth.LoginModule = disabled acct_mgr.* = enabled  [account-manager] password_format = htpasswd password_file = /path/to/password.file
Finally restart the web server and made the plugins available from web.
/sbin/service httpd reload

Monday, January 5, 2009

Make a trac backup

I was able to make a backup of trac database and import all the data to other machine. So all the tickets, milestones, etc. were imported to another machine. Here is the procedure.

Make a backup of the current database.
mysqldump -u charith -p --databases trac > dbdump.sql
Then I copy it to the target machine and import it and create a new database called "trac" and allow permission to user charith,
grant all privileges on trac.* to charith@localhost identified by 'password';
I tried to use mysqlimport command,
mysqlimport trac --replace --user=root dbdump.sql
mysqlimport: Error: Table 'trac.dbdump' doesn't exist, when using table: dbdump

But I was able to import it successfully as root by,
mysql trac < dbdump.sql
But, still trac give the following error: "The 'repository_dir' has changed, a 'trac-admin resync' operation is needed".
So I synchronize the repository by,
trac-admin /path/to/env/ resync
Finally, I was able to import the data to the new environment.

Thursday, January 1, 2009

Install trac - project management tool

I spent few days to install trac software in my machine. I learnt lot of things while installing this software. Here is the procedure I followed,

1) Start Web server

First it need to confirm web server is running. We can start is as a service by,
System -> Administration -> Services
enabling the httpd and starting it.

Then can test it is running by browsing it using, http://localhost

To allow acces to the outsiders, need to enable webserver as a trusted service in firewall,
System -> Firewall

And need to enable port forwarding in the router which is depend on the router type.

Then you can get the public assigned to the router by browsing the www.whatismyip.com

You should be able to access http://public_ip

2) Running a subversion server
install subversion using yum as root
yum install subversion
Create svn repository
svnadmin create /srv/svn/
make httpd can access all files in repository
chown -R apache.apache /srv/svn chmod g+s /srv/svn/db
then create password file
vim /srv/trac/conf/trac.htpasswd
then add user password to it
htpasswd -m /srv/trac/conf/trac.htpasswd charith
configure apache by editing /etc/httpd/conf.d/subversion.conf
add folowwing lines to it
    DAV svn    SVNPath /srv/svn    AuthType Basic    AuthName "svn"    AuthUserFile /srv/trac/conf/trac.htpasswd    Require valid-user  
restart httpd service. This service need to be running to be reload. If not it will out put as "failed"
/sbin/service httpd reload
then upload the code to the repository
svn import -m "intial upload" /home/charith/SvnTestfile:///srv/svn/SvnTest
Can test the subversion surver running properly by checking out the code to some other folder
svn co http://localhost/srv/svn/SvnTest
Make repository access by apache
chcon -R -h -t httpd_sys_content_t /srv/svn/

3) Installing trac
install trac using yum
yum install trac
create a directory to store trac project
mkdir -p /srv/trac
create new trac environment using trav-admin
trac-admin /srv/trac/test initenv
make folders own by apache
chown -R apache.apache /srv/trac
edit the file /etc/httpd/conf.d/trac.conf to point to new project environment
# Replace all occurrences of /srv/trac with your trac root below
# and uncomment the respective SetEnv and PythonOption directives.
    SetEnv TRAC_ENV /srv/trac/charith
   AuthType Basic
   AuthName "trac"
   AuthUserFile /srv/trac/conf/trac.htpasswd
   Require valid-user
    SetHandler mod_python
    PythonHandler trac.web.modpython_frontend
    PythonOption TracEnv /srv/trac/charith
restart httpd service. This service need to be running to be reload. If not it will out put as "failed"
/sbin/service httpd reload
Now you should be able to access the trac in local mahine using
http://localhost/cgi-bin/trac.cgi

If you have enable SELinux there are few things to do, I used following commands to enable web server to access trac and subversion repositories.
chcon -R -t httpd_sys_content_t /srv/trac chcon -R -t httpd_sys_content_t /srv/svn
Easiest thing is to view the SELinux warning message from the top pannel. It contains the command to configure the SELinux.