Shaun Mccran

My digital playground

28
O
C
T
2009

ColdFusion scoping issues and the Var scope

One of the more common problems with a ColdFusion application, especially when it starts to grow or involves more than one developer is variable scoping, and scope bleed through issues. More recently I have had to re examine the framework of an application, in an effort to track and eliminate any instances of this.

Not properly scoping a variable, IE:

view plain print about
1<cfset myUnscopedVar = "Foo">

Forces ColdFusion to add the variable to the 'variables' scope. This scope is available to the entire template. This is even more important when you consider CFC's and the potential damage that a leaked variable could cause. One of the major benefits of OO in ColdFusion is the encapsulation that it provides. As soon as you start declaring un scoped variables, then you lose that.

Mike Schierberl has quite an in-depth blog about this subject, http://www.schierberl.com, he goes into a great deal of depth about this subject, and he has built and maintains the varScoper project. The varScoper allows you to scan your code base for un scoped variables, and after a quick inspection of its output it seems very reliable. I'm not sure its 100% foolproof, but would be a valuable addition to a QA process.

Changes to the Var scope in Coldfusion 9

I am currently not using ColdFusion 9 in any environment; in fact my hosting company is still on 7! That said it appears that there are some significant changes to the Var scope in ColdFusion 9.

Ben Forta sums it up nicely here:

http://forta.com/blog/index.cfm/2009/6/21/The-New-ColdFusion-LOCAL-Scope

He does touch on an interesting point in the article above. I quite like the structured layout of a CFC, and part of that regime for me is declaring all the Vars at the top of a function. It sort of matches the layout of an Action Script class as well, declaring all your constants etc at the top of the script. It is also a very easy coding standard to adopt and enforce if you are part of a larger team.

24
O
C
T
2009

Android Rss reader roundup

I've been looking at a few RSS readers for the Android platform recently, and some of them have been a bit hit and miss.
So I've decided to put together a quick rundown of the ones I've tried, with Pro's and Con's. So far they have all been uninstalled, but I'll keep updating this periodically as I find new ones.

Update 1: Added Rss Store

Update 2: Added Greed (Google news reader), newsRob

GReed
One of the more popular RSS reader applications if the reviews are anything to go by. I was initially a bit sceptical about using this, mainly because I did not have a Google Reader account (http://www.google.com/reader). I tentatively signed up for one, and installed the application. Much like a lot of other Android content this simply sync's with your online account settings. Add an RSS feed into your Google account, and it will be pushed to your Android phone. This means that you can basically add any feed at all. Its a really easy application to use, it has a clear menu system, it is very easy to see what you have read. You can view the 'latest' feed updates, or view individual feeds, and paging is done through a simple left-right icon system. Highly recommended.

NewsRob
Another application that uses the Google Reader account. Thid application is more basic than GReed. It goes off and gets the headline and the first line or two of an article in the background, so it is actually quicker to load an article. The problem lies in that it only gets the first line, so you have to click through to the related site to read the article. It also uses a lot more battery, I'm guessing due to running as a background service caching the intro to the RSS articles.

PureRss
This is a decent enough looking RSS reader, easily installed and up and running. The display area for articles is very small, and often the link through to a full article did not work. Also did not allow me to find an RSS feed on a site, I needed to manually copy and paste the URL.

AndRead RSS reader
A polished looking application, but most of the functions are in the menu button, which makes it a bit harder to get around. It pre populates a whole slew of categories, and fills them with recommended feeds, none of which I wanted. Also you have to have a 'category' to add a feed to it, which is a little annoying. The main problem with this application is that it didn't get my feeds! I tried three different sites, and it got the headlines, but no article data.

Rss Store
This sounded like one of the more promising RSS readers out there except when you fire it up it is half advertising space. This is a catalogue of pre determined RSS feeds, loosely catalogued under different headings, like business, leisure and sport. If the feed you are looking for is in there, then great, otherwise your a bit stuck. You can search, and add new feed sources, except that they are not actually added. The application logs a request for your feed to be added in a future iteration of the application. To me this is a huge backward step in software development, and is incredibly inflexible. This App came off quickly!

23
O
C
T
2009

Pop quiz! Create an object of items and counts from a paragraph of text

I was digging around in some old code the other day, having a 'server' tidy up, and I came across a pair of code challenges that a company set for me a few years back. They were to try and gauge how you approach a problem, and see if you are at least familiar with the cfml code base. I quite like Ray Camden's Friday challenge idea, so in a blatant homage, I'm posing these two code challenges in the same way. This one this week, and a numeric one next week.

The challenge:

Take a paragraph of text and return a data object(whatever format you want) of the words in it, and their frequency. This is the example paragraph given.

view plain print about
1The old lady pulled her spectacles down and looked over them about the room;
2then she put them up and looked out under them. She seldom or never looked THROUGH
3them for so small a thing as a boy; they were her state pair, the pride of her heart,
4and were built for "style," not service -- she could have seen through a pair of
5stove-lids just as well.

The type of object and the method of producing it are entirely open. You an choose how to handle punctuation and text casing.

I've written a test form, and a solution myself, but it is always interesting to see how different minds approach the same problem.

I'll give it a while, and then post my solution here.

Update Here is a CFC that I put together to solve this. It strips out the punctuation, and creates a Structure of the words, and their count.

view plain print about
1<cfcomponent displayname="Parser" hint="Parses a set of text" output="false">
2
3    <cffunction name="parseText" hint="Parses a passed in section of text, returns a struct of values" access="public" output="true" returntype="Struct">
4        <cfargument name="rawString" required="true" hint="Text to parse">
5
6        <!--- list items to remove --->
7        <cfset var itemsToRemove = '-,;,",.'>
8        <cfset var parsedString = structNew()>

9        <cfset var part = "">

10
11        <!--- Clean the punctuation out of the arg --->
12        <cfset var cleanedString = ReplaceList(arguments.rawString, itemsToRemove, " ")>
13        <cfset cleanedString = lCase(Replace(cleanedString, ",", " ", "ALL"))>
14
15        <cfloop list="#cleanedString#" index="part" delimiters=" ">
16            <cfif NOT StructKeyExists(parsedString, "
#part#")>
17                <!--- Add to struct --->
18                <cfset parsedString[part] = 1>

19            <cfelse>
20                <!--- increment count, get it and add one --->
21                <cfset parsedString[part] = parsedString[part] + 1>
22            </cfif>
23        </cfloop>
24
25        <cfreturn parsedString />
26    </cffunction>
27
28</cfcomponent>

18
O
C
T
2009

Converting Word Press Cumulus plugin to BlogCFC

The other day I saw the Word Press Blog Cumulus plugin (http://wordpress.org/extend/plugins/wp-cumulus/) on a fellow bloggers site, and thought 'I like that, I wonder if it will work inside the Blog CFC framework'. I thought I'd convert it so that it would.

The Cumulus plugin uses the regular Blog category cloud and turns it into a three dimensional rotating globe. It does this using a flash object, and a series of parameters passed in as flashvars.

view plain print about
1<s/cript type="text/javascript" src="#application.rootURL#/includes/swfobject.js"></script>
2    <div id="flashcontent">This will be shown to users with no Flash or Javascript.</div>
3
4    <s/cript type="text/javascript">
5        var so = new SWFObject("#application.rootURL#/includes/tagcloud.swf", "tagcloud", "170", "120", "7", "##ffffff");
6        // uncomment next line to enable transparency
7        //so.addParam("wmode", "transparent");
8        so.addVariable("tcolor", "0x3258B8");
9        so.addVariable("mode", "tags");
10        so.addVariable("distr", "true");
11        so.addVariable("tspeed", "100");
12        so.addVariable("tagcloud", "#variables.tagsList#");
13        so.write("flashcontent");
14    </s/cript>

You need to include the 'swobjects.js' reference call to process to swf, otherwise the 'flashcontent' div will be displayed.

The flashvars include the variable 'tagcloud', this controls which tags are displayed, what their colors are, and where the go (URL). These are generated in a cfsavecontent variable almost as a list.

view plain print about
1<cfsavecontent variable="variables.tagsList"><tags><cfloop query="tags">
2                <cfif tags.tagCount EQ min>
3                    <cfset size="9">
4                <cfelseif tags.tagCount EQ max>
5                    <cfset size="20">
6                <cfelseif tags.tagCount GT (min + (distribution*2))>
7                    <cfset size="16">
8                <cfelseif tags.tagCount GT (min + distribution)>
9                    <cfset size="13">
10                <cfelse>
11                    <cfset size="11">
12                </cfif><a href='#application.rootURL#/index.cfm?mode=cat%26catid=#tags.categoryid#' style='#size#' <cfif len(variables.color)> color='0x#variables.color#' </cfif> <cfif len(variables.hicolor)> hicolor='0x#variables.hicolor#' </cfif> >#lcase(tags.tag)#</a></cfloop></tags></cfsavecontent>

The swf will control the color of the Tags based on their sizing, or you can specify a 'color' and a 'hicolor', which are the regular color and the highlight color respectively. I have placed the swfobject.js and the tagcloud.swf in my site/includes/ directory, but you can put it where you want, just edit the links.

You can download the code from RIA forge here: Link

Thanks to Roy Tanck for the documentation on how the Cumulus plugin works:

http://www.roytanck.com/2008/05/19/how-to-repurpose-my-tag-cloud-flash-movie/

_UNKNOWNTRANSLATION_ /