Skip to content

Instantly share code, notes, and snippets.

@zzuhan
zzuhan / micro-tpl.js
Created May 12, 2014 14:12
micro tpl 极小的模板系统,支持数据递归
var microTpl = {
render: function (tpl, data) {
if(!tpl || !data) {
throw new Error("tpl or data can't be empty, microlTpl.render");
}
// 占位符的正则 the regex of placeholder
var rendered,
rPlaceholder = /\{([^}]+)\}/g,
@zzuhan
zzuhan / *md-compatible.js
Created June 4, 2014 14:43
how to write amd,cmd,browser environment supported js code
/*
* this series is write like the title
*/
{
"db":{
"host":"127.0.0.1",
"port":3306,
"user":"root",
"password":"",
"database":"crawler"
},
"baseSite":"http://s3131212.com/links/"
}
@zzuhan
zzuhan / overwrite-require1.js
Last active March 15, 2019 06:55
[node-overwrite] nodejs中覆盖 #nodejs
// 方法1
var Module = require('module');
const originalLoad = Module._load;
// 重写require方法,用来覆盖vscode
Module._load = function(request, parent){
if(request == 'vscode') {
return require('./mock/vscode');
@zzuhan
zzuhan / exec.ts
Created March 15, 2019 06:48
[node-childprocess] nodejs子进程 #nodejs
// 摘自vscode-vsce中
function exec(command: string, options: IOptions = {stopOnError: true}, cancellationToken?: CancellationToken): Promise<{ stdout: string; stderr: string; }> {
return new Promise((c, e) => {
let disposeCancellationListener: Function = null;
const child = cp.exec(command, { ...options, encoding: 'utf8' } as any, (err, stdout: string, stderr: string) => {
if (disposeCancellationListener) {
disposeCancellationListener();
disposeCancellationListener = null;
@zzuhan
zzuhan / doc.markdown
Created March 15, 2019 06:53
[vscode document] vscode的文档服务 #vscode
@zzuhan
zzuhan / error-handle.js
Created March 15, 2019 07:12
[error-handle] nodejs的错误处理 #nodejs
//
process.on('uncaughtException', onFatal);
// 未处理的process的reject
process.on('unhandledRejection', onFatal);
return require('co')(function* () {
yield start()
}).catch(onFatal);
@zzuhan
zzuhan / class-check.js
Created March 26, 2019 09:14
[js class] js class中的一些操作 #js
mySprite instanceof Sprite;
@zzuhan
zzuhan / check.js
Created March 26, 2019 09:16
[js check] js的基本检测 #js
Array.isArray()
// 类检测
mySprite instanceof Sprite;
// 基础类型检测?
@zzuhan
zzuhan / getClosestInstanceFromNode
Last active April 3, 2019 02:46
[js react] react中常见的代码 #js #todo
function getClosestInstanceFromNode(node){
}