Friday, April 16, 2010

List ports listening

netstat -tlnp | grep 8080 netstat -tlnp | grep java

List all installed jre linux

/usr/sbin/update-alternatives --config java
There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java + 2 /usr/java/jdk1.6.0_18/bin/java Enter to keep the current selection[+], or type selection number:

Thursday, March 25, 2010

Find the large hidden files in your file system

find {/path/to/yourdirectory} -type f -size +{file-size-in-kb}k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
where $8 will show your directory and $5 size of the directory.

Friday, January 1, 2010

Desprado Song

Desperado, why don't you come to your senses?
You been out ridin' fences for so long now
Oh, you're a hard one
I know that you got your reasons
These things that are pleasin' you
Can hurt you somehow
Don' you draw the queen of diamonds, boy
She'll beat you if she's able
You know the queen of hearts is always your best bet

Now it seems to me, some fine things
Have been laid upon your table
But you only want the ones that you can't get

Desperado, oh, you ain't gettin' no youger
Your pain and your hunger, they're drivin' you home
And freedom, oh freedom well, that's just some people talkin'
Your prison is walking through this world all alone

Don't your feet get cold in the winter time?
The sky won't snow and the sun won't shine
It's hard to tell the night time from the day
You're loosin' all your highs and lows
Ain't it funny how the feeling goes away?

Desperado, why don't you come to your senses?
Come down from your fences, open the gate
It may be rainin', but there's a rainbow above you
You better let somebody love you, before it's too late        

Monday, July 13, 2009

Google Voice Gizmo5 Sipphone and Ekiga on Ubuntu

This summary is not available. Please click here to view the post.

Thursday, June 25, 2009

JSON, DOJO and innerHtml and Java Handler.

JSON : JavaScript Object Notation, it is the data interchange format, It simplify the data exchange between client side to server side script. In the example we will pass two string and return a Java MAP response.

DOJO : Is the working dog for ajax communication.

innerHtml: this is useful to replace a element in the html document to be replaced with a ajax response. call the element by dojo.byId("someid") then replace the content of the id by innerHtml. The id can be given to any html element.

Our Architecture
Format data to JSON content---> Dojo ---------> xhrPost.Post --> Java Handler process-------> send back JSON response to DOJO------> DOJO display on html.
Our Javascript
//Ajax call to return a list of attributes function processBalanceAjaxLookup( CardNo,pinNo, callbackfunction){ var ajaxCommand = {}; ajaxCommand.command="BalanceLookup"; ajaxCommand.formData={"CardNo":CardNo,"pinNo":pinNo}; ajaxCommand.requestURI="/"; var bindArgs = { url: "/ajax", handleAs: "json-comment-filtered", content: {ajaxCommandData: [JSON.stringify(ajaxCommand)]}, error: function(type, errObj){ }, load: function(type, data){ callbackfunction(type); } }; var requestObj = dojo.xhrPost(bindArgs); } //function to be called by the jsp function checkBalance() { var CardNo = document.getElementById("Number").value; var pinNo=document.getElementById("Pin").value; processBalanceAjaxLookup(No,pinNo,processBalanceAjaxLookupCallback); } //call back function or the response function function processBalanceAjaxLookupCallback(attributeData){ //response token var tokens = dojo.objectToQuery(attributeData).split("&") //inner html tags that have to be replaced. var errorTag=dojo.byId("gcError"); var balanceTag = dojo.byId("gcBalance"); var dateTag=dojo.byId("gcDate"); var cardNoTag=dojo.byId("gcNo"); for(var i = 0; i < tokens.length;i++){ var responseData = tokens[i].split("="); if(responseData[0] == "validity"){ if (responseData[1]== "valid" ){ }else{ balanceTag.innerHTML=""; dateTag.innerHTML=""; errorTag.innerHTML="Invalid Card"; } } else if(responseData[0] == "balance") { balanceTag.innerHTML=responseData[1]; } else if(responseData[0] == "date") { var nowdate = new Date(); //alert (nowdate); dateTag.innerHTML= nowdate ; } else if(responseData[0] == "CardNo") { cardNoTag.innerHTML=responseData[1]; } else if(dojo.byId(responseData[0])) errorTag.innerHTML = responseData[1]; } }
The Html code which calls the function
< a href="#getBalance" class="nyroModal" onClick= javascript: checkBalance()>< img src="images/checkBalance-Btn.gif" width="140" height="41" />
The Java Code
public JSONObject process(HttpServletRequest request, WebApplicationContext factory, JSONObject ajaxData) throws JSONException { JSONObject rval = null; try { String balance= new String("199393.00"); //process the info and return Map responseMap = new HashMap (); if ( CardNo != null ){ responseMap.put("validity", "valid"); responseMap.put( "CardNo", maskGc(CardNo)); responseMap.put("date", formatDate); responseMap.put("balance", balance); rval= new JSONObject(responseMap); }else{ responseMap.put("validity", "invalid"); responseMap.put( "CardNo", ""); responseMap.put("date", ""); responseMap.put("balance", ""); rval= new JSONObject(responseMap); } } catch (Exception e) { e.printStackTrace(); throw new JSONException("Error retrieving Card Balance."); } return rval; }
An Abstract class to invoke the Spring handler and process AJAX calls
public class AbstractAjaxServlet extends HttpServlet { private static Logger myLogger = Logger.getLogger(AbstractAjaxServlet.class); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { doProcess(req, resp); } catch (IOException e) { e.printStackTrace(); throw e; } } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { doProcess(req, resp); } catch (IOException e) { e.printStackTrace(); throw e; } } /** * Parses an incoming ajax command object and uses the command name to perform * a Spring lookup for an appropriate handler. Returns the handler's return value * as JSON back to the caller. * * @param req * @param res * @throws IOException */ private void doProcess(HttpServletRequest req, HttpServletResponse res) throws IOException { myLogger.info("> doProcess", null); res.setContentType("text/json-comment-filtered"); if (req.getParameterValues("ajaxCommandData") == null) { return; // We don't know how to handle the request. } String json = req.getParameterValues("ajaxCommandData")[0]; try { JSONObject jsonObject = new JSONObject(json); // Delegation time. String command = jsonObject.getString("command"); // Take the command string and lookup a Spring object to handle it. String handlerName = command; handlerName = handlerName.substring(0, 1).toUpperCase() + handlerName.substring(1); handlerName = "AjaxHandler" + handlerName; WebApplicationContext factory = WebApplicationContextUtils.getWebApplicationContext(req.getSession().getServletContext()); if (!factory.containsBean(handlerName)) { throw new IOException("Invalid ajax handler " + handlerName); } AbstractAjaxHandler handler = (AbstractAjaxHandler) factory.getBean(handlerName); JSONObject returnValue = handler.process(req,factory,jsonObject); res.getWriter().println("/* " + returnValue + " */"); } catch (JSONException e) { e.printStackTrace(); throw new IOException(e.toString()); } myLogger.info("< doProcess", null); } }

Masking for Credit Cards

This will show only the last 4 digits .

private String maskGc(String oS){ int beginIndex=0; int endIndex=12; if (oS.length()>15){ oS= oS.replace(oS.substring(beginIndex, endIndex), "****************"); return oS; } Output: ****************3456