Skip to content

Instantly share code, notes, and snippets.

@cgwxyz
cgwxyz / stripslashes.py
Created June 11, 2014 02:43
python删除字符串slash
def stripslashes(s):
import re
r = re.sub(r"\\(n|r)", "\n", s)
r = re.sub(r"\\", "", r)
return r
@cgwxyz
cgwxyz / ip2addr.py
Last active August 29, 2015 14:02
根据IP通过sogou接口获取地理位置相关信息
def ip2addr(ip):
import urllib
import httplib
import chardet #字符集检测Module,返回dict
config = {
'api_host':'www.sogou.com',
'api_script':'/websearch/features/ipsearch.jsp'
}
@cgwxyz
cgwxyz / python-proc-name.py
Last active June 13, 2019 06:59
python设置当前进程名称(linux ps时显示)
try:
import dl
libc = dl.open('/lib/libc.so.6')
libc.call('prctl', 15, 'myproc', 0, 0, 0) #执行后ps -A,显示为myproc的进程
#参数2:15 /linux/prctl.h定义 #define PR_SET_NAME 15
except:
pass
@cgwxyz
cgwxyz / urllib2_post.py
Last active August 29, 2015 14:02
Python urllib2 post sample
config = {
'api_host':'github.com',
'api_script':'test.php'
}
params = {
'code':1,
'file_id':123454,
'file_name':"v/test.mp4",
'file_size':3653.32
}
@cgwxyz
cgwxyz / urldecode_encode.lua
Last active June 23, 2020 14:09
lua urlencode/urldecode
function encodeURI(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end