Skip to content

Instantly share code, notes, and snippets.

@adamcameron
adamcameron / jsonWeirdness.cfm
Created April 2, 2013 01:41
Demonstrating ColdFusion messing with boolean values from JSON
<cfsavecontent variable="json">
{
"trueMatch1": {
"setting": true
},
"falseMatch": {
"setting": false
},
"trueMatch2": {
"setting": true
@adamcameron
adamcameron / listing.cfm
Last active December 16, 2015 21:29
Does a file / directory listing of the specified directory, kind of emulating the directory-browsing functioanlity of a web server.
<cfscript>
// directory to create listing for, defaulting to the current one
param name="URL.dir" type="string" default=getDirectoryFromPath(getCurrentTemplatePath());
dirCurrent = createObject("java", "java.io.File").init(URL.dir).getCanonicalPath();
dirBase = createObject("java", "java.io.File").init(expandPath("/")).getCanonicalPath();
slash = createObject("java", "java.io.File").separatorChar; // As this displays I'm gonna incur Sean's wrath and use the "correct" slash for the sake of UX
// create the domain/port part of the URL
@adamcameron
adamcameron / listing.php
Last active December 16, 2015 22:49
A PHP version of listing.cfm
<?php
// directory to create listing for, defaulting to the current one
if (array_key_exists("dir", $_GET)){
$dirCurrent = $_GET["dir"];
}else{
$dirCurrent = getcwd();
}
// sort out some baseline dirs / URLs
$dirCurrent = realpath($dirCurrent);
@adamcameron
adamcameron / functions.cfc
Last active December 16, 2015 23:59
A series of functions, each implementing a test of whether a path is within the current webroot.
component {
public boolean function matt(path) {
var boolReturn = false;
var local = {};
local.isInRoot = (listLen( arguments.path, "\/") - listLen(ExpandPath('/'), "\/"));
if (local.isInRoot GTE 0) {
boolReturn = true;
}
return boolReturn;
@adamcameron
adamcameron / tests.cfc
Last active December 16, 2015 23:59
Tests for functions.cfc
component extends="mxunit.framework.TestCase" {
public void function beforeTests(){
variables.testFunctions = createObject("functions");
}
public void function testCurrentFilePath(){
if (structKeyExists(variables, "testFunction")){ // this variable is defined in extending CFCs. These tests are "abstract" in this CFC
test(getCurrentTemplatePath(), variables.testFunction);
@adamcameron
adamcameron / testAdam.cfc
Created May 4, 2013 12:29
An implementation of tests.cfc
component extends="tests" {
public void function beforeTests(){
super.beforeTests();
variables.testFunction = variables.testFunctions.adam;
}
}
@adamcameron
adamcameron / untriagedCf10Bugs.cfm
Created June 14, 2013 11:58
This generates a table of untriaged ColdFusion 10 bugs, pulling the data from the Adobe bugbase
<cfscript>
bugsUrl = "https://bugbase.adobe.com/index.cfm?event=qSearchBugs&page=1&pageSize=500&type=Bugs&product=1149&version=7770&state=OPEN&status=UNVR";
bugUrl = "https://bugbase.adobe.com/index.cfm?event=bug&id=";
httpConnection = new Http(URL=bugsUrl, method="get");
bugsJsonP = httpConnection.send().getPrefix().fileContent;
bugsJson = removeChars(bugsJsonP, 1, 2);
bugs = deserializeJson(bugsJson, false).query;
</cfscript>
<cfquery name="bugsSorted" dbtype="query">
@adamcameron
adamcameron / TestArrayReduce.cfc
Created July 25, 2013 19:13
arrayReduce() function, and unit tests
component extends="mxunit.framework.TestCase" {
/**
* @hint CFML implementation of Array.reduce(), similar to Javascript's one ref https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
* @array Array to reduce
* @callback Callback function to use to reduce. Will receive the following arguments: element (of current iteration of the all), index, array, (optional) result (of preceeding call to callback())
* @initialValue The initial value to use to start the reduction
*/
private any function arrayReduce(required array array, required any callback, any initialValue){
var startIdx = 1;
if (!structKeyExists(arguments, "initialValue")){
@adamcameron
adamcameron / componentTemplate.cfm
Created August 3, 2013 16:32
Some code to generate unique CFCs for benchmarking CFC-loading when ColdFusion either saves class files, or does not.
<cfoutput>
<#cf#component output="false">
<#cf#function name="init" returntype="#componentReturnType#" access="public" output="false" hint="Initialises and returns the object">
<#cf#argument name="configFile" type="string" required="true" hint="Config file name">
<#cf#set var jsonConfig = "">
<#cf#file action="read" file="##expandPath('./')####arguments.configFile##" variable="rawConfig">
@adamcameron
adamcameron / cfdumpDemo.cfm
Last active December 21, 2015 05:38
Demonstrates incompat between CF and Railo in how Railo handles to TOP attribute for arrays and queries.
<cfscript>
q = queryNew("");
queryAddColumn(q, "id", "integer", [1,2,3,4,5,6]);
a = makeArray(6);
st = makeStruct(6);
writeDump(var=q, top="3");
writeDump(var=a, top="3");
writeDump(var=st, top="3");