Skip to content

Instantly share code, notes, and snippets.

@wellercs
wellercs / cf_QueryOfQueriesDivideByZeroNotThrowingError
Created July 27, 2012 22:56
CF query of queries divide by zero not throwing error
<cfquery name="qryTest" datasource="dsnCommon">
SELECT 0 AS col1, 0 AS col2
</cfquery>
<cfquery name="qqTest" dbtype="query">
SELECT (col1 / col2) AS col3
FROM qryTest
</cfquery>
<cfdump var="#qqTest#">
@wellercs
wellercs / cf_IsNullFormat
Created July 27, 2012 23:01
Easy method for setting cfqueryparam null attribute
<cfcomponent name="utilities" output="false" hint="I provide various utility functionality">
<cffunction name="init" access="public" returntype="any" output="false" hint="Initializes the Service">
<cfreturn this />
</cffunction>
<cffunction name="isNullFormat" access="remote" returntype="any" output="false" hint="I return whether something is null">
<cfargument name="input" type="any" required="true" />
<cfset var inputdatatype = "">
<cftry>
@wellercs
wellercs / tsql_DisplayDateTimeAndTimePeriod
Created July 27, 2012 23:04
t-sql display date, time, time period
SELECT
GETDATE() AS this_date_time
, CONVERT(VARCHAR, GETDATE(), 101) AS this_date
, RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) AS this_time
, ( CONVERT(VARCHAR, GETDATE(), 101) + ' ' + RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) ) AS this_date_time
@wellercs
wellercs / tsql_FindFirstCharacterWithCharIndex
Created July 27, 2012 23:07
Searching on first character with CHARINDEX
DECLARE @AlphaNumChars varchar(50)
SET @AlphaNumChars = 'a,1,m,s'
SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE CHARINDEX(LEFT(TABLE_NAME,1),@AlphaNumChars) > 0
@wellercs
wellercs / tsql_GetFirstItemFromListUsingSubstringAndCharIndex
Created July 27, 2012 23:11
t-sql get first item from list using substring and charindex
DECLARE @InvalidList varchar(50)
DECLARE @ValidList varchar(50)
SET @InvalidList = 'Item1-Item2-Item3'
SET @ValidList = 'Item1 > Item2 > Item3'
SELECT
CASE
WHEN CHARINDEX('>',@InvalidList) = 0 THEN @InvalidList
ELSE LTRIM(RTRIM(REPLACE(SUBSTRING(@InvalidList,1,CHARINDEX('>',@InvalidList)),'>','')))
END
@wellercs
wellercs / js_DataErrorMessage
Created July 27, 2012 23:16
Validate client-side with dataset property
<html>
<head>
<title>Data Error Message Sandbox</title>
<script type="text/javascript">
function checkForm() {
var myformelement = document.getElementById('myformelement');
var usermessage = document.getElementById('usermessage');
if (myformelement.value == "") {
try {
alert(myformelement.dataset.errorMessage);
@wellercs
wellercs / cfhttp_caller.cfm
Created January 15, 2013 01:53
test cfhttp encoding in url
<cfparam name="url.scope" default="">
<cfhttp url="http://#cgi.http_host#/sandbox/receiver.cfm?scope=#url.scope#" method="post" resolveurl="no">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
</cfhttp>
<cfdump var="#cfhttp#">
<cfchart format="png" chartwidth="270" xaxistitle="Visits last 7 Days" show3d="no" foregroundcolor="##333333" showborder="no" fontbold="yes" tipStyle="none" url="" showLegend="true">
<cfchartseries type="line" query="chartData" itemcolumn="dateRange" valuecolumn="FLASHvisits" datalabelstyle="none" seriesLabel="FloorPlan">
<cfif chartData.showVTS><cfchartseries type="line" query="chartData" itemcolumn="dateRange" valuecolumn="VTSvisits" seriesColor="blue" datalabelstyle="none" seriesLabel="IDS"></cfif>
<cfif chartData.showMobile><cfchartseries type="line" query="chartData" itemcolumn="dateRange" valuecolumn="MOBILEvisits" seriesColor="red" datalabelstyle="none" seriesLabel="Mobile"></cfif>
</cfchart>
<!---
The line that the stack trace says it's erroring on is:
<cfif chartData.showMobile><cfchartseries type="line" query="chartData" itemcolumn="dateRange" valuecolumn="MOBILEvisits" seriesColor="red" datalabelstyle="none" seriesLabel="Mobile"></cfif>
--->
@wellercs
wellercs / Response-cfc-example
Created April 6, 2013 20:43
Example of working with Response.cfc
<cffunction name="validateDemo" access="public" returntype="any" output="false">
<cfargument name="fname" type="string" required="true">
<cfargument name="lname" type="string" required="true">
<cfargument name="email" type="string" required="true">
<cfargument name="throwerror" type="boolean" required="false" default="false">
<cfset var local = {}>
<cftry>
<cfset local.responseobject = new Response()>
@wellercs
wellercs / Response-cfc-jquery-example
Created April 6, 2013 21:47
jQuery example of calling a function that consumes Response.cfc
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: '/sandbox/Demo.cfc', // this can be found at https://gist.github.com/wellercs/5327556
data: {
method: 'validateDemo',
fname: "John",
lname: "Doe",
email: "bademail",