Skip to content

Instantly share code, notes, and snippets.

Chris Macagare

  • Germany
View GitHub Profile
@Macagare
Macagare / reRemoveColumns.cfm
Created Oct 24, 2014
remove query columns via regex match
View reRemoveColumns.cfm
<cfscript>
private query function reduceQueryColumns(required query source, required string columns) {
var qReduced = "";
query name="qReduced" dbtype="query" { writeOutput("select #arguments.columns# from arguments.source") };
return qReduced;
}
private query function reRemoveColumns(required query source, required string regex) {
var columns = listToArray(arguments.source.columnlist);
for (var i = arrayLen(columns); i >= 1 ; i = i - 1) {
@Macagare
Macagare / mergeStructs
Created Oct 16, 2014
merge multiple structs in coldfusion
View mergeStructs
<cfscript>
private struct function mergeStructs(required array structs) {
var base = {};
var len = arrayLen(arguments.structs);
for (var i = 1; i <= len; i = i + 1) {
for (key in arguments.structs[i]) base[lcase(key)]=arguments.structs[i][key];
}
return base;
}
</cfscript>
@Macagare
Macagare / merge coldfusion structs
Created Oct 14, 2014
merge coldfusion structs
View merge coldfusion structs
<cfscript>
private struct function mergeStructs(required array structs) {
var result = {};
var argsLen = arrayLen(arguments.structs);
for ( var j = 1; j <= argsLen; j = j + 1 ) {
var keys = structKeyArray(arguments.structs[j]);
var keysLen = arrayLen(keys);
for ( var i = 1; i <= keysLen; i = i + 1 ) {
var key = lcase(keys[i]);
result[key] = arguments.structs[j][key];
@Macagare
Macagare / shuffle divs via javascript
Last active Aug 29, 2015
shuffle divs inside a div container
View shuffle divs via javascript
$(function () {
var parent = $("#container");
var divs = parent.children();
while (divs.length) {
parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);
}
});
View mxunit test snippet
<!--- see: http://christianmuellerdesign.wordpress.com/2014/05/23/getting-startet-with-coldfusion-and-mxunit/ --->
<cfcomponent displayname="mxunit.framework.Test" extends="mxunit.framework.TestCase">
<cffunction name="firstTest" access="public" returntype="void">
<cfscript>
addTrace("expected vs. actual" );
assertTrue(true);
assertEquals(this.expected, true);
</cfscript>
</cffunction>
View analyse railo cache sizes
<h1>Caches Overview</h1>
<h2>cacheType</h2>
<cfdump var="#cacheCount('cacheType')#" label="cacheType" />
cache cacheType size: <cfoutput>#(SizeOf( cacheGetAll("", "cacheType") )/1024)/1024#</cfoutput> MB<br/>
@Macagare
Macagare / file.cfm
Last active Aug 29, 2015
Floor current dateTime to influence the Last-Modified header. Header widgets will only be loaded from server every 15 minutes. Reduces server load when the requested content needs to be generated.
View file.cfm
<cfscript>
function foor15Min(t) {
var roundedMinutes = INT(minute(t) / 15 ) * 15;
return CreateDateTime(year(t), month(t), day(t), hour(t),roundedMinutes,0)
}
</cfscript>
<CFHEADER NAME="Cache-Control" VALUE="public, max-age=900">
<CFHEADER NAME="Last-Modified" VALUE="#LSDateFormat(#foor15Min( DateConvert( 'Local2UTC', now() ) )#, 'ddd, dd mmm yyyy')# #LSTimeFormat(#foor15Min( DateConvert( 'Local2UTC', now() ) )#, 'HH:mm:ss')# GMT">
@Macagare
Macagare / normalize.cfm
Last active Dec 25, 2015
normalize query string for query of queries
View normalize.cfm
<cffunction name="normalizeChar" returntype="string" hint="Replaces characters with their non accented closest equivalents" output="true">
<cfargument name="str" type="string" required="true" />
<cfreturn ReplaceList( str,"á,é,í,ó,ú,ý,à,è,ì,ò,ù,â,ê,î,ô,û,ã,ñ,õ,ä,ë,ï,ö,ü,ÿ,À,È,Ì,Ò,Ù,Á,É,Í,Ó,Ú,Ý,Â,Ê,Î,Ô,Û,Ã,Ñ,Õ,Ä,Ë,Ï,Ö,Ü",
"a,e,i,o,y,u,a,e,i,o,u,a,e,i,o,u,a,n,o,a,e,i,o,u,y,A,E,I,O,U,A,E,I,O,U,Y,A,E,I,O,U,A,N,O,A,E,I,O,U") />
</cffunction>
<cffunction name="normalizeColumn" returntype="query" output="true" hint="normalize single column and add new column [column]_norm">
<cfargument name="qSource" type="query" required="true" />
<cfargument name="column" type="string" required="true" />
<cfset var normColumn = arguments.column & "_norm" />
@Macagare
Macagare / gist:6884565
Created Oct 8, 2013
coldfusion structAppend2, adds value to a new created key
View gist:6884565
void function structAppend2(required struct base, required string key, required any value) {
var paramStruct = {};
paramStruct[arguments.key] = arguments.value;
structAppend(arguments.base,paramStruct);
}
@Macagare
Macagare / gist:6883387
Last active Dec 24, 2015
cfscript version of query to map conversion made for railo
View gist:6883387
/**
* converts query to sturct map
*
* @param query source query to convert
* @param string key key for the main subkeys, when empty first column taken
* @return struct converted map
*
*/
struct function toMap( required query source, required string key, string ignore="" ) {
var map = {};
You can’t perform that action at this time.