Skip to content

Instantly share code, notes, and snippets.

@adamcameron
adamcameron / findEntry.cfm
Created Jul 25, 2012
Example of using finally incorrectly: http://bit.ly/O9EXTS
View findEntry.cfm
function findEntry(filePath, entry) {
var file = "";
var line = "";
try {
file = fileOpen(filePath, "read", "UTF-8");
line = "";
while (!fileIsEOF(file)) {
line = fileReadLine(file);
@adamcameron
adamcameron / findEntryFixed.cfm
Created Jul 25, 2012
Example of using finally correctly: http://bit.ly/O9EXTS
View findEntryFixed.cfm
function findEntry(filePath, entry) {
var file = "";
var line = "";
try {
file = fileOpen(filePath, "read", "UTF-8");
line = "";
while (!fileIsEOF(file)) {
line = fileReadLine(file);
@adamcameron
adamcameron / Application.cfc
Created Jul 28, 2012
Investigation into applicationStop(): http://bit.ly/OlLnTM
View Application.cfc
// Application.cfc
component {
this.name = "testApplicationStop";
this.applicationTimeout = createTimeSpan(0, 0, 1, 0);
function onApplicationStart(){
application.key = createUuid();
application.startedAt = timeFormat(now(), "HH:MM:SS.LLL") & "<br />";
application.firstVar = "First var using #application.startedAt#";
@adamcameron
adamcameron / testCfinsertAndCfUpdate.cfm
Created Jul 29, 2012
This tests CFINSERT and CFUPDATE to see if they parameterise their values (http://bit.ly/MN0XYS)
View testCfinsertAndCfUpdate.cfm
<cfif structKeyExists(form, "btnSubmit")>
<cfif form.btnSubmit EQ "ADD">
<cfinsert tablename="tbl_test" datasource="scratch_mysql" formfields="tst_data">
<cfelseif form.btnSubmit EQ "UPDATE">
<cfupdate tablename="tbl_test" datasource="scratch_mysql" formfields="tst_id,tst_data">
</cfif>
</cfif>
<cfquery name="q" datasource="scratch_mysql">
SELECT tst_id, tst_data
FROM tbl_test
@adamcameron
adamcameron / medalsChart.cfm
Created Jul 31, 2012
A CFCHART showing some medals, and that CF "phones home" (indeed, not even its own home!) when saving to PDF (http://bit.ly/N9cH2K)
View medalsChart.cfm
<!--- medalsChart.cfm --->
<cfchart chartheight="400" chartwidth="400" title="Medals at the Olympics @ 2/8/2012" format="html" seriesplacement="stacked">
<cfchartseries label="Bronze" type="bar" seriescolor="8C7853">
<cfchartdata item="NZ" value="2">
<cfchartdata item="GB" value="4">
<cfchartdata item="USA" value="10">
</cfchartseries>
<cfchartseries label="Silver" type="bar" seriescolor="E6E8FA">
<cfchartdata item="NZ" value="0">
@adamcameron
adamcameron / doLoop.cfm
Created Aug 2, 2012
An example of how to implement looping in a ColdFusion custom tag (http://bit.ly/T5ikmR)
View doLoop.cfm
<!--- doLoop.cfm --->
<cf_loop iterations="10" index="i">
<cfoutput>[#i#]</cfoutput>Hello World<br />
</cf_loop>
@adamcameron
adamcameron / view.cfm
Created Aug 2, 2012
A demonstration of looping custom tags in ColdFusion. Part 1: view.cfm (http://bit.ly/T5ikmR)
View view.cfm
<!--- view.cfm --->
<cfimport taglib="/shared/CF/other/customTags/looping" prefix="ui">
<cfoutput>
<ui:table data="#q#" headers="true" columnnames="id,english,maori" border="2" cellpadding="2" cellspacing="2">
<tr><td>#id#</td><td>#english#</td><td>#maori#</td></tr>
</ui:table>
<hr />
@adamcameron
adamcameron / data.cfm
Created Aug 2, 2012
A demonstration of looping custom tags in ColdFusion. Part 2: data.cfm (http://bit.ly/T5ikmR)
View data.cfm
<!--- data.cfm --->
<cfscript>
q = queryNew("");
queryAddColumn(q, "id", [1,2,3,4]);
queryAddColumn(q, "English", ["one","two","three","four"]);
queryAddColumn(q, "Maori", ["tahi","rua","toru","wha"]);
a = [
[1,"one","tahi"],
[2,"two","rua"],
@adamcameron
adamcameron / table.cfm
Created Aug 2, 2012
A demonstration of looping custom tags in ColdFusion. Part 3: table.cfm (http://bit.ly/T5ikmR)
View table.cfm
<!--- table.cfm --->
<cfif THISTAG.ExecutionMode EQ "Start">
<cfscript>
param name="attributes.data"; // no type checking, just existence checking
param name="attributes.headers" type="boolean" default=false;
param name="attributes.columnNames" type="string"; // this'll be treated as a list
currentRow = 1;
@adamcameron
adamcameron / ClassViewer.java
Created Aug 7, 2012
ClassViewer uses Java reflection to generate a text report of a class's structure and behaviours (http://bit.ly/QzT9ZX)
View ClassViewer.java
import java.util.*;
import java.lang.reflect.*;
public class ClassViewer
{
private static final String nl = System.getProperty("line.separator");
public static final String viewClassByName(String name)
throws Exception
{