Skip to content

Instantly share code, notes, and snippets.

View mrandrewmills's full-sized avatar

Andrew Mills mrandrewmills

View GitHub Profile
@mrandrewmills
mrandrewmills / motherFusker.js
Created November 28, 2015 19:00
compare 2 image URLs, use delta to infer numerical sibling images
/**
* Name: motherFusker.js
* Purpose: compare 2 image URLs, use delta to infer numerical sibling images
* Date: 11-28-15
*/
/**
* Constructor function
*
* Example:
@mrandrewmills
mrandrewmills / CustomElementsFormIDExample.cfm
Created January 14, 2016 03:29
show how to access formID
<cfscript>
// get data from the "Alerts" Custom Element
data = application.ADFDemo.ceData.getCEData( customElementName = "Alerts" );
</cfscript>
<!--- loop over our results --->
<cfloop from="1" to="#arrayLen(data)#" index="itm">
<cfdump var="#data[itm].formID#" label="formID">
<cfdump var="#data[itm].values#" label="Values">
</cfloop>
@mrandrewmills
mrandrewmills / getFactors.js
Created March 12, 2016 21:08
returns factors for an integer
/**
* getFactors - find all factors of an integer in pairs
* @param, N, an integer
* returns a multidimensional array (e.g. 4 gets: [1,4],[2,2],[4,1])
*/
function getFactors(N) {
"use strict";
var x;
@mrandrewmills
mrandrewmills / disemvowel.js
Created March 31, 2016 03:12
case-insensitive regex that strips vowels out of a string
/**
* disemvowel - remove vowels from a string
* @param {string} phrase - the string you want to "disemvowel"
*/
function disemvowel(phrase) {
"use strict";
return phrase.replace(/[aeiou]/ig, "");
}
@mrandrewmills
mrandrewmills / Euclid.js
Created May 1, 2016 17:27
a little JavaScript kata inspired by Dr. Marcus du Sautoy's discussion of Euclid's "Greatest Common Divisor" algorithm.
var Euclid = {};
Euclid.gcd = function greatestCommonDivisor( a, b) {
"use strict";
var lilNum, bigNum, modulo;
lilNum = Math.min( a, b);
bigNum = Math.max( a, b);
@mrandrewmills
mrandrewmills / renderScriptOnceExample.cfm
Last active November 9, 2016 13:45
Example using CommonSpot ADF renderScriptOnce method to load JWPlayer once and only once
<cfsavecontent variable="outputHTML">
<cfoutput>
<script type="text/javascript" src="/common/commonspot/templates/js/jwplayer/jwplayer.js"></script>
<script type="text/javascript">jwplayer.key="PUT_YOUR_API_KEY_HERE_OBVIOUSLY";</script>
</cfoutput>
</cfsavecontent>
<cfoutput>
#application.adf.scriptsService.renderScriptOnce("JWPlayer", outputHTML)#
</cfoutput>
@mrandrewmills
mrandrewmills / jsharing_function_k_fix.js
Last active July 1, 2016 10:51
possible 508 fix for function K(a) in JWPlayer's Sharing plugin
// improved (added line 10)
function k(a) {
var b = i("div", ["jw-sharing-row", "jw-sharing-" + a])
, c = i("span", ["jw-sharing-svg-row-icon", "jw-sharing-icon-" + a])
, d = i("span", ["jw-sharing-cell"], c);
b.appendChild(d);
var e = i("textarea", ["jw-sharing-text"]);
return new u(e).on("click tap", l, e),
e.setAttribute("readonly", "true"),
e.setAttribute("title", a)
@mrandrewmills
mrandrewmills / CEDataArrayToQuery
Created October 8, 2016 17:27
Converts an array of structures returned by getCEData method within CommonSpot's ADF into a ColdFusion query
<cffunction name="CEDataArrayToQuery" returntype="query" description="convert array of structs from getCEData into a CF query">
<cfargument name="CEDataArray" type="array" required="yes">
<cftry>
<!--- begin by getting struct keys from Values first --->
<cfset valueKeys = StructKeyList(arguments.CEDataArray[1].Values)>
<!--- then create our query, using those keys --->
<cfset qData = QueryNew(valueKeys)>
@mrandrewmills
mrandrewmills / JavaScript Puzzle One
Created October 15, 2016 18:39
Challenge: Identify the cause of the bug, and fix it by changing only a single line.
var timeValue = "2:00 PM";
var apptTimes = "10:00 AM, 12:00 PM, 3:00 PM";
if (apptTimes.indexOf(timeValue) > -1) {
// selected time has already been added to apptTimes previously
alert("This time has already been added before.");
}
@mrandrewmills
mrandrewmills / JS_OOP_NotesAndExamples.js
Created October 17, 2016 16:46
Notes and examples for the two approaches to JS OOP
// JavaScript OOP Notes & Examples
// The "Singleton" Approach
var fizzbuzz = {
start: 1,
stop: 100,
modFizz: 3,
modBuzz: 5,
sayFizz: "fizz",
sayBuzz: "buzz",