This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def threeSum(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: List[List[int]] | |
""" | |
nums = sorted(nums) | |
res = [] | |
n = len(nums) | |
for i in range(n-2): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
contextvars is added in unreleased cpython, I build it from master branch | |
Python 3.8.0a0 (heads/master:3b20d345, Mar 10 2018, 13:23:11). | |
Also modify 2 lines in curio/kernel.py: | |
kernel.py Line 327: | |
> task._ctx = contextvars.copy_context() | |
kernel.py Line 827: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Requires: | |
pip install click sqlparse | |
""" | |
import re | |
from textwrap import indent, dedent | |
import click | |
import sqlparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
from inspect import getclasstree | |
def classtree(cls, indent=0, fillchar='-'): | |
""" | |
Print class tree | |
Args: | |
cls: base class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flask | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def index(): | |
return "hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |