Skip to content

Instantly share code, notes, and snippets.

View Petelin's full-sized avatar

lin Petelin

View GitHub Profile
@Petelin
Petelin / .fpath\_go
Created April 1, 2017 02:55
zsh补全脚本
### in zsh config
compdef _go go
### 补全脚本
(pycharm_ascle) [~]$ cat .fpath/_go
#compdef go
_1st_arguments=(
"test"
"dev"
@Petelin
Petelin / corotinue_os.py
Created March 1, 2017 09:23
使用yield实现的操作调度, 包括一个非阻塞的 sleep 方法
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : zhangxiaolin
# E-mail : [email protected]
# Date : 16/11/3 16:03
# Desc : ...
from queue import Queue
import socket
import select
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : zhangxiaolin
# E-mail : [email protected]
# Date : 16/11/4 14:49
# Desc : ...
"""
唯一一个限制字典:不能存以 `_` 开头的key
@Petelin
Petelin / gist:dcbb2145d31cc1a0926e4f28a9e3000c
Created October 12, 2016 07:42
django 拆分大 hit 为分批 hit 数据库
from django.core.paginator import Paginator
def chunked_iterator(queryset, chunk_size=10000):
paginator = Paginator(queryset, chunk_size)
for page in range(1, paginator.num_pages + 1):
for obj in paginator.page(page).object_list:
yield obj
for event in chunked_iterator(Event.objects.all()):
print event
@Petelin
Petelin / .gitignore
Created July 29, 2016 08:28
for python project and mac
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# VIM
*.swp
@Petelin
Petelin / limit.py
Created April 28, 2016 02:29 — forked from hartror/limit.py
Finding safe ways to limit a forked proccess's memory in Python.
#!/usr/bin/env python
import os
import psutil
import resource
import subprocess
import sys
import time