Skip to content

Instantly share code, notes, and snippets.

Pengfei Xue pengfei-xue

View GitHub Profile
@pengfei-xue
pengfei-xue / redis_migrate.py
Last active Nov 3, 2017 — forked from iserko/redis_migrate.py
A simple script to migrate all keys from one Redis to another
View redis_migrate.py
#!/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
@pengfei-xue
pengfei-xue / applescript_notes_to_evernote.scpt
Created Dec 18, 2016
apple script to migrate from notes to evernote
View applescript_notes_to_evernote.scpt
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
View clean_merged_branches
#!/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
View aes_encryption.py
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()
@pengfei-xue
pengfei-xue / ubuntu-support-chinese
Created May 7, 2015
ubuntu Chinese character garbled
View ubuntu-support-chinese
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
@pengfei-xue
pengfei-xue / pre-commit
Created Feb 4, 2015
pre-commit hook run pep8 against py files
View pre-commit
#!/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
@pengfei-xue
pengfei-xue / autocomplate_fabric.sh
Created Jan 24, 2015
fabric auto complete script
View autocomplate_fabric.sh
# 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
View benchmark+go+nginx.md

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
@pengfei-xue
pengfei-xue / install_tfs.sh
Last active Dec 28, 2015
install taobao file system in centos5 box
View install_tfs.sh
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
@pengfei-xue
pengfei-xue / get_ip_percentage.pl
Created Jun 6, 2013
get ip percentage from nginx log
View get_ip_percentage.pl
#!/usr/bin/perl
use NetAddr::IP;
unless (@ARGV) {
print "usage: $0 file1 file2 file3\n";
exit;
}
You can’t perform that action at this time.