Sunday, January 16, 2011

Change SSH port in Ubuntu

You can edit ssh configurations within /etc/ssh/sshd_config file.
That's all :)

Sunday, January 9, 2011

How to monitor your apache status.

I'll using mod_status which apache2 has provided for.
It's easy to use and you can also use perl script to grab some information you'd like to.

Let's see if you've already got mod_status
browse to your /etc/apache2/mods-available/ 
just list the items and have a look. I think for apache2 they've just put it in already.

So now let's have a test.
$apache2ctl full status
If  it said that you need to add some kind of extended status,
Let's head to the /etc/apache2/apache2.conf and added this code at the end of file.
ExtendedStatus On
Now, your apache status will come up with full information.

If you need more configuration, please have it configured in /etc/apache2/mods-available/status.conf
<IfModule mod_status.c>

# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Uncomment and change the ".example.com" to allow
# access from other hosts.
<Location /server-status>
     SetHandler server-status
     Order allow,deny
     Order deny,allow
     Deny from all
     Allow from localhost ip6-localhost
     Allow from .example.com
</Location>
 </IfModule>


Wednesday, January 5, 2011

Heap Sort Algorithms with Java

It's my homework before new year.
Well not much to talk today. Let's have a look.
//*************Find Left and Right****************//
public static int left(int i){
          return (2*i)+1;
}
public static int right(int i){
          return (2*i)+2;
}
//************Max Heapify**********************//
public static void max_heapify(int x[],int i){
int l = left(i);
int r = right(i);
int largest;
     if(l<=(heap_size) && x[l] > x[i]){
          largest = l;
     }
     else
          largest = i;
     if(r<=(heap_size) && x[r] > x[largest]){
          largest = r;
     }
     if(largest != i){
          //SWAP
          int temp = x[i];
          x[i] = x[largest];
          x[largest] = temp;
          max_heapify(x,largest);
     }
}
public static void build_max_heap(int x[]){
     for(int i = (x.length/2)-1;i>=0;i--){
          max_heapify(x,i);
     }
}
public static void heap_sort(int x[]){
     build_max_heap(x);
     int temp;
     heap_size = x.length-1;
          for(int i = heap_size;i>=0;i--){
               temp = x[0];
               x[0] = x[i];
               x[i] = temp;
               heap_size--;
               max_heapify(x,0);


         }
}
These algorithms were derived from "Introduction to Algorithms by T Cormen, C Leiserson, R Rivest, and C Stein"

Have fun :)