Skip to content

Instantly share code, notes, and snippets.

@huangts
huangts / cmd.sh
Last active April 9, 2021 03:29 — forked from kelvinn/cmd.sh
[Example of using Apache Bench (ab) to POST JSON to an API] #http #压力测试
# 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/
@huangts
huangts / regex-note.js
Last active April 9, 2021 03:31
[常用正则表达式] #regex
// 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)
@huangts
huangts / connect-winston.js
Last active April 9, 2021 04:26
express and connect #nodejs
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);
}
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);
@huangts
huangts / date_format.js
Created January 5, 2013 04:30
javascript date format function
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