Skip to content

Instantly share code, notes, and snippets.

View whiteclover's full-sized avatar
:octocat:
On vacation

White Clover whiteclover

:octocat:
On vacation
View GitHub Profile
@whiteclover
whiteclover / geventcherry.py
Last active August 29, 2015 14:10
gevent patch for cherrpy
#!/usr/bin/env python
import cherrypy
from cherrypy import _cprequest
from cherrypy.lib import httputil
import sys
import logging
from cherrypy.process import servers
try:
import tornado.ioloop
import tornado.iostream
import socket
class WebRequest(object):
import cherrypy
from jinja2 import Environment, FileSystemLoader
import os
def create_server():
euterpectl = EuterpeRoot()
route = cherrypy.dispatch.RoutesDispatcher()
route.mapper.explicit = False
@whiteclover
whiteclover / benchmark.md
Created May 19, 2014 09:21
Hello world Bench Mark

Hello World! Benchmark

Machine

	Architecture:          x86_64
	CPU op-mode(s):        32-bit, 64-bit
	Byte Order:            Little Endian
	CPU(s):                8

On-line CPU(s) list: 0-7

@whiteclover
whiteclover / cache.py
Last active August 29, 2015 13:57
a cache for method
#!/usr/bin/python
import functools
from threading import RLock
import logging
class CacheNullValue(object):
pass
import random
try:
import cStringIO as StringIO
except:
import StringIO
chs = ['a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t','u','v','w','x',
'y','z','A','B','C','D','E','F','G','H','I','J','K','L',
@whiteclover
whiteclover / gevent_q.py
Created August 16, 2013 06:25
gevent q demo
from gevent import queue
q = queue.Queue()
def queue_put(msg):
q.put_nowait(msg)
class memoize:
# class as decorator
def __init__(self, function):
self.function = function
self.memoized = {}
def __call__(self, *args):
try:
return self.memoized[args]
except KeyError:
@whiteclover
whiteclover / google_ajax_search.py
Last active December 19, 2015 04:38
google ajax search
#!/usr/bin/python3
import json
import urllib.request, urllib.parse
def google_ajax_search(searchfor):
query = urllib.parse.urlencode({'q': searchfor})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query
search_response = urllib.request.urlopen(url)
search_results = search_response.read().decode("utf8")
results = json.loads(search_results)
@whiteclover
whiteclover / htmlparser.py
Created July 1, 2013 00:09
TouHou Project Artist urls Fetch xml parser demo
#!/usr/bin/python
# -*- coding: utf-8 -*-
# this shell is uesed for fetching TouHouProject artists's urls ,and prepares for fetch albumss and songs
import urllib2
import HTMLParser
from urlparse import urljoin
FILTERURLS = ["/cgi-bin/feedback", '?C=N;O=D', "?C=M;O=A", "?C=S;O=A", "?C=D;O=A", "/", "cp_images.sh", "fix_unicode.sh", "mv_images.sh", "ren13.py"]