Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Macagare

  • Germany
View GitHub Profile
@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">
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/>
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>
@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]);
}
});
@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 / 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 / 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 / autoincrement.sql
Created Nov 26, 2014
update table autoincrement offset
View autoincrement.sql
ALTER TABLE tbl AUTO_INCREMENT = 5;
@Macagare
Macagare / split_string.sql
Created Nov 27, 2014
convert comma separated string into temporary table with individual rows
View split_string.sql
DROP procedure IF EXISTS split_string;
DELIMITER $$
CREATE PROCEDURE split_string (list TEXT)
BEGIN
DECLARE max INT DEFAULT 0;
DECLARE i INT DEFAULT 1;
DECLARE elem INT DEFAULT 0;
SET max = length(list) - length(replace(list, ',', ''));
You can’t perform that action at this time.