Archive for January, 2010

Automating the Web with WWW::Mechanize

January 25th, 2010

And yes, the double colon does mean Perl. However, I know that Python also has the same class modeled after the Perl module. So even if py- is your favorite prefix, this should still be useful.

WWW::Mechanize gives you basic access to a “web browser” from your Perl scripts. It has the concept of getting, putting, ticking and clicking. Use an image map, or enter text into a text box. It even has a back button! Using all these and more, one can make quite the script to do most anything. I’ve used this before to create a script that logged into a Google Search Appliance and download a backup file. (Since for some reason, there is no way to push backups from within a GSA)

More recently, I decided to automate the downloading of PDF statements from my bank’s website. This is a popular use for WWW::Mechanize, and I’ll go through a quick script which will do just this.
» Read more: Automating the Web with WWW::Mechanize

Creating Services using SMF in OpenSolaris

January 22nd, 2010

OpenSolaris has by far, one of the best service management interfaces that I have used. Below I am going to go over a simple way to turn in shell script into a service managed by the OS.
» Read more: Creating Services using SMF in OpenSolaris

Blue Monday

January 20th, 2010

January 25th is an important day… it’s not a holiday, it’s not a paid day off… it is…

WinterBluesThe

L        o        n        g        e        s        t

and

most depressing

day of the year

» Read more: Blue Monday

Hibernate Embeddable Objects

January 18th, 2010

Hibernate Embeddable Objects are a really neat way to organize your data model.  Especially, if you have the same few columns in a number of different tables, that all pertain to the same thing. The example commonly used is Addresses.  You may have a number of tables that each have fields pertaining to address information and you don’t want to have to do all the mappings for each entity again and again.  If the column names are the same across each table, you can just add an @Embeddable annotation.
» Read more: Hibernate Embeddable Objects

Is trying to learn a new language every year worth it?

January 15th, 2010

While spending time recently looking for something new to learn that looked interesting, and it still being so close to new years, I was reminded of a bit of advice from the book “The Pragmatic Programmer,” learn a new language every year. But is learning a new language every year actually helpful?
» Read more: Is trying to learn a new language every year worth it?

Keep your dataTable clean with a custom popup

January 13th, 2010

The basic idea is to output some data to a user in a table and allow them to take an action on each row individually. A fairly straightforward solution is to create a separate page to link to, passing the necessary row information along. If the action is simple enough, like a single checkbox, you could just embed the necessary component(s) in each row of the table. Too many components, however, can bloat the table and make the UI cumbersome to the user. Instead we can create a popup window to overlay our page, containing whatever components are needed, and activate it by a link embedded in our table. Passing the row information is a little trickier, but the result is a cleaner interface and a better user experience.
» Read more: Keep your dataTable clean with a custom popup

Building Perl modules on OpenSolaris

January 11th, 2010

Anyone that’s worked with Perl is probably familiar with CPAN.pm. CPAN.pm is the bundled module that handles downloading and installing modules from the CPAN repository. It usually works flawlessly but I’ve noticed that on OpenSolaris the process can be a bit more spotty.
» Read more: Building Perl modules on OpenSolaris

Spring’s refreshable beans

January 8th, 2010

A couple of days ago I found out about a really nice feature in Spring, called ‘refreshable bean’.

Spring’s vision a refreshable bean is a dynamic-language-backed bean that monitors changes to its source code and then reloads itself when changes occur. And it is all this is done without restarting/re-deploying entire app. Sweet!
» Read more: Spring’s refreshable beans

Who Bound Port 8080

January 6th, 2010

“Port 8080 required by Tomcat v6.0 Server at localhost is already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s).”

I have been seeing this error from Tomcat every time I reboot my Windows development box.
» Read more: Who Bound Port 8080

YUI3 Lets You Call Webservices With No Server Required

January 4th, 2010

I like YUI3, mostly because I can use it to fill in the gaps between HTML4 and HTML5, and also because a single line of code can make a button zoom around the page:

  var myAnim = new YAHOO.util.Anim('testButton', 
                      { width: { to: 400 }  }, 
                      1, 
                      YAHOO.util.Easing.easeOut);

Also, I can define data sources and polling intervals completely client side, without having to wait for everyone to finish implementing the event-source tag. YUI3 defines 3 useful objects: DataSource, DataSchema, and DataType. DataSource defines a generic source of data. It could be a function, a file, or a web service. Once the DataSource has been configured, you can pull from and publish to the specified location. Here’s a simple example:

YUI().use("datasource-function", function(Y) {
   var getDate = function() {
     return new Date();
   },
   dateDataSource = new Y.DataSource.Function({source:getDate}),
   callback = {
      success: function(e){
                  alert("Current Time is: " + e.response.results[0]);
               },
      failure: function(e){
                  alert("Error!: " + e.error.message);
               }
    };
 
    dateDataSource.request(null, callback);
}

Above, we’ve got some basic YUI steps. The first line defines a block of YUI code that depends on the datasource-function component. In the block, we define a method to get the current date and time, and a DataSource the pulls its information from that function. Next up, we define a callback to handle the possible return situations when the data source requests information. The last line requests data from the function.

YUI will call the getDate function, take the output from that function and pass it as an event to the callback. If there was no problem, the browser will pop up a window telling you what time it is.

Enough of that, let’s turn it up to 11. We will change up the data source to pull from a webservice first:

   stockDataSource = 
            new Y.DataSource.Get({source:"http://www.stocks.com/NASDAQ"},

The Get data source knows to look for a URL. We’ll pretend this one will give us the NASDAQ index number. We will also pretend that the response looks like this:

<stocks>
  <stock>
     <name>NASDAQ</name>
     <value>189.14</value>
  </stock>
</stocks>

So, now we need to define the schema for the data source. Simple enough, we just need to plug in a schema definition:

  stockDataSource.plug({fn: Y.Plugin.DataSourceXMLSchema, cfg: {
     schema: {
          resultListLocator: "stocks",
          resultFields: [{key:"value"}]
     });

Above, we’ve defined the resultListLocator to the be xpath to a list of results, in this case stock nodes. Then we specify the fields of that we’re interested in, namely the value node. The DataSchema will be applied to all data coming into the data source. Now, we just modify the callback handler to deal with the new information, like so:

   callback = {
      success: 
        function(e) {
          alert("The NASDAQ Index is currently: " + e.response.results[0].value);
        },
      ...
   };

The response contains an array results, which is a list of objects exposing the resultFields as properties. And now when stockDataSource.sendRequest(null, callback); is executed, the DataSource will consume the webservice, format the XML into an array of objects, attach them to the response event and pass it on to the callback function. No server handling required.