Skip to content

Instantly share code, notes, and snippets.

View mrandrewmills's full-sized avatar

Andrew Mills mrandrewmills

View GitHub Profile
@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 / howManyXinYthruZ.js
Last active April 16, 2016 15:06
Trivia question solver. (e.g. how many number between 1 and 2000 have the number 2 in them?)
/**
* howManyXinYthruZ.js - solves those annoying "How Many X's Are There In Y Through Z?" puzzles
* @type {object}
* @namespace
*/
var puzzle = {
/**
* Our variables/properties. No need to assign values, our function does that for us.
@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 / 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 / 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",
@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 / 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 / JavaScript Puzzle Two (jQuery)
Created January 10, 2017 22:40
Challenge: Explain the cause of the bug, and fix it by changing only a single line.
// 1st given: the .get call on line 5 should fire only when .sidebar is present
// 2nd given: the current page does NOT have any element with a .sidebar attribute
if ($('.sidebar')) {
$.get( "ajax/fundraising.html", function( data ) {
$( '.sidebar' ).html( data );
});
}