Skip to content

Instantly share code, notes, and snippets.

@shau-lok
shau-lok / pyenv_using.md
Created May 2, 2017 04:05
pyenv 使用方法

pyenv的一些使用方法

  1. 系统装了什么版本
pyenv versions
  1. 安装 2.7.8版本
@shau-lok
shau-lok / str_unqote.py
Created June 9, 2017 05:18
python string unqote like ( '%3D' convert to '=' )
from urllib.parse import unquote
source = """ uniqueStateKey%3DAGyeMYtcAQAAYH8YnvGA-6CWZgEfgwez_yYOviyzfmpwyMP17WgWfYYEFEuW%26o%3D_jXHRQnHQudOQi0KRQkI-eYbvhjGd5Qvvvv%26h%3De317ru"""
result = unqote(soure)
# result: uniqueStateKey=AGyeMYtcAQAAYH8YnvGA-6CWZgEfgwez_yYOviyzfmpwyMP17WgWfYYEFEuW&o=_jXHRQnHQudOQi0KRQkI-eYbvhjGd5Qvvvv&h=e317ru
@shau-lok
shau-lok / file_name_replace.md
Created June 16, 2017 08:38
目录全局替换文件名

全局更换文件名

situation

➜ ls -al

total 12
drwxr-xr-x 3 root root 4096 Jun 16 04:27 .
@shau-lok
shau-lok / Command Line.md
Created June 22, 2017 03:23
Parsing JSON from command line using Python or jq

using python

curl -s http://www.telize.com/geoip/46.19.37.108 | python -mjson.tool
{
    "area_code": "0",
    "asn": "AS196752",
    "continent_code": "EU",
 "country": "Netherlands",
@shau-lok
shau-lok / decorator.py
Created August 3, 2017 03:53
decorator
def log(text):
def decorator(func):
def wrapper(*args, **kwargs):
print('%s %s():' % (text, func.__name__))
return func(*args, **kwargs)
return wrapper
return decorator
@shau-lok
shau-lok / zip-uzip-file.md
Created August 8, 2017 03:22
linux zip / unzip file

压缩文件

# 压缩一个文件
$ tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

c: 创建一个压缩包
z: 压缩成gzip
v: 可视化,可以查看进度条
f: 可以设定文件名
@shau-lok
shau-lok / grep.md
Last active August 8, 2017 08:40
linux grep

grep

# 在某个文件进行查找
$ grep login /usr/bin/log.txt

# 多个文件中查找
$ grep login /etc/passwd /etc/shadow 

# 获取有关键字的文件名字 (-l)
@shau-lok
shau-lok / python_file.py
Created September 8, 2017 06:57
python read file
# read line by line
with open('a.txt', 'r') as f:
for line in f:
print(line)
# read full content
with open('a.txt', 'r') as f:
print(f.read())
# write content
@shau-lok
shau-lok / urlencode.py
Created September 14, 2017 07:50
url + params
from urllib.parse import urlencode
url = 'https://www.example.com'
params = {
'param1': 'p1',
'param2': 'p2'
}
url = f'{url}?{urlencode(params)}'
@shau-lok
shau-lok / socks_proxy.py
Last active September 19, 2017 12:33
python socks proxy
# pip install pysock
import socket
import socks
import requests
proxy_host = '127.0.0.1'
proxy_port = 1080
auth_user = 'imUser'
auth_password = 'imPassword'