This file contains 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 itertools import islice, chain | |
#!/usr/bin/python3 | |
def batch(iterable, size): | |
source_iter = iter(iterable) | |
while True: | |
batch_iter = islice(source_iter, size) | |
try: | |
first_element = next(batch_iter) | |
except StopIteration: |
This file contains 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
# -*- coding:utf-8 -*- | |
from jinja2 import Environment | |
from jinja2 import FileSystemLoader | |
if __name__ == "__main__" | |
data = {} | |
env = Environment(loader=FileSystemLoader('{0}/templates/'.format(os.path.dirname(__file__)))) | |
template = env.get_template('risk_rule_daily.html') | |
html = template.render(**data) |
This file contains 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 setup_logger_2(logger_name, level=logging.INFO, handler='all', log_file=''): | |
""" | |
:param logger_name: | |
:param log_file: | |
:param level: | |
:param handler: file or stream or all | |
:return: | |
""" | |
log_setup = logging.getLogger(logger_name) |
This file contains 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
fibs = {0: 0, 1: 1} | |
def _fib(n): | |
if n in fibs: return fibs[n] | |
if n % 2 == 0: | |
fibs[n] = ((2 * fib((n / 2) - 1)) + fib(n / 2)) * fib(n / 2) | |
return fibs[n] | |
else: | |
fibs[n] = (fib((n - 1) / 2) ** 2) + (fib((n+1) / 2) ** 2) | |
return fibs[n] |