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
// 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
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
var f = function (n) { | |
var s = ""; | |
// 0 is falsy, the ternary then evaluates to the value right of the colon | |
s += n % 3 ? "" : "Fizz"; | |
s += n % 5 ? "" : "Buzz"; | |
// empty string is also falsy | |
return s ? s : n; | |
}; | |
console.log(f(7)); |
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 solutions = {}, | |
coins = [1,5,7,9,11]; | |
var process = function (t) { | |
if (t == 0) { | |
// solved | |
return 0; | |
} else if (t < 0) { | |
// wrong path; return really large number | |
return 2e10; |
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 array = [1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17], | |
c = {}, // counters | |
s = []; // sortable array | |
for (var i=0; i<array.length; i++) { | |
c[array[i]] = c[array[i]] || 0; // initialize | |
c[array[i]]++; | |
} // count occurrences | |
for (var key in c) { |
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
State of binary switches: 0,0,0,0,0,0 | |
Corresponding combination: | |
State of binary switches: 0,0,0,0,0,1 | |
Corresponding combination: 100 | |
State of binary switches: 0,0,0,0,1,0 | |
Corresponding combination: 5 | |
State of binary switches: 0,0,0,0,1,1 | |
Corresponding combination: 5,100 | |
State of binary switches: 0,0,0,1,0,0 | |
Corresponding combination: 4 |
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 ArrayAdditionI(arr) { | |
// code goes here | |
var max = Math.max.apply( Math, arr ), | |
idx = arr.indexOf(max); | |
if (idx>-1) { arr.splice(idx, 1) } | |
return arr | |
} |
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
mongorestore --host mongodb1.example.net --port 37017 --username user --password pass /opt/backup/mongodump-2011-10-24 |
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 getQuery (searchString, callback) { | |
mongo.MongoClient.connect( | |
uri, | |
function(err, db) { | |
if(err) throw err; | |
query = { "$text": { "$search": searchString.toString() } }; | |
var cursor = db.collection("quotes").find( |