Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
xiazhibin / shell.md
Last active October 29, 2018 02:49
Shell

一些常用表达式

  • OS=$(uname -s) # Darwin
  • ARCH=$(uname -m) # x86_64
  • if是检测commad执行的返回情况,正常(exit code为0)则True
if command; #等价于 command;if [$? -eq 0]
then 
  .... 
else 
@xiazhibin
xiazhibin / elasticsearch.md
Last active November 8, 2017 07:27
elasticsearch.md

文档元数据

索引(_index/index)

  • 文档存在哪里

类型(_type/type)

  • 文档表示的对象类别

id(_id)

  • 文档唯一标识
@xiazhibin
xiazhibin / 数据库小笔记.md
Last active January 18, 2018 08:19
数据库小笔记

select with update 问题

  • 同一个进程对表的同一行select with update是没有问题的
  • 不同进程对表的同一行select with update是会造成lock transaction。要等其中一方commit
  • idle in transaction,如果开启了一个空闲的事务,会有一个超时时间,postgres会断开这个transaction。解决方法是try catch掉,重新commit

数人数,里面可能有重复的

z_uid     c_uid
1 a
1 b
@xiazhibin
xiazhibin / wather.py
Last active March 22, 2018 12:35
wather for forked thread
class Watcher:
def __init__(self):
self.child = os.fork()
print 'child', self.child
if self.child == 0:
return
self.watch()
def watch(self):
@xiazhibin
xiazhibin / print_signal.py
Created January 19, 2018 03:44
list all signal
import signal
def handle_hup(sig, frame):
print "get signal: %s"%sig
signal.signal(signal.SIGHUP, handle_hup)
if __name__ == '__main__':
ign = signal.SIG_IGN
@xiazhibin
xiazhibin / pre_fork.py
Last active January 19, 2018 08:17
pre-fork model
# coding=utf-8
import os, logging
import random
import signal
import time
import sys
@xiazhibin
xiazhibin / secure_filename.py
Last active February 8, 2018 09:57
secure_filename with chinese
_filename_gbk_strip_re = re.compile(u"^[\u4e00-\u9fa5A-Za-z0-9_.-]+$")
def secure_filename(filename):
if isinstance(filename, text_type):
from unicodedata import normalize
filename = normalize('NFKD', filename).encode('utf-8', 'ignore')
if not PY2:
filename = filename.decode('utf-8')
for sep in os.path.sep, os.path.altsep:
@xiazhibin
xiazhibin / demo.py
Created February 23, 2018 12:34
解构URL
from urllib import urlencode
from urlparse import urlparse, urlunparse, parse_qsl
url = 'https://www.baidu.com?fuxk=true&m=1'
url_parts = list(urlparse(url))
query = dict(parse_qsl(url_parts[4]))
query.update({'nimabi': 1111})
url_parts[4] = urlencode(query)
print urlunparse(url_parts)
@xiazhibin
xiazhibin / full_permutation.py
Created March 4, 2018 11:12
full_permutation
def full_permutation(arr, cursor):
if cursor == len(arr) - 1:
print arr
return
for i in range(cursor, len(arr)):
arr[cursor], arr[i] = arr[i], arr[cursor]
full_permutation(arr, cursor + 1)
arr[cursor], arr[i] = arr[i], arr[cursor]
def ngetmprint(list, ans, m):
if m == len(list):
ans = ans + list
print ans
elif m == 0:
print ans
else:
ngetmprint(list[1:], ans + list[0:1], m - 1)
ngetmprint(list[1:], ans, m)