Skip to content

Instantly share code, notes, and snippets.

@ForbesLindesay
ForbesLindesay / every.js
Created May 21, 2012 00:07
Every, Some and Reduce
Array.prototype.every = function (fn) {
return this.reduce(function (a, b){ return a && fn(b); }, true);
}
@ForbesLindesay
ForbesLindesay / test.md
Created May 21, 2012 00:19
Test Markdown

Heading 1

Heading 2

[1,2,3].filter(function(v){return v>2;});
@ForbesLindesay
ForbesLindesay / aliases.js
Created May 21, 2012 00:24
Array Methods
(function () {
Array.prototype.select = Array.prototype.map;
Array.prototype.where = Array.prototype.filter;
Array.prototype.all = Array.prototype.every;
Array.prototype.any = Array.prototype.some;
Array.prototype.agregate = Array.prototype.reduce;
Array.prototype.fold = Array.prototype.reduce;
} ());
@ForbesLindesay
ForbesLindesay / for-loop.html
Created May 21, 2012 00:37
EJS - Blog Post
<ul>
<% for(var i = 0; i<items.length; i++){ %>
<li><%= items[i].name %></li>
<% } %>
</ul>
@ForbesLindesay
ForbesLindesay / gist:2760060
Created May 21, 2012 00:38
Wordpress Notes
@ForbesLindesay
ForbesLindesay / contains.js
Created May 24, 2012 09:14
contains, distinct, group by, select many
Array.prototype.contains = function(value, comparison){
comparison = comparison || function(A,B){
return (A === B);
};
return this.some(function(item){
return comparison(item, value);
});
};
function getAllUserDetails(id, cb){
database.findUserByID(id, function(err,user){
if(err) return cb(err);
var roles,friends;
user.getRoles(function(err,res){
if(err) return cb(err);
roles = res;
next();
});
user.getFriends(function(err,res){
@ForbesLindesay
ForbesLindesay / longCompare.js
Created August 16, 2012 09:37
Compare two strings really carefully to work out what's different
function longCompare(actual, expected) {
function format(str) {
if (typeof str === 'string') {
return JSON.stringify(str).replace(/^\"/g, '\'').replace(/\"$/g, '\'');
} else {
return str;
}
}
for (var i = 0; i < actual.length || i < expected.length; i++) {
if (actual.charAt(i) !== expected.charAt(i)) {
@ForbesLindesay
ForbesLindesay / syncLikeFunctionality.js
Created August 21, 2012 12:43
syncLikeFunctionality for Q
module.exports.not = not_qjs;
function not_qjs(promise) {
return promise.then(function (value) {
return !value;
});
}
function continue_qjs(result) {
return once_qjs(function continue_qjs() {
return result;
@ForbesLindesay
ForbesLindesay / gist:3448771
Created August 24, 2012 10:14
Merge Upstream Changes
git checkout master
git pull upstream master
git rebase master