Need a "rock star" ColdFusion speaker for 7/30/2010 event in Dallas

ColdFusion, General, Technology, Conferences, CFML
Last year was the second annual Dallas TechFest, which is a 1-day multi-platform event centered around programming.  They approached me at that time about bringing ColdFusion into the event, and giving us a dedicated track in one of the rooms.  I made a optimistic claim that we could bring in 50+ CFML devs from the area, and low and behold, we ended up with 70+ people that registered with the discount code from our user group.  It was very successful and had a good buzz with the local community.  Additionally, we blew the PHP and Ruby groups out of the water! :)  

For 2010, the organizers have offered a travel and expenses budget to to each track (CF being one of those) to pay for travel and expenses to get one "rock star" from each of the technologies. Based on last year's attendees, I would say that a large percentage were beginner-intermediate, with our regular core of advanced guys around as well.  The event will be on Friday July 30, in Addison.  Unfortunately this falls during the same week as CFUnited, which obviously zaps a number of speakers from the pool of availability, but if you are interested in speaking, please let me know!  I am dshuck pretty much everywhere... gmail, twitter, facebook, etc.

UDF: pcase() - Captilize first letter of each word in a string

ColdFusion, Tips and Tricks, Technology, CFML, UDF
This is a UDF that I keep on hand for converting strings to "proper case", such as a person's name.  For instance, in a database we might have a name stored like DAVID B. SHUCK, but when they log into our site and we welcome them, we don't necessarily want to shout it at them!   Saying "Hello David B. Shuck..." would hopefully be a bit less abrasive. 

Enter the user-defined function pcase().  Through the use of regular expressions we are doing a search for word patterns and capitalizing the first letter in each word.  Enjoy!




<cffunction name="pcase" access="public" output="false" returntype="string">
    <cfargument name="string" type="string" required="true" />
    <cfreturn REReplaceNoCase(LCase(arguments.string),"(^[a-z*]|[ *][a-z*])","\U\1\E","all") />
</cffunction>

Implicit constructor and CF9 style implicit accessors without ColdFusion 9

ColdFusion, Tips and Tricks, Technology, CFML
One of the broadly welcomed features of ColdFusion 9 has been the addition of implicit getters and setters to CFCs.  What this means is that you no longer have to hand code the repetitive boiler plate getXXX() and setXXX() methods for each property in your model objects. However, you don't need ColdFusion 9, (or even ColdFusion for that matter) to enjoy the benefits of the new implicit accessors with the version 9 release.  Since ColdFusion 8, developers have had access to the OnMissingMethod() method which makes tasks like this very simple to implement on your own.  The OnMissingMethod is also available in current versions of OpenBlueDragon and Railo.

For my implementation of this, I use a standard BaseBean class in a number of my projects which is extended by all of my model class objects.  By leveraging the OnMissingMethod() in this BaseBean, I create these implicit accessors, in addition to an implicit constructor init() method as well.

There are multiple examples on the internet that show how you can use OnMissingMethod(), but for the most part, the examples that I have come across do not protect the class from being having infinite previously undefined properties added to it from the outside.  For instance, I could have a class named Person.cfc with define properties of "firstName" and "lastName", but nothing would stop someone from doing Person.setThisIsNotAProperty(true) and that value would be dynamically added to the Person instance.  While some might argue that the flexibility that this approach offers is a positive thing, I prefer to lock my classes down just a bit more.  For instance I like the fact that I can open up a model class and see exactly what properties it can contain with clearly defined <cfproperty/> tags.   From a maintainability standpoint the idea of "mystery" dynamic properties strike me as just wrong.

For my implicit constructor, I take an approach where I loop through any named arguments that were passed, and if the name matches a property that I have defined with <cfproperty/>, then it will be passed to a setter method.  Any arguments that are passed that are not defined as a property are discarded.

So let's take a look at what this looks like.  First I will paste the entire BaseBean, and below we will break it apart to discuss what is going on.
<cfcomponent output="false">
	
		
	<cffunction name="init" access="public" output="false" returntype="BaseBean">
		<cfset var i = "" />
		<cfset initializePropertyList() />
		<cfloop list="#this.propertyList#" index="i">
			<cfif StructKeyExists(arguments,i)>
				<cfset set(i,arguments[i]) />
			</cfif>
		</cfloop>		
		<cfreturn this />
	</cffunction>
	
	
	<cffunction name="initializePropertyList" access="private" output="false" returntype="void">
		<cfset var i = "" />
		<cfif NOT StructKeyExists(this,"propertyList")>
			<cfset this.propertyList = "" />
			<cfif ArrayLen(GetMetadata(this).properties)>
				<cfloop from="1" to="#ArrayLen(GetMetadata(this).properties)#" index="i">
					<cfset this.propertyList = ListAppend(this.propertyList,GetMetadata(this).properties[i].name)>
				</cfloop>
			</cfif>
		</cfif>		
		<cfreturn />	
	</cffunction>


	
	<cffunction name="onMissingMethod" access="public" output="false" returntype="any">
		<cfargument name="missingMethodName" type="string" required="true" />
		<cfargument name="missingMethodArguments" type="struct" required="true" />
		
		<cfset var property = "" />
								
		<cfif ReFindNoCase("^[gs](et)",arguments.missingMethodName)>
			<cfset property = ReReplaceNoCase(arguments.missingMethodName,"^[gs](et)","") />
			<cfset initializePropertyList() />

			<cfif ListFindNoCase(this.propertyList,property)>
				<cfif StructIsEmpty(arguments.missingMethodArguments)>
					<cfreturn get(property) />
				<cfelse>
					<cfset set(property,arguments.missingMethodArguments[1]) />
					<cfreturn this />
				</cfif>	
			<cfelse>
				<cfthrow message="The class #GetMetadata(this).name# does not have a property named #property# so the implicit #arguments.missingMethodName#() method is not available." />		
			</cfif>

		</cfif>	
		<cfreturn />	
	</cffunction>
	
	<cffunction name="get" access="public" output="false" returntype="any">
		<cfargument name="property" type="string" required="true" />
		<cfset var value = "" />
				
		<cfset value = variables[arguments.property] />
			
		<cfreturn value />	
	</cffunction>
	
	<cffunction name="set" access="public" output="false" returntype="void">
		<cfargument name="property" type="string" required="true" />
		<cfargument name="value" type="any" required="true" />
		
		<cfset variables[arguments.property] = arguments.value />
		
		<cfreturn />
	</cffunction>
	
</cfcomponent>

Before we walk through the actual flow, I would like to point out the method initializePropertyList() that you see here:
<cffunction name="initializePropertyList" access="private" output="false" returntype="void">
	<cfset var i = "" />
	<cfif NOT StructKeyExists(this,"propertyList")>
		<cfset this.propertyList = "" />
		<cfif ArrayLen(GetMetadata(this).properties)>
			<cfloop from="1" to="#ArrayLen(GetMetadata(this).properties)#" index="i">
				<cfset this.propertyList = ListAppend(this.propertyList,GetMetadata(this).properties[i].name)>
			</cfloop>
		</cfif>
	</cfif>		
	<cfreturn />	
</cffunction>

By using the GetMetadata() function, we are able to introspect our instance and create a list of property names which we can reference in our other methods.  This is what enables us to enforce the rules that I described above in which we make sure that a property exists before setting it in the constructor or through an implicit accessor.  You will see in both the init() and OnMissingMethod() methods that we call this method to ensure the list of properties is available before testing against it.

With that established, let's take a look at the init() constructor method:
<cffunction name="init" access="public" output="false" returntype="BaseBean">
	<cfset var i = "" />
	<cfset initializePropertyList() />
	<cfloop list="#this.propertyList#" index="i">
		<cfif StructKeyExists(arguments,i)>
			<cfset set(i,arguments[i]) />
		</cfif>
	</cfloop>		
	<cfreturn this />
</cffunction>

After making sure that our propertyList has been initialized, we loop through that list and if there is a matching named argument, we call the set() method which sets that value into the variables scope.

So with the object initialized, let's take a look at our accessors.  For our example, let's say that we have a Person object and we are doing to set our firstName property like this: person.setFirstName("Dave").  Since that setter method doesn't exist in our Person class, the OnMissingMethod() below will be invoked. 
<cffunction name="onMissingMethod" access="public" output="false" returntype="any">
	<cfargument name="missingMethodName" type="string" required="true" />
	<cfargument name="missingMethodArguments" type="struct" required="true" />
	
	<cfset var property = "" />
							
	<cfif ReFindNoCase("^[gs](et)",arguments.missingMethodName)>
		<cfset property = ReReplaceNoCase(arguments.missingMethodName,"^[gs](et)","") />
		<cfset initializePropertyList() />

		<cfif ListFindNoCase(this.propertyList,property)>
			<cfif StructIsEmpty(arguments.missingMethodArguments)>
				<cfreturn get(property) />
			<cfelse>
				<cfset set(property,arguments.missingMethodArguments[1]) />
				<cfreturn this />
			</cfif>	
		<cfelse>
			<cfthrow message="The class #GetMetadata(this).name# does not have a property named #property# so the implicit #arguments.missingMethodName#() method is not available." />		
		</cfif>

	</cfif>	
	<cfreturn />	
</cffunction>

We are then doing a regular expression test to see if the missing method names starts with either "get" or "set".  If so, we derive the name of the target property by stripping the "get" or "set" off of the string.  After making sure that our propertyList has been defined, we then look in that list to see if the target property actually exists in the instance.  If it does, the request is then routed on to either the getter or the setter depending on whether arguments were passed to it.  Otherwise an exception will be thrown to let the developer know that he or she has attempted to access an undefined property.

One thing you might notice is that when our conditional block routes the request to the setter, we return an instance of the class itself.  This allows us to do method chaining like this:  person.setFirstName("Dave").setLastName("Shuck").  it should be noted that this is not the approach that Adobe took with ColdFusion 9.

So let's take a look at it in action.  Here is our Person.cfc class.
<cfcomponent output="false" extends="BaseBean">
	
	<cfproperty name="id" type="string" />
	<cfproperty name="firstName" type="string" />
	<cfproperty name="lastName" type="string" />
	
</cfcomponent>

As you can see in the <cfcomponent/> tag, we are extending our BaseBean which is all that we need to have a workable domain class object.

When we put this together and access it in our code, we can do this:
<cfset person = CreateObject("component","Person").init(id=7,firstName="Dave", lastName="Shuck") />

<cfdump var="#person#" />



Once we have an instance, we can modify those properties like so:
<cfset person.setId(8).setFirstName("Johnny").setLastName("Rotten") />



I have not actually tested this on Railo, but I can confirm that it works in OpenBlueDragon (including GAE version), and ColdFusion versions 8 and 9. 


Link to the HFDP 4 CF Connect recordings

ColdFusion, Technology
I have been asked more times than I would like to admit to put together a list of the meeting recordings that we have archived for our "Head First Design Patterns for ColdFusion Developers" series that the DFWCFUG has been doing since September of last year.  I will be appending to that entry in the next couple of months as we near the end, so you may want to bookmark it for future reference if you are interested in following.

The entire archive can be found here.


First Run in my Vibram Five Fingers KSOs

General, Health, Running
Vibram Five Finger KSOs on the sidewalkI just got back from my first run in my new Vibram Five Fingers KSOs that I got for Christmas.  To call them a minimalist running shoe would be an understatement.  They are essentially a rubber sole strapped to your foot by way of neoprene, nylon, and velcro.  I was first kind of intrigued on the theory of them after seeing this review on wired.com over the summer.  In fact, if you don't know anything about the Vibram Five Fingers, go watch that 2 minute video to see where I am coming from.
 
As that video explains, traditional running shoes encourage us to run in a pattern that our bodies weren't designed for.  The big heals typically cause us to follow a heal-to-toe pattern where the heal - and subsequently your leg - end up taking the shock of each step.  Barefoot runners do not run like this, but instead land more on the ball of the foot, allowing the foot and leg to work together to become a shock absorber.  A lot of studies suggest that the latter approach leads to less of the common injuries associated with running, such as shin splints, calf strain, and plantar fasciitis. 

Over the summer, I began developing a calf strain injury that I simply couldn't shake.  It started when one day I was feeling great and decided to tack on 2 miles to my regular run.  From that day on, my legs absolutely lit up with pain when I would try to run.  Eventually I just took a month off of running an began easing myself back in following the Couch To 5K running program, building up to a longer run.  While that approach has worked, I still feel a constant tinge in my left leg when I run where I feel like I am almost on the verge of hurting it again.

The more that I read about the Vibram Five Fingers and the more reviews that I read from people that have used them, I wondered if they might actually offer me a solution for not only avoiding injury, but getting stronger, and running more like I was designed to run from the beginning!

For Christmas, after hearing me talk about them again and again, my wife surprised me with a pair of the black KSOs (Keep Stuff Out), which are an improvement on the original design in that they come a bit higher on the foot to keep dirt and stuff out from the foot.  And today ( December 26th ) I went for my first run.

I was a little bit apprehensive to be honest.  I had heard a number of people say that it works your legs in a different fashion - most notably your calves - so start by doing shorter runs and working your way up to longer runs over time.  I have had such great results with the Couch To 5K program, both with my introduction into running, and in my calf strain recovery, that I decided to invoke it yet again and start with Week 1 of the program.  This is essentially 9 sets of 60 second run/90 second walk.  Given my running speed that equates to a little less than a mile of actually running, and in hindsight, I feel that I could have definitely pushed a lot harder than that.

It was such a cool experience!  I absolutely loved everything about it.  On one hand, I could feel little things - even the cracks in the sidewalk - but not so much that it created pain or was any kind of interference.  It just made me feel more in tune with my scene.  I found that I had to take slightly shorter steps in an effort to make my foot land where I needed it to, but it became natural in mere moments.  On the 1 mile track that I run there are a couple of steep hills and I found myself digging in on these hills to tackle them rather than feeling dread as I saw them approaching.  There is something about the whole experience that felt very liberating, and gave me almost a primal, tribal pleasure as I kept thinking about the fact that this is how man has run for millenia!

Aside from the mental feeling, I got finished and realized that not a single thought went to my legs.  Over the past 6 months or so, they haven't been far from the front of my mind when I ran as I kept wondering when I was going to push them too far and tweak them again.  I got home and felt completely exhilarated.  My legs feel great, and I am looking forward to my next run!


Remaking Prodigy's Smack My B**** Up using Ableton

Technology, Music
Very cool video showing a producer named Jim Pavloff re-creating this Prodigy classic using Ableton music production software, bringing in the samples one at a time and modifying them eventually building the entire track.   I need me some Ableton! .... and some talent. :(



Making Prodigy's "Smack My Bitch Up" in Ableton by Jim Pavloff


Search

Various Links

HikeTheCanyon.org - Rim-to-Rim hike of the Grand Canyon.
Dave Shuck on Twitter - Follow me on Twitter.
Scriptalizer - Minify your Javascript and CSS