This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Eratosthenes(max) { | |
var elim = {}, | |
primes = []; | |
for (var i=2; i<=max; i++) { | |
if ( !elim[i] ) { | |
primes.push(i); | |
for (var j=i*2; j<=max; j+=i) { | |
elim[j] = true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is what you would do if you liked things to be easy: | |
// var stringifyJSON = JSON.stringify; | |
// but you don't so you're going to write it from scratch: | |
var stringifyJSON = function(obj) { | |
if (obj===null) { | |
return 'null'; | |
} else if (typeof obj === 'number' || 'boolean') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alfred://customsearch/Mozilla%20Developer%20Network%20Search/mdn/utf8/plus/https://developer.mozilla.org/en-US/search?q={query} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hue, cell, | |
grades = 100, | |
query = ''; | |
for (var i = 0; i < grades; i++) { | |
hue = i * 360 / grades | |
query = '<div style="float:left;' + | |
'width:' + (100/grades) + '%;' + | |
'height:20px;' + | |
'background-color: hsl(' + hue + ', 100%, 75%);"></div>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function permutator(inputArr) { | |
// the output matrix of all permutations | |
var results = []; | |
// takes the array of character set | |
function permute(columnOptions, path) { | |
var place, newPath, path = path || []; | |
// for a given row | |
// go through the options for "which column" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = ''; | |
request.on('data', function (partial) { | |
data += partial; | |
}); | |
request.on('end', function () { | |
data = JSON.parse(data); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function powerset(alphabet) { | |
var p = [[]]; | |
for (var i=0; i < alphabet.length; i++) { | |
// here the value of len is set at the beginning | |
for (var j = 0, l = p.length; j < l; j++) { | |
p.push(p[j].concat(alphabet[i])); | |
// inspector | |
console.log(p); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
passport.use(new LocalStrategy( // a new Local instance | |
function(username, password, done) { // passing in a function | |
User.findOne({ username: username }, function (err, user) { // Mongo interface | |
if (err) { return done(err); } // generic error | |
if (!user) { return done(null, false); } // user not found | |
if (!user.verifyPassword(password)) { return done(null, false); } // wrong password | |
return done(null, user); // authenticated, returns 'user' | |
}); | |
} | |
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Methods for cycling through the models in a Backbone Collection | |
# Usage: | |
# | |
# c = new MyCollection([...]) | |
# nextModel = c.modelAfter(myModel) | |
# myModel == c.modelBefore(nextModel) | |
# # true | |
# | |
class MyCollection extends Backbone.Collection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code { | |
padding: 2px 3px; | |
color: #d14; | |
background-color: #f7f7f9; | |
border: 1px solid #e1e1e8; | |
white-space: nowrap; | |
} |