my recent reads..

Exercising Regular Expressions and Arrays in Javascript

I've been working a bit with AJAX, and that soon prompted me to brush up on my Javascript. In the past I'd never used it to do more than a little validation or form "glue". Now revisiting the language from a true programmer's perspective, I recognise that it is pretty capable!

Speak Good Singlish! is a sample that gives regular expression and multi-dimensional array handling a good workout. It's a Singlish translator implemented in Javascript. I can't remember what sparked the idea to use this as an example, but somehow I got thinking back to ole "Jive" and "Valley girl" translators that have been floating around the net for many years.

The RegExp object usage in the sample is fairly standard, but the array handling is not.

I'm using a 2D array for the "lexicon" - basically a list of regex matches and replacements. For example the following fragment. You'll note that the second dimension can contain either a simple string or an array (as the replacement element):

var slexicon = [
[ '\\benglish\\b', 'Singlish' ] ,
[ '\\bdo\\b', [ 'do', 'do until sian', 'do sure can one' ] ]
There's a core routine that iterates through the array and performs the substitutions. Where an array substitution is present, it uses a funtion inline to pick a random element from the array to perform the substitution:
// do the translation
for (var i = 0; i < slexicon.length ; i++) {
var slexiconRow = slexicon[i];
var theRegex = new RegExp( slexiconRow[0], "gim" );
var theReplacement = slexiconRow[1];
if (theReplacement instanceof Array ) {
dataOut = dataOut.replace( theRegex, function (match) {return randomElement(theReplacement)} );
} else {
dataOut = dataOut.replace( theRegex, theReplacement );
The randomElement function is simplicity itself:
// returns random element of an array
var randomElement = new Function("x", "return x[Math.floor(Math.random() * (x.length))]");
The HTML page contains the whole script inline, so it is easy to review in-place with a "view source". Enjoy!
read more and comment..

Simple Perl clients for Axis2 with SOAP::Lite

SOAP::Lite is an incredibly powerful little module that makes using Perl for SOAP clients a piece of cake (groan).

True to the spirit of Perl, it makes simple things simple. This is all you need to do to interrogate the "Version" Axis (1+2) service:

#!/usr/bin/perl -w
use SOAP::Lite;
print SOAP::Lite
-> proxy('http://localhost/axis2/services/Version')
-> getVersion()
-> result;

The output:
Hello I am Axis2 version service , My version is 1.1

The SOAP request that this generates is as basic as it gets, and as you can see most of it is dedicated to the envelope definition:
<?xml version="1.0" encoding="UTF-8"?>

The example does illustrate one very important capability of SOAP::Lite - the automatic marshaling of the response into a usable Perl structure. In this case, its just a string.

One of the difficulties with SOAP::Lite at present is the dearth of good documentation and examples. This does tend to make doing more complex operations feel like you are living on the edge, but that's where the fun begins for some I guess;) I will look at some more complex request and response topics in a further post.
read more and comment..

AXIS Revisited on OC4j - AXIS 2

Apache Axis2 is the core engine for Web services. It is a complete re-design and re-write of the widely used Apache Axis SOAP stack to build on the lessons learnt from Apache Axis. Version 1.1 was released in Nov'06. My first simple test was to update my deployment on Oracle OC4J.
Happily, it deployed just as easily as the original Axis, as I reported in a previous post.

Deployment of the Axis2 webapp is a little different, but just as straightforward. This is what I did:

  1. Download the Standard Binary Distribution and explode into a local folder
  2. In the $AXIS2_HOME/webapp directory, use ant to build the war file: ant create.war
  3. This creates the $AXIS2_HOME/dist/axis2.war file
  4. edit $ORACLE_HOME/j2ee/home/config/application.xml to add <web-module id="axis2" path="file:/d:/axis2/dist/axis2.war"/>
  5. edit $ORACLE_HOME/j2ee/home/config/http-web-site.xml to add <web-app application="default" name="axis2" root="/axis2"/>

And that's it. Axis2 up and running in my OC4J home at http://localhost/axis2/
read more and comment..

Time to upgrade: Linux on Dell 9150

Just recently I bit the bullet - the PCs I had at home no longer had the horsepower (memory mainly) to run the stuff I wanted (Oracle mainly). So I gave myself an early birthday present - a Dell 9150 with the Pentium D processor and 4Gb RAM. Very nice box - running the pre-installed XP was a scream.

The 250Gb HDD came fully allocated for Windows, but my intention was to get it dual booting Linux. There were a few issues, but nothing a few days of messing around and downloading/cutting CDs couldn't fix.

First, to repartition the HDD I used qtparted from a Knoppix boot CD. This worked with no problems at all - Knoppix even booted into a high resolution display and I was able to knock the XP partition down to 50Gb without reinstalling.

Things weren't so straightforward when I started the Linux install, where I was planning Red Hat. I first tried RHEL WS 4 and got nowhere because the installer booted into a graphics mode that the machine couldn't display. I couldn't be bothered persisting because I was really more motivated to go RHEL AS 3 (for compatibility with other systems I'm involved with). I had some update 1 CDs on hand (old I know), but nothing to lose so I proceeded to install. Bad idea - I had driver problems with everything from the Dell USB keyboard (only recognised after plugging/unplugging after boot, and always kicked kudzu into action); USB support in general; the Intel Pro100/1000 NIC (not supported by the e1000 driver); and the display driver (ATI Rage x600).

So nothing to do but spend (quite) a few hours downloading update 6. Luckily this proved to be worthwhile effort - after installing most of the issues are resolved. I still needed to update the e1000 driver, and my display is still running VESA compatible mode but that's OK for me since when booted into Linux I'm mainly just using it as a server. If I want the graphics, sound etc then that usually means I've booted back into XP to dive into Age of Empires III or somesuch;-)

So overall - I'm really happy with the 9150, although I must say where there were a few moments while dealing with Dell's terrible support for Linux on the desktop machines that I was wondering if I made the right buying decision. Dell really should get their act together in terms of supporting Linux on the "consumer" range.
read more and comment..