Sunday, August 29, 2010

ping ip address every Nth second to keep VPN connection alive

Sometimes 'ping myipadress -t' to keep vpn connection alive doesn't work. Below is Java way.

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class VPNKeepAlive {
   public final static int TIMEOUT = 3000;
   public final static String URL = "myipaddress"; //ip address or domain name
   public static void main(String[] args) {
      try {
         InetAddress inetAddress = InetAddress.getByName(URL);
         while(true) {
            if(inetAddress.isReachable(TIMEOUT)) {
               Thread.sleep(60000);
            }
         }
      } catch (UnknownHostException e) {
         System.err.println(e);
      } catch (IOException e) {
         System.err.println(e);
      } catch (InterruptedException e) {
         System.err.println(e);
      }
   }
}

Wednesday, August 25, 2010

PHP Y2K38 Bug :furthest date can be stored is on 19 January 2038 ?

$date = '2040-02-01';
$format = 'l d F Y H:i';
$mydate1 = strtotime($date);
echo date($format, $mydate1);

If you’re seeing a date in the late 60’s or early 70’s ,your php affected by Y2K38 Bug.

alternative solution:

Use DateTime class in PHP version 5.2.
$mydate2 = new DateTime($date);
$mydate2->format($format),

Tuesday, August 24, 2010

javascript : trim white space

// trim blank space at the string
function trim_string( string ) {
   return string.replace(/(^\s*)|(\s*$)/g, '');
}

// trim blank space at the beginning
function left_trim_string( string ) {
   return string.replace(/(^\s*)/g, '');
}

// trim blank space at the end
function right_trim_string( string ) {
   return string.replace(/(\s*$)/g, '');
} 

Sunday, August 22, 2010

jquery find selected checkbox

this code will go thru for every checkbox that is checked.
example :
$("input[type=checkbox]:checked").each(function() {
//code here
});
//$("<element>[<attribute>=<value>]:<condition>")

Wednesday, August 18, 2010

Fast searching with jquery selector

If you wish to use any of the meta-characters (#;&,.+*~':"!^$[]()=>|/ ) as a literal part of a name, you must escape the character with two backslashes: \\. For example, if you have an an input with name="names[]", you can use the selector$("input[name=names\\[\\]]").