Category: Programming

Using proguard obfuscator through the Wireless Toolkit

When you develop an application you might want to protect your code. A good way to accomplish this is using obfuscation. Proguard is a good open-source tool you can use for this purpose. To use it through the Wireless Toolkit (WTK), after downloading Proguard, you need to tell the WTK where it can find the obfuscator. You can do that by editing the file ktools.properties that you can find under %WTK%wtklibWindows, where %WTK% is the root directory of the Wireless Toolkit. Basically, you just need to add the two following lines to the aforementioned file:

Read more...

The Function class in JavaScript

Most programmers know how to define and use a function in JavaScript. For example the following function displays an alert containing the string passed in as a parameter:

 
function displayAlert(sText) {
  alert(sText);
}
// Then you call it this way
displayAlert("Hello World!");

How many developers, however, know that JavaScript functions are actually objects? Indeed, you can define the previous function using the Function class:

 
var displayAlert = new Function("sText", "alert(sText);");
//...and you call it the same way
displayAlert("Hello World!");

For those who didn’t figure it out, the syntax of the Function class is the following:

Read more...

How to store and extract XML data in and from an Oracle DataBase (DB)

Here are some snippets of code showing how to accomplish this:

    
CREATE TABLE SampleTable (id number primary key, person XMLType)
This first example creates a table with only two columns: id and person. The first is the PK of the table and the second is of XMLType type. The latter is going to contain our XML data.

Now let’s insert one row in the table.

 
INSERT INTO SampleTable VALUES (1, XMLType('XMLString'))

Where you must replace XMLString with any string representing XML. For example, you can replace it with:

Read more...

Using Javascript to detect the key pressed

Often it is useful to intercept the key pressed within an element of an HTML form, like a textbox and so on. For this purpose you can use Javascript to extract the code of the key that was pressed. Here is a snippet of code you can use–of course adapting it to your needs.

   
function keyPressed(e){
  var code;
  if(window.event){ //IE
   code = e.keyCode;
  }
  else{ //other browsers
    code = e.which;
  }
  //check, for example, if the Enter key was pressed (code 13)
  if(code == 13){
    //Enter key pressed
  }
  else{
    //Another key pressed
  }
}

Note: keyCode is used by Internet Explorer while which is used by the other browsers.

Read more...