Skip to content

Instantly share code, notes, and snippets.

@lsm
lsm / Validator.js
Created April 11, 2011 16:57
email,nickname,mobile,password
// RegExp copied from sina weibo;)
function makeReFn(regStr) {
var re = typeof regStr == 'string' ? new RegExp(regStr) : regStr;
return function (beRegStr) {
if (re.test(beRegStr)) {
return true;
} else {
return false;
}
@lsm
lsm / gsfixer.js
Created July 1, 2011 05:24
Exporter/importer to fix crapped gridfs files for node-mongodb-native < 0.9.4.4
var mongodbSrc = require('./mongodb-0.9.4-3');
var mongodbDst = require('./mongodb-0.9.6-1');
/**** Edit start ****/
var SRC_HOST = '10.0.0.31';
var SRC_PORT = 27017;
var SRC_DB_NAME = 'mydb';
var SRC_ROOT_COLLECTION = 'images';
var FILE_QUERY = {}; // default to all
@lsm
lsm / background_demo.js
Created August 5, 2011 11:07 — forked from kosso/background_demo.js
Background Service notification for Titanium
/* Kosso : March 12th 2011
This the only way I managed to do this without the app crashing on resume.
Done slightly differently to the KS example, since they unregister the service and
do not use a setInterval timer.
*/
//############ in app.js :
// test for iOS 4+
@lsm
lsm / gist:1544579
Created December 31, 2011 17:01
Compare Buffer and String
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var dataString = ['xxx', 'ssss', 'yyyyy', '1121212', 'aaaaa'];
var dataBuffer = [new Buffer('xxx'), new Buffer('ssss'), new Buffer('yyyyy'), new Buffer('1121212'), new Buffer('aaaaa')];
suite.add('Buffer#copy', function() {
var offset = 0;
dataBuffer.forEach(function(chunk) {
@lsm
lsm / benchmark_js_oo
Last active October 13, 2015 05:17
Benchmark between different implementation of javascript 'class'
# npm install genji benchmark
var genji = require('genji');
var Benchmark = require('benchmark');
var Base = genji.Base;
var util = require('util'),
times = 500000;
@lsm
lsm / binary_parser.js
Created February 14, 2013 09:03
Javascript binary parser by Jonas Raoni Soares Silva
/**
* Binary Parser.
* Jonas Raoni Soares Silva
* http://jsfromhell.com/classes/binary-parser [v1.0]
*/
var chr = String.fromCharCode;
var maxBits = [];
for (var i = 0; i < 64; i++) {
maxBits[i] = Math.pow(2, i);
@lsm
lsm / base.js
Last active December 15, 2015 12:48
Feature rich Javascript OO implementation
/**
* Javascript OO helpers
*/
/**
* Module exports.
*/
exports.Base = Base;
@lsm
lsm / stdio-2.js
Created January 22, 2016 00:49 — forked from isaacs/stdio-2.js
/*
In a child process, each of the stdio streams may be set to
one of the following:
1. A new file descriptor in the child, dup2'ed to the parent and
exposed to JS as a Stream object.
2. A copy of a file descriptor from the parent, with no other
added magical stuff.
3. A black hole - no pipe created.

Keybase proof

I hereby claim:

  • I am lsm on github.
  • I am lsm (https://keybase.io/lsm) on keybase.
  • I have a public key ASBpGnftcilmP_g7XoeQkY4v2zyOLF9vafd8a8yy_5pTmAo

To claim this, I am signing this object:

@lsm
lsm / app.js
Last active July 14, 2016 18:59
express -> micromono
var app = require('express')()
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')
app.use(express.static(path.join(__dirname, 'public')))
app.get('/', function(req, res){
res.render('index.pug')
})