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)


Recreating your jQuery Sortable() sort order

A reader pinged me with an interesting question.  He was using jQuery the jQuery sortable behavior to allow users to order widgets on a page and then save their layout.  The issue he was having was figuring out how to recreate the layout when the user reloaded the page.

As always there is more than one way to skin a cat, but I came up with a quick demo to illustrate one way to do this.  If we have the user defined sort order it should be easy enough to recreate the view.  I can think of several other ways to accomplish this, but this was the most straight forward way of handling the problem.

For my example I created a div representing my sortable container.  Within the container I created four divs repesenting my sortable children named “div1” through “div4” (I am very creative first thing in the morning).  I then hard-coded a “user defined” sort order that sorts them from “div4” down to “div1”.  Since I know the sort order it is just a matter of looping through my child elements and putting them in their proper place.  This is done by looking at the sort order array and inserting the selected element after the previous element in the sort order.  We skip the first element in the sort order since it obviously will not have a previous element.  The end result being all the divs nicely ordered, just as the user saved them.

Storing complex objects in memcached on Railo

Lately I have been doing a lot of research into making sites run efficiently and to a larger extent, load  more quickly.  Yesterday I installed memcached and had it up and running on a test server.  Once the memcached daemon is installed and ready to go you will just need to install a java client that will work for Railo.  My friend Gabe wrote this post that covers what is required to get this up and running on an ACF server.  Getting it running on Railo is little different, just extract the jar files for the Java memcached client into the directory that contains your railo.jar file.

I had a simple proof-of-concept application up quickly, I was able to set a string value in the cache and pull it back from the cache easily.  Things got a little bit bumpy when I tried to store a complex object in cache.  The result coming back from the cache set was coming back as true which would indicate that the object was successfully set in cache.  When I tried to get the object back from cache and dump it, it always returned a null value.  Logging into memcached through telnet I could see there actually was a value stored for the key but it was not returning.

Since I knew I could store simple values with no problem I decided to take the path of least resistance.  Using the Railo serialize() function I could convert complex objects to a string representation and insert it into the cache.  When I pull the value out of cache I evaluate() it and return the object value.  Since I would end up creating a facade for setting/getting objects in cache this is not really an issue.  I know ACF handles this without the need for a work around so it just left me scratching my head.  I would imagine the difference is how Railo and ACF implements the data types, but I have not had time to verify this although if I have some free time this afternoon I intend to look in to this.

Here is a code sample I wrote to get this going.  Basically it is the same as Gabe’s code with some changes to make it work with Railo.

 serverlist = "";
 serverList = serverlist.split(",");
 pool = createObject("java","com.danga.MemCached.SockIOPool");
 pool = pool.getInstance();
 if(not pool.isInitialized()){
 poolInit = pool.isInitialized();

 memcached = createObject("java", "com.danga.MemCached.MemCachedClient");
 someData = queryNew('a, b');
 queryAddRow(someData, 1);
 querySetCell(someData, 'a', 'apple');
 querySetCell(someData, 'b', 'orange');
 dump(memcached.set("someData", serialize(someData)));