Skip to content

Instantly share code, notes, and snippets.

View JamoCA's full-sized avatar

James Moberg JamoCA

View GitHub Profile
@JamoCA
JamoCA / IESafari_ButtonJSTest.cfm
Last active August 27, 2015 18:03
Using inline onclick JS to submit a form fails to post fields when using Internet Explorer, Edge & Safari. Firefox & Google Chrome work.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Untitled</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<p>When using Internet Explorer 11, Edge & Safari (not sure of all versions), this fails to post the fields "Fuseaction" and "ContinueBtn" with the form.<br>
This functions properly when using either Firefox or Chrome.<br>
@JamoCA
JamoCA / dump2.cfm
Last active August 29, 2015 13:56
ColdFusion Custom Tag to allow all params to be safely passed regardless of ColdFusion version. Also removes comments & compresses whitespace.
<cfif thisTag.executionMode neq "start"><cfexit method="exitTag"></cfif><cfsetting enablecfoutputonly="YES">
<!--- Server-based optimization technologies (like Google PageSpeed) may minify
or rewrite the HTML/JS/CSS and break CFDump's output.
Defaults for optional attributes, taken from the docs
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_d-e_08.html --->
<cfparam name="attributes.var" default="">
<cfparam name="attributes.output" default="browser">
<cfparam name="attributes.format" default="html">
<cfparam name="attributes.abort" default="false">
<cfparam name="attributes.label" default="">
@JamoCA
JamoCA / ColdFusionNumberTest.cfm
Last active August 29, 2015 13:56
What is an integer? Validity, identification & parsed values should be consistent across all ColdFusion functions & tags. A "non-breaking space" chr(160) has been added to tests as I occassionally seen this character imported via CFSpreadsheet.
<!--- 2/21/2014 ColdFusion Number Test
What is an integer? Validity, identification & parsed values should be consistent across all ColdFusion functions & tags. A "non-breaking space" chr(160) has been added to tests as I occassionally seen this character imported via CFSpreadsheet. --->
<cfset isRailo = isDefined("Server.Railo")>
<cfset nbsp = chr(160)>
<cfset BadValues = ["1 5", " 5", "5 ", "3.14", ".99", "2.00", "2147483648", "005", "1+1", "5-1", "2/1", "3*2", "5#nbsp#", "#nbsp#5", "1#nbsp#5", "6,0", "0,6", "1,000", "$1,000", "$,1,2,$,2352345,$", "1,2,3,4"]>
<cfset c = 0>
<cfset TestQuery = QueryNew("i","integer")>
<cfset queryaddRow(TestQuery)>
@JamoCA
JamoCA / Pikaday_dateJS.js
Created March 6, 2014 19:44
Pikaday jQuery plugin with my modifications to add DateJS integration. (DateJS can parse strings like "next friday".) http://www.datejs.com/
/*!
* Pikaday 1.2.0 (Downloaded on 3/6/2014)
*
* Copyright © 2014 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday
* DateJS modifications by James Moberg | 3/6/2014 | http://about.me/jamesmoberg
*/
(function (root, factory)
{
'use strict';
@JamoCA
JamoCA / BlockedCookies.cfm
Created May 1, 2014 19:01
Block access to ColdFusion web application based on bogus, pre-existing cookies that aren't used.
<cfscript>
BadCookieList = [
"ASP.NET_SessionID",
"ISFIRSTVISIT",
"PHPSESSID",
"REMEMBERCOUNTRY",
"RESOURCEINFO",
"SESSIONS",
"SS_MID",
"USERINFO",
@JamoCA
JamoCA / isAjaxRequest.cfm
Last active August 29, 2015 14:01
This ColdFusion 8-11 UDF will query the server's request headers to determine if the request is an Ajax form post from jQuery. (jQuery adds a special header to all ajax requests.)
<!-- Compatible with ColdFusion 8-11.
4/28/2015 Rewritten to compensate for new undocumented CF10/11 behavior regarding getHTTPRequestData().
https://bugbase.adobe.com/index.cfm?event=bug&id=3042675
https://bugbase.adobe.com/index.cfm?event=bug&id=3581691
http://www.bennadel.com/blog/2824-gethttprequestdata-may-break-your-request-in-coldfusion-but-gethttprequestdata-false-may-not.htm
--->
<cffunction name="isAjaxRequestPost" output="false" returntype="boolean" access="public">
<cfset var response = StructNew()>
<cfset response.AjaxHeader = getPageContext().getRequest().getHeader("X-Requested-With") />
@JamoCA
JamoCA / cfhttp_test.cfm
Created June 13, 2014 17:56
Sample ColdFusion code to compare response times of ColdFusion CFHTTP against HTTPRequestCFC & CFX_HTTP5.
<!---
CFHTTP https://wikidocs.adobe.com/wiki/display/coldfusionen/cfhttp
HTTPRequestCF http://coldfusion9.blogspot.com/2012/03/custom-cfhttp-tag.html
CFX_HTTP5 http://www.cftagstore.com/tags/cfxhttp5.cfm
Here are the results that I received:
ColdFusion 10 CFHTTP: 9.04 CFC: 18.14 CFX_HTTP5: 1.26
ColdFusion 9 CFHTTP: 8.08 CFC: 158.92 CFX_HTTP5: 2.4
ColdFusion 8 CFHTTP: 4.86 CFC: 149.14 CFX_HTTP5: 2.14
--->
@JamoCA
JamoCA / web.config
Created August 8, 2014 21:29
IIS 7 Web Font Hosting Rules for Emigre Web Fonts. Disables hotlinking & directory listing.
<?xml version="1.0" encoding="UTF-8"?>
<!-- IIS 7 Disable hotlinking and directory listing. http://www.emigre.com/EULWEB.php -->
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Hotlinking Prevention" stopProcessing="true">
<match url=".*\.(woff|eot)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^https?://www\.yourdomain\.com/.*$" negate="true" />
@JamoCA
JamoCA / hashids.cfm
Last active August 29, 2015 14:05
Sample Implementation of the ColdFusion hashids library http://www.hashids.org/coldfusion/
<cfscript>
/* Download and install the hashids CFC https://github.com/dswitzer/hashids.coldfusion */
hashids = new Hashids(salt="this is my salt"
,minLen=8
,alphabet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
id_to_hash = listtoArray("1"); // try "1,2,3" and "3,2,1" and "1,1,1"
writeoutput('original = #arrayToList(id_to_hash)#<br>');
hashed_id = hashids.encrypt(id_to_hash);
@JamoCA
JamoCA / inputSelectAll.js
Created September 10, 2014 18:32
Select all text in field upon focus. Chrome's mouseup event prevents select() from working without this hack.
$(function(){
/* Select all text in field upon focus.
Chrome's mouseup event prevents select() from working without this hack.
Add "selectAll" class to input fields or modify to work with any input field */
$('body').on('focus', 'input:text.selectAll', function(){
$(this).one('mouseup', function(e){
e.preventDefault();
}).select();
});
});