⌘T | go to file |
⌘⌃P | go to project |
⌘R | go to methods |
⌃G | go to line |
⌘KB | toggle side bar |
⌘⇧P | command prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent.futures import ThreadPoolExecutor | |
from tornado.concurrent import run_on_executor, Future | |
from tornado import httpclient,ioloop,web,gen | |
import request | |
import sys | |
httpclient.AsyncHTTPClient.configure('tornado.curl_httpclient.CurlAsyncHTTPClient', max_clients=10) | |
# TODO: remove | |
class Foo(Exception): pass | |
def dot(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import redis | |
import logging | |
logger = logging.getLogger('service.redis_lock') | |
CONN = redis.Redis(host='localhost') | |
def acquire_lock(lockname, identifier, wait_time=20, timeout=15): | |
end = time.time() + wait_time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton(object): | |
_instance = None | |
def __new__(cls, *args, **kswargs): | |
if cls._instance is None: | |
cls._instance = super(Singleton, cls).__new__(cls, *args, **kswargs) | |
return cls._instance | |
class SingletonParent(object): | |
_instance = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def singleton(cls): | |
_instance = {} | |
def wrapper(): | |
if cls not in _instance: | |
_instance[cls] = cls() | |
return _instance[cls] | |
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A(): | |
def __init__(self): | |
self.v = [1,2,3,4,5,6] | |
self.step = 0 | |
def __iter__(self): | |
return self | |
def next(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import time | |
from threading import Thread | |
def get_responses(): | |
urls = ['http://www.baidu.com', 'http://www.amazon.cn', 'http://www.taobao.com', 'http://www.alibaba.com'] | |
start = time.time() | |
for url in urls: | |
print url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import time | |
from threading import Thread | |
#define a global variable | |
some_var = 0 | |
class IncrementThread(Thread): | |
def run(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import thread | |
from threading import Thread, Condition, Event, Lock, currentThread | |
from Queue import Queue | |
class ItemQ(object): | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
//1 | |
type I interface { | |
Get() int | |
Set(int) |