Skip to content

Instantly share code, notes, and snippets.

View yiminghe's full-sized avatar

yiminghe yiminghe

View GitHub Profile
@yiminghe
yiminghe / no-react-intl.js
Last active December 17, 2021 10:19
no-react-intl
const { createIntl,createIntlCache } = require('@yiminghe/no-react-intl');
const cache = createIntlCache()
const intl = createIntl({
locale: 'en',
messages: {
hello:'hello {name}'
}
}, cache);
@yiminghe
yiminghe / index.html
Last active December 17, 2021 07:26
vba demo
<!DOCTYPE html>
<html>
<head>
<title>vba demo</title>
<meta charset="UTF-8" />
</head>
<body>
<div>
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 July 20, 2021 06:10
re2 vs RegExp
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 March 17, 2021 06:03
haskell applicative function in 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 December 31, 2014 06:42
implement alert using rc-dialog
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 November 6, 2014 08:12
requirebin sketch
var XTemplate = require('xtemplate');
alert(new XTemplate('{{x}}').render({x:2}));
@yiminghe
yiminghe / index.js
Created November 6, 2014 08:11
requirebin sketch
var XTemplate = require('xtemplate');
alert(new XTemplate('{{x}}').render({x:2}));
@yiminghe
yiminghe / q_error_propagation.js
Created February 2, 2012 11:28
promise using Q about error propagation
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 January 30, 2012 10:13
how to use kissy overlay on nodejs
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;