Skip to content

Instantly share code, notes, and snippets.

View ityoung's full-sized avatar
New journey

Shin Yang ityoung

New journey
View GitHub Profile
ityoung /
Created May 22, 2019 08:24
An example of Tornado
import asyncio
from handler import server
from libs.redis import MyRedis
async def init_redis():
await MyRedis.redis()
if __name__ == '__main__':
import aioredis
class MyRedis(object):
_redis = None
async def redis(cls):
if not cls._redis:
cls._redis = await aioredis.create_redis('redis://localhost')
ityoung /
Last active March 19, 2019 03:39
Dynamically create routes with flask. 动态生成flask路由. Mock server可能会用到
for i in ['aa', 'bb']:
option = {}
option['endpoint'] = i
rule = app.url_rule_class('/' + i, methods=('GET',), **option)
app.view_functions[i] = lambda: jsonify({'success': i})
def save_img(path, url):
def update_path():
def get_img_url(url):
def get_page_num():
ityoung /
Last active March 26, 2018 08:57
analysis a python file of module calls.
class ModuleFinder(object):
def __init__(self):
self.find_next_line = False
self.father_module = None
self.modules = []
def find_modules_next_line(self, code, module=None):
"""code: line to find modules"""
if '\\' not in code[-1]:
ityoung /
Last active March 15, 2018 03:49
A code snippet of unittest in tornado and motorengine.
from tornado.web import Application
from tornado.testing import AsyncHTTPTestCase
from apps.account.handlers import CheckEnv
import unittest
import motorengine
class MyTestCase(AsyncHTTPTestCase):
def setUp(self, auto_connect=True):
super(MyTestCase, self).setUp()