Friday, October 16, 2009

Convert Java Date to Mysql Date

Normal 0 21 false false false MicrosoftInternetExplorer4

public static String toMysqlDateStr(Date date){

if (date==null)

return "NULL";

SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

return '\''+sdf.format(date)+'\'';

}

Wednesday, March 18, 2009

How to measure distance on google maps ?

Use the page here , you just click on points and the distance will appear either in miles or in kilometers. You can also mark multiple points and calculate a real length of a path.

Wednesday, March 11, 2009

Check if a String contains letter

public static boolean containsLetter(String s) {
if ( s == null )
return false;
boolean letterFound = false;
for (int i = 0; !letterFound && i < s.length(); i++)
letterFound = letterFound
|| Character.isLetter(s.charAt(i));
return letterFound;
}

Friday, February 27, 2009

Get MimeType of A File

Use activation.jar to access javax.activation API.

File file = new File("foo.jpg");
String mimeType = new MimetypesFileTypeMap().getContentType(file)); // image/jpeg

alternatively , you can use filename to detech the mime type :
String mimeType = new MimetypesFileTypeMap().getContentType("foo.jpg")); // image/jpeg

Thursday, January 22, 2009

Redirect StdErr to Stdin in Batch and Shell Scripts

On windows command prompt :

mybatch.bat 1> log.txt 2>&1

This redirects stdin to log.txt and stderr to stdin

On Bash Linux Shell:
grep * &> allout.txt


Friday, October 31, 2008

Get Remote IP Address In Axis SOAP Server

Obtain remote IP from ServletRequest :

import javax.servlet.http.HttpServletRequest;

import org.apache.axis.MessageContext;

import org.apache.axis.transport.http.HTTPConstants;

public static String getSOAPRemoteIP() {

MessageContext context = MessageContext.getCurrentContext();

String address = null;

if(context!=null &&

context.containsProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST))

{

HttpServletRequest servletReq = (HttpServletRequest)

context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);

if (servletReq != null)

address = servletReq.getRemoteAddr();

}

return address;

}

Tuesday, September 2, 2008

Google Chrome Ready For Download

Google has released a new browser named Google Chrome. This browser is expected to become most widespred computer program ever written. Google Chrome will set the standarts for Web2.0 and Web3.0 technologies.

Chrome is a ligtweight browser and does not consume your CPU and memory and it makes Chrome fast and reliable.

Download Here

Here is a gread comic book for chrome on googlebooks site

At first impression Google Chrome is not working properly with PHP-Admin !!!