Skip to content

Instantly share code, notes, and snippets.

View mjclemente's full-sized avatar

Matthew J. Clemente mjclemente

View GitHub Profile
@mjclemente
mjclemente / singleLine.cfm
Created October 10, 2019 20:00 — forked from JamoCA/singleLine.cfm
ColdFusion UDF to trim, strip multiple spaces and remove undesireable space characters (non-breaking space, tab, line feed, carriage return)
function singleLine(s){
s = replacelist(s, "#chr(9)#,#chr(10)#,#chr(12)#,#chr(13)#,#chr(160)#", " , , , , ");
return trim(reReplace(s, "[[:space:]]{2,}", " ", "all"));
}
@mjclemente
mjclemente / syntax.css
Last active June 27, 2019 10:38 — forked from edwardhotchkiss/syntax.css
Solarized Light Pygments CSS / Jekyll
.highlight {
background-color: #efefef;
border: 1px solid #ddd;
-moz-box-shadow: 1px 1px rgba(0,0,0,0.1);
-webkit-box-shadow: 1px 1px rgba(0,0,0,0.1);
box-shadow: 1px 1px rgba(0,0,0,0.1);
overflow: hidden;
}
@mjclemente
mjclemente / task.cfc
Created January 17, 2019 20:04 — forked from bdw429s/task.cfc
CommandBox Task Runner to download packages from RiaForge
/**
* Scrape all the binaries from RiaForge
*/
component {
property name="progressableDownloader" inject="ProgressableDownloader";
property name="progressBar" inject="ProgressBar";
function run() {
directoryCreate( resolvePath( 'downloads' ), true, true );
var projects = deserializeJSON( fileRead( 'http://riaforge.org/index.cfm?event=json.projects' ) );
@mjclemente
mjclemente / isEmailDomainValid.cfm
Last active January 30, 2018 21:35 — forked from JamoCA/isEmailDomainValid.cfm
ColdFusion UDF to validate if an email address' MX record exists.
<!--- 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. --->
<!--- some elements are incorporated from @pfreitag's post here: https://www.petefreitag.com/item/487.cfm --->
<cfscript>
public boolean function isEmailDomainValid( required string email, string dnsServer = '8.8.8.8', numeric timeout = 2000, numeric retries = 1 ){
var mxRecords = [];
var emailDomain = email.listLast( '@' ).trim();
if ( !isValid( 'email', email ) )
return false;
@mjclemente
mjclemente / Word and Character Count.scpt
Last active November 22, 2017 01:11 — forked from markschwarz/Word and Character Count.scpt
Word and Character Count service for Mac OS X
-- Word and Character Count service for Mac OS X
-- Adds a Word and Character Count option to the text selection context menu
-- Use Automator to create a new service, then select the Run AppleScript action. Make
-- sure the service is set to receive "text", at the top of the window. Paste in this code
-- and save as "Word and Character Count". Now switch to a new app, select some text,
-- right-click, go to Services, and find the new option.
-- Copyright 2015, Noah Slater <nslater@apache.org>
@mjclemente
mjclemente / compressHtml
Created February 16, 2017 22:52 — forked from kevindb/compressHtml
ColdFusion Compress HTML
/**
* @hint Removes whitespace from HTML code
Originally authored by Jordan Clark (JordanClark@telus.net)
*/
public string function compressHtml(
required string html,
numeric level = 2
){
local.response = this.trim(arguments.html);
@mjclemente
mjclemente / pbkdf2.cfm
Created June 23, 2016 20:10 — forked from ryanguill/pbkdf2.cfm
PBKDF2 in CF: This is an example and test of hashing passwords in CFML using PBKDF2. Save this file as pbkdf2.cfm and run it for more information.
<cfscript>
struct function hashPasswordPBKDF2 (required string password, numeric iterations = 10000, numeric saltByteLength = 8) {
if (iterations < 100000) {
throw(message="Iterations must be greater than or equal to 100000");
}
if (saltbytelength < 8) {
throw(message="SaltByteLength must be greater than or equal to 8");
}
@mjclemente
mjclemente / xss-owasp-cheatsheet
Created May 12, 2016 21:44 — forked from sseffa/xss-owasp-cheatsheet
xss-owasp-cheatsheet
#
# https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
# based on the RSnake original http://ha.ckers.org/xss.html
# Retrieved on 2013-11-20
# Much of this wildly obsolete
#
# XSS Locator 2
'';!--"<XSS>=&{()}
@mjclemente
mjclemente / gist:31abdfe8ac97c43940ed
Last active September 14, 2015 14:05 — forked from ghidinelli/gist:e01b83b6a2e628c17cd5
getRemoteAddress() for ColdFusion with or without common load balancers/firewalls
<cffunction name="getRemoteAddress" output="false" access="public" returntype="string" hint="Identify the remote user IP address">
<cfset var pc = getHTTPRequestData().headers />
<cfset var arrIP = "" />
<cfif structKeyExists(pc, "X-Forwarded-For") AND len(pc["X-Forwarded-For"])>
<!--- the x-forwarded-for header sometimes includes values that are too long like "172.27.156.64, 67.98.222.16". The regexp picks out just the matches. http://support.f5.com/kb/en-us/solutions/public/12000/200/sol12264.html --->
<cfset arrIP = reMatch('\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b', pc["X-Forwarded-For"]) />
<cfif arrayLen(arrIP)>
<cfreturn arrIP[1] />
<cfelse>