Skip to content

Instantly share code, notes, and snippets.

View dead-horse's full-sized avatar
🤖
I may be slow to respond.

Yiyu He dead-horse

🤖
I may be slow to respond.
View GitHub Profile
@dead-horse
dead-horse / dump.js
Created November 13, 2012 03:29
mongodb数据库定时备份
/*!
* dump.js, dump mongodb.
* Copyright(c) 2012 Taobao.com
* Author: busi.hyy <busi.hyy@taobao.com>
*
* 每天凌晨3点从mongo dump一份到指定文件夹,前缀为20121113_
* 只保留最近七天的dump文件
* Example: `node dump 127.0.0.1:27071 back database collection1 collection2 ...`
*/
@dead-horse
dead-horse / benchmark.js
Created April 29, 2016 03:11
assgin_for_in_of
'use strict';
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const suite = new Benchmark.Suite();
suite
.add('Object.assign', function() {
@dead-horse
dead-horse / bufTest.cc
Created August 20, 2012 09:33
两种传递buffer的方法
#include <node.h>
#include <v8.h>
#include <node_buffer.h>
#include <iostream>
using namespace std;
using namespace v8;
using namespace node;
Handle<Value> slowBuffer(const Arguments& args) {
HandleScope scope;
@dead-horse
dead-horse / gist:3402650
Created August 20, 2012 09:31
解析非utf8和ascii编码的buffer
#include <node.h>
#include <v8.h>
#include <node_buffer.h>
#include <iostream>
using namespace std;
using namespace v8;
using namespace node;
Handle<Value> test(const Arguments& args) {
HandleScope scope;
@dead-horse
dead-horse / front_end_utils.js
Created June 21, 2012 08:22
front end utils
/**
* 复制对象、数组
* @param {Object} obj [原始对象]
* @return {Object} [复制的对象]
*/
function clone(obj){
var objClone;
if (obj.constructor == Object){
objClone = new obj.constructor();
}else{
/***
* 这是一个测试与向导程序。
* 如果未开启mongoDB,则无需任何改变,可以运行一个nodejs的“hello world”小程序。
* 如果开启了mongoDB,则去config.js文件按指引操作,可以运行获得一个通过mongoskin模块连接的nodejs+mongodb测试小程序。
***/
var http = require('http'),
db = require('./config').db;
http.createServer(function(req, res){
res.writeHead(200, {"content-type":"text/html;charset=utf8"});
if(db){
var createGame = require('voxel-engine');
var game = module.exports = createGame({
generateChunks: false,
texturePath: 'textures/',
materials: [
['grass', 'dirt', 'grass_dirt'], 'brick', 'cobblestone', 'bluewool', 'glowstone', 'diamond', 'grass_dirt', 'grass'
// ,'meow'
],
//materialFlatColor: true,
var check = require('./');
var rule = {
name: 'string',
age: {type: 'int', max: 200},
gender: ['male', 'female'],
working: 'boolean',
salary: {type: 'number', min: 0},
birthday: 'date',
now: 'dateTime',
var Cutter = require('cutter');
var net = require('net');
/**
* must return length of head + body
*/
function packetLength(data) {
return 4 + data.readInt32BE(0);
}
var cutter = new Cutter(4, packetLength);
// error in next tick
try {
setImmediate(function () {
throw new Error('error happened');
});
} catch (err) {
// 捕获不到异常
}
// get json by callback