Wednesday, March 2, 2011

Windows 7 minimized progress indicator

Just noticed a new feature in Windows 7 (I don't actually know this was introduced in 7).

See the "Backup and. . ." button? I was running a backup using with Windows Backup utility and minimized it when I noticed the green progress underlay on the restore button. Nice stuff!

Friday, February 11, 2011

Really good presentation on how Dev and Ops work well. . .and together

Velocity 09: John Allspaw, "10+ Deploys Per Day: Dev and Ops Cooperation at Flickr"

A colleague at my new job shared this slideshow with me and the link to the video was in the comments. I wish I could have seen this before leaving my last job. In my current job, we're already doing most of this.

And here's another article with some crossover in team membership and philosophy:
http://www.quora.com/How-does-Etsy-manage-development-and-operations

Tuesday, August 24, 2010

Coldfusion Structure and StructInsert()

I've been doing a lot of Ajax driven features lately and, since so much of the older server-side I'm working with is in Coldfusion, I've been building a lot of private services in CF which return data in JSON. When I first started creating the CF services, I'd do a bit of massaging of data in CF and then loop over the data building a manually coded JSON string for output.

When I discovered Coldfusion's serializeJSON() function, I was very happy and I had a lot less typing to do. The first problem arose when I converted some of my CF code using native CF arrays and structures and ultimately pushed into the serializeJSON() function--my Javascripts, which consumed the JSON data, broke.

After doing some searching on the web, I learned that most everyone else using CF had encountered this problem--CF Struct keys are serialized to ALL-CAPS. I tend to use basic-camel case for all my variable names and this helps me keep track of things between CF (non-case sensitive) and Javascript (case sensitive). As soon as I started using serializeJSON(), my Javascripts broke and, upon closer inspection, I discovered the letter case problem. So, for a while, I started setting all my JSON key values in Javascript to ALL-CAPS whenever the JSON was to come from my CF services. Yesterday, all of this came full circle and I am back to normalcy.

The second problem that came up yesterday was when I was consuming two different CF services in the same front-end page. The first was generating JSON from a CF structure that a colleague had build and the second I had built. I first built all of my Javascript around my own CF-to-JSON service and everything was working fine. I reviewed the code and made sure that the JSON structure/signature output by my colleague's service and my own were identical. As soon as I began consuming  my colleague's service, my Javascripts broke again. When I inspected the JSON output, all the keys were in camel case!

It took a while but I finally discovered the difference between my colleague's JSON service and my own. My colleague initialized keys into the CF structure using structInsert() whereas I had never used that function--I have always enjoyed using CF's short-hand (magic--always avoid magic in coding!) for adding keys and values to a structure.

--using short-hand, magic:
myStruct.firstMember = "value";
Using the above technique, the letter casing of the keyName WILL NOT be preserved during serialization.

--using structInsert(structReference, keyName, value, allowOverwrite):
myStruct = structNew();
structInsert(myStruct, "firstMember", "value", true);
Using the above technique, the letter casing of the keyName will be preserved during serialization.

Also note that, using the structInsert() technique, if you set the allowOverwrite param to true, you can revert back to the short-hand, dot-notation (NOT magic) for updating structure member values after they are already initialized. This WILL NOT degrade preservation of your letter casing during serialization.

Finally, my JSON object keys in my Ajax call-back functions are readable again!!

Tuesday, June 15, 2010

Handy CFScript Cheat Sheet

Was looking up the CFScript syntax for Try/Catch again and found this:

CFSCRIPT ColdFusion Cheat Sheet

Thursday, June 10, 2010

Readable string concatenation in CFScript

Once again, (still) working on refactoring large blocks of spaghetti CFML code for all the right reasons. I'm still moving over to CFScript where I'm able as part of the process and I came across a bit of a code readability obstacle.

So, you may know that in JavaScript, you can concatenate a string variable as follows:
var someText = "This is the first part. ";
someText += "And this is the second. ";
alert(someText);
//alert text is "This is the first part. And this is the second. "
This is really a short-hand for:
var someText = "This is the first part. ";
someText = someText + "And this is the second. " ;
alert(someText);
//alert text is "This is the first part. And this is the second. "
Well, as it turns out, += doesn't work on strings in CFScript. So, I got to thinking about how we concatenate string variables with literals in Coldfusion:
var string1 = "This is the first part. ";
var string2 = string1 & "And this is the second. ";
writeOutput(string2);
//results in "This is the first part. And this is the second. "
. . .and that is what led me do test using &= for short-hand concatenation. It works!
 var someText = "This is the first part. ";
someText &= "And this is the second. ";
writeOutput(string2);
//results in "This is the first part. And this is the second. "
This is very valuable to me for two reasons that are really the same reason. First, when I break concatenation up into multiple lines, it's more readable and the logic is clear--especially when there may be one or more variables within the string. Second, the editor I'm using right now is CFEclipse on Eclipse and the color coding and error detection in there seems to get easily confused when long literals mixed with variables are placed in one assignment statement. Here is an example of what I'm writing about:
screen_text = "ERROR Something went wrong. Something went wrong. Something went wrong. Something went wrong. Something went wrong. Something went wrong. Something went wrong. Something went wrong. Something went wrong. #errorBrief# Something went wrong. #errorDetails# ";
With short-hand concatenation, I can make this easier for me, other developers AND text-editors and IDEs to make sense of what's going on here:
screen_text = "ERROR Something went wrong. Something went wrong. ";
screen_text &= "Something went wrong. Something went wrong. Something went wrong. ";
screen_text &= "Something went wrong. Something went wrong. Something went wrong. ";
screen_text &= "Something went wrong. ";
screen_text &= errorBrief; 
screen_text &= " Something went wrong. ";
screen_text &= errorDetails;
Some might suggest that that is no different than "inline" concatenation:
screen_text = "ERROR Something went wrong. Something went wrong. "
  & "Something went wrong. Something went wrong. Something went wrong. "
  & "Something went wrong. Something went wrong. Something went wrong. "
  & "Something went wrong. "
  & errorBrief
  & " Something went wrong. "
  & errorDetails; 
. . .and, on a basic level, it is NO different. I would just say that in a more real-world scenario, short-hand concatenation is more portable. If I need to refactor the concatenation and, say, move different parts of it to different parts of my business logic, the short-hand concatenation will be easier to move around without much, if any, modification.

Tuesday, June 8, 2010

CFLocation in CFScript

I often find myself converting old, long blocks of CFML to CFScript before attempting to refactor, modularize and patternize that code. I do this both to make the code more readable for me and to make the code more portable since much of my refactoring will be done in CFScript anyway. Unfortunately CFScript doesn't support all of the same functions provided for in CFML--in fact, CFScript functions are a very limited set unless you start digging into the Java functions and how to access them in Coldfusion. Yesterday I ran into a need to have CFLocation in my CFScript. It took me a while but I found a really old blog entry with the following solution:
GetPageContext().getResponse().sendRedirect([URL String]);
It works just as I need it to. I haven't yet done the research but I'm assuming this is an example of accessing the Java side of CF. It will be interesting to explore the three functions AND how, apparently, Java supports chaining similar to the jQuery does.

Monday, June 7, 2010

Split Code View in Eclipse


I just learned about a feature in Eclipse that I was missing from my Homesite+ days.

Some background
For me, Eclipse easily replaces Homesite+ for Coldfusion editing because it has good color coding, auto-formatting and intellisense for CF, HTML, CSS, JavaScript, jQuery and MANY other languages.
Sometimes all of the above languages are, unfortunately, all in the same file and Eclipse is just fine and helpful with this--although, sometimes the color coding gets a little confused on what's going on and reminds me to take every opportunity to refactor old, ugly code.
I use the Aptana (non-pro version) plugin for front-end code support (HTML, CSS, JavaScript, jQuery etc.) and CFEclipse for Coldfusion.
When I'm ready to get off my bum and code in a real OO language, Eclipse also supports (and, I believe, originally was made for) Java Development.

OK, get on with it already
Sometimes I edit very long CF files and would like to copy or migrate code from one part of the file to another.
Sometimes the length of the file makes it difficult to do this carefully and accurately. Enter split code editing.

In this video, I right-click the tab for the file I'm editing and select "New Editor." You can also select the tab you want to split-edit and go to the Window menu to select "New Editor"
You can edit and save in either tab.
Each tab tracks changes in the other.
I haven't tested whether each tab tracks "unsaved" changes in the other.
Switching between recent tabs via the keyboard is control+F6 (hold down to select from context menu or quick-release to go to most recent "other" tab.