Skip to content

Instantly share code, notes, and snippets.

View tonyseek's full-sized avatar

Jiangge Zhang tonyseek

View GitHub Profile
@tonyseek
tonyseek / base.py
Last active August 29, 2015 14:21
The base class of entity models.
__all__ = ['EntityModel']
class EntityModel(object):
"""The base class of entity models.
All entity models are comparable and hashable. There are some meta
attributes:
- ``id_attr_name``
@tonyseek
tonyseek / adb-screencap
Created May 9, 2015 14:18
Capture screen of Android devices with adb
#!/usr/bin/env sh
if [ -z $1 ]; then
echo "usage: $0 FILENAME.png" > /dev/stderr
exit 1
fi
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > $1
@tonyseek
tonyseek / git-web
Last active March 25, 2019 16:29
View your Git repository in the browser.
#!/usr/bin/env python
"""
The MIT License (MIT)
Copyright (c) 2019 Jiangge Zhang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@tonyseek
tonyseek / withenv
Created January 24, 2015 10:48
foreman run alternative
#!/usr/bin/env sh
exec env $(cat .env 2>/dev/null | xargs) $@
@tonyseek
tonyseek / gulpfile.coffee
Created January 18, 2015 05:59
Flask + Browserify + Gulp + Stylus
gulp = require 'gulp'
uglify = require 'gulp-uglify'
sourcemaps = require 'gulp-sourcemaps'
stylus = require 'gulp-stylus'
rename = require 'gulp-rename'
source = require 'vinyl-source-stream'
buffer = require 'vinyl-buffer'
browserify = require 'browserify'
del = require 'del'
pkginfo = require './package.json'
@tonyseek
tonyseek / formula.py
Last active June 28, 2022 09:13
render latex formula with matplotlib and pillow.
try:
from StringIO import StringIO as BytesIO
except ImportError:
from io import BytesIO
import matplotlib.pyplot as plt
def render_latex(formula, fontsize=12, dpi=300, format_='svg'):
"""Renders LaTeX formula into image."""
@tonyseek
tonyseek / blog.tonyseek.com.conf
Created November 30, 2014 11:00
partial nginx config of my blog
server {
listen 80;
server_name blog.tonyseek.com;
root /srv/blog.tonyseek.com/;
# digg has a broken https support while sni extension has been enabled.
if ($http_user_agent !~ Digg ) {
rewrite ^ https://$server_name$request_uri? permanent; # enforce to use https
}
@tonyseek
tonyseek / captcha.py
Created November 26, 2014 02:51
A example of wheezy.captcha
import random
from wheezy.captcha.image import captcha
from wheezy.captcha.image import background
from wheezy.captcha.image import curve
from wheezy.captcha.image import noise
from wheezy.captcha.image import smooth
from wheezy.captcha.image import text
from wheezy.captcha.image import offset
from wheezy.captcha.image import rotate
from operator import itemgetter
class Step(tuple):
location = property(itemgetter(0))
milestone = property(itemgetter(1))
step = Step(['nowhere', 'nothing'])
assert step.location == 'nowhere'
@tonyseek
tonyseek / ext.py
Last active April 6, 2019 12:54
Fixes the nonstandard OAuth interface of Tencent WeChat with Flask-OAuthlib.
from .weixin_compat import fixup_weixin_oauth
oauth = OAuth()
weixin = oauth.remote_app(
'weixin',
app_key='WEIXIN',
request_token_params={'scope': 'snsapi_base'},
base_url='https://api.weixin.qq.com',
authorize_url='https://open.weixin.qq.com/connect/oauth2/authorize',
access_token_url='https://api.weixin.qq.com/sns/oauth2/access_token',