This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* 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 ...` | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Benchmark = require('benchmark'); | |
const benchmarks = require('beautify-benchmark'); | |
const suite = new Benchmark.Suite(); | |
suite | |
.add('Object.assign', function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 复制对象、数组 | |
* @param {Object} obj [原始对象] | |
* @return {Object} [复制的对象] | |
*/ | |
function clone(obj){ | |
var objClone; | |
if (obj.constructor == Object){ | |
objClone = new obj.constructor(); | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* 这是一个测试与向导程序。 | |
* 如果未开启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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// error in next tick | |
try { | |
setImmediate(function () { | |
throw new Error('error happened'); | |
}); | |
} catch (err) { | |
// 捕获不到异常 | |
} | |
// get json by callback |
NewerOlder