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 / step.js
Created May 17, 2012 09:12
JavaScript简单异步执行
/**
* 使用方法:
* step(function (data, next) {
* // step 1, do somethings...
* next(null, data);
* }, function (data, next) {
* // step 2, do somethings...
* next(null, data);
* }, function (err, data) {
* // callback
@leizongmin
leizongmin / expand_dir.js
Created May 22, 2012 03:14
Node.js遍历目录(异步)
var fs = require('fs');
var path = require('path');
var THREAD = require('os').cpus().length;
var expand = function (file, callback) {
fs.stat(file, function (err, stats) {
if (err)
return callback(err);
if (!stats.isDirectory()) {
return callback(null, stats.size);
@leizongmin
leizongmin / test.go
Created July 24, 2012 05:54
http性能测试程序
package main
import (
"fmt"
"runtime"
"time"
"os"
"io/ioutil"
"net/http"
"strconv"
@leizongmin
leizongmin / file.js
Created August 1, 2012 05:28
使用指定上下文来加载文件
/**
* 被加载的模块
*/
console.log('require file: random=' + random);
@leizongmin
leizongmin / gist:3311670
Created August 10, 2012 06:13 — forked from fxsjy/gist:3291755
Memcached in JavaScript based on Node.JS
//author: Sun, Junyi (weibo.com/treapdb)
//usage: node --nouse-idle-notification --expose-gc --max-old-space-size=8192 memcached.js
var config ={
port: 11211,
max_memory: 100 // default 100M bytes
}
var net = require('net');
var LRU = function (max) { // this LRU implementaion is based on https://github.com/chriso/lru
@leizongmin
leizongmin / encrypt.js
Created August 14, 2012 04:47
Node.js/PHP 密码验证相关函数
'use strict';
var crypto = require('crypto');
/**
* 32位MD5加密
*
* @param {string} text 文本
* @return {string}
*/
@leizongmin
leizongmin / lxMiniPHP.php
Created August 23, 2012 05:01
PHP基础操作类库
<?php
/*!
* PHP基础操作类库
*
* @author 老雷 <[email protected]>
* @date 2012-08-23 12:43:45
*/
/**
@leizongmin
leizongmin / gist:3432652
Created August 23, 2012 05:02
遍历目录并生成缩略图的PHP程序
<?php
/**
* 生成缩略图
*/
function makethumb ($srcFile, $dstFile, $dstW, $dstH) {
$dstW = intval($dstW);
$dstH = intval($dstH);
if($dstW == 0 && $dstH == 0)
return false;
@leizongmin
leizongmin / gist:3742269
Created September 18, 2012 09:38
根据标题生成URL函数
/**
* 生成用于title的URL
*
* @param {string} title
* @return {string}
*/
function titleUrl (title) {
if (typeof(title) !== 'string') return false;
return title.trim().replace(/[^0-9a-zA-Z \-]/g, '').replace(/[ ]+/g, '-').replace(/[\-]+/g, '-').toLowerCase();
}
@leizongmin
leizongmin / make-pem.cmd
Created September 25, 2012 02:40
创建PEM格式的SSH证书
@echo off
openssl genrsa -out ca-key.pem 2048
openssl req -new -out ca-req.csr -key ca-key.pem
openssl x509 -req -in ca-req.csr -out ca-cert.pem -signkey ca-key.pem -days 7300
openssl pkcs12 -export -in ca-cert.pem -out ca-cert.p12 -inkey ca-key.pem