Skip to content

Instantly share code, notes, and snippets.

View JamoCA's full-sized avatar

James Moberg JamoCA

View GitHub Profile
@JamoCA
JamoCA / DateHash_Unhash.cfm
Last active September 6, 2022 23:16
ColdFusion UDF to format a date/time value to string format "yyyymmddHHmmssll" and back again. #dateHash(Now())# #dateUnHash("20140704")#
<cfscript>
/* 1/24/2011 james Moberg [email protected]
@param numberofChars, number of characters (Optional, 12 = default)
@param d, date/time string or object (Optional, now() = default)
@return Returns a yyyyMMddHHmmssll string (depending on length of numberofChars.)
Updated 20220903 to support millisecond */
string function dateHash(numeric numberofChars=12, date=now()) hint="I convert a date object to yyyymmddHHmmssll" {
var response = '';
if(not isvalid("date", arguments.date)) {
arguments.date = now();
@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 / JsoupTableParse.cfm
Last active March 11, 2016 08:52
Sample ColdFusion script to parse a webpage and extract table data using jsoup.
<cfhttp url="http://target_website_with-table.com/" username="#CGI.Http_User_Agent#"></cfhttp>
<cfscript>
jsoup = CreateObject("java", "org.jsoup.Jsoup");
HTMLDocument = jsoup.parse(CFHTTP.fileContent);
/* Identify a specific table containing the data to scrape */
TheTable = HTMLDocument.select("##tableByID");
/* Alternate DOM select methods if table doesn't have a unique ID
@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 / iispeed.config
Last active January 5, 2016 16:13
Default IISpeed configuration for IIS/ColdFusion
# enable iispeed on this website
IISpeed on
#IISpeed diagnose
# enable certain filters
# more filters at http://www.iispeed.com/pagespeed/optimizations
IISpeed RewriteLevel CoreFilters
IISpeed EnableFilters insert_dns_prefetch
IISpeed EnableFilters collapse_whitespace,trim_urls
@JamoCA
JamoCA / isEmailDomainValid.cfm
Last active April 10, 2018 18:43
ColdFusion UDF to validate if an email address' MX record exists. (Spammers tend to generate random domain strings when submitting comment spam.)
<!--- NOTE: This technique is not 100% accurate because some DNS servers don't allow MX queries or may be slow to respond,
but this will identify addresses that are potentially bad or suspicious. --->
<cfscript>
function isEmailDomainValid(email){
var local.email = arguments.email;
var local.DNSServer = '8.8.8.8'; /* Google DNS */
var local.timeout = 2000;
var local.attempts = 1;
var local.valid = true;
var local.emailDomain = trim(listlast(local.email,'@'));
@JamoCA
JamoCA / Verify_Googlebot.cfm
Last active January 30, 2018 10:59
Here's a raw proof-of-concept script written in ColdFusion that identifies & blocks fake Googlebots. This can be easily expanded to cache DNS responses & log new bots.
<cfscript>
/* based on info from http://googlewebmastercentral.blogspot.com/2006/09/how-to-verify-googlebot.html */
badBot = 0;
blockBadBots = 0;
ip = cgi.remote_addr;
userAgent = CGI.Http_User_Agent;
/* Sample request values */
//userAgent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
//ip = "179.179.65.180"; //bad