Utility Function: IsColor()

I think that there are some valid colors that the REGEX is going to reject, but here is another one that I find useful:


<cffunction name="IsColor" access="public" output="false" returntype="boolean">
    <cfargument name="color" type="string" required="true" />
        
    <cfset var local = structNew() />
    <cfset local.colorNames = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,white,yellow" />
    <cfset local.regex = "^(##([\dA-F]{3}|[\dA-F]{6})|([\dA-F]{3}|[\dA-F]{6}))$" />
    <cfset local.returnValue = false />
        
    <cfif listFind(local.colorNames, arguments.color) OR arrayLen(REMatchNoCase(local.regex, arguments.color)) gt 0>
        <cfset local.returnValue = true />
    </cfif>
    
    <cfreturn local.returnValue />
</cffunction>

 

Utility Function: ListRemoveDuplicates()

I often use lists behind the scenes, and if I'm looping through and processing stuff, I had to reprocess something if its been duplicated in the list.


<cffunction name="ListRemoveDuplicates" access="public" returntype="string" output="false">
    <cfargument name="lsList" type="string" required="false" default="">
    <cfargument name="delimiters" type="string" required="false" default=",">

    <cfset var lsNewList = "">

    <cfloop list="#arguments.lsList#" index="listItem" delimiters="#arguments.delimiters#">
        <cfif NOT listFind(lsNewList, listItem, arguments.delimiters)>
            <cfset lsNewList = listAppend(lsNewList, listItem, arguments.delimiters)>
        </cfif>
    </cfloop>

    <cfreturn lsNewList>
</cffunction>

This should probably be ListRemoveDups() as is more fitting for CF, but I prefer the longer name

 

Utility Function: GetCurrentDirectory()

This one is really short... I use code like this all over the place, and its always cumbersome to do the nested function call every time.


<cffunction name="GetCurrentDirectory" output="false" access="public" returntype="string">
    <cfreturn GetDirectoryFromPath(GetBaseTemplatePath()) />
</cffunction>

 

Utility Function: DateBetween()

I get so tired of doing date comparisons to see if a date is between two other dates. Its not hard, but I always feel like it should be a method.


<cffunction name="DateBetween" output="false" access="public" returntype="boolean">
    <cfargument name="testDate" type="date" required="true" />
    <cfargument name="lowDate" type="date" required="true" />
    <cfargument name="highDate" type="date" required="true" />
    <cfargument name="inclusive" type="boolean" required="false" default="true" />
    
    <cfif arguments.inclusive>
        <cfreturn (lowDate lte testDate AND testDate lte highDate) />
    <cfelse>
        <cfreturn (lowDate lt testDate AND testDate lt highDate) />
    </cfif>
</cffunction>

 

CakePHP: What I like

I've been doing a lot of thinking about frameworks lately, and about how much work it is to get a MVC/Model2 framework going in ColdFusion compared to in other languages/servers. This lead me to investigate the documentation for a number of non-ColdFusion server/frameworks that I've used, or are popular, and I've been trying to round out a list of what I like and why.

The first installment of this mini-series is on CakePHP. Please remember that while I may have used some of these frameworks, I'm not an expert, so I might be missing the thing that makes that framework cool. If so, let me know that you think the best parts of the framework are, and I'll see if I agree.

 

Updates to Regex Tester

I've updated my old regular expression testing tool. Previously, it only did ColdFusion 8 regular expression testing. Now it also performs tests against Java's regular expression matching. Click here to view my ColdFusion 8 and Java Regex Tester.

 

More Entries

Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.