Skip to content

Instantly share code, notes, and snippets.

View zqqf16's full-sized avatar
:electron:
Focusing

zqqf16 zqqf16

:electron:
Focusing
View GitHub Profile
@zqqf16
zqqf16 / meta.py
Created December 26, 2013 05:29
A simple code to learn meta class.
#!/usr/bin/env python
class Meta(type):
def __new__(self, name, bases, attrs):
print('Meta: __new__: {} | {} | {} | {}'.format(self, name, bases, attrs))
return super(Meta, self).__new__(self, name, bases, attrs)
def __init__(cls, name, bases, attrs):
print('Meta: __init__: {} | {} | {} | {}'.format(cls, name, bases, attrs))
super(Meta, cls).__init__(name, bases, attrs)
@zqqf16
zqqf16 / crawl.py
Last active December 28, 2015 07:59
获取天弘基金以及华夏基金最近5天收益信息
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import requests
class Spider(object):
def __init__(self, url, pattern, encoding):
self.url = url
self.pattern = pattern
@zqqf16
zqqf16 / colorit.py
Created October 25, 2013 10:14
Print color in terminal
#!/usr/bin/env python
#-*- coding: utf-8 -*-
__all__ = ['paint']
COLOR_FORMAT = '\033[%dm\033[%d;%dm%s\033[0m'
COLOR_NAME = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
ATTRIBUTE_NAME = ['blod', 'underscore', 'blink', 'reverse', 'concealed']
@zqqf16
zqqf16 / getfile.py
Created October 22, 2013 03:10
Get changed files from diff
#!/usr/bin/env python
import re
import sys
import argparse
FILE_RE = re.compile(r'^Index: (.*)$')
def get_files_from_diff(diff):
res = []
@zqqf16
zqqf16 / levenshtein.py
Last active December 20, 2015 13:19
Implement the Levenshtein-distance algorithm.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''Implement the Levenshtein-distance Algorithm'''
def levenshtein(source, dest):
'''Return the levenshteiin distance between source and dest'''
row_len = len(source) + 1
col_len = len(dest) + 1
@zqqf16
zqqf16 / http.py
Last active December 20, 2015 03:09
A simple http server based on "SimpleHttpServer". Supports uploading files.
"""Simple HTTP Server.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
Support upload files
"""
@zqqf16
zqqf16 / simple_regexp.c
Created June 6, 2013 15:13
一个简单的正则表达式匹配器,摘自《代码之美》第一章
int match(char *regexp, char *text)
{
if (regexp[0] == '^')
return matchhere(regexp+1, text);
do {
if (matchhere(regexp, text))
return 1;
} while (*text++ != '\0');
@zqqf16
zqqf16 / t.py
Last active November 29, 2022 02:23
A command line translation tool.
#!/usr/bin/env python3
import sys
import uuid
import time
import hashlib
import requests
YOUDAO_URL = 'https://openapi.youdao.com/api'
APP_KEY = '4eb54b2bc1173f2b'