Skip to content

Instantly share code, notes, and snippets.

View async-regexp.js
import * as regexp from "@yiminghe/regexp";
(async function () {
const fakeData = ["x", "a", "b", "c", "a", "a", "b"];
let index = 0;
let length = fakeData.length;
let promise;
let stream = [];
// push data to steam
setInterval(() => {
stream.push(fakeData[index++ % length]);
@yiminghe
yiminghe / re2
Created Jul 20, 2021
re2 vs RegExp
View re2
var RE2 = require("re2");
var re=new RE2('(a+a+)+y');
const str=''+('a'.repeat(20))+'';
let start=Date.now();
console.log(!!str.match(re));
console.log(Date.now()-start);
start=Date.now();
console.log(!!str.match(/(a+a+)+y/));
@yiminghe
yiminghe / applicative.js
Last active Mar 17, 2021
haskell applicative function in js
View applicative.js
function callFn(f, ...args) {
if (f.length === 0) {
return f();
}
if (f.length === args.length) {
return f(...args);
}
if (f.length > args.length) {
const ret = f.bind(null, ...args);
ret.fn_name = `(${f.fn_name}(bind))`;
@yiminghe
yiminghe / gist:710f5d34d1a9a789acf9
Created Dec 31, 2014
implement alert using rc-dialog
View gist:710f5d34d1a9a789acf9
var tmp = document.createElement('div');
document.body.appendChild(tmp);
var React = require('react');
var Dialog = require('rc-dialog');
function alert(str){
var dialog = <Dialog title="alert" visible="true">{str}</Dialog>;
React.render(dialog,tmp);
}
@yiminghe
yiminghe / index.js
Created Nov 6, 2014
requirebin sketch
View index.js
var XTemplate = require('xtemplate');
alert(new XTemplate('{{x}}').render({x:2}));
@yiminghe
yiminghe / index.js
Created Nov 6, 2014
requirebin sketch
View index.js
var XTemplate = require('xtemplate');
alert(new XTemplate('{{x}}').render({x:2}));
@yiminghe
yiminghe / q_error_propagation.js
Created Feb 2, 2012
promise using Q about error propagation
View q_error_propagation.js
var d = Q.defer(),
ret = [],
p = d.promise;
var p2 = p.then(
function (v) {
ret.push("e1 :" + v);
throw "e1";
},
function (r) {
@yiminghe
yiminghe / kissy-overlay-on-nodejs.js
Created Jan 30, 2012
how to use kissy overlay on nodejs
View kissy-overlay-on-nodejs.js
var path = require("path"),
fs = require("fs");
var jsdom = require("jsdom").jsdom;
document = jsdom("<html><head></head><body></body></html>");
window = document.createWindow();
location = window.location;
navigator = window.navigator;
window.document = document;