INSERT GRAPHIC HERE (include hyperlink in image)
Subtitle or Short Description Goes Here
ideally one sentence >
def jsonp(f): | |
"""Wrap a json response in a callback, and set the mimetype (Content-Type) header accordingly | |
(will wrap in text/javascript if there is a callback). If the "callback" or "jsonp" paramters | |
are provided, will wrap the json output in callback({thejson}) | |
Usage: | |
@jsonp | |
def my_json_view(request): | |
d = { 'key': 'value' } |
#!/usr/bin/env python | |
""" | |
How to use it: | |
1. Just `kill -2 PROCESS_ID` or `kill -15 PROCESS_ID` , The Tornado Web Server Will shutdown after process all the request. | |
2. When you run it behind Nginx, it can graceful reboot your production server. | |
3. Nice Print in http://weibo.com/1682780325/zgkb7g8k7 | |
""" |
from peewee import * | |
class BModel(Model): | |
class Meta: | |
database = db | |
@classmethod | |
def create_table(cls, *args, **kwargs): | |
for field in cls._meta.get_fields(): | |
if hasattr(field, "pre_field_create"): |
get_latest_release() { | |
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api | |
grep '"tag_name":' | # Get tag line | |
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value | |
} | |
# Usage | |
# $ get_latest_release "creationix/nvm" | |
# v0.31.4 |
import functools | |
def force_async(fn): | |
''' | |
turns a sync function to async function using threads | |
''' | |
from concurrent.futures import ThreadPoolExecutor | |
import asyncio | |
pool = ThreadPoolExecutor() |
import axios from 'axios' | |
/** | |
* Config global for axios/django | |
*/ | |
axios.defaults.xsrfHeaderName = "X-CSRFToken" | |
axios.defaults.xsrfCookieName = 'csrftoken' | |
export default axios |
import re | |
TIMEDELTA_REGEX = (r'((?P<days>-?\d+)d)?' | |
r'((?P<hours>-?\d+)h)?' | |
r'((?P<minutes>-?\d+)m)?') | |
TIMEDELTA_PATTERN = re.compile(TIMEDELTA_REGEX, re.IGNORECASE) | |
def parse_delta(delta): |