This is a maintained listing of all the different ways to debug and profile Node.js applications. If there is something missing or an improvement, post a comment! :)
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 Nothing = {Nothing: true} | |
function MaybeGenerator() { | |
var g = arguments[arguments.length - 1] | |
// list of functions that test for any "Nothing" values | |
var maybes = [].slice.call(arguments,0,arguments.length - 1) | |
return function(value) { | |
var generator = g.apply(null,[].slice.call(arguments,1)) | |
var result |
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
# Meet Chef | |
## Recap : Terminology | |
+ node | |
A host where the Chef client will run (db,web,worker) | |
+ chef client | |
The command line program of that configures servers | |
+ chef server | |
A database-backed web server that stores searchable information about your production servers. |
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
module.exports = function(array, value) { | |
var left = 0; | |
var right = array.length - 1; | |
var tracker = []; | |
while (left <= right) { | |
var mid = Math.floor((left + right) / 2); | |
tracker.push(array[mid]); | |
if (array[mid] == value) return tracker ; | |
if (array[mid] < value) { | |
left = mid + 1; |
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 preorder = exports.preorder = function (head, tracker) { | |
if (head == null) return; | |
tracker.push(head.data); | |
preorder(head.left, tracker); | |
preorder(head.right, tracker); | |
} | |
var inorder = exports.inorder = function (head, tracker) { | |
if (head == null) return; | |
inorder(head.left, tracker); |
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 cache = {}; | |
var fabonacci = module.exports = function(n) { | |
if (n == 0) return 0; | |
if (n == 1) return 1; | |
if (!cache[n]) { | |
cache[n] = fabonacci(n - 1) + fabonacci(n - 2); | |
} | |
return cache[n]; | |
} |
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 count2 = function(n) { | |
if (n == 0) return 0; | |
var power = 1; | |
while (10 * power < n) power *= 10; | |
var first = Math.floor(n / power); | |
var remain = n % power; | |
var n2s = 0; | |
if (first > 2) { |
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
module.exports = function (book, word) { | |
var words = book.replace(/.,/, ' ').toLowerCase().split(' '); | |
var dict = {} | |
words.forEach(function(w) { | |
if (dict[w]) { | |
dict[w] += 1; | |
} else { | |
dict[w] = 1; | |
}; | |
}); |
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
module.exports = function (seq) { | |
var maxsum = -1000000000; | |
var sum = 0; | |
for (var i = 0; i < seq.length; i++) { | |
sum += seq[i]; | |
if(sum > maxsum) { | |
maxsum = sum; | |
} | |
if (sum < 0) { | |
sum = 0; |
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
module.exports = function (seq) { | |
var maxsum = 0; | |
for (var i = 0; i < seq.length; i++) { | |
var sum = 0; | |
for (var j = i; j < seq.length; j++) { | |
sum += seq[j]; | |
if(sum > maxsum) { | |
maxsum = sum; | |
} | |
}; |