Skip to content

Instantly share code, notes, and snippets.

@adamcameron
adamcameron / findEntry.cfm
Created July 25, 2012 18:00
Example of using finally incorrectly: http://bit.ly/O9EXTS
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 July 25, 2012 18:04
Example of using finally correctly: http://bit.ly/O9EXTS
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 July 28, 2012 12:27
Investigation into applicationStop(): http://bit.ly/OlLnTM
// 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 July 29, 2012 12:11
This tests CFINSERT and CFUPDATE to see if they parameterise their values (http://bit.ly/MN0XYS)
<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 July 31, 2012 20:09
A CFCHART showing some medals, and that CF "phones home" (indeed, not even its own home!) when saving to PDF (http://bit.ly/N9cH2K)
<!--- 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 August 2, 2012 07:35
An example of how to implement looping in a ColdFusion custom tag (http://bit.ly/T5ikmR)
<!--- doLoop.cfm --->
<cf_loop iterations="10" index="i">
<cfoutput>[#i#]</cfoutput>Hello World<br />
</cf_loop>
@adamcameron
adamcameron / view.cfm
Created August 2, 2012 22:23
A demonstration of looping custom tags in ColdFusion. Part 1: view.cfm (http://bit.ly/T5ikmR)
<!--- 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 August 2, 2012 22:27
A demonstration of looping custom tags in ColdFusion. Part 2: data.cfm (http://bit.ly/T5ikmR)
<!--- 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 August 2, 2012 22:29
A demonstration of looping custom tags in ColdFusion. Part 3: table.cfm (http://bit.ly/T5ikmR)
<!--- 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 August 7, 2012 07:11
ClassViewer uses Java reflection to generate a text report of a class's structure and behaviours (http://bit.ly/QzT9ZX)
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
{