Thursday, July 4, 2013

Create RSA public & private keys in Linux

Using following command you can create public & private keys in Linux.

ssh-keygen -t rsa

This command can be executed in any SSH enabled Linux machine. RSA keys will be stored in .ssh directory created in your home directory.

Thursday, April 25, 2013

Validate email address in JS

Following java script function can be used to check email validation.

function checkEmail() {        

var email = document.getElementById('txtEmail');      

  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;        
   if (!filter.test(email.value)) {      
   alert('Please provide a valid email address');      
   email.focus;      
   return false;   
}

Wednesday, April 17, 2013

Informix set connection timeout

jdbc:informix-sqli://192.168.2.15:1528/database:INFORMIXSERVER=online;user=sujith;password=sujith;INFORMIXCONRETRY=3;INFORMIXCONTIME=60

Above JDBC connection URL can be used for connection timeout issues in Informix database.

INFORMIXCONRETRY : connection retry times
INFORMIXCONTIME : connection time

Connection timeout can be occurred due to database slowness and after maximum connection reach.
You have to change JDBC connection URL.

Thursday, April 4, 2013

Verify HOST servers entrusted certificates in JAVA

In sometimes, it has to be trusted the certificates in JAVA client when applications are developed. This may occur when hosting URL doesn't match with certificate URL.

Following JAVA code can be used to verify host as a trusted host.

   static {
   javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier(){

   public boolean verify(String hostname,
               javax.net.ssl.SSLSession sslSession) {
       if (hostname.equals("192.168.11.123")) {
          return true;
       }
          return false;
       }
   });
     } 

Sunday, March 24, 2013

MySQL cluster JDBC URL


Following code can be used to create a JDBC Connection to MySQL cluster. Here, cluster contains two nodes as 192.168.2.23 & 192.168.2.24.

Class.forName("com.mysql.jdbc.Driver").newInstance();

url = "jdbc:mysql:loadbalance://
                + “192.168.2.23:3306, 192.168.2.24:3306/YourDataBaseName”
                + "?"
                + “user=YourUserName&password=YourPassword”
                + "&loadBalanceConnectionGroup=first&loadBalanceEnableJMX=false&autoReconnect=true";

DriverManager.getConnection(url);

Monday, March 18, 2013

Check application running in Linux


#!/bin/bash

PID1=`ps -eaf | grep app1.jar |grep -v  grep |wc -l`
if [ $PID1 -eq 0 ]
        then
        cd /apps/app1/
        java -jar -Xms32m -Xmx64m app1.jar &
        echo "app1.jar ....................................... Started"
        sleep 1
        else
        echo "app1.jar      ..................................... Already Running"
fi

Above script can be used to check application status. If "app1.jar" is running, it will be printed "Already Running" else, it will start the "app1.jar".

Friday, March 8, 2013

Find 12 months previous date

Following SQL commands can be used to find the date before 12 months

In Informix,
select * from table where connected_date  < today - (12 UNITS MONTH)

In MySQL,
select * from table where added_date>DATE_ADD(TODAY,INTERVAL -12 MONTH)