Skip to content

Instantly share code, notes, and snippets.

@guyskk
guyskk / test_dict_locals.py
Created January 22, 2016 15:46
被注释掉的语句都是会报错的
#!/usr/bin/env python
# coding: utf-8
from __future__ import unicode_literals, absolute_import, print_function
k1 = 'v1'
k2 = 'v2'
module_items = locals()
module_keys = ['k1', 'k2']
# print({k: locals()[k] for k in module_keys})
@guyskk
guyskk / shadowsocks-server.service
Last active January 30, 2024 05:18
shadowsocks server systemd service
[Unit]
Description=Shadowsocks Server
After=network.target
[Service]
ExecStart=/usr/local/bin/ssserver -c /etc/shadowsocks/ss-config.json
Restart=on-abort
[Install]
WantedBy=multi-user.target
@guyskk
guyskk / init.vim
Created May 26, 2016 09:34
nvim config
if has('vim_starting')
set runtimepath+=~/.config/nvim/bundle/neobundle.vim/
endif
call neobundle#begin(expand('~/.config/nvim/bundle'))
NeoBundleFetch 'Shougo/neobundle.vim'
NeoBundle 'altercation/vim-colors-solarized'
NeoBundle 'scrooloose/nerdtree'
NeoBundle 'tpope/vim-fugitive'
NeoBundle 'mattn/emmet-vim'
def handle_default_optional_desc(some_validater):
def wrapped_validater(*args, **kwargs):
default = kwargs.pop("default", None)
optional = kwargs.pop("optional", False)
desc = kwargs.pop("desc", None)
origin_validater = some_validater(*args, **kwargs)
def validater(value):
if value is None:
if default is not None:
@guyskk
guyskk / jookr.py
Last active October 26, 2022 15:42
import os
SQL = "INSERT INTO table (`value1`,`value2`,) VALUES ('%s','%s');\n"
def main():
for fname in os.listdir("."):
# step1
name, ext = os.path.splitext(fname)
if ext != ".txt":
@guyskk
guyskk / flask_context.py
Last active January 12, 2018 02:13
理解Flask上下文环境
import flask
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "hello"
@guyskk
guyskk / diagnose.py
Created January 30, 2017 14:35
print your platform information and package information
# coding:utf-8
import platform
def pkginfo():
for pkg in ['setuptools', 'pip', 'wheel',
'virtualenv', 'distutils', 'cython']:
try:
version = getattr(__import__(pkg), '__version__', 'Unknown')
print('{} = {}'.format(pkg, version))
@guyskk
guyskk / classtree.py
Last active March 22, 2017 12:58
Print class tree, include all sub classes alive in Python VM
# coding:utf-8
from inspect import getclasstree
def classtree(cls, indent=0, fillchar='-'):
"""
Print class tree
Args:
cls: base class
@guyskk
guyskk / validator_string.py
Created April 16, 2017 14:20
validator string DSL parser by pyparsing
# https://pythonhosted.org/pyparsing/
from pyparsing import *
# https://pyparsing.wikispaces.com/file/view/jsonParser.py
def make_keyword(kwd_str, kwd_value):
return Keyword(kwd_str).setParseAction(replaceWith(kwd_value))
TRUE = make_keyword("true", True)
FALSE = make_keyword("false", False)
NULL = make_keyword("null", None)
@guyskk
guyskk / pysql_format.py
Created November 16, 2017 06:20
Format SQL in python source code
"""
Requires:
pip install click sqlparse
"""
import re
from textwrap import indent, dedent
import click
import sqlparse