Skip to content

Instantly share code, notes, and snippets.

View boughtonp's full-sized avatar

Peter Boughton boughtonp

View GitHub Profile
@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: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 / 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: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() />
<cfsetting showdebugoutput=false />
<cfset ascii32to126 = "!""##$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~">
<cfcontent reset type="text/plain">
<cfoutput>
Unmodified:
#ascii32to126#
encodeForJavaScript:
#encodeForJavaScript(ascii32to126)#
@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+"