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 datetime | |
def get_week(): | |
today = datetime.date.today() | |
month = today.month | |
year = today.year | |
day = today.day | |
weekday = today.weekday() | |
start = today + datetime.timedelta(0-weekday) |
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) |
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" | |
) | |
type I interface { | |
Talk() | |
} |
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" | |
) | |
type Foo struct { | |
age int | |
name string | |
} |
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
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
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
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
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
from datetime import datetime | |
def format_show_time(v, start=None, end=None): | |
diff = datetime.now() - v | |
if diff.seconds < 60: | |
s = ('%s%s') % (diff.seconds, '秒前') | |
elif diff.seconds >= 60 and diff.seconds < 3600: | |
s = ('%s%s') % (diff.seconds / 60, '分钟前') | |
elif diff.seconds >= 3600 and (v > start and v < end): | |
s = ('%s%s') % ('今天', datetime.strftime(v, format='%H:%M')) |
NewerOlder