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 Queue import PriorityQueue | |
| from datetime import datetime | |
| import threading | |
| class Delayed(object): | |
| # 返回:计划执行时间 | |
| # 单位: datetime | |
| def plan_time(self): | |
| pass |
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 datetime import datetime | |
| from multiprocessing import Lock | |
| def utc_now_timestamp_ms(): | |
| return int(datetime.utcnow().timestamp() * 1000) | |
| class Timer: | |
| """ | |
| 定时器 |
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 bisect | |
| import md5 | |
| class ConsistentHashRing(object): | |
| """Implement a consistent hashing ring.""" | |
| def __init__(self, replicas=100): | |
| """Create a new ConsistentHashRing. | |
| :param replicas: number of replicas. |
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
| #轮询 | |
| SERVER_LIST = [ | |
| '10.246.10.1', | |
| '10.246.10.2', | |
| '10.246.10.3', | |
| ] | |
| def round_robin(server_lst, cur = [0]): | |
| length = len(server_lst) | |
| ret = server_lst[cur[0] % length] | |
| cur[0] = (cur[0] + 1) % length |
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 longestsubstr(strs): | |
| left, res= 0, 0 | |
| chars = {} | |
| for right in range(len(strs)): | |
| cur= strs[right] | |
| if cur in chars: | |
| left = max(left, chars[cur] + 1) |
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
| # -*- encoding=utf-8 -*- | |
| # 导入包 | |
| import cv2 | |
| from functools import reduce | |
| from PIL import Image | |
| # 计算两个图片相似度函数ORB算法 | |
| def ORB_img_similarity(img1_path,img2_path): |
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
| class _1bit(object): | |
| def hammingWeight(self, num): | |
| count = 0 | |
| while num: | |
| num = num & num-1 | |
| count += 1 | |
| return count |
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
| #like nametuplen:amedtuple(typename, field_names, verbose=False, rename=False) | |
| # | |
| def record_factory(cls_name, field_names): | |
| try: | |
| field_names = field_names.replace(',', ' ').split() # <1> | |
| except AttributeError: # no .replace or .split | |
| pass # assume it's already a sequence of identifiers | |
| field_names = tuple(field_names) # <2> | |
| def __init__(self, *args, **kwargs): # <3> |
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 __get__(self,instance,owner): | |
| pass | |
| def __set__(self,instance,value): | |
| pass | |
| def __delete__(self,instance): | |
| pass | |
| #DEMOS | |
| class Int_validation: | |
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 typed_property(name, expected_type): | |
| storage_name = '_' + name | |
| @property | |
| def prop(self): | |
| return getattr(self, storage_name) | |
| @prop.setter | |
| def prop(self, value): | |
| if not isinstance(value, expected_type): |