Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python2.6
#-*- coding:utf8 -*-
from tornado.ioloop import IOLoop
from tornado.web import Application, StaticFileHandler
from tornado.options import define, options, parse_command_line
from tornado.httpserver import HTTPServer
from tornado import template
from handler import *
import logging
import os
@chao-he
chao-he / more.html
Created November 22, 2013 08:54
more的web版本
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
var qs = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
@chao-he
chao-he / wget.py
Last active December 29, 2015 02:09
python version of wget
#!/usr/bin/python26
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from tornado.ioloop import IOLoop
from tornado.options import parse_command_line
from tornado.options import options,define
from tornado.escape import utf8
from urllib import quote_plus
from collections import deque
import simplejson as json
import logging
@chao-he
chao-he / BatchHttpRequest.py
Created November 22, 2013 11:28
批量的http请求
from tornado.httpclient import AsyncHTTPClient
class BatchHttpRequest(object):
def __init__(self, urllist, callback):
self.pendings = len(urllist)
self.response = []
self.callback = callback
for url in urllist:
AsyncHTTPClient().fetch(url, callback=self.complete)
@chao-he
chao-he / mock-http-server.py
Created November 22, 2013 11:43
a dummy http server
import socket
import logging
HOST = '' # Symbolic name meaning the local host
PORT = 9000 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
@chao-he
chao-he / simple-xpath-parser.py
Created November 25, 2013 02:31
a simple xpath-like expression parser
def XpathLeef(o, path):
if path.startswith("{"):
path = path[1:-1]
for x in path.split(","):
if x not in o:
continue
yield utf8("%s:%s" % (x, o[x]))
elif path in o:
yield utf8("%s:%s" % (x, o[path]))
from collections import deque
import copy
class Selector(object):
def __init__(self, fields):
self.model = {}
self._build(fields)
def _build(self, fields):
for expr in fields:
@chao-he
chao-he / pusher.py
Last active December 29, 2015 09:59
beanstalk client
#!/usr/bin/env python26
import sys
from tornado import ioloop
from tornado.options import define,options,parse_command_line
from beanstalkt import Client as BeansClient
define("bs_host", default="localhost")
define("bs_port", default=11300)
define("using", default="input")
@chao-he
chao-he / fetch.py
Created November 26, 2013 06:46
http fecth with beanstalk input
#!/usr/bin/python26
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from tornado.ioloop import IOLoop
from tornado.options import parse_command_line
from tornado.options import options,define
from tornado.escape import utf8
from beanstalkt import Client as BeansClient
from beanstalkt import TimedOut
from urllib import quote_plus
from urlparse import urlparse
@chao-he
chao-he / worker.py
Created November 26, 2013 08:27
beanstalk worker
#!/usr/bin/python26
from tornado.ioloop import IOLoop
from tornado.options import parse_command_line
from tornado.options import options,define
from tornado.escape import utf8
from beanstalkt import Client as BeansClient
from beanstalkt import TimedOut
from urllib import quote_plus
from urlparse import urlparse
from collections import deque