This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) # 平滑图像处理,高斯滤波 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def check_dict_common_keys(dict_list): | |
| """ | |
| check the dict common keys in the dict list | |
| :param dict_list: [{},{}...] | |
| :return: set() | |
| """ | |
| if len(dict_list) >= 2: | |
| common_keys = set(dict_list[0].keys()) | |
| for dict_item in dict_list[1:]: | |
| common_keys.intersection_update(set(dict_item.keys())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from memory_profiler import profile | |
| from itertools import filterfalse | |
| @profile(precision=1) | |
| def test(): | |
| a = [] | |
| for i in range(100000): | |
| a.append((10.23 + i, {"data": i})) | |
| b = filterfalse(lambda x: float(x[0]) >= 1000.26, a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sort_by_domain(sites): | |
| sitebits = [site.lower().lstrip('http://').split('.') for site in sites] | |
| for site in sitebits: | |
| site.reverse() | |
| print(sitebits) | |
| return [('.'.join(reversed(site))) for site in sorted(sitebits)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import sys | |
| async def execute(command, cwd=None, shell=True): | |
| process = await asyncio.create_subprocess_exec(*command, | |
| stdout=asyncio.subprocess.PIPE, | |
| stderr=asyncio.subprocess.PIPE, | |
| cwd=cwd, | |
| shell=shell) | |
| std_out, std_err = await process.communicate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def dict_common_keys(dict_list): | |
| """ | |
| check python dict list common keys | |
| :param dict_list: [{},{}...] | |
| :return: | |
| """ | |
| if len(dict_list) >= 2: | |
| common_keys = set(dict_list[0].keys()) | |
| for dict_item in dict_list[1:]: |