Skip to content

Instantly share code, notes, and snippets.

@guileen
guileen / packetParser.js
Created January 7, 2014 07:43
node.js packet parser
/**
* @param {Socket} socket auto handle 'data' event, and emit 'packet' event.
* @param {Object} options options params
* options.headSize the size of header
* options.getBodySize function(headBuffer) return bodySize
*/
exports.autoParsePacket = function (socket, options) {
var headSize = options.headSize;
var getBodySize = options.getBodySize;
if(!headSize || headSize <= 0) {
@guileen
guileen / gist:bdb610291025e9f64db3
Created August 22, 2014 08:15
佛祖保佑.txt
_oo0oo_
o8888888o
88" . "88
(| -_- |)
0\ = /0
___/`---'\___
.' \\| |-- '.
/ \\||| : |||-- \
/ _||||| -:- |||||- \
| | \\\ - --/ | |
storage:
dbPath: "/data/db"
journal:
enabled: true
systemLog:
destination: file
path: "/var/log/mongodb.log"
logAppend: true
timeStampFormat: iso8601-utc
processManagement:
@guileen
guileen / p2pclient.go
Last active September 3, 2019 07:31
Go P2P Demo
// golang p2p udp client
package main
import (
"fmt"
"net"
"log"
"encoding/binary"
"encoding/hex"
@guileen
guileen / hash.js
Created December 22, 2010 02:15
nodejs crc32 function
/**
* Calculates the hash/checksum of a string. Default algorithm is MD5.
*
* @param {String} str
* @param {String} algorithm
* @return {String} checksum
* @api public
*/
exports.hash = function (str, algorithm) {
if (algorithm === 'crc32') {
@guileen
guileen / README.md
Created September 21, 2017 13:42
Grab english words to 单词本

Features

抽取所有英文单词的基本形式,小写,计数。

Usage

python to_word_list.py path_to_text.txt min_word_count

e.g.

@guileen
guileen / app.js
Created April 20, 2011 23:55
Express Custom 404
var express = require('express'),
mongoose = require('mongoose'),
app;
app = module.exports = express.createServer();
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
@guileen
guileen / _service.md
Last active September 28, 2016 09:14 — forked from naholyr/_service.md
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@guileen
guileen / async.js
Created March 11, 2012 15:59
parallel javascript
// This is an lite version of `async`, see https://github.com/caolan/async
//
// es5shim.js is required for old version browsers
//
// Author: Gui Lin
// Email: guileen@gmail.com
var async = {};
@guileen
guileen / addkey
Last active July 25, 2016 21:44
git shell commands
#!/bin/sh
# If the user is not root
if [ "$USERNAME" != "root" ]
then
# Dislpay a notice and stop
echo "Sorry, only root can use this command."
exit 1