Skip to content

Instantly share code, notes, and snippets.

@s7github
s7github / MidLeft.cfm
Last active December 16, 2015 15:49
"Common Coldfusion String Functions" _ MidLeft(string, start, num) - Returns n characters from the left side of starting position in the string
<cffunction name="MidLeft" returntype="string" output="no" hint="Returns numChars characters from the left side of startPos in the string">
<cfargument name="stringVal" type="string" required="yes" default="">
<cfargument name="startPos" type="numeric" required="yes" default="1">
<cfargument name="numChars" type="numeric" required="yes" default="0">
<!--- If startPos exceeds length of string argument then start picking characters from string end position --->
<cfif arguments.startPos gt len(arguments.stringVal)>
<cfset arguments.startPos = len(arguments.stringVal)>
</cfif>
<cfset var fromPos = arguments.startPos - arguments.numChars + 1>
@s7github
s7github / DateFormatPlus.cfm
Last active December 16, 2015 15:49
Coldfusion common date functions _ DateFormatPlus(date, mask, [customMaskValue1]) - Formats date with optional custom mask options. Each custom mask starts with $ sign and followed by a number in mainMask. For eg. $1 will be replaced by custom mask given as 1st parameter after mainMask parameter and $2 will be replaced by 2nd parameter after mai…
<cffunction name="DateFormatPlus" returntype="string" output="yes" hint="Formats date with optional custom mask options. Each custom mask starts with $ sign and followed by a number in mask. For eg. $1 will be replaced by custom mask value given as 1st parameter after mask parameter and $2 will be replaced by 2nd parameter after mask.">
<cfargument name="dateVal" required="yes" type="date" default="#now()#">
<cfargument name="mask" required="yes" type="string" default="yyyy-mm-dd">
<!--- Apply default date mask --->
<cfset var newDate = dateFormat(arguments.dateVal, arguments.mask)>
<!--- Apply custom date mask --->
<cfloop from="1" to="#arrayLen(arguments)-2#" index="loopIndex">
<cfset var maskPos = find("$#loopIndex#", newDate) - 1>
<cfswitch expression="#arguments[loopIndex+2]#">
@s7github
s7github / readCFCoreClass.cfm
Last active August 29, 2015 14:12
Get list of methods available in Coldfusion core class files (recursively)
<cffunction name="readCFCoreClass" output="false" hint="Get list of methods available in Coldfusion core class files (recursively)">
<cfargument name="searchFolder" type="string" required="true" hint="Path of specific folder in which to be searched (with backslash at end)">
<cfargument name="searchFile" type="string" required="true" hint="Path of specific class file to be searched (without .class extension)">
<cfargument name="searchRecurse" type="boolean" required="false" default="false" hint="Search should be recursive or not?">
<!--- Container for final results --->
<cfset var searchResults = queryNew("Class,Method,Return_Type", "varchar,varchar,varchar")>
<!--- Path of folder into which jar file "<CF installation path>/WEB-INF/lib/cfusion.jar" is extracted --->
<cfset var searchRootParentPath = "">
@s7github
s7github / 0_reuse_code.js
Last active August 29, 2015 14:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console