Skip to content

Instantly share code, notes, and snippets.

View RRRoger's full-sized avatar
:octocat:
Wubba lubba dub dub

Roger RRRoger

:octocat:
Wubba lubba dub dub
View GitHub Profile
@RRRoger
RRRoger / try_except_log.py
Created September 21, 2018 03:19
装饰器 抓取接口异常 创建接口日志
def try_except_log(func):
"""
# 供参考
装饰器:
1.抓取异常
2.创建日志
"""
def wrapper(*args, **kw):
@RRRoger
RRRoger / short_uuid.py
Created November 5, 2018 08:38
获取short_uuid函数
# -*- encoding: utf-8 -*-
from uuid import uuid4
uuidChars = (
"a", "b", "c", "d", "e", "f", "g",
"h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z",
@RRRoger
RRRoger / 月加减.py
Created November 5, 2018 08:41
月加减
def add_months(dt, months):
"""
月加减
:param dt: datetime 实例
:param months: 加多少月
:return:
"""
month = dt.month - 1 + months
year = dt.year + month / 12
month = month % 12 + 1
@RRRoger
RRRoger / time_cost.py
Created November 5, 2018 08:43
计算函数耗时多久
def time_cost(f):
"""
:param f: function
:return: 计算函数耗时多久
"""
def _wrapper(*args, **kwargs):
now = time.time()
res = f(*args, **kwargs)
log_txt = u'函数 %s 耗时 %.2fs!' % (f.__name__, time.time() - now)
_logger.info(log_txt)
@RRRoger
RRRoger / date_range.py
Last active November 5, 2018 08:44
获取一个时间区间的list
def date_range(begin_date, end_date):
"""
获取一个时间区间的list
"""
dates = []
dt = datetime.datetime.strptime(begin_date, "%Y-%m-%d")
date = begin_date[:]
while date <= end_date:
dates.append(date)
dt = dt + datetime.timedelta(1)
@RRRoger
RRRoger / min2millisec.py
Created September 21, 2018 03:12
min2millisec
def min2millisec(t):
"""
将`03:36`转化成毫秒
:param t: min string like '00:43'
:return: millisec int
"""
if not t:
return t
tim = t.split(":")[::-1]
depth = 0
@RRRoger
RRRoger / gitCommand
Last active January 9, 2019 05:47
gitCommand
git reset --hard HEAD^
@RRRoger
RRRoger / true_is_false.py
Last active January 12, 2019 05:32
True is False
# -*- coding: utf-8 -*-
False, True = True, False
if True:
print True, 1
else:
print False, 0
@RRRoger
RRRoger / constellation.py
Created January 28, 2019 03:12
get the constellation by your input
# -*- encoding: utf-8 -*-
def _get_stars(date):
res = ''
star_key = {
1: ('摩羯座', '水瓶座'),
2: ('水瓶座', '双鱼座'),
3: ('双鱼座', '白羊座'),
4: ('白羊座', '金牛座'),
5: ('金牛座', '双子座'),
@RRRoger
RRRoger / phrases.ini
Last active January 31, 2019 08:25
搜过输入法自定义短语配置文件
; 搜狗输入法--自定义短语配置文件
; 自定义短语说明:
; 1、自定义短语支持多行、空格、指定位置。
; 2、每条自定义短语最多支持30000个汉字,总共支持100000条自定义短语。
; 3、自定义短语的格式如下:
; 单行的格式:
; 字符串+英文逗号+数字(指定排序位置)=短语