Category Archives: Javascript

Ode to Node


ColdFusion has just turned 20 years old and I have been developing with it for 16 of those 20 years; almost half my life. I still use ColdFusion every day in my professional life, but I do not feel the excitement for the language as I used to. I can remember when I actually looked forward to the new features introduced with each new release, but those days have past.

I have recently been looking in to other languages to get some sense of excitement back. First I have been looking into Node. The great part about Node is it is easy to pick up and run with if you know javascript.

A few weeks back we had a hackathon at work and this was my first real application hands on with Node. The project was an end-user level interface that allowed creating an issue and having Node interface with Jira through web services to create issues and assign it to the right project bucket. In retrospect, there definitely are easier projects to choose for your first Node project (especially when you are dealing with the learning curve and you have finite amount of time to get the project done). However, I did pull it off with about 15 minutes to spare. I didn’t win the hackathon, but I had a working Node project and a lot of insight in how to get things done in Node.

I started a little side project to continue learning Node, a Diablo 3 character comparison tool which allows you to compare two Diablo 3 characters side by side. This project focuses on a lot of middleware and making things work as well as hooking into the Battle.net API service. The project is structured much like a ColdBox app with routes, handlers and services. It is a work in progress and I am adding new things as I learn them. I have a demo up and running at http://diablo.kisdigital.com and the full source up at https://github.com/robertz/chardiff.

Next up is a look at Go (http://golang.org)

Advertisements

FireSSH plugin for Firefox


While scanning through my news feeds this morning I found a cool plugin for Firefox called FireSSH that, as the name alludes too, allows you to SSH to a host from your web browser.  Once the plugin is installed you can paste an SSH address in the url bar and go.

Now I just need to find something like this for Chrome.

Creating Javascript arrays on the fly


The need to build a Javascript array is pretty non-existent since many scripting engines (or at least the ones I use) can natively return objects in JSON.  However, if for some reason you cannot get your data back as JSON I whipped up a quick example of how it can be done.  This is more a note for myself, but maybe someone will find it useful.

First we take the data that we already have available in ColdFusion and build the Javascript array.  In our Javascript we create a new variable and set it to the value ColdFusion has built for us.  Below is the code:

<cfscript>
 dataString = "";
 // Build an array of people to play with
 people = arrayNew(1);
 people[1].name = "Jim";
 people[1].hairColor = "Brown";
 people[1].eyeColor = "Brown";
 people[2].name = "John";
 people[2].hairColor = "Black";
 people[2].eyeColor = "Blue";
 people[3].name = "Jane";
 people[3].hairColor = "Blonde";
 people[3].eyeColor = "Green";
 // The "important" stuff (tm)
 jsArray = "[";
 for(y = 1; y lte 3; y = y + 1){
  dataString = listAppend(dataString, "{ name: '#people[y].name#', hairColor: '#people[y].hairColor#', eyeColor: '#people[y].eyeColor#' }");
 }
 jsArray = jsArray & dataString;
 jsArray = jsArray & "]";   
</cfscript>
<cfoutput>
<script type="text/javascript">
 var peopleArray = #jsArray#;
 function dumpArray( obj ){
  for(var i = 0; i < obj.length; i++){
   for(j in obj[i]){
    document.write('<strong>' + j + ':</strong> ' + obj[i][j] + '<br />');
   }
   document.write('<br />');
  }
 }
 dumpArray(peopleArray);
</script>
</cfoutput>