Skip to content

Instantly share code, notes, and snippets.

View boughtonp's full-sized avatar

Peter Boughton boughtonp

View GitHub Profile
@boughtonp
boughtonp / NameCase.cfm
Created June 1, 2014 15:40
NameCase - Capitalise first letter of each word, with exceptions (McIntire,Mackie,O'Connor)
<cffunction name="NameCase" returntype="String" output=false access="public"
hint="Capitalise first letter of each word, with exceptions (McIntire,Mackie,O'Connor)"
>
<cfargument name="Text" type="String" required=true />
<cfscript>
// Uppercase first letter of every word, except special cases...
var Name = rereplace
( lcase(Arguments.Text)
, "\b(?!(?:a[lp]|dell[ae]|de[rl]?|d[ai]|l[eo']|of|the|v[oa]n)\b)\w+"
<cfsetting showdebugoutput=false />
<cfset ascii32to126 = "!""##$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~">
<cfcontent reset type="text/plain">
<cfoutput>
Unmodified:
#ascii32to126#
encodeForJavaScript:
#encodeForJavaScript(ascii32to126)#
@boughtonp
boughtonp / gist:dcd50e8e654c705df6c8
Created April 30, 2014 18:53
QueryStringToStruct
<cffunction name="QueryStringToStruct" returntype="struct" output=false access="public"
hint="Converts a querystring into a struct of name value pairs."
>
<cfargument name="QS" type="string" required=true />
<cfargument name="Decode" type="Boolean" default=true />
<cfargument name="Delimiter" type="String" default=","
hint="Used to delimit values provided from multiple keys of same name."
/>
<cfset var Results = StructNew() />
@boughtonp
boughtonp / Application.cfc
Last active August 29, 2015 13:58
Using JSoup on CF10 with input from CFHTTP
component
{
This.Name = "jsoup_with_cfhttp";
This.JavaSettings = { LoadPaths:["./jsoup-1.7.2.jar"] };
}
@boughtonp
boughtonp / gist:9705827
Created March 22, 2014 11:39
StructToQueryString
<cffunction name="StructToQueryString" returntype="String" output=false access="public"
hint="Converts a struct into a url-encoded querystring."
>
<cfargument name="Data" type="Struct" required=true />
<cfset var QS = '' />
<cfif NOT StructCount(Arguments.Data)><cfreturn '' /></cfif>
<cfloop item="local.Key" collection=#Arguments.Data#>
@boughtonp
boughtonp / Usage Example for isSameInstance custom assertion
Last active August 29, 2015 13:57
Workaround for incorrect assertSame / assertNotSame functionality in Testbox - for official fix see https://ortussolutions.atlassian.net/browse/TESTBOX-76
addAssertions( new path.to.below.Component() );
$assert.isSameInstance( ObjA , ObjB );
@boughtonp
boughtonp / gist:6731929
Created September 27, 2013 17:18
Regex to find all property types...
\b(orm|sql|)type\s*+=\s*+\S+(?<=<cfproperty\s[^>]{1,500}|\sproperty\s[^;]{1,500})
@boughtonp
boughtonp / gist:6713441
Created September 26, 2013 12:26
Regex to find incorrectly var scoped rc variables in script-syntax CFCs
function\s+\w+\(event,rc,prc\)\s++([^v}]++|v(?!ar\s++rc)|(?<!\n\t)\})*var\s++rc
component
{
function init()
{
this.stuff = {'a a':'a','b b':'b','c c':'c'};
var keys = StructKeyList(this.stuff);
for (var i=1; i<=listLen(keys); i++)
{
@boughtonp
boughtonp / getRequestTimeout.udf.cfm
Created January 24, 2012 01:23
Function to return request timeout for Railo.
<cffunction name="getRequestTimeout" output="false">
<cfadmin
type="web" password="yourwebadminpassword"
action="getApplicationSetting"
returnvariable="local.DefaultAppSettings"
/>
<cfif DefaultAppSettings.AllowURLRequestTimeout AND StructKeyExists(Url,'RequestTimeout')>
<cfreturn createTimespan( 0 , 0 , 0 , Url.RequestTimeout ) />