Skip to content

Instantly share code, notes, and snippets.

Avatar
🙂
New journey

Shin Yang ityoung

🙂
New journey
View GitHub Profile
@ityoung
ityoung / tornado-index.py
Created May 22, 2019
An index.py example of Tornado
View tornado-index.py
import asyncio
from handler import server
from libs.redis import MyRedis
async def init_redis():
await MyRedis.redis()
if __name__ == '__main__':
View redis-singleton.py
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 Mar 19, 2019
Dynamically create routes with flask. 动态生成flask路由. Mock server可能会用到
View flask-dynamic-router.py
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})
View parse_img_demo.py
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 Mar 26, 2018
analysis a python file of module calls.
View ModuleFinder.py
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 Mar 15, 2018
A code snippet of unittest in tornado and motorengine.
View tornado_motorengine_testing.py
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()
You can’t perform that action at this time.