Skip to content

Instantly share code, notes, and snippets.

@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') {
We couldn’t find that file to show.
@guileen
guileen / xcower
Created April 9, 2011 04:01
xcower -Sy $aur_pkg
#! /bin/sh
TARGET_DIR=/tmp/abs
TARGET=
S_ARG=
sync=
C_ARG=
F_ARG=
PAC_F_ARG=
COWER=`which cower`
@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 / gist:940293
Created April 25, 2011 08:54
Dead code removal of closure compiler and uglifyjs
(function(){
var DEBUG=false,
NEVER_READ='hello';
(function() {
if(DEBUG){
console.log('Hello world');
}
})();
@guileen
guileen / gist:949739
Created April 30, 2011 15:13 — forked from kennethkalmer/gist:278814
node.js SMTP Server
/*
smtpd.js is SMTP server written for node.js
MIT License
*/
var tcp = require('tcp');
var sys = require('sys');
@guileen
guileen / how_equals_works.js
Created May 11, 2011 05:53
How javascript equals works
var console = console || require('console');
function foo(n){
this.name = n;
}
foo.prototype.toString = function(){ return this.name };
console.log(new foo('key') === 'key'); // false
console.log(null === undefined); // false
console.log(new foo('key') == 'key'); // true
console.log(null == undefined); // true
@guileen
guileen / gist:972892
Created May 15, 2011 04:41
stormjs demo
function test_assign(_) {
var x = foo(_);
x.a = foo(x, _);
x.a.b = foo(x.a, _);
x['x']['y'] = foo(x.a, _);
( x || y)['x'] = foo(_);
}
// compile by stormjs ================>
@guileen
guileen / gist:973054
Created May 15, 2011 11:10
nodejs parallel control flow by bitwise operation
var _a=0x01, _b=0x02, _c=0x04, _d=0x08, _e=0x10, _f=0x20, _done=0;
var triggers = [
function(){
// a,b 完成后,执行 d,execute d() when a and b done.
if(_done & (_a | _b)){
triggers.splice(triggers.indexOf(this), 1);
d(function(){
_done |= _d;
@guileen
guileen / Trigger.js
Created September 11, 2011 10:48
A new flow control example, for cross reference
var Trigger = function() {
this.__callbacks = [];
this.__done = [];
};
Trigger.prototype = {
set: function(name) {
var self = this;
return function(err, result) {
if (err)