Skip to content

Instantly share code, notes, and snippets.

@ciaranarcher
ciaranarcher / Application.cfc
Created July 4, 2011 12:33
ColdFusion Timeout Experiment
<cfcomponent output="false">
<cfset this.name = "testApp" />
<cfset this.clientManagement = false />
<cfset this.sessionManagement = false />
<cffunction name="onError" access="public" returntype="void" output="false" hint="">
<cfargument name="err" type="any" required="true" />
<cflog log="application" type="error" text="onError() called in '#this.name#' application: #ARGUMENTS.err.message#" />
@ciaranarcher
ciaranarcher / getTicks.cfm
Created July 6, 2011 16:53
Function to Convert a ColdFusion Date to a .NET Ticks Representation
<cffunction name="getTicks" access="public" returntype="numeric" output="false" hint="Returns the number of .NET ticks representing a the given date.">
<cfargument name="dateValue" type="date" required="true" />
<!---
http://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.71).aspx
http://stackoverflow.com/questions/386341/c-how-do-i-convert-ticks-to-minutes
--->
<cfset var ticksAtEpochZero = 621355968000000000 /> <!--- Number of .NET ticks at Epoch time (January 1 1970 00:00) --->
<cfset var ticksPerSec = 10000000 />
@ciaranarcher
ciaranarcher / dynamic-finder.cfm
Created July 25, 2011 18:23
ColdFusion DAO Dynamic Finder Example
<cffunction name="onMissingMethod" access="public" returntype="query" output="false" hint="Dynamic finder.">
<cfargument name="missingMethodName" type="string" required="true" />
<cfargument name="missingMethodArguments" type="struct" required="true" />
<cfset var searchFields = [] />
<cfset var qRead = "" />
<cfset var searchItem = "" />
<cfset var i = 0 />
<cfset var searchValue = "" />
@ciaranarcher
ciaranarcher / month-loop.cfm
Created July 29, 2011 13:36
ColdFusion - loop through the months in a year
<cfoutput>
<select name="birthMonth">
<cfloop index="i" from="2010-01-01" to="2011-01-01" step="#createTimeSpan(31, 0, 0, 0)#">
<option value="">#dateFormat(i, "MMM")#</option>
</cfloop>
@ciaranarcher
ciaranarcher / app.rb
Created September 9, 2011 14:51
Toy Sinatra
require 'rubygems'
require 'sinatra'
require 'active_record'
require 'logger'
class DatabaseSIA < ActiveRecord::Base
self.abstract_class = true
@ciaranarcher
ciaranarcher / logging-helper.rb
Created November 3, 2011 09:05
Logging Helper Example
# Helper class for logging.
# This class will allow the user get a standard Ruby Logger instance.
# Any specific log file configuration (e.g. rollover size etc)
# should be done within this class.
# @todo - should we run all log() calls through this class?
#
# @author Ciaran Archer
class LoggerHelper
@log_dir = "./logs"
@ciaranarcher
ciaranarcher / email_helper.rb
Created November 3, 2011 09:43
Email Helper
# Helper class for sending emails.
#
# @author Ciaran Archer
class EmailHelper
# @author Ciaran Archer
# @param [String] to
# @param [String] subject
# @param [String] body
# @param [String] from
@ciaranarcher
ciaranarcher / base.rb
Created November 22, 2011 13:45
Base Database Module
require "singleton"
module SIA
# Singleton class to enable database access for those occasions where a model will just not do.
# @author Ciaran Archer
class Database
include Singleton
@databases = nil
# Setup database connections with configuration file.
@ciaranarcher
ciaranarcher / client.rb
Created November 22, 2011 14:59
AR Benchmark Example
class Client < DatabaseSIA
# set a non-defualt primary key
set_primary_key :clientid
end
@ciaranarcher
ciaranarcher / profile_example.rb
Created November 23, 2011 10:44
Profiling Example
profile_data = JRuby::Profiler.profile do
results = SIA::SIAModels::Client.get_all
results.each do |c|
puts "#{c[:clientid]} #{c[:firstname]} #{c[:status]} #{c[:customersince]} #{c[:emailactive]}"
end
end
profile_printer = JRuby::Profiler::GraphProfilePrinter.new(profile_data)
profile_printer.printProfile(STDOUT)