This file contains hidden or 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 java.util.Arrays; | |
public class TimSortTest { | |
public static void main(String[] args) { | |
int arr[] = {3, 6, 8, 9, 15, 13, 11, 7, 42, 58, 100, 22, 26, 39, 38, 43, 50, | |
70, 46, 10, 36, 56, 58, 56, 59, 10, 71, 89,46, 10, 36, 56, 58, 56, 59, 10, 71, 89}; | |
System.out.println("before sort: " + Arrays.toString(arr)); | |
System.out.println("array length: " + arr.length); | |
TimSort.sort(arr, 0, arr.length, null, 0, 0); |
This file contains hidden or 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 six | |
class Field(object): | |
def __init__(self, key, default=None): | |
self.key = key | |
class BaseMapper(type): | |
def __new__(cls, name, bases, attrs): |
This file contains hidden or 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
for color in itertools.product([x for x in range(30, 38)], [y for y in range(40, 48)]): | |
print('\x1b[{0}m\x1b[{1}m{0}{1}\x1b[0m'.format(*color)) |
This file contains hidden or 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 sys | |
import inspect | |
import textwrap | |
def error(): | |
raise ZeroDivisionError | |
try: | |
error() | |
except: |
This file contains hidden or 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
find . -name "*.py" |xargs cat |grep -v ^$ |wc -l |
This file contains hidden or 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 socket | |
import select | |
import argparse | |
''' | |
epoll 水平触发模式demo | |
''' | |
SERVER_HOST = '127.0.0.1' | |
EOL1 = b'\n\n' | |
EOL2 = b'\n\r\n' |
This file contains hidden or 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
# borrow from bottle.py | |
def _re_flatten(p): | |
''' Turn all capturing groups in a regular expression pattern into | |
non-capturing groups. ''' | |
if '(' not in p: return p | |
return re.sub(r'(\\*)(\(\?P<[^>]+>|\((?!\?))', | |
lambda m: m.group(0) if len(m.group(1)) % 2 else m.group(1) + '(?:', p) |
This file contains hidden or 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
#!/usr/bin/env python | |
# encoding: utf-8 | |
import logging | |
from logging.handlers import RotatingFileHandler | |
from flask_sqlalchemy import get_debug_queries | |
# ... | |
app.config['DATABASE_QUERY_TIMEOUT'] = 0.001 |
This file contains hidden or 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
# copy from https://docs.python.org/3.5/library/re.html | |
import collections | |
import re | |
Token = collections.namedtuple('Token', ['typ', 'value', 'line', 'column']) | |
def tokenize(code): | |
keywords = {'IF', 'THEN', 'ENDIF', 'FOR', 'NEXT', 'GOSUB', 'RETURN'} | |
token_specification = [ |
This file contains hidden or 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-*- | |
# python2.x | |
import socket | |
import struct | |
import fcntl | |
def get_ip_address(ifname): | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
return socket.inet_ntoa(fcntl.ioctl( | |
s.fileno(), |