Skip to content

Instantly share code, notes, and snippets.

View hanksudo's full-sized avatar
:octocat:
Follow your passion.

Hank Wang hanksudo

:octocat:
Follow your passion.
View GitHub Profile
@hanksudo
hanksudo / lambda_way_1.py
Last active August 29, 2015 14:13
Python lambda practice 1
# method 1
x = [2, 3, 4, 5, 6]
y = []
for v in x:
y += [v*5]
assert x == [2, 3, 4, 5, 6]
assert y == [10, 15, 20, 25, 30]
@hanksudo
hanksudo / lambda_way_2.py
Last active August 29, 2015 14:13
Python lambda practice 2
# method 1
x = [2, 3, 4, 5, 6]
y = []
for v in x:
if v % 2:
y += [v * 5]
assert x == [2, 3, 4, 5, 6]
assert y == [15, 25]
@hanksudo
hanksudo / lambda_way_3.py
Last active August 29, 2015 14:13
Python lambda practice 3
# method 1
x = [2, 3, 4]
y = [4, 5]
z = []
for i in x:
for j in y:
z += [i + j]
assert x == [2, 3, 4]
#!/bin/sh
YOUR_DB='mydb'
NEW_OWNER='new_owner'
for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $YOUR_DB`;
do
psql -c "alter table $tbl owner to $NEW_OWNER" $YOUR_DB;
done
for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" $YOUR_DB`;
@hanksudo
hanksudo / chinese_word_on_image.py
Created April 15, 2015 11:54
Chinese Word on image (font path is Mac OSX)
# -*- coding: utf-8 -*-
import os
from PIL import Image, ImageDraw, ImageFont
def name_printer(type, attending=None, surgery=None, date=None):
if type == 'adm_plan':
adm = Image.open('con_1.jpg')
font_file = os.path.join("/System/Library/Fonts/", '儷黑 Pro.ttf')
wfont = ImageFont.truetype(font_file, size=24)
@hanksudo
hanksudo / hash_to_json.rb
Last active August 29, 2015 14:19
(Ruby) hash to json
require 'json'
a = {
:category => {
:mongo => "mango",
:python => "python snake",
:fruit => {
:password => "apple"
},
:animals => ["dog", "cat", "fish"]
@hanksudo
hanksudo / auto_correct_pep8.md
Created April 18, 2015 10:55
(Python) pep8 auto correct in post-commit

prerequisites

pip install autopep8 chmod a+x
vim .git/hooks/post-commit
chmod a+x .git/hooks/post-commit

post-commit

@hanksudo
hanksudo / auto_commit_in_every_directories.sh
Last active August 29, 2015 14:20
(shell) Run command in every directories
#!/bin/sh
# check git unstaged and auto commit
DIR=$( cd "$( dirname $(readlink $BASH_SOURCE))" && pwd )
for d in $DIR/*/
do
(cd "$d" &&
! `git diff --quiet --ignore-submodules HEAD &>/dev/null` &&
pwd &&
git ci -am 'update' &&
git push
@hanksudo
hanksudo / geoip_test.py
Created May 4, 2015 16:27
(Python ) geoip2 test script
# -*- coding: utf-8 -*-
from os import path
import geoip2.database
ips = """
223.143.56.227
101.8.221.38
1.34.73.244
42.70.123.135
14.0.209.138
@hanksudo
hanksudo / fabfile.py
Created June 13, 2015 14:29
Use Fabric with Vagrant
from fabric.api import env, local, run
def vagrant():
env.user = 'vagrant'
env.hosts = ['127.0.0.1:2222']
result = local('vagrant ssh-config | grep IdentityFile', capture=True)
env.key_filename = result.split()[1]