Skip to content

Instantly share code, notes, and snippets.

View rogerz's full-sized avatar

Rogerz Zhang rogerz

View GitHub Profile
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
CustomError.prototype = Object.create(Error.prototype);
@rogerz
rogerz / grep.sh
Last active August 29, 2015 14:02
system admin cheatsheet
* filter and count IPs
```shell
grep -F 'SLEEP%285%29' /var/log/nginx/www.letsface.cn/access_www.letsface.cn.log | grep -F '26/May/' | awk '{print $1}' | sort | uniq -c | sort -nr
```
@rogerz
rogerz / docker.md
Created May 25, 2014 08:58
docker cheetsheat

export DOCKER_HOST=tcp://localhost:4243

@rogerz
rogerz / vpn auto connect
Created May 25, 2014 01:54
auto connect to VPN
on idle
tell application "System Events"
tell current location of network preferences
set vpn to the service "VPN name"
if vpn is not null then
if current configuration of vpn is not connected then
connect vpn
end if
end if
end tell
@rogerz
rogerz / nginx.conf
Created May 23, 2014 03:28
nginx config for websocket
# include a variable for the upgrade header
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name example.com;
@rogerz
rogerz / deploy.sh
Created March 16, 2014 03:36
rsync command for deploying
rsync ./ ec2:~/wechat-demo --exclude '.git*' --compress --links --copy-unsafe-links --perms --recursive --times --delete --delete-excluded --progress
@rogerz
rogerz / gist:9577726
Last active August 29, 2015 13:57
run node app under 80 without root
sudo apt-get install libcap2-bin
sudo setcap cap_net_bind_service=+ep /usr/local/bin/node
# https://www.digitalocean.com/community/articles/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps

syntax

command { [-setting]... "image"|-operation }... "output_image"

setting options

+ option is generally used to turn off the setting, or reset it to its normal default state

@rogerz
rogerz / module-wrapper.js
Last active December 30, 2015 07:49
wrap a script for CommonJS and AMD
/* https://github.com/yields/case/blob/master/dist/Case.js */
(function () {
var Case = {};
if (typeof define === 'function' && define.amd) {
define(function(){ return Case; });
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = Case;
} else {
this.Case = Case;
}
C-x h (M-x mark-whole-buffer)
C-M-\ (M-x indent-region)