Skip to content

Instantly share code, notes, and snippets.

View icsaas's full-sized avatar
🎯
saasing

iac icsaas

🎯
saasing
View GitHub Profile
@icsaas
icsaas / sort.py
Created November 21, 2013 03:20
simplest python k-way merging sort
import heapq
import random
import threading
#k thrads
k=4
#Generate n numbers for each thread to process.
n=10
#/bin/bash
# Author : laomo <laomo@lmbj.net>
# Donate Address : https://ripple.com//send?to=rQKFznLaiyT55YXSS33fE6NgTjKbrnN4gT
sudo apt-get update
sudo apt-get install libxss1 libstdc++5 ia32-libs freeglut3
#optional(for see the tasks)
sudo apt-get install htop
wget http://boinc.berkeley.edu/dl/boinc_7.2.33_x86_64-pc-linux-gnu.sh
@icsaas
icsaas / gist:8730499
Created January 31, 2014 11:36
gevent example
import gevent
from gevent import monkey
#patches stdlib (including socket and ssl modules) to cooperate with other greenlets
monkey.patch_all()
import urllib2
urls=['http://baidu.com','http://cqu.edu.cn','http://www.python.org']
def print_head(url):
@icsaas
icsaas / tornadofetch.py
Created January 31, 2014 11:41
tornado example
from tornado import ioloop
from tornado.httpclient import AsyncHttpClient
urls=['http://www.google.com/','http://baidu.com']
def print_head(response):
print '%s: %s bytes: %r' %(response.request.url,len(response.body),response.body[:50])
http_client=AsyncHTTPClient()
from rq import Queue, Worker, Connection
if __name__ == '__main__':
with Connection():
q = Queue()
Worker(q).work()
from time import sleep
import tornado
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
class BackgroundMix(tornado.web.RequestHandler):
"""将block任务放入线程池中执行
EXAMPLE:
# blocking task like querying to MySQL
from concurrent.futures import ThreadPoolExecutor
from functools import partial, wraps
import time
import tornado.ioloop
import tornado.web
EXECUTOR = ThreadPoolExecutor(max_workers=4)
from concurrent.futures import ThreadPoolExecutor
from functools import partial, wraps
import time
import tornado.ioloop
import tornado.web
EXECUTOR = ThreadPoolExecutor(max_workers=4)
def authenticated(method):
"""Decorate methods with this to require that the user be logged in."""
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
if not self.current_user:
if self.request.method == "GET":
url = self.get_login_url()
if "?" not in url:
url += "?" + urllib.urlencode(dict(next=self.request.uri))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.