This file contains 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 http = require("http"); | |
var fs = require("fs"); | |
var stat = fs.statSync("./index.html"); | |
var server = http.createServer(function(req, res) { | |
switch(req.url) { | |
case "/": { | |
res.writeHead(200, { | |
'content-type': 'text/html', |
This file contains 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
{ | |
flatten: function(obj) { | |
function flatten(obj) { | |
return _.reduce(obj, function(memo, value, key) { | |
if (_.isObject(value)) { | |
_.forEach(flatten(value), function(v, k) { | |
memo[key + "." + k] = v; | |
}); | |
} else { | |
memo[key] = value; |
This file contains 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(global) { "use strict"; | |
var each = function(obj, iterator, context) { | |
if (obj == null) return; | |
if (Array.prototype.forEach && obj.forEach === Array.prototype.forEach) { | |
obj.forEach(iterator, context); | |
} else if (isArray(obj)) { | |
for (var i = 0, l = obj.length; i < l; i++) { | |
if (iterator.call(context, obj[i], i, obj) === {}) return; | |
} |
This file contains 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 randomHex() { | |
return (((1<<24) * Math.random())|0).toString(16); | |
} |
This file contains 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 escaper = function(value) { | |
assert(_.isString(value), "Can escape only the strings"); | |
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); | |
} |
This file contains 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 unflatten(path, obj, value) { | |
var key, child, result; | |
if (Object.prototype.toString.call(path) == '[object Object]') { | |
result = {}; | |
for (key in path) { | |
if (path.hasOwnProperty(key)) { | |
unflatten(key.split('.'), result, path[key]); | |
} | |
} |
This file contains 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
combine = (list, index = 0, combination = [], result = []) -> | |
if (list[index]) | |
for value in list[index] | |
combination[index] = value; | |
combine(list, index + 1, combination, result); | |
else | |
result.push(combination[..]); | |
return result; |
This file contains 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() { "use strict"; | |
var global = this; | |
/** | |
* Each iterator. | |
* | |
* @param {object} props | |
* @param {function} func | |
* @param {object} [context] |
This file contains 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
/** | |
* My Module. | |
* | |
* @package | |
* @author Sergey Kamardin <[email protected]> | |
*/ | |
define( | |
[ | |
], | |
function() { |
This file contains 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
/** | |
* Combine algorithm. | |
* | |
* @author Sergey Kamardin <[email protected]> | |
* | |
* Usage: | |
* | |
* combine(['a','b']) | |
* | |
* Will return ['ab', 'ba']; |
NewerOlder