Skip to content

Instantly share code, notes, and snippets.

View mrandrewmills's full-sized avatar

Andrew Mills mrandrewmills

View GitHub Profile
@mrandrewmills
mrandrewmills / CodingStyles.php
Last active August 29, 2015 14:12
What Coding Styles Can Tell About A Coder
// This coder is a dangerous madman who NEVER tests his function output
function encryptEmailAddress($emailAddress, $secretKey){
$emailAddress = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, pack('H*', $secretKey), str_repeat(chr(16-(strlen($emailAddress)%16)), (16-(strlen($emailAddress)%16))), MCRYPT_MODE_CBC, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
return strtr(base64_encode($emailAddress), '+/', '-_');
}
@mrandrewmills
mrandrewmills / fizzbuzz01.js
Last active August 29, 2015 14:16
fizzbuzz 0.1
/*
* fizzbuzz() object
* I play the fizzbuzz game (http://en.wikipedia.org/wiki/Fizz_buzz)
*
* properties:
* start - integer (optional, defaults to 1)
* finish - integer (optional, defaults to 100)
* modFizz - integer (optional, defaults to 3)
* modBuzz - integer (optional, defaults to 5)
* txtFixx - string (optional, defaults to "fizz")
@mrandrewmills
mrandrewmills / FizzBuzz QUnit Test
Created March 22, 2015 19:56
traversing a returned array with a QUnit test
QUnit.test( "check individual results", function(assert){
for (x = fizzbuzz.start; x <= fizzbuzz.finish; x++) {
assert.ok(
(results[x] == x) ||
(results[x] == 'fizz') ||
(results[x] == 'buzz') ||
(results[x] == 'fizzbuzz') , "We expect results[x] is equal to x, 'fizz', 'buzz', or 'fizzbuzz.'");
}
});
@mrandrewmills
mrandrewmills / JSLintAndRegex.js
Created April 30, 2015 02:16
JSLint vs. Regex, before and after
// before
phrase = phrase.replace(/[^a-zA-Z]/g, "");
// after
phrase = phrase.match(/[a-zA-Z]/g);
phrase = phrase.toString();
phrase = phrase.replace(/[,]/g, "");
@mrandrewmills
mrandrewmills / howFast.js
Created May 6, 2015 03:22
quick and dirty JavaScript code to test execution speed of a function/method
var start, stop, duration;
start = new Date();
// the function or method you want to test
fizzbuzz.play();
stop = new Date();
duration = stop.getTime() - start.getTime();
console.log( duration + " milliseconds");
@mrandrewmills
mrandrewmills / scytaleV01.js
Created May 12, 2015 03:23
first stab at scytale encryption (see Simon Singh's "The Code Book" for details)
function scytale(d, msg) {
var ciphertext = "", baton = [];
// wrap blank parchment around baton
for (x = 0; x < d; x += 1) {
baton[x] = "";
}
// write message on wrapped parchment
@mrandrewmills
mrandrewmills / CSGetSubsitesRightWay.cfm
Created June 20, 2015 21:33
retrieving subsite info from CommonSpot with their API
<cfscript>
/* Sources:
http://www.paperthin.com/commonspot/help/api_help/content/invokeviacf.html
http://www.paperthin.com/commonspot/help/api_help/content/components/subsite.html
*/
subSiteComponent = Server.CommonSpot.api.getObject('Subsite');
aboutUsSubsites = subSiteComponent.getChildSubsites('/about/');
@mrandrewmills
mrandrewmills / fixProgressiveJPEG
Created August 2, 2015 11:25
convert progressive JPEGs into regular ones
<!---
credit to Oscar A. Revalo and Simon Bingham
see http://www.oscararevalo.com/blog/index.cfm/2008/1/26/CFImage-and-PJPEG-Images for details
--->
<cffunction name="fixProgressiveJPEG" access="public" returntype="void">
<cfargument name="source" type="string" required="true" />
<cfargument name="filename" type="string" required="true" />
<cfset var oImage="" />
@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>