Skip to content

Instantly share code, notes, and snippets.

Adam Coard acoard

Block or report user

Report or block acoard

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
acoard / gist:a0cc64d4f657312f44e1
Created Apr 20, 2015
Javascript promises style
View gist:a0cc64d4f657312f44e1
//Question: if you have a function which may or may not do some async, do you use a promise for the non-async path?
//Option A: Only return promise when doing async:
function OptionA(input){
if ( requiresQuery() ){
var defer = Q.deferred();
acoard / randomElement.js
Created Mar 4, 2014
Adds a .randomElement() method to lists by extending Object.prototype
View randomElement.js
//This little snippet does the bad practice of overloading default JavaScript objects. I know it's bad taste, sue me.
//It only works on arrays.
//['a', 'b', 'c'].randomElement()
Object.prototype.randomElement = function(){
var randomIndex = Math.floor(Math.random() * this.length);
return randomString = this[randomIndex];
You can’t perform that action at this time.