Tuesday 17 September 2013

Mysql setting the different timezone as default

When you install mysql it uses system time zone as a default time zone, and you may need to specify the different timezone as a default time zone.

1. stop the msql server

2. Go to http://dev.mysql.com/downloads/timezones.html and download "POSIX standard Time zone description tables, version 2011n"

3. unzip "timezone_2011n_posix.zip", copy and paste the files where mysql is installed, on my machine for windows its "C:\ProgramData\MySQL\MySQL Server 5.5\data\mysql"

4. Edit my.ini, for windows its where you have installed mysql, on my windows machine its at "C:\ProgramData\MySQL\MySQL Server 5.5", and add the following entry at the end:
 default-time-zone = UTC

5. Save my.ini

6. Restart the mysql server.

7.  Run the following query to check if the timezone is set to what you are after.
SELECT @@global.time_zone

Note: If you allready have the latest timezone files from the url mentioned in the step 2, you can skip step 2 and 3.

Saturday 10 November 2012

Manually creating a user


Sometimes creating the user with "useradd" utility does not properly configure the user account and hence we have to rely on manually creating one, which is quite simple.

For setting up the user manually we have to edit 3 files, copy one folder and we are done.
We are assuming that you have the write access to the fiels and folders, that is you have root access or you can do sudo

Lets say we need to create a user called "jd".
1. edit /etc/passwd
linux-b0yq:~ #vim /etc/passed
enter the following entry
jd::1000:100:jd:/home/jd:/bin/bash
where
jd is the user login
1000 is the UID
100 is the GID
jd is full name
/home/jd is the home directory
/bin/bash shell to start when the user logs in.

2. edit /etc/shadow
linux-b0yq:~ # vim /etc/shadow
enter the following entry
jd:*:15654:0:99999:7:::
where
We are leaving the password field(2nd field) as *, because it takes a hash value which we do not know, so we will rest the password of this user using "passwd"


3. edit /etc/group, where you can add the new user jd to a new group or to the existing group, lets say we add to the new group called dev_group.
linux-b0yq:~ # vim /etc/group
enter the following entry
dev_group::500:jd
where
dev_group is the new group
500 is the GID
jd is the user that belong to this group, you can also add the multiple comma separated users here.

Creating the home directory for the user.

copy the /etc/skel to /home/ and rename it to jd.
linux-b0yq:~ # cp -r /etc/skel /home/
linux-b0yq:~ # mv /home/skel/ /home/jd
Changing the  owner ship of the user's home directory
linux-b0yq:~ # ls -all /home/jd
you will get the output like
rwxr-xr-x 31 root     users  4096 Nov 10 21:05 jd
Note the third field where it says "root", that is the owner of this directory is root, now we have to change the ownership of this folder to jd
linux-b0yq:~ # chown -Rv jd /home/jd
One last this is that we have to set the user jd's password.
linux-b0yq:~ # passwd jd

Enter the password and and reenter the password.

The user jd is good as gold.

Sunday 16 October 2011

Java implementation of Call Back Method- Observer Pattern

Call back method mechanism is based on the Observer pattern.


Prerequisite in understanding this implementation:
The java's concept of Polymorphsim plays big in the implementation of Observer pattern, so you have to be comfortable with this concept.

Building blocks of the call back method:

1.       Observer
2.       Subject
3.       Interface


Observer
What it means is that the object will wait and observe for an event to occur, and when the event occurs it will do something special, i.e. a special method that it defines, get run.  This object is called the Observer.

Subject
There is another object, called Subject.
What does this object “Subject” do:
1.       Registers an observer with itself.
2.       When some special event occurs( special condition is met), it calls observer’s special method.

Interface
Interface is glue that will hold this whole structure together and forms the back bone of this mechanism.
Let the rubber meet the road.

Step 1:
Let’s start by defining an interface.

package com.src.callback.eventInterfaces;

/**
 * Event NumberGreaterThan5Event, action happens
 * when the number is greater than 5.
 *
 * @author Harbir H/ Adofo
 *
 */
public interface NumberGreaterThan5Event {

      /*
       * declaring an event when the number greater than 5
       */
      public abstract void numberGreaterThan5Event();
}


Step 2:
Let’s create an observer that implements the interface “NumberGreaterThan5Event”.

package com.src.callback.call;

import com.src.callback.eventInterfaces.NumberGreaterThan5Event;

/**
 * The class Observer represent the observer building block
 * of the Observer pattern.
 * The name "Observer" depicts the purpose of this class in
 * context with  the Observer Pattern.
 * @author Harbir H/ Adofo
 *
 */
public class Observer implements NumberGreaterThan5Event {

      @Override
      public void numberGreaterThan5Event() {
            System.out
                        .println("Observer: I know that you have entered number greater than 5");
      }
}

Step3:
Let’s create a subject that will call a method on the observer when an event occurs i.e. when a special condition is met.  In other words subject will notify the observer.
 
package com.src.callback.notifier;

import com.src.callback.eventInterfaces.NumberGreaterThan5Event;

/**
 * The class Subject represent the subject building block
 * of the Observer pattern.
 * The name "Subject" depicts the purpose of this class in
 * context with the Observer Pattern.
 *
 * @author Harbir H/ Adofo
 *
 */
public class Subject {

   private NumberGreaterThan5Event numberGreaterThan5Event;

      /*
       * will accept the objects that will implement NumberGreaterThan5Event
       *
       * @param numberGreaterThan5Event
       */
      public Subject(NumberGreaterThan5Event numberGreaterThan5Event) {
            /*
             * initializing the numberGreaterThan5Event or registering the object
             * that implements NumberGreaterThan5Event
             */
            this.numberGreaterThan5Event = numberGreaterThan5Event;

      }

      public void getNum(int num) {
            if ((num >= 5) && (num <= 9)) {
                  /*
                   * special event has occurred, i.e. we have received a number that
                   * is greater than 5
                   */
                  numberGreaterThan5Event.numberGreaterThan5Event();
            }
      }
}

  • Observer does not have to know about the Subject, unless the Observer is registering itself with the Subject.  We will use another class to run our little call back application and register the Observer with the Subject.
  • Subject will only notify the observers that are registered with it.

 
Step 4:
Creating  the CallBack main class, that runs our little call back application.

package com.src.callback.runner;

import java.util.Scanner;

import com.src.callback.call.Observer;
import com.src.callback.notifier.Subject;
/**
 * CallBackApp demonstrates the implementation
 * of the call back method (Observer  Pattern).  
 * Registers the observer with the subject.
 *
 * @author Harbir H/ Adofo
 *
 */
public class CallBackApp {
      private static Observer observer;
      private static Subject subject;
      private static boolean conti = true;
      private static Scanner scanner;

      public static void main(String[] args) {
            observer = new Observer();
            subject = new Subject(observer); // Registering the observer with
                                                                  // subject.

            scanner = new Scanner(System.in);// to input the data
            enterData();
      }

      public static void enterData() {
            System.out.println(" In the Runner do Something");
            do {
                  System.out.println(" Enter the Value:");
                  int val = scanner.nextInt();
                  subject.getNum(val); // information is being sent to the subject. If
                                                      // the condition is met the notification
                                                      // will be sent.
            } while (conti);
      }

}


Monday 23 May 2011

Setting the PATH in linux.

The reason I am posting this is that as I was migrating from Windows to Linux, I had to configure the PATH variable, as I have to set the development environment and I have not been able to find the straight forward answer, on how to set the Linux PATH variable:

Using openSUSE 11.4

Checking the existing value of the PATH variable:
Just to see what does it look like currently(you can even skip this, nothing exciting):
use echo command.

root:~ # echo $PATH
it will be something like this:
/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin 

Setting the PATH variable value temporarily:
Lets say you want to set the "eclipse" command to the PATH.
"eclipse" command is in the folder /home/userOne/eclipseFolder
root:~ # $PATH":/home/userOne/eclipseFolder"

The above statement will append :/home/userOne/eclipseFolder to the existing value of the PATH.

Setting the PATH variable value permanently:
We will be defining the variable in the following file:
/etc/bash.bashrc.local
If the above file does not exists, then create it.

The following are the contents of this file(bash.bashrc.local)



#setting path for tomcat home directory and exporting it.
export CATALINA_HOME=/home/nyatui/tomcatPack/tomcat6         

#setting path for eclipse home directory
ECLIPSE_HOME=/home/nyatui/eclipse

PATH=$PATH:$ ECLIPSE_HOME
export  PATH

I hope this helps someone :)