Friday, June 12, 2009

Strange Thing Happens To Me

I just resently bought ASROCK motherboard G31M-S. It has realtek 8103EL onboard LAN. Debian 5.0 just installed default r8169 driver. J2EE did not work, glass-fish v2 just went kaputt. I did not have any net connection. So :
1. I downloaded r8101 drivers using puppy Linux.
2. Extract the drivers.
3. rmmod r8169.
4. build r8101.
5. insmod r8101.ko.
6. init 6.
7. VOILA my LAN alive and kicking.
8. strangely my glass-fish running well.
9. WHY : I don't know

Bye

Thursday, May 21, 2009

Installing Apache Server in Debian 5.0 - Lenny

I need to install web server for intranet server. I have a Debian 5.0 box. Therefore it is natural to have apache server installed the newest
  • I logged in as su (Super User). BTW you need to have gcc library installed properly. It means you have to have complete library.
  • I downloaded httpd-2.2.11.tar.bz2.I moved downloaded file into /opt by typing this command : mv httpd-2.2.11.tar.bz2 /opt/. Now the file was moved to /opt.
  • I went to /opt by typing cd /opt.
  • I extract httpd-2.2.11.tar.bz2 with this command : tar xjv httpd-2.2.11.tar.bz2. Directory httpd-2.2.11 was created
  • I went in to that directory : cd /opt/httpd-2.2.11
  • Then I read INSTALL file. It says that I should use this script
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start

  • Since I wanted Apache lives inside "/usr/local/apache2" so I changed the script. The script then looked like this :
$ ./configure --prefix=/usr/local/apache2
$ make
$ make install

  • The first command that I typed was "./configure --prefix=/usr/local/apache2"
  • Next I invoke "make" to build various executables. It was about 10 minutes compilation time in my 512 MB PC.
  • Next I invoke "make install" to install the executables. Running time was about 3 minutes.
  • To start apache server I invoked "/etc/init.d/apache start"
  • I tested the installation by using firefox browser. I typed in address bar : 127.0.0.1. Then I saw the result.
  • I congratulate my self by eating salad and chicken.

Installing FIrefox 3 in Debian 5.0 - Lenny

I needed to have a browser which is familiar with me Firefox. My default Debian 5.0 Installation does not have this browser. So I downloaded from mozilla.com
  • In my computer firefox-3.0.10.tar.bz2 was downloaded into /temp. I directly downloaded it from mozilla.com
  • I moved it into /opt (Since I fell comfortable with installing new software in that directory)
  • I submitted a command like this : tar xjf firefox-3.0.10.tar.bz2. This command created a new directory : firefox
  • Then I went to /usr/bin by typing : cd /usr/bin
  • I created a softlink to /opt/firefox/firefox by typing : ln -s /opt/firefox/firefox. This action created a softlink file named firefox which linked to /opt/firefox/firefox
  • I created a menu Item Inside the Internet sub menu in my Debian 5.0

Now after installing firefox 3.0 I needed installing flash plugin.
  • I moved the downloaded file into /opt by issuing : mv install_flash_player_10_linux.tar.gz /opt/
  • I extracted the file by issuing command : tar xzf install_flash_player_10_linux.tar.gz. It created a new directory : install_flash_player_10_linux
  • I went to the directory : install_flash_player_10_linux
  • Then I issued a command inside the directory : ./flashplayer-installer
  • I was asked where is my browser installed. I answer with this : /opt/firefox. Because it is where my browser installed.
  • Then I was asked to proceed with the Installation and I said Y.
  • I tested my installation by invoking firefox : IT WAS ALIVE AND KICKING.

Sunday, April 26, 2009

6 - Stack

A Stack is a collection of items in which only the most recently added item may be removed. The latest added item is at the top. Basic operations are push and pop. Often top and isEmpty are available, too. Also known as "last-in, first-out" or LIFO (see NIST-DADS' definition of stack). We may think a stack is a cramp storage area, where the first item going in, will certainly last to comes out.

Basic operation of stack are :
  1. push
  2. pop
The program bellow is an example of simple stack operation :

#include "iostream"
using namespace std;

#define n 10
int Stack[n]; //declaring a stack
int Top; //declaring the Top index of a stack
int i; //general counter

void initialize(void)
{
Top = -1;
}

int stillunfilledup(void)
{
if (Top < n-1) //stack is not full yet
{
return 1;
}
else
{
return 0;
}
}

void push(int X)
{
Top =Top +1;
Stack[Top] = X;
}

int notempty(void)
{
if (Top > -1)
{
return 1;
}
else
{
return 0;
}
}

int pop()
{
int X=Stack[Top];
Top = Top -1;
return X;
}


int main(void)
{
int X;
int i;

initialize();


cin >> X;
while (X != 9999) //loop for pushing. As long as the user do not input 999, the loop runs
{
if (stillunfilledup()) //stack is not full yet
{
push(X);
}
else //stack is full
{
cout << "Stack is full";
break;
}
cin >> X;
}

cout << endl << endl << endl;
for (i = 0; i < n; i++)//loop for popping
{
if (notempty())
{
X = pop();
cout << "Pops the " << Top+1 << " th member" << X << endl;
}
else
{
cout << "empty";
}
}
}

Thursday, April 23, 2009

5 - Sorting Algorithm : Shell Sort

Another sorting algorithm is Shell Sort. It is based on insertion sort. This sorting method performs multiple passes through the array. Every time it passes the array it performs insertion sort. It divide the arry into several sets. A set grows every time the algorithm works on the array. Of course we need to understand that each members' location is not adjacent to each other (NOT CONTIGOUS). I will present two Shell sort alogoritms : one is for ascending sort and the other is for descending sort :

The first one is ascending sort :
#include "iostream"
using namespace std;

int main(void)
{
int data[8] = {5, 6, 3, 4, 8, 9, 2, 1};
int i;
int j;
int temp;
int increment;

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

increment = 3;
while (increment > 0)
{
for (i=0; i < 8; i++)
{
j = i;
temp = data[i];
while ((j >= increment) && (data[j-increment] > temp))
{
data[j] = data[j - increment];
j = j - increment;
}
data[j] = temp;
}
if (increment/2 != 0)
increment = increment/2;
else if (increment == 1)
increment = 0;
else
increment = 1;
}

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

return 0;
}

And here is for descending sort :
#include "iostream"
using namespace std;

int main(void)
{
int data[8] = {5, 6, 3, 4, 8, 9, 2, 1};
int i;
int j;
int temp;
int increment;

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

increment = 3;
while (increment > 0)
{
for (i=0; i < 8; i++)
{
j = i;
temp = data[i];
while ((j >= increment) && (data[j-increment] < temp))
{
data[j] = data[j - increment];
j = j - increment;
}
data[j] = temp;
}
if (increment/2 != 0)
increment = increment/2;
else if (increment == 1)
increment = 0;
else
increment = 1;
}

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

return 0;
}

4 - Sorting Algorithm : Insertion Sort

Another sorting algorithm that we can use is insertion sort. We can use it for doing ascending or descending sorting :
  1. If we need to do ascending sort, then we need to compare two elements : if we find an element whose value is greater than temp place its value to right.
  2. If we need to do descending sort, then we need to compare two elements : if we find an element whose value is less than temp place its value to right.
First we have a program Insertion Sort - Ascending :
#include "iostream"
using namespace std;

int main (void)
{
int data[8] = {5, 6, 3, 4, 8, 9, 2, 1};
int i;
int j;
int k;
int temp;

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

for (i = 1; i < 8; i++)
{
temp = data[i];
j = i-1;
while ((j >= 0) && (data[j] > temp))
{
data[j+1] = data[j];
j = j-1;
}
data[j+1] = temp;
}

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}
return 0;
}

Next we are presented with Insertion Sort - Descending :

#include "iostream"
using namespace std;

int main (void)
{
int data[8] = {5, 6, 3, 4, 8, 9, 2, 1};
int i;
int j;
int k;
int temp;

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

for (i = 1; i < 8; i++)
{
temp = data[i];
j = i-1;
while ((j >= 0) && (data[j] < temp))
{
data[j+1] = data[j];
j = j-1;
}
data[j+1] = temp;
}
cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}
return 0;
}

Next we will discuss Shell Sort

3 - Sorting Algorithm : Selection Sort

The code below is an example of Selection Sort - ascending. It ascending sorts an array :
#include "iostream"
using namespace std;

int main (void)
{
int data[8] = {5, 6, 3, 4, 8, 9, 2, 1};
int i;
int j;
int k;
int temp;

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

for (i = 0; i < 8; i++)
{
int k = i;
for (j = i + 1; j < 8; j++)
{
if (data[j] < data[k]) // Ascending Sort
{
k = j;
}
}
int t = data[i];
data[i] = data[k];
data[k] = t;
}

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

return 0;
}

Next we have descending sort :
#include "iostream"
using namespace std;

int main (void)
{
int data[8] = {5, 6, 3, 4, 8, 9, 2, 1};
int i;
int j;
int k;
int temp;

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

for (i = 0; i < 8; i++)
{
int k = i;
for (j = i + 1; j < 8; j++)
{
if (data[j] > data[k]) //descending sort
{
k = j;
}
}
int t = data[i];
data[i] = data[k];
data[k] = t;
}

cout << endl;
for (i = 0; i < 8; i++)
{
cout << data[i];
}

return 0;
}