Skip to content

Instantly share code, notes, and snippets.

View nooperpudd's full-sized avatar

Winton nooperpudd

  • China
View GitHub Profile
def single_task(lock_arg, lock_prefix="lock-", timeout=CeleryConfig.LOCK_DEFAULT_TIMEOUT):
"""
:param lock_arg: set the lock key of the task parameter
:param lock_prefix:
:param timeout: set the lock key timeout
Enforce only one celery task at a time.
"""
def task_exec(func):
@functools.wraps(func)
@nooperpudd
nooperpudd / group_by.py
Created August 23, 2017 14:36
group list
@register.filter
def group_by(l, arg):
"""
group the list l as the number of arg
l:list
arg: an integer number
return: an iter data
"""
for i in range(0, len(l), arg):
yield l[i:i + arg]
@nooperpudd
nooperpudd / opencv.py
Created November 3, 2017 08:22
opencv mask
import cv2
import numpy
image = cv2.imread("test.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # convert image to gray
# cv2.imshow("image",gray)
blur_image = cv2.GaussianBlur(gray, (5, 5), 0) # 平滑图像处理,高斯滤波
@nooperpudd
nooperpudd / loads_func.py
Last active January 7, 2018 09:34
load function
import importlib
import inspect
from functools import lru_cache
@lru_cache(maxsize=10240)
def loads_requests():
commands = {}
modules_data = inspect.getmembers(importlib.import_module(__name__))
for func_name, func in modules_data:
if inspect.isfunction(func) and func_name.startswith("On"):
@nooperpudd
nooperpudd / address.py
Created March 30, 2018 11:17
check address port is down or not
import socket
import sys
import urllib.parse
from contextlib import closing
def check_address_port(tcp):
"""
:param tcp:
:return:
"""
$ gem update --system # 这里请翻墙一下
$ gem -v
2.6.3
$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
$ gem sources -l
https://gems.ruby-china.org
# 确保只有 gems.ruby-china.org
#https://coderwall.com/p/jo39na/python-decorators-using-self
# todo it inlater
states = {"a":"b", "b":"c", "c":"d", "d","end"}
class Foo:
#skip some staff
def will_change_state(f):
def wrapper(*args):
ret = f(*args)
import pkgutil
def import_submodules(context, root_module, path):
"""
Import all submodules and register them in the ``context`` namespace.
for examples:
>>> import_submodules(locals(), __name__, __path__)
def _transaction(watch_arg=None, use_pipe=True, ):
# """
# wrapper class
# :return:
# """
#
# def wrapper(func):
# """
# :return:
# """
.. with r.pipeline() as pipe:
... while 1:
... try:
... # 关注一个key
... pipe.watch('xiaorui.cc')
... current_value = pipe.get('xiaorui.cc')
... next_value = int(current_value) + 1
... #事物开始
... pipe.multi()
... pipe.set('xiaorui.cc', next_value)