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
from datetime import date | |
from datetime import date | |
class Person(object): | |
def __init__(self, birth_day, sex, children): |
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" | |
"reflect" | |
"runtime" | |
) | |
func Decorator(decoPtr, fn interface{}) (err error) { | |
var decoratedFunc, targetFunc reflect.Value |
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 Processor interface { | |
step1() | |
step2() | |
step3() | |
} |
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 random | |
class MontyHallGame(object): | |
CAR = "car" | |
GOAT = "goat" | |
def __init__(self, attempts, changed): | |
self.attempts = attempts | |
self.doors = {} |
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 BatchLruCache(object): | |
def __init__(self, maxsize, timeout): | |
self.maxsize = maxsize | |
self.timeout = timeout | |
self.cache = OrderedDict() | |
self.Omitted_object = OmittedType() | |
self.is_full = False | |
def __call__(self, func): |
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 re | |
str = "<img /><a>srcd</a>hello</br><br/>" | |
str = re.sub(r'</?\w+[^>]*>','',str) | |
print str |
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
1. You Can't Write Perfect Software. | |
2. Design with Constracts. (可以使用测试来做到这一点) | |
3. 尽快崩溃,更容易发现代码的问题。 | |
4. 如果有一个 bug,哪怕是很小的一个类型没有检查,就说明糟糕的事情已经发生,是程序员本身思考的不够全面。 | |
5. Crash Early. | |
6. 死程序带来的危害通常比带有疾患的程序要小得多。 | |
7. If It Can't Happen, Use Assertions to Ensure That It Won't. | |
8. 不要用断言代替真正地错误处理(例如异常)。断言检查的是绝不应该发生的事情。 |
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
1. Use the Power of Command Shells. | |
2. Use a Single Editor Well. | |
3. Always Use Source Code Control. | |
4. Fix the Problem, Not the Blame. | |
5. 设法找出问题的根源,而不是问题的特定表现。 | |
6. 需要与报告 bug 的人面谈,以搜集更多的数据。 | |
7. 充分地测试边界条件,又测试现实中最终用户的使用模式。 | |
8. 出 bug 时,不要首先就怀疑是第三方库或者系统的问题。 |
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
#coding=utf-8 | |
import jieba | |
import numpy as np | |
from sklearn.svm import * | |
from numpy import * | |
def load_data(file_name): |
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
1. 系统中的每一项知识都必须具有单一,无歧义,权威的表示。 | |
2. 无耐性的重复是一种容易检测和处理的重复方式,但是需要接受训练,并愿意为以后的痛苦而预先花一些时间。 | |
3. 避免开发者之间的重复一定要要不断地交流和确认。 | |
4. Eliminate Effects Between Unrelated Things. (消除无关事物之间的影响,正交性,解耦) | |
5. 编写正交性系统的好处:提高生产率和降低风险。 | |
6. 项目团队要有正交性,职责明确。检查下发生改动时需要涉及多少人,人数越多,团队正交性越差。 | |
7. 编写代码时不要依赖你无法控制的事物的属性。 | |
8. 让代码保持解耦,避免使用全局数据。 |
NewerOlder