Skip to content

Instantly share code, notes, and snippets.

View leizongmin's full-sized avatar
😴
I may be slow to respond

LEI Zongmin leizongmin

😴
I may be slow to respond
View GitHub Profile
@leizongmin
leizongmin / test-promise-2-result.txt
Last active March 23, 2017 05:29
Test Node.js Promise
$ time node test-promise-2
exec Promise.resolve() 100000 times
Node.js v4.8.1, native Promise
test: 496ms
0.58 real 0.50 user 0.08 sys
$ time node test-promise-2 bluebird
exec Promise.resolve() 100000 times
Node.js v4.8.1, bluebird Promise
test: 61ms
@leizongmin
leizongmin / package.json
Last active March 29, 2017 11:51
Node.js实现的端口扫描器 scan-port
{
"name": "scan-port",
"version": "1.0.0",
"description": "端口扫描器",
"main": "scan.js",
"dependencies": {
"cli-color": "^1.2.0",
"progress": "^1.1.8",
"yargs": "^7.0.2"
},
@leizongmin
leizongmin / INSTALL.rst
Created February 14, 2017 07:45 — forked from jensens/INSTALL.rst
sentry setup with docker-compose

In order to run this image do: docker-compose up -d to get all up. On first run DB initialization and initial user setup is done like so:

First start a bash in the container: docker-compose exec sentry /bin/bash. Then, inside bash, do sentry upgrade wait until it asks you for an inital user. When finished exit the bash.

When in doubt check with docker-compose ps if all went fine.

@leizongmin
leizongmin / jsonp.js
Created December 20, 2016 02:56
简单JSONP请求器
function jsonp(url, f) {
return new Promise((resolve, reject) => {
f = f || 'callback';
const n = `_jsonpCb` + Date.now() + parseInt(Math.random() * 100000, 10);
window[n] = (data) => {
resolve(data);
document.body.removeChild(s);
};
const s = document.createElement('script');
s.onerror = (e) => reject(e);
@leizongmin
leizongmin / mininal-maven-pom.xml
Last active December 3, 2016 02:21 — forked from torgeir/minimal-maven-pom.xml
A minimal maven pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gd.wa</groupId>
<artifactId>minimal-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
@leizongmin
leizongmin / createPromiseCallback.js
Last active December 20, 2017 03:40
兼容Promise的callback函数
function createPromiseCallback() {
const callback = (err, ret) => {
if (err) {
callback.reject(err);
} else {
callback.resolve(ret);
}
};
callback.promise = new Promise((resolve, reject) => {
callback.resolve = resolve;
@leizongmin
leizongmin / coroutine.js
Last active October 17, 2016 07:27
利用generator与promise实现coroutine
'use strict';
// 检查是否为Promise对象
function isPromise(p) {
return typeof p.then === 'function' && typeof p.catch === 'function';
}
// coroutine包装函数
function cotoutineWrap(genFn) {
const fn = function () {
@leizongmin
leizongmin / fuck-webpack.js
Created September 23, 2016 08:00
使用browserify自动打包
'use strict';
const fs = require('fs');
const path = require('path');
const browserify = require('browserify');
const express = require('express');
const open = require('open');
const app = express();
app.get('/entry/:name.js', function (req, res, next) {
@leizongmin
leizongmin / cipher.js
Last active September 23, 2016 03:25
Node.js 加密解密
'use strict';
/**
* 数据加解密模块
*
* @author Zongmin Lei <leizongmin@gmail.com>
*/
const assert = require('assert');
const crypto = require('crypto');
@leizongmin
leizongmin / tcp-proxy.js
Created September 19, 2016 09:01
tcp proxy
'use strict';
const net = require('net');
function printUsage() {
console.log('Usage:');
console.log(' $ node tcp-proxy 3306 remote.ucdok.com 3306');
process.exit();
}