Archive for the 'Development' Category

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.

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!

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?

ColdFusion 8 and IIS7 on 64 bit Vista

I was having some issues getting my development environment for ColdFusion setup today at home.  I found ColdFusion 8 Vista SP1 Solution! posted by Dale Fraser explaining how to properly configure IIS when installing ColdFusion 8 with IIS7.  I proceeded with his simple instructions for IIS and then uninstalled/reinstalled ColdFusion and everything is perfect.

CFQueryparam Lists

I know for a fact that I have justified not using a queryparam when dealing with lists as I was not aware of the attribute described in this post. Pretty helpful bit of information here posted by Dan Wilson.

http://www.nodans.com/index.cfm/2009/1/12/CFQueryparam-and-Lists

Not my proudest work, but I thought it was funny.

Apparently ColdFusion doesn't appreciate using the IN criteria multiple times in a query with 25000+ values each.

CF_queryprocessor_error1

CF_queryprocessor_error2

Transact SQL StripNonNumeric Function

I was looking to scrub some phone fields that allow for some dirty varchar values at the moment, so I needed a tool to strip non-numeric values from the existing data to determine which records had legit phone numbers and which did not.  Here is a quick function I wrote to help me with this in case anyone needed something similar. I included both the StripNonNumeric function and a more generic StripPattern function that you can use to basically do the same thing, but strip any pattern you like.

SQL:
  1. CREATE CREATE dbo.StripNonNumeric(@value AS VARCHAR(MAX)) RETURNS VARCHAR(MAX) AS
  2. BEGIN
  3.     DECLARE @len AS INT
  4.     DECLARE @pattern AS VARCHAR(5)
  5.     DECLARE @result AS VARCHAR(MAX)
  6.    
  7.     SET @len = LEN(@Value)
  8.     SET @pattern = '[0-9]'
  9.     SET @result = ''
  10.    
  11.     WHILE @len> 0
  12.     BEGIN
  13.         SET @result = @result + CASE WHEN SUBSTRING(@value,@len,1) LIKE @pattern THEN SUBSTRING(@value,@len,1) ELSE '' END
  14.         SET @len = @len - 1
  15.     END
  16.     RETURN reverse(@result)
  17. END
  18.  
  19.  
  20. CREATE FUNCTION dbo.StripPattern(@value AS VARCHAR(MAX), @pattern AS VARCHAR(100)) RETURNS VARCHAR(MAX) AS
  21. BEGIN
  22.     DECLARE @len AS INT
  23.     DECLARE @result AS VARCHAR(MAX)
  24.    
  25.     SET @len = LEN(@Value)
  26.     SET @result = ''
  27.    
  28.     WHILE @len> 0
  29.     BEGIN
  30.         SET @result = @result + CASE WHEN SUBSTRING(@value,@len,1) LIKE @pattern THEN SUBSTRING(@value,@len,1) ELSE '' END
  31.         SET @len = @len - 1
  32.     END
  33.     RETURN reverse(@result)
  34. END

MVC for You and Me (cf.Objective() Joe Rinehart)

This is an introductory session to discuss the basic concepts of model view controller.

  • Model
    • Contains properties and methods. 
    • Avoid dependencies.
    • The data and the logic; repository for all system knowledge.
    • No knowledge of the view or controller.
  • Controller 
    • Tightly coupled with the model and the view.
    • Seperates the model from the view; acts as the mediator.
  • View 
    • Displays the user interface
    • Allows the user to interface with the model.
  • Key Concepts
    • The controller can know about the view and the model and write to the model.
    • "Seperation of Conerns" is a key term in Object-Oriented Design
      • It dictates that a given unit in a system should not have more than one concern.
      • Everything should do one thing and do it well.