Skip to content

Instantly share code, notes, and snippets.

@adamcameron
adamcameron / booleanTest.cfm
Last active December 21, 2015 10:29
Cross-platform version of Aurel's code
<cfscript>
void function test(string title, array values) {
writeOutput("<h3>#title#</h3>");
for (var v in values) {
writeDump(var=v,expand=false);
try {
b = v ? true : false;
writeOutput ("#v# is true: #b#");
} catch (any e) {
writeOutput ("#e.message# #e.detail#");
@adamcameron
adamcameron / tidier.cfm
Created August 27, 2013 13:16
Showing much tidier to populate an array of structs
l.response.body.result = ArrayNew(1);
for(l.i=1;l.i lte l.events.recordcount;l.i = (l.i + 1)){
arrayAppend(l.response.body["result"], {
"id" = l.events.id;
"start" = DateDiff("s","1/1/1970",l.events.startdate) * 1000;
"end" = DateDiff("s","1/1/1970",l.events.enddate) * 1000;
"title" = l.events.title;
"class" = "class";
"url" = l.url;
});
@adamcameron
adamcameron / test.cfm
Last active December 23, 2015 22:39
Proof of concept of making a <cfoutput>-performing custom tag
Content before<br>
<cfset msg = "Content within">
<cf_withoutput callback="#toUpper#">
#msg#<br>
</cf_withoutput>
Content after<br>
<cfscript>
function toUpper(string){
return ucase(string);
<cfhttp
method="get"
url="https://bugbase.adobe.com/index.cfm?event=qSearchBugs&page=1&pageSize=10&product=1149&version=7770&gridsortcolumn=AD_S_DEFECT_ID&gridsortdirection=DESC"
useragent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36"
>
<cfdump var="#cfhttp#">
@adamcameron
adamcameron / qoq.cfm
Created October 11, 2013 20:01
Cross-platform QoQ.
<cfscript>
numbers = queryNew(
"id,en,ma",
"integer,varchar,varchar",
[
[1, "one", "tahi"],
[2, "two", "rua"],
[3, "three", "toru"],
[4, "four", "wha"]
]);
@adamcameron
adamcameron / nullTypeCheck.cfm
Created October 19, 2013 15:47
Null type check
<cfset nullValue = null>
<cfoutput>
isSimpleValue(): #isSimpleValue(nullValue)#<br>
isObject(): #isObject(nullValue)#<br>
class: #nullValue.getClass().getName()#<br>
</cfoutput>
@adamcameron
adamcameron / defer.cfm
Created October 20, 2013 15:27
Very basic treatment of deferring the processing of a job, with callback handlers and monitoring functions.
<cfscript>
public struct function defer(required function job, function onSuccess, function onFailure, function onError, function onTerminate){
var deferThread = "";
try {
cfthread.status = "Running";
thread name="deferThread" action="run" attributecollection=arguments {
try {
successData.result = job();
cfthread.status = "Completed";
@adamcameron
adamcameron / sample.cfm
Created October 23, 2013 14:15
Pseudocode for VARing question
function f(){
var foo = "bar";
// 20-odd lines of code
for (){
var variableOnlyUsedInLoop = "something";
// etc
}
}
@adamcameron
adamcameron / BigDecimal.cfm
Created October 26, 2013 14:21
Demonstrates FP inaccuracy
<cfscript>
// will result in floating point inaccuracy
all = precisionEvaluate((60 / 55) / (40 / 55));
a = precisionEvaluate(60 / 55);
b = precisionEvaluate(40 / 55);
c = precisionEvaluate(a / b);
writeDump(var={
all = all,
a = b,
@adamcameron
adamcameron / cfparam.cfm
Created October 28, 2013 16:30
Demonstrating bug 3364510. The cfparam.cfm example raises an exception if URL.required is not set. This is expected behaviour. The param.cfm example does NOT raise an exception. This is wrong. Tested on CF 9,0,1,274733 and 10,0,11,285437: both have same failure Also tested on Railo 4.1.1.009: it works fine; and OpenBD 3,1: also works fine
<cfparam name="URL.required">
Don't output this unless that required variable is set