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 / gist:5261395
Created March 28, 2013 07:38
合并多个对象
function merge () {
var ret = {};
for (var i in arguments) {
var m = arguments[i];
for (var j in m) ret[j] = m[j];
}
return ret;
};
@leizongmin
leizongmin / gist:5270060
Created March 29, 2013 10:18
简单REST客户端
<?php
class REST {
public static $headers = array();
public static function exec ($ch) {
curl_setopt($ch, CURLOPT_HTTPHEADER, self::$headers);
ob_start();
curl_exec($ch);
@leizongmin
leizongmin / gist:5432138
Created April 22, 2013 02:51
1、遍历目录里面的所有文件 2、列出目录下的所有文件
var fs = require('fs');
var path = require('path');
/**
* 遍历目录里面的所有文件
*
* @param {string} dir 目录名
* @param {function} findOne 找到一个文件时的回调
* 格式:function (filename, stats, next)
* @param {function} callback 格式:function (err)
@leizongmin
leizongmin / gist:5524197
Created May 6, 2013 09:28
CentOS 6 防火墙配置
# 添加
/sbin/iptables -I INPUT -p tcp --dport 10000 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
# 直接编辑
vim /etc/sysconfig/iptables
# 内容
-A INPUT -p tcp -m tcp --dport 20 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
@leizongmin
leizongmin / test.js
Last active December 17, 2015 04:39
用来简单测试某段程序的执行效率
Test ...
time passed: 4807ms, interval: 1ms -- spent: 4806ms, rss: 94.1M (+35.41M)
time passed: 8196ms, interval: 1ms -- spent: 3388ms, rss: 104.68M (+10.57M)
time passed: 10667ms, interval: 1ms -- spent: 2470ms, rss: 180.91M (+76.23M)
time passed: 13473ms, interval: 1ms -- spent: 2805ms, rss: 98.75M (-82.15M)
time passed: 17132ms, interval: 2ms -- spent: 3657ms, rss: 99.21M (+0.46M)
time passed: 19619ms, interval: 1ms -- spent: 2486ms, rss: 177.95M (+78.73M)
time passed: 22538ms, interval: 0ms -- spent: 2919ms, rss: 95.06M (-82.89M)
time passed: 25632ms, interval: 1ms -- spent: 3093ms, rss: 97.29M (+2.23M)
time passed: 28832ms, interval: 1ms -- spent: 3199ms, rss: 102.23M (+4.94M)
@leizongmin
leizongmin / gist:5596814
Last active December 17, 2015 10:39
合并目录下的所有文件
/**
* 合并目录下的文件
*/
var fs = require('fs');
var path = require('path');
/**
* 遍历目录里面的所有文件
*
@leizongmin
leizongmin / list_domain.js
Created July 4, 2013 05:03
暴力遍历子域名
/**
* 暴力遍历子域名
*
* @author 老雷<leizongmin@gmail.com>
*
*
* 启动参数: <域名> <子域名最大位数> <并发数> <结果保存到哪个文件>
* 如: safe360.com 10 10 fuck.txt
*/
@leizongmin
leizongmin / http-proxy.clj
Last active December 20, 2015 14:19
简单的HTTP代理服务器
;;;; HTTP代理服务器
;;;; @author 老雷<leizongmin@gmail.com>
(ns http-proxy
(:require [http]))
(defn- ^Object parse-url [^String url]
(def i1 (.index-of url "://"))
(def i2 (+ i1 3))
(def i3 (.index-of url "/" i2))
@leizongmin
leizongmin / simple-mysql-pool.js
Created August 14, 2013 07:13
简单的MySQL连接池
/**
* Simple MySQL Pool
*
* @author 老雷<leizongmin@gmail.com>
*/
var util = require('util');
var events = require('events');
var mysql = require('mysql');
var debug = require('debug')('my:mysql');
@leizongmin
leizongmin / readRemoteFile.js
Created September 5, 2013 02:12
Node.js 读取远程文件
var http = require('http');
/**
* 读取远程文件
*
* @param {String} url
* @param {Function} cb
* - {Error} err
* - {Buffer} buf
*/