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 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
{ | |
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
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
var bigInt = 1000000000; | |
console.log(process.argv); | |
function asBuf() { | |
var buf = new Buffer(""); | |
for (var i = 0; i < bigInt; i++) { | |
if (i % 10000 == 0) console.log(process.memoryUsage()['rss'] / 1024 / 1024 + 'mb'); | |
buf = Buffer.concat([buf, new Buffer("a")]); |
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 Actor(min, max) { | |
var self = this; | |
this.id = Math.floor(min + Math.random() * (max - min + 1)); | |
var actor = function() { return self.action.apply(actor, arguments); } | |
Object.setPrototypeOf(actor, this); | |
return actor; | |
} |
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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
type List struct { | |
Items []int | |
} |
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
package gcd | |
import "fmt" | |
import "math/big" | |
func Dedup(l []int64) []int64 { | |
list := make([]int64, len(l)) | |
copy(list, l) | |
last := len(list) - 1 |
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 inherits = require("inherits-js"); | |
var Generator; | |
/** | |
* @abstract | |
* @class Generator | |
* @constructor | |
*/ | |
Generator = function() { | |
var self = this; |
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 <gobwas@gmail.com> | |
* | |
* Usage: | |
* | |
* combine(['a','b']) | |
* | |
* Will return ['ab', 'ba']; |
OlderNewer