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 immu = require('immutable'); | |
var StateMachine = function(data) { | |
this._data = {}; | |
this.state = immu.fromJS(this._data); | |
this.setState(data); | |
} | |
StateMachine.prototype.setState = function(data) { | |
var state = this.state.mergeDeep(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
/* | |
用于Stylish | |
网址前缀:https://www.baidu.com/s? | |
网址前缀: http://www.baidu.com/s? | |
*/ | |
#content_left>*:not(.result):not(.result-op):not(.leftBlock):not(#super_se_tip):not(#rs_top_new):not(.hit_top_new):not(.se_common_hint), | |
#ec_im_container>[id], | |
.ad-block { | |
position: relative !important; |
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 generate(max) { | |
var counter = 0; | |
var density = 0.7; | |
var queue = []; | |
function gen(node) { | |
node.value = counter++; | |
if (counter >= max) return; // this is buggy. may cause real node count > max because it was already generated to the queue. | |
if (Math.random() < density) { | |
queue.push(node.left = {}); |
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 MidIterator = function(root) { | |
this.stack = [root]; | |
this.__pushLeft(root); | |
}; | |
MidIterator.prototype.__pushLeft = function(node) { | |
if (!node) return; | |
var left = node.left; | |
while (left) { | |
this.stack.push(left); | |
left = left.left; |
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 format(fmt){ | |
var args = Array.prototype.slice.call(arguments, 1); | |
for (var i=0; i<args.length; ++i){ | |
var reg = new RegExp('([^\\\\]|^)(?:\\{' + i + '\\})', 'g'); | |
fmt = fmt.replace(reg, '$1' + args[i]); | |
} | |
return fmt; | |
} | |
console.log(format('Hello, {0}!', 'world', 'jim')); |
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
// 极其弱的版本,对于[1, [], 2]这样的奇怪情况(嵌套的是空链)会跪,回头修回头修 | |
var ListNode = function(value, next){ | |
// 虽然是简单结构,但是为了Hidden Type优化做成个class | |
this.value = value; | |
this.next = next; | |
}; | |
var LinkedList = function(){ | |
this.head = this.tail = new ListNode(null, null); |
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
// app.js | |
for (var controller in routes){ | |
var mod = routes[controller]; | |
app.all('/' + controller + ':action', function(req, res){ | |
var action = req.params.action; | |
if (action in mod){ | |
mod[action](req, res); | |
}else{ | |
res.statusCode = 404; | |
res.send('404 not found'); |
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 hrtime = (function(){ | |
if (typeof window !== 'undefined'){ | |
// browser | |
if (typeof window.performance !== 'undefined' && typeof performance.now !== 'undefined'){ | |
// support hrt | |
return function(){ | |
return performance.now(); | |
}; | |
}else{ | |
// oh no.. |
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 DeCasteljauBezier(points, density, step){ | |
//if (points.length < 3) return null; | |
console.time('bezier'); | |
var ps = points.map(function(p){ | |
return { | |
x: p.x, | |
y: p.y | |
}; | |
}), | |
results = [], |
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
<!doctype html> | |
<html> | |
<head> | |
<title>CSS3文字渐变</title> | |
<meta charset="UTF-8"> | |
<style type="text/css"> | |
body { | |
margin:0; | |
padding:0; | |
background:#fff; |