Skip to content

Instantly share code, notes, and snippets.

View zheplusplus's full-sized avatar

Zhe Lin zheplusplus

View GitHub Profile
@zheplusplus
zheplusplus / cartesian_product.js
Created October 24, 2013 03:34
Cartesian product
function cartesianProduct(sets) {
return sets.reduce(function(items, nextSequence) {
return nextSequence.map(function(element) {
return items.map(function(item) {
var copyItem = item.slice(0);
copyItem.push(element);
return copyItem;
});
}).reduce(function(sum, current) {
return sum.concat(current);
@zheplusplus
zheplusplus / test.js
Last active December 20, 2015 08:39
Automation based tokenizer
var tknz = typeof require === 'undefined' ? window.tokenizer
: require('./tokenizer');
var t = tknz.Tokenizer();
t
.simpleSymbols('=+-*/%<>!.', 'operator')
.simpleSymbols('(', 'op_paren')
.simpleSymbols(')', 'cl_paren')
.simpleSymbols('{', 'op_brace')
.simpleSymbols('}', 'cl_brace')
.simpleSymbols(';', 'semicolon')
@zheplusplus
zheplusplus / markdown_split.js
Created June 4, 2013 08:53
Markdown split sample regex
/* inline codes are within two ` */
'a``b``c``d`e``f'.split(/``((?:[^`]|`[^`])*)``/)
/* ["a", "b", "c", "d`e", "f"] */