Skip to content

Instantly share code, notes, and snippets.

View Petelin's full-sized avatar

lin Petelin

View GitHub Profile
@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
@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 / 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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : zhangxiaolin
# E-mail : petelin1120@gmail.com
# Date : 16/11/4 14:49
# Desc : ...
"""
唯一一个限制字典:不能存以 `_` 开头的key
@Petelin
Petelin / corotinue_os.py
Created March 1, 2017 09:23
使用yield实现的操作调度, 包括一个非阻塞的 sleep 方法
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : zhangxiaolin
# E-mail : petelin1120@gmail.com
# Date : 16/11/3 16:03
# Desc : ...
from queue import Queue
import socket
import select
@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 / pre-commit
Created April 1, 2017 02:56
git 提交前pep8检查
(pycharm_ascle) [~]$ cat .git-templates/hooks/pre-commit
#!/usr/bin/env bash
git diff --cached -- '*.py' | `which pep8` --max-line-length=119 --show-source --diff
if [ $? -gt 0 ]; then
echo
echo '--------'
echo 'Lint check failed.'
exit 1
@Petelin
Petelin / gist:1835fe063c38c01cf10a141736d14a9b
Created October 28, 2017 14:33
只用yield关键字, 纯python实现协程
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : zhangxiaolin
# E-mail : petelin1120@gmail.com
# Date : 16/11/3 16:03
# Desc : ...
import queue
from queue import Queue
import socket
@Petelin
Petelin / selfloop
Last active November 2, 2017 05:29
基于select+asynico的基础实现
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : zhangxiaolin
# E-mail : petelin1120@gmail.com
# Date : 17/11/1 20:00
# Desc : ...
import types
from selectors import DefaultSelector, EVENT_WRITE, EVENT_READ
from collections import deque
dash_id=xxxx
api_key=xxx
app_key=xxx
# 1. export
curl -X GET "https://app.datadoghq.com/api/v1/dash/${dash_id}?api_key=${api_key}&application_key=${app_key}" > dash.json
# 2. edit dash.json
move "graphs", "title", "description" up one level in the json hierarchy, from being beneath "dash" to being at the same level