This file contains hidden or 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" | |
| ) | |
| type I interface { | |
| Talk() | |
| } |
This file contains hidden or 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" | |
| ) | |
| type Foo struct { | |
| age int | |
| name string | |
| } |
This file contains hidden or 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) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
NewerOlder