Skip to content

Instantly share code, notes, and snippets.

View brucekirkpatrick's full-sized avatar

Bruce Kirkpatrick brucekirkpatrick

View GitHub Profile
@brucekirkpatrick
brucekirkpatrick / getFilesInDirectoryAsArray.php
Last active December 2, 2017 04:54
Function to return only the files in a directory, and optionally do this recursively.
<?php
function getFilesInDirectoryAsArray($directory, $recursive, $arrFilter=array()) {
$arrItems = array();
if(substr($directory, strlen($directory)-1, 1) != "/"){
$directory.="/";
}
if(count($arrFilter)){
$filterMap=array();
for($i=0;$i<count($arrFilter);$i++){
$filterMap[$arrFilter[$i]]=true;
@brucekirkpatrick
brucekirkpatrick / FunctionTest.cfc
Last active January 2, 2016 01:39
Functions passed as values should work like this in all CFML engines.
<cfcomponent output="yes">
<cffunction name="getF" output="no">
<cfreturn function(a){ return a+1;}>
</cffunction>
<cfscript>
function test2(closure1=function(a){ return a+1;}){
return arguments.closure1(4);
}
</cfscript>
@brucekirkpatrick
brucekirkpatrick / scrypt.cfm
Created November 10, 2013 23:00
Using scrypt hashing in coldfusion or railo
<cfscript>
password="test1234";
N = 65536; // CPU cost parameter.
r = 16; // Memory cost parameter.
p = 1; // Parallelization parameter.
// Note: SCryptUtil has default of 16 byte random salt and 256-bit key
SCryptUtil=createobject("java", "com.lambdaworks.crypto.SCryptUtil", "/path/to/scrypt-1.4.0.jar");
// generate a hash
hashedPassword=SCryptUtil.scrypt(password, N, r, p);
@brucekirkpatrick
brucekirkpatrick / getImplicitVariableAccessAsHTMLTable
Last active December 27, 2015 07:09
CFML UDF to output the railo 4+ implicit variables debug log as a table at the end of your request.
<cffunction name="getImplicitVariableAccessAsHTMLTable">
<cfargument name="railoWebAdminPassword" type="string" required="yes">
<cfscript>
var uniqueStruct={};
var ts=0;
var q=0;
var output=0;
var count=0;
var jsoutput=0;
admin action="getDebug" type="web" password="#arguments.railoWebAdminPassword#" returnVariable="ts";
@brucekirkpatrick
brucekirkpatrick / jquery.unserialize.js
Last active March 11, 2018 22:59 — forked from rcmachado/jquery.unserialize.js
Takes a string in format "param1=value1&param2=value2" and returns an javascript object. Improved to handle multiple values with same name and to unescape url encoded values.
/**
* $.unserialize
*
* Takes a string in format "param1=value1&param2=value2" and returns an object { param1: 'value1', param2: 'value2' }. If the "param1" ends with "[]" the param is treated as an array.
*
* Example:
*
* Input: param1=value1&param2=value2
* Return: { param1 : value1, param2: value2 }
*