CF Blog

10 maart 2010
REReplaceCallback UDF
If you've used pretty much any modern language, you know all about callback functions.  Unfortunately CFML is capable of doing it, but the language itself doesn't leverage the feature anywhere.  In particular, a callback for the replace operation is of great value.  Ben Nadel has blogged about such things a couple times, and now I'm [...]
10 maart 2010
New Site (Redesign) Launched - Co.ldFusion Blog

I just wanted to announce that I have re-designed my blog to be a little more up to the times. Though I have never been one to blog frequently, I will do my best to start blogging as often as possbile... I am aiming at once or twice a day.... and going from there... So if you have requests on topics or just things you'd like to comment on, please feel free to let me know.

I am going to incorporating a few new features on the blog (adding on to the Jedi's Work) to also allow integration to twitter and the ability to push my posts from facebook here too... I spend sometime on Twitter and FaceBook and I want to make sure that gets posted here.... your thoughts on that? (Good?, Bad?) Let me hear from ya on it...

Also, Free ColdFusion Hosting is back up... For those that have been emailing me asking about it.... Sorry for the down time, working on some good things to come... Please stay tuned!

~p


10 maart 2010
My move from using cfhttp and rssatom.cfc to cffeed.

For the last year or so, I had been using cfhttp and rssatom.cfc to read and parse rss feeds so that I could display the content on a site running on ColdFusion 7. I recently upgraded the server to ColdFusion 9, but shortly afterward started to receive the error, "An error occurred while Parsing an XML document. Content is not allowed in prolog". The error was not consistent, but occurred twenty to thirty times a day. I figured it was a good time to move to the more current cffeed tag that became available in ColdFusion 8 and see if it would resolve the issue.

The move to cffeed was painless and the tag really makes consuming feeds really easy. I had to adjust my output as the structure outputted from cffeed was different than the structure outputted from rssatom.cfc. One issue I did run into was with the post date which was stored in the updated key of the entry structure. The datetimestamp was stored as in iso8601 format and could not be outputted with the ColdFusion dateformat function. After a little searching, I found the DateConvertISO8601 UDF at CFLib.org that formatted the date as an ODBCdatetime stamp which I could use with the dateformat function.

The final piece to this was the fact that I needed to display different items in the feeds at different places on my site. We show the most recent blog post on our homepage and the most recent post from different columns on specific sub pages within the site. This was accomplished by looping through the structure and finding posts that have a specific term key within the category struct.

Here is an example of the code used to display a blog post from a specific column in a blogger feed:

Read in rss feed and cache contents for an hour.

<cfset feedurl = "http://blog.example.org/feeds/posts/default">
<cfset cacheMinutes = 60>

<!--- check if cached, and not too old --->
<cfif not structKeyExists(application,"feedcache") or dateDiff("n", application.feedcache.created, now()) gt cacheMinutes>
<cffeed source="#feedurl#" name = "feeddata_blog" timeout="20">
<cfset application.feedcache = structNew()>
<cfset application.feedcache.feeddata_blog = feeddata_blog>
<cfset application.feedcache.created = now()>
</cfif>

include DateConvertISO8601.cfm template to load UDF.

<cfinclude template="DateConvertISO8601.cfm">

Loop through the feed struct and find the specific column that needs to be displayed.

<cfif StructKeyExists(application.feedcache.feeddata_blog.entry[1].category[1], "term")>
<cfset keyList = Structkeylist(application.feedcache.feeddata_blog.entry[1].category[1])>
<cfset keyList = ListSort(keyList, "TEXT")>
<cfelse>
<cfabort>
</cfif>
<p>
<div id="blog">
<cfset item = 0>
<cfloop index="i" from="1" to="#ArrayLen(application.feedcache.feeddata_blog.entry)#">
<cfif application.feedcache.feeddata_blog.entry[i].category[1].term eq 'Column B'>
<cfset item = #i#>
<cfbreak>
</cfif>
</cfloop>
<cfoutput>
<div class="capsblue">
<a href="#application.feedcache.feeddata_blog.entry[i].link[1].href#" target="_blank" class="text">#ucase(application.feedcache.feeddata_blog.entry[i].link[1].title)#</a>
</div>
<cfif application.feedcache.feeddata_blog.entry[item].category[1].term IS NOT "">
<div class="copy">#application.feedcache.feeddata_blog.entry[item].category[1].term#</div>
</cfif>
<cfif application.feedcache.feeddata_blog.entry[item].author[1].name IS NOT "">
<div class="copy">#application.feedcache.feeddata_blog.entry[item].author[1].name#</div>
</cfif>
<cfset sDate = application.feedcache.feeddata_blog.entry[item].updated>
<cfset ts = #DateConvertISO8601( sDate, 0 )#>
<cfif isDate(ts)>
<div class="copy">#dateformat(ts, "full")#</div>
</cfif>
<p align="left">#application.rsscachetours.feeddata_tours.entry[item].content[1].value# <a href="http://example.org/search/label/Column%20B">Read more ...</a>
</p>
</cfoutput>
In the end, I'm no longer getting the original error and I'm displaying content from the feed with less code and complexity.
9 maart 2010
Infinite entities, cfgrid and one cfc to handle the data

While writing SpreadEdit I wanted every entity to be editable via cfgrid.  In particular I thought it would be cool to have one cfc on the back end to process the data from cfgrid no matter what entity it was working with.  With ColdFusion 9 and ORM this proved possible and is pretty cool, check out the screencast.  Code the other side of the embed.

Here is the code for genericGrid.cfc:

<cfcomponent>
 
<cffunction name="getData" access="remote" returnformat="JSON">
     <cfargument name="page" required="true">
     <cfargument name="pageSize" required="true">
     <cfargument name="gridSortColumn" required="true">
     <cfargument name="gridSortDirection" required="true">
     <cfargument name="entity" required="true">
 
     <cfif ! len( arguments.gridSortColumn )>
          <cfset arguments.gridSortColumn = "1">
 
     </cfif>
 
     <cfset local.getTasks = ormExecuteQuery( " FROM #arguments.entity# ORDER BY #arguments.gridSortColumn# #arguments.gridSortDirection#" )>
 
    <cfreturn queryconvertforgrid( entityToQuery( local.getTasks ), Arguments.page, Arguments.pageSize)>
 
</cffunction>
 
<cffunction name="setData" access="remote">
     <cfargument name="action" required="true">
     <cfargument name="row" required="true">
     <cfargument name="changed" required="true">
     <cfargument name="entity" required="true">
     <cfif arguments.action eq "U">
          <cfset local.obj = entityLoad( arguments.entity, arguments.row, true )>
          <cfloop collection="#arguments.changed#" item="local.key">
               <cfinvoke component="#local.obj#" method="set#local.key#">
                    <cfinvokeargument name="#local.key#" value="#arguments.changed[ local.key ]#">
               </cfinvoke>
          </cfloop>
     <cfelseif arguments.action eq "I">
          <cfset local.obj = entityNew( arguments.entity )>
          <cfloop collection="#arguments.row#" item="local.key">
               <cfif local.key neq "CFGRIDROWINDEX">
                    <cfinvoke component="#local.obj#" method="set#local.key#">
                         <cfinvokeargument name="#local.key#" value="#cleaned( arguments.row[ local.key ] )#">
                    </cfinvoke>
               </cfif>
          </cfloop>
     </cfif>
     <cfset entitySave( local.obj )>
</cffunction>
 
<cffunction name="cleaned" access="private" >
     <cfargument name="string" required="true">
     <cfset var ret = arguments.string>
     <!--- check for date --->
     <cfif reFind( "[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}T[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}",
               ret )>
          <cfset ret = rereplaceNoCase( ret, "T", " " )>
     </cfif>
     <cfreturn ret>
</cffunction>
 
 
</cfcomponent>
9 maart 2010
NCDevCon - Free and amazing conference

After a successful CFinNC, the folks at Triangle Area ColdFusion's User Group (TACFUG) are organizing NCDevCon 2010. The conference will be held May 22-23, 2010 at my favorite school - Centennial Campus of NC State University in Raleigh.

The conference will cover a wide variety of web development and design topics including ColdFusion, Flex and AIR, ᅠJavascript and CSS.ᅠ

Just like CFinNC the registration for this event will be freeᅠand includes entry to the weekend event and to all presentations. Since attendance is limited, please register early so that you do not miss out on this fantastic conference.

Register @ᅠᅠhttp://ncdevcon2010.eventbrite.com/

Thanks and hope to see you at NCDevCon!

9 maart 2010
Day two with FW/1
Playing around with FW/1 today I decided to take a look at the differences at how services differ from working with domain objects.  Skimming through the FW/1 documentation I did notice the framework has a built in function to populate a bean, namely the fw.populate() function.  Calling a bean (an object with getter/setter methods) is [...]
9 maart 2010
How much memory does my ColdFusion variable really use? Part III
Finally, nearly the last part (there's one more coming...). In part II I talked about the different problems we'd run into using the instrumentation code out-of-the-box without modifying it for the special scenario of using it to size ColdFusion variables

How much memory does my ColdFusion variable really use? – Part III is a post from: Blog in Black

9 maart 2010
Why MMOs aren't fun...
Why can MMOs leave you with the worst experience of any gaming genre? The "MM" part. Massively multiplayer games leave plenty of room for you to play with total douchebags. The guys that find it fun to ruin experience of folks new to the game. A game could be the funnest game ever created, but if a level 60 is running around the level 3 area, killing all the monsters before the level 3s can, what's the fun? At your level, killing those level 3 rats is all there is in the game for you. If they're all dead, you get frustrated and quit playing. [More]
9 maart 2010
Google Public Data Explorer Features Flash Charting
Title says it all. Some really nice Flash charting examples. Check it out.
9 maart 2010
HP Slate Allows Access To ALL Of The Internet
Who says you can't have it all? Check out this YouTube video showing the web, Flash and Air on an upcoming HP Slate Device:

Also, see this Wired story.