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
# post_loc.txt contains the json you want to post | |
# -p means to POST it | |
# -H adds an Auth header (could be Basic or Token) | |
# -T sets the Content-Type | |
# -c is concurrent clients | |
# -n is the number of requests to run in the test | |
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/ |
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
// id card (china) | |
var idCardPatt = /^(\d{14}|\d{17})(\d|[xX])$/i; | |
// ObjectId (MongoDB) | |
var mongoDbObjectIdPatt = /^((\d|([a-f]|[A-F])){24})$/i; | |
// tel | |
var telPatt = /\d{3}-\d{8}|\d{4}-\d{7}/; | |
// mobile (china) |
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 winston = require('winston'); | |
var express = require('express'); | |
var app = express.createServer(); | |
// enable web server logging; pipe those log messages through winston | |
var winstonStream = { | |
write: function(message, encoding){ | |
winston.info(message); | |
} |
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 crc32 = (function() { | |
function utf8encode(str) { | |
var utf8CharCodes = []; | |
for (var i = 0, len = str.length, c; i < len; ++i) { | |
c = str.charCodeAt(i); | |
if (c < 128) { | |
utf8CharCodes.push(c); | |
} else if (c < 2048) { | |
utf8CharCodes.push((c >> 6) | 192, (c & 63) | 128); |
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
Date.prototype.format = function(format) | |
{ | |
var o = { | |
"M+" : this.getMonth()+1, //month | |
"d+" : this.getDate(), //day | |
"h+" : this.getHours(), //hour | |
"m+" : this.getMinutes(), //minute | |
"s+" : this.getSeconds(), //second | |
"q+" : Math.floor((this.getMonth()+3)/3), //quarter | |
"S" : this.getMilliseconds() //millisecond |