ColdFusion ListToArray - includeEmptyField

Most ColdFusion developers have probably realized at some point that ListToArray ignores empty values between delimiters altogether.  What I mean is that "a,,,b,c,d" would return an array with only 4 items in it, rather than 6 items with two of them being empty.  This has been frustrating to say the least.  ColdFusion 8 to the rescue, ListToArray now has a third arguments "includeEmptyField" that defaults to false, but if true will not ignore empty values. See the following code for an example:

ColdFusion:
  1. <cfset letters="a,,,b,c,d" />
  2. <cfdump var="#listToArray(letters,',',true)#" label="listToArray(letters,',',true)" />
  3. <cfdump var="#listToArray(letters,',',false)#" label="listToArray(letters,',',false)" />

The above code results in the following output. Nothing unexpected here, but a welcome addition nonetheless.

ColdFusion’s serializeJSON(): Query of Query vs Database Query

So I was working on an ajax request that reloads a select based on it's dependency to the selection made in an adjacent select, and noticed that all of a sudden, the javascript helper I was using was no longer working.  This came as a surprise as this had been stable for quite some time and the scenario I was using it for seemed identical to those I have used it for in the past.  After spending some time looking into it, I realized the problem.  My function that returned the results to reload the select in this scenario was using a Query of Query, where in the past I had always been returning a Query result straight from the database.  Upon taking a peak at the actual JSON object returned from serializeJSON() and realized that the keys for the data object returned from a normal Query would always return in all caps, and the JavaScript followed this assumption.  The Query of Query actually returned the keys in the exact case used for the select in the query itself.  Look at this example to see what I mean:

ColdFusion:
  1. <!--- ColdFusion query against the database with it's json string ---> 
  2. <cfquery name="getResources" datasource="#helpers.config.getDatasource()#">
  3.     select id, name
  4.     from sport
  5.     group by id, name
  6.     order by name
  7. </cfquery>
  8.  
  9. {
  10.     "ROWCOUNT":2,
  11.     "COLUMNS":["ID","NAME"],
  12.     "DATA": {
  13.         "ID":["1","2","3"],
  14.         "NAME":["Football","Baseball","Soccer"]
  15.     }
  16. }
  17.  
  18.  
  19.  
  20.  
  21.  
  22. <!--- ColdFusion query of query with it's json string ---> 
  23. <cfquery name="getResources" dbtype="query">
  24.     select id, name
  25.     from [local].getSports
  26.     group by id, name
  27.     order by name
  28. </cfquery>
  29.  
  30. {
  31.     "ROWCOUNT":2,
  32.     "COLUMNS":["ID","NAME"],
  33.     "DATA": {
  34.         "id":["1","2","3"],
  35.         "name":["Football","Baseball","Soccer"]
  36.     }
  37. }

Scriptaculous Sortable: onUpdate and onChange events

Today I was working with some nexted Sortable lists using the Sortable class from Scriptaculous.  My list looked something like this.

HTML:
  1. <ul id="list">
  2.     <li id="item_EA13CC21-D86C-4A8D-84A6-016262DBA72E">Room 1</li>
  3.     <li id="item_291BF49D-9FBA-446B-8C32-0E43C0879830">Room 2</li>
  4.     <li id="item_0F8BF7B5-9AF7-4DE0-885C-17BE57126444">Room 3</li>
  5.     <li id="item_0F72290C-FC72-4887-91FF-21E1D460B6FA">Room 4</li>
  6. </ul>

For some reason the onUpdate event did not seem to fire. I found a post here mentioning that not only do the list items have to each have unique ID's, which mine clearly do, but they must also following a naming scheme something like [name]_[id] which mine seems to follow as well. Upon further investigation, it turns out that it needs be formatted with an [name]_[integer]. I assume this is required in order for the class to offer the sequence method.

Clearing options AND optgroups in a select

Until today, I always cleared options from a select by doing something like this:

JavaScript:
  1. //Clear select of exiting options
  2. element.options.length = 0;

A quick Google search turned up this blog post where they had this helpful snippet:

JavaScript:
  1. //Clear select of exiting options and optgroups
  2. while (element.hasChildNodes()) {
  3.      element.removeChild(element.firstChild);
  4. }

This clears all items in the select and there is no noticeable performance loss when dealing with a select with a reasonable number of options.

Brett Favre’s supposed cracked rib

http://sports.espn.go.com/nfl/trainingcamp09/news/story?id=4434939

Something inside of me says this is yet another media stunt by the attention craving Brett Favra.  Saying he believes he has an injury, that is of course not listed on the injury report, gives him two benefits.  He either looks heroic if he has success despite it or he can fall back on it as an excuse if he tanks it again like last week.  Someone needs to deflate this guy's ego.  Hopefully that someone is Briggs or Urlacher!

Inheritance in ColdFusion: Private is more like Protected

We are beginning to utilize inheritance with ColdFusion in one of our new applications we are building currently at work.  We have some parent classes that really have few, if any, methods that should be initialized directly as they where designed to be extended by various other classes.  I realized I wanted some sort of access to use for these methods similar to Protected access in Java.  In the past, I tried to utilize the Package access that ColdFusion supports, but that ended in disaster as I did not do my homework and it did not truly understand what it means for two classes to be in the same Package.  I'm not sure if this changed or I just read it wrong, but it turns out that Private access in ColdFusion is not implemented the same as it is in many other languages.  My understanding of Private in most languages is that the access is limited to the immediate class and nothing else.  it turns out that in ColdFusion it is actually accessible within the immediate class, but also available to any of it's subclasses.  This was good news as it offers a solution that I was looking for.  However, it poses a new question.  Is there no truly private access in a ColdFusion component?  I have heard mention that the variables scope is private as well, but upon running some tests, confirmed it is private to the extent of the private access used for functions which means again, that is is available to a class's subclasses as well.

One one hand, I am delighted to find that I can protect methods in my parent class, but on the other, I am left wondering what would one do if they wanted a private method or attribute in a ColdFusion class.  If anyone has any insight on this, please let me know!

Good Article touching on the current “financial crisis”

Parlez-Vous E.U.?

This guy really hit it on the head with his mention of personal accountability.  It's about time people start owning up to the mistakes they have made and dig themselves out of the hole.  Children who's parents bail them out constantly through life end up weak and unable to make it on their own in many cases.  I see a distinct comparison between that and the scenario today where the government is hell bent on cleaning up after all the irresponsible people in this country.  That said, I am not accusing everyone that has foreclosed or gone bankrupt as being irresponsible.  Obviously layoffs, deaths in the family, and other situations represent truly unforeseen scenarios that could lead to financial troubles, but if it's just because someone racked up the credit cards or bought a home they couldn't afford then I really have no sympathy, nor do I want to be taxed to bail them out!

SVN Command Line

First I'll start off with some background information on the reason for my diving into SVN Command Line.  On a project I am involved with, we currently submit database scripts to a centralized location within our project repository.  Being that we are fairly early in development, and the fact that we actually use a largely database driven layout, there are a LOT of scripts being commit.  When it comes time to release, someone is presented with the task of taking the SQL files from a range of revisions, reviewing, and building one compilation script for the release.  Nobody likes to be this person :)

I decided to build a tool to allow someone to enter a repository path and a range of revisions and have it output a compiled database script to their browser to  allow them to review, edit if need be, and database it so it is available for future deployments or simply for reference.  I won't get into the views so much, but I will fill you in on some gotcha's that I encountered as well as provide a couple of ColdFusion functions that might prove helpful.

First thing's first, here is the documentation for all things SVN Command Line.  Here are some pointers that may prove helpful for someone on a similar venture:

I wanted to be able to run the command line from the application without having to install the client on the server, so I just packaged the actual executable and corresponding DLL's in my project and all my functions run against the executable directly.  Here is the package of files I included to do this.

I put together a couple of functions that leverage SVN Command Line to get log information as well as the contents of a file at a given revision.  Here is the code if you want to check it out.  The reason for the formatPath functions is to account for spaces in file names or directories.  I figured there is a strong possibility I could find other formatting concerns as this is used more, so I might as just wrap a function around it so if I do find another it's an easy update.  Also, something that hung me up for a while is that the paths used in your command line are case sensitive so just be aware of this.  It is not really an issue when you are getting the paths directly from Subversion and outputting them in your command line since they come out with the correct case, but still something to keep in the back of your mind.

At this point we have clearly only scratched the surface of simplifying our release process using SVN Command Line.  I will post more information as we expand on this project.

Transact SQL: Using partition by with row_number()

I stumbled across something interesting today when looking at the documentation for Transact SQL's row_number() function.  In the past, when using row_number(), I had limited myself to simple scenarios only using the over clause with "order by". Here is an example where I take a simple resultset containing 7 grades and rank them in descending order:

SQL:
  1. SELECT row_number() over(ORDER BY grades.grade DESC) AS grade_rank, grades.grade
  2. FROM
  3. (
  4.     SELECT 99 AS grade
  5.     union
  6.     SELECT 87
  7.     union
  8.     SELECT 71
  9.     union
  10.     SELECT 83
  11.     union
  12.     SELECT 78
  13.     union
  14.     SELECT 63
  15.     union
  16.     SELECT 92
  17. ) grades

 

In the documentation found here I found mention of using not only "order by", but also something I was unfamiliar with called "partition by", within the over clause. Upon reading further, I learned that this can be of value if you wanted to apply some sort of rank or sequence to subsets within a resultset rather than the entire resultset. A relevant example I came up with was taking a resultset that contains grades for multiple students in multiple classes and ranking the students' grade in descending order within each class. Here is the query:

SQL:
  1. SELECT classid, studentid, row_number() over(partition BY classid ORDER BY classid ASC, grade DESC) AS class_rank, grade
  2. FROM
  3. (
  4.     SELECT 1 AS classid, 1 AS studentid, 99 AS grade
  5.     union
  6.     SELECT 1 AS classid, 2 AS studentid, 87 AS grade
  7.     union
  8.     SELECT 1 AS classid, 3 AS studentid, 71 AS grade
  9.     union
  10.     SELECT 2 AS classid, 4 AS studentid, 83 AS grade
  11.     union
  12.     SELECT 2 AS classid, 5 AS studentid, 78 AS grade
  13.     union
  14.     SELECT 2 AS classid, 6 AS studentid, 63 AS grade
  15.     union
  16.     SELECT 2 AS classid, 7 AS studentid, 92 AS grade
  17. ) student_grades

Running this query will show you 3 students ranked in order of grade descending for class 1 and 4 students ranked in order of grade descending for class 2. Pretty sweet, huh?

Apparently Doug Dascenzo didn’t rule?!?

http://fireloupiniella.wordpress.com/2007/03/01/84-doug-out-dascenzo/

 So, on that note...is he a first or second ballot HOF'er?