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
/***
* 这是一个测试与向导程序。
* 如果未开启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){
@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{
@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 / 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 / dump.js
Created November 13, 2012 03:29
mongodb数据库定时备份
/*!
* dump.js, dump mongodb.
* Copyright(c) 2012 Taobao.com
* Author: busi.hyy <[email protected]>
*
* 每天凌晨3点从mongo dump一份到指定文件夹,前缀为20121113_
* 只保留最近七天的dump文件
* Example: `node dump 127.0.0.1:27071 back database collection1 collection2 ...`
*/
Command.prototype.executeSubCommand = function(argv, args, unknown) {
args = args.concat(unknown);
if (!args.length) this.help();
if ('help' == args[0] && 1 == args.length) this.help();
// <cmd> --help
if ('help' == args[0]) {
args[0] = args[1];
args[1] = '--help';

Data Mining

records -> knowledge

hard by human

autonomous driving

local file = io.open("urls.txt", "r");
local arr = {}
local lines = file:lines()
for line in file:lines() do
table.insert (arr, line);
end
local i = 0
request = function()
i = (i % #arr) + 1
return wrk.format(nil, arr[i])
#! /bin/sh
while [ 1 ]
do
START=$(($(date +%s%N)/1000000))
curl -s -i http://localhost:3000 | grep X-Response-Time
END=$(($(date +%s%N)/1000000))
var mkdirp = require('mkdirp');
var http = require('http');
var fs = require('fs');
var path = require('path');
var tmp = path.join(__dirname, 't.tgz');
var opts = {
hostname: 'cnpm.oss.aliyuncs.com',
method: 'GET',
port: 80,