Skip to content

Instantly share code, notes, and snippets.

curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
@wangtai
wangtai / install_pyenv.sh
Last active October 21, 2018 09:54 — forked from ysaotome/install_pyenv.sh
pyenv install for CentOS 6.5 x86_64
#!/bin/zsh
# pyenv install for CentOS 6.5 x86_64
yum install -y gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite-devel bzip2-devel zlib libffi-devel
git clone git://github.com/yyuu/pyenv.git ~/.pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@wangtai
wangtai / bobp-python.md
Created March 10, 2016 03:29 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
def resize(file_path):
# import pdb; pdb.set_trace()
save_path = os.getcwd() + "/tmp/xxx.gif"
im = Image.open(file_path)
if im.format == 'GIF':
# rename file
new_file_path = file_path.split('.')[0] + '.gif'
@wangtai
wangtai / nginx.conf
Last active August 29, 2015 14:12
nginx reverse proxy example
upstream main {
server web1.local:80;
server web2.local:80;
server web3.local:80;
}
location /some/path/ {
if ($host ~* "(.+)\.test\.bugua\.com$") {
set $new_host $1.bugua.com;
}
proxy_set_header Host $new_host;
(function() {
if ( typeof Object.prototype.uniqueId == "undefined" ) {
var id = 0;
Object.prototype.uniqueId = function() {
if ( typeof this.__uniqueid == "undefined" ) {
this.__uniqueid = ++id;
}
return this.__uniqueid;
};
}
def datetime_to_seconds(time_in):
epoch = datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)
delta = time_in - epoch
return delta.total_seconds()
def get_ip(request):
try:
real_ip = request.META['HTTP_X_FORWARDED_FOR']
reg_ip = real_ip.split(",")[0]
except KeyError:
try:
reg_ip = request.META['REMOTE_ADDR']
except KeyError:
return 0
@wangtai
wangtai / private.xml
Last active May 26, 2016 06:25
Karabiner Mapping Control + HJKL on Arrow keys. Mapping Control + D/U on Page Down/Up. Control + Delete_Left on Delete_Right
<?xml version="1.0"?>
<!--
List of KeyCode
https://github.com/tekezo/Karabiner/blob/version_10.4.0/src/bridge/generator/keycode/data/KeyCode.data
List of ModifierCode
https://github.com/tekezo/Karabiner/blob/version_10.4.0/src/bridge/generator/keycode/data/ModifierFlag.data
List of ConsumerKeyCode
https://github.com/tekezo/Karabiner/blob/version_10.4.0/src/bridge/generator/keycode/data/ConsumerKeyCode.data
List of PointingButton
https://github.com/tekezo/Karabiner/blob/version_10.4.0/src/bridge/generator/keycode/data/PointingButton.data