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); } } }
tips and tricks, examples,code snippet and links about Java, JavaScript, jquery, css, html, unix/linux, oracle, mysql, php and web designs that related to my interest
Sunday, August 29, 2010
ping ip address every Nth second to keep VPN connection alive
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
example :
$("input[type=checkbox]:checked").each(function() { //code here }); //$("<element>[<attribute>=<value>]:<condition>")
Wednesday, August 18, 2010
Fast searching with jquery selector
#;&,.+*~':"!^$[]()=>|/
) 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\\[\\]]")
.Attribute Contains Selector [name*=value]
AttributeSelects elements that have the specified attribute with a value containing the a given substring.
Attribute Contains Word Selector [name~=value]
AttributeSelects elements that have the specified attribute with a value containing a given word, delimited by spaces.
Attribute Ends With Selector [name$=value]
AttributeSelects elements that have the specified attribute with a value ending exactly with a given string.
Attribute Equals Selector [name=value]
AttributeSelects elements that have the specified attribute with a value exactly equal to a certain value.
Attribute Not Equal Selector [name!=value]
AttributeSelect elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.
Attribute Starts With Selector [name^=value]
AttributeSelects elements that have the specified attribute with a value beginning exactly with a given string.
full reference : http://api.jquery.com/category/selectors/
jquery selector cheat sheet : http://www.skidoosh.co.uk/jquery/jquery-selectors-and-attribute-selectors-reference-and-examples-v2/