Skip to content

Instantly share code, notes, and snippets.

View tonyseek's full-sized avatar

Jiangge Zhang tonyseek

View GitHub Profile
@tonyseek
tonyseek / conrotine_task_manager.py
Created April 26, 2012 05:39
The demo of a corotine task manager.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from Queue import Queue
# ---------------------
# Corotine Task Manager
# ---------------------
@tonyseek
tonyseek / getter-sample.php
Created May 22, 2012 13:37
Implementing dynamic getter and setter in PHP.
<?php
class ModelBase {
static $attr_accessible = array();
static $attr_readable = array();
static $attr_writable = array();
public function __get($attr) {
$getter = "get_{$attr}";
if (in_array($attr, static::$attr_accessible) || in_array($attr, static::$attr_readable)) {
@tonyseek
tonyseek / demo.py
Last active August 23, 2017 04:52
Use "mixin" to make a mapped class be commentable with SQLAlchemy.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import datetime
from flask import Flask
from mixins import db
from models import Post, User
@tonyseek
tonyseek / demo.php
Created June 18, 2012 07:58
Implementing observer pattern in PHP >= 5.4
<?php
require_once 'observer.php';
require_once 'subject.php';
use Common\Observer\Observer;
use Common\Observer\Subject;
class Notice
{
use Subject;
@tonyseek
tonyseek / checklink.py
Created June 25, 2012 17:41
Visit all links of a website.
@tonyseek
tonyseek / extract_captcha.py
Created July 26, 2012 13:13
Distinguish captcha with PIL and Tesseract
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
import StringIO
import requests
import PIL.Image
import tesserwrap
@tonyseek
tonyseek / vimrc
Last active March 31, 2018 04:03
[DEPRECATED] My Configuration of VIM
syntax on
filetype off
" format and user interface
set nocompatible
set number
set softtabstop=4 tabstop=4 shiftwidth=4
set expandtab
set autoindent
set hlsearch
@tonyseek
tonyseek / owdo
Created August 23, 2012 02:57
OVER GREAT FIREWALL DO ANYTHING
#!/usr/bin/env sh
if [ -n "`ifconfig | grep tun`" ]; then
export http_proxy="http://10.x.x.x:xxxx" # this proxy could only be used throught VPN.
else
export http_proxy="http://127.0.0.1:8087" # this is goagent proxy
fi
export https_proxy=$http_proxy
if [[ -n "$@" ]]; then
$@
@tonyseek
tonyseek / traversal.py
Created September 3, 2012 09:59
A traversal style dispatcher which is alike Quixote.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
def dispatch(entry_object, path, spliter="/"):
"""Starting with an entry object and dispatching the request by url path.
>>> class GroupList(object):
... exports = frozenset(["create"])
...
@tonyseek
tonyseek / test_validators.py
Created September 6, 2012 09:08
Simple validator for Quixote request input.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from functools import partial
from unittest import TestCase, main
from quixote.errors import QueryError
from validators import validate, ValidateError