Skip to content

Instantly share code, notes, and snippets.

View coldfire-x's full-sized avatar

coldfire.x coldfire-x

  • Beijing
View GitHub Profile
@coldfire-x
coldfire-x / redis_migrate.py
Last active November 3, 2017 17:36 — forked from iserko/redis_migrate.py
A simple script to migrate all keys from one Redis to another
#!/usr/bin/env python
import argparse
import redis
def connect_redis(conn_dict):
conn = redis.StrictRedis(host=conn_dict['host'],
port=conn_dict['port'],
db=conn_dict['db'])
return conn
@coldfire-x
coldfire-x / applescript_notes_to_evernote.scpt
Created December 18, 2016 15:59
apple script to migrate from notes to evernote
tell application "Notes"
set theMessages to every note
repeat with thisMessage in theMessages
set myTitle to the name of thisMessage
set myText to the body of thisMessage
#!/bin/bash
for i in `git branch --merged master -r | while read; do br=${REPLY#*origin/}; if [[ $br == *"/"* ]]; then echo $br; fi; done;`;do
if [ $i == "origin/master" -o $i == "->" -o $i == "HEAD" ];then
echo "ignore $i"
continue
fi
printf "Delete branch * \e[0;32m $i \e[0m * ? [Y|n]: "
read answer
@coldfire-x
coldfire-x / aes_encryption.py
Created June 10, 2015 06:34
aes encryption
import base64
import hashlib
from Crypto import Random
from Crypto.Cipher import AES
class AESCipher(object):
def __init__(self, key):
self.bs = 32
self.key = hashlib.sha256(key.encode()).digest()
@coldfire-x
coldfire-x / ubuntu-support-chinese
Created May 7, 2015 14:54
ubuntu Chinese character garbled
vim /var/lib/locales/supported.d/local
zh_CN.UTF-8 UTF-8
en_US.UTF-8 UTF-8
zh_CN GB2312
sudo dpkg-reconfigure locales
@coldfire-x
coldfire-x / pre-commit
Created February 4, 2015 14:01
pre-commit hook run pep8 against py files
#!/usr/bin/env bash
git diff --cached -- '*.py' | `which pep8` --max-line-length=119 --show-source --diff
if [ $? -gt 0 ]; then
echo
echo '--------'
echo 'Lint check failed.'
exit 1
fi
@coldfire-x
coldfire-x / autocomplate_fabric.sh
Created January 24, 2015 10:40
fabric auto complete script
# auto complete for fab
function _fab_complete() {
local cur
if [[ -f "fabfile.py" || -d "fabfile" ]]; then
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=($(compgen -W "$(fab -F short -l)" -- ${cur}))
return 0
else
        # no fabfile.py found. Don't do anything.
return 1

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@coldfire-x
coldfire-x / install_tfs.sh
Last active December 28, 2015 07:19
install taobao file system in centos5 box
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
yum install mysql.`uname -i` yum-plugin-replace
yum replace mysql --replace-with mysql55
yum remove mysql mysql-devel
yum install mysql55 mysql55-server mysql55-devel
yum install svn -y
yum install -y libtool.x86_64 libtool-ltdl-devel.x86_64 libtool-ltdl.x86_64
yum install -y zlib-devel mysql-devel
yum install -y readline.x86_64 readline-devel.x86_64
@coldfire-x
coldfire-x / get_ip_percentage.pl
Created June 6, 2013 10:20
get ip percentage from nginx log
#!/usr/bin/perl
use NetAddr::IP;
unless (@ARGV) {
print "usage: $0 file1 file2 file3\n";
exit;
}