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
ityoung / tornado-index.py
Created May 22, 2019 08:24
An index.py 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
@classmethod
async def redis(cls):
if not cls._redis:
cls._redis = await aioredis.create_redis('redis://localhost')
@ityoung
ityoung / flask-dynamic-router.py
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.url_map.add(rule)
app.view_functions[i] = lambda: jsonify({'success': i})
def save_img(path, url):
pass
def update_path():
pass
def get_img_url(url):
pass
def get_page_num():
@ityoung
ityoung / ModuleFinder.py
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
ityoung / tornado_motorengine_testing.py
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()