二月 11
142857 X 1 = 142857

142857 X 2 = 285714

142857 X 3 = 428571

142857 X 4 = 571428

142857 X 5 = 714285

142857 X 6 = 857142

同样的数字,只是调换了位置,反复的出现。

那么把它乘与7是多少呢? (Read More..)
一月 16

对温度进行转换的代码,个人觉得很经典:

class Temperature(object):
    coefficients = {'c': (1.0, 0.0, -273.15), 'f': (1.8, -273.15, 32.0),
                    'r': (1.8, 0.0, 0.0)}
    def _ _init_ _(self, **kwargs):
        # default to absolute (Kelvin) 0, but allow one named argument,
        # with name being k, c, f or r, to use any of the scales
        try:
            name, value = kwargs.popitem( )
        except KeyError:
            # no arguments, so default to k=0
            name, value = 'k', 0
        # error if there are more arguments, or the arg's name is unknown
        if kwargs or name not in 'kcfr':
            kwargs[name] = value             # put it back for diagnosis
            raise TypeError, 'invalid arguments %r' % kwargs
        setattr(self, name, float(value))
    def _ _getattr_ _(self, name):
        # maps getting of c, f, r, to computation from k
        try:
            eq = self.coefficients[name]
        except KeyError:
            # unknown name, give error message
            raise AttributeError, name
        return (self.k + eq[1]) * eq[0] + eq[2]
    def _ _setattr_ _(self, name, value):
        # maps settings of k, c, f, r, to setting of k; forbids others
        if name in self.coefficients:
            # name is c, f or r -- compute and set k
            eq = self.coefficients[name]
            self.k = (value - eq[2]) / eq[0] - eq[1]
        elif name == 'k':
            # name is k, just set it
            object._ _setattr_ _(self, name, value)
        else:
            # unknown name, give error message
            raise AttributeError, name
    def _ _str_ _(self):
        # readable, concise representation as string
        return "%s K" % self.k
    def _ _repr_ _(self):
        # detailed, precise representation as string
        return "Temperature(k=%r)" % self.k
一月 04

程序员世界里有哪些名言警句呢?Jun Auza 列出了一些启迪人心的至理名言,它们大多来自产业界富于经验的人们。  
下文列出前10个供读者欣赏:

10. “People think that computer science is the art of geniuses but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones.”- Donald Knuth
10. “人们认为计算机科学是天才的艺术,但事实完全相反:只是很多人在共同建立起来的事物之上工作,就像一条由小石头铺成的小径。”—— Donald Knuth

9. “First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack.”- George Carrette
9. “首先学会计算机科学和所有的理论。然后发展出一个编程风格。之后便要忘掉所有这些,以自由的方式探索。”—— George Carrette

8. “Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris.”- Larry Wall
8. “大多数的你们都熟悉程序员的美德。它们有三点:懒,不耐烦,以及狂妄自大。”—— Larry Wall

7. “Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other,with no structural integrity, but just done by brute force and thousands of slaves.”- Alan Kay
7. “今日的大多数软件很像埃及金字塔,由千百万砖头堆砌起来,层层相切,没有着整体的结构,是由畜力和成千上万奴隶的力量建立起来的。”—— Alan Kay

6. “The trouble with programmers is that you can never tell what a programmer is doing until it’s too late.”- Seymour Cray
6. “程序员的问题是,不到太晚,你永远无法知道一个他在做着些什么。”—— Seymour Cray

5. “To iterate is human, to recurse divine.”- L. Peter Deutsch
5. “人理解迭代,神理解递归。”—— Peter Deutsch

4. “On two occasions I have been asked [by members of Parliament]: ‘Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?’ I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.”- Charles Babbage
4. “有两次我被(国会议员)问道:‘ Mr. Babbage,如果你输入计算机错误的数据,正确的答案会出来吗?’我完全无法理解能产生此种问题的大脑的混乱。”

3. “Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”- Linus Torvalds
3. “大部分好的程序员编程并不是为了钱或名望,而只是因为纯粹的乐趣。”—— Linus Torvalds

2. “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”- Martin Golding
2. “编程的时候,总是想着那个维护你代码的人会是一个知道你住在哪儿的有暴力倾向的精神病患者。”—— Martin Golding

1. “There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”- C.A.R. Hoare
1. “有两种生成一个软件设计方案的途径。一个是把它做得如此简单,以致于明显不会有漏洞存在。另一个是把它做的如此复杂,以致于不会有明显的漏洞存在。” —— C.A.R. Hoare

感谢JavaPy

十一月 30
UTF-8:Unicode TransformationFormat-8bit,允许含BOM,但通常不含BOM。是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节),中文使用24为(三个字节)来编码。UTF-8包含全世界所有国家需要用到的字符,是国际编码,通用性强。UTF-8编码的文字可以在各国支持UTF8字符集的浏览器上显示。如,如果是UTF8编码,则在外国人的英文IE上也能显示中文,他们无需下载IE的中文语言支持包。

GBK是国家标准GB2312基础上扩容后兼容GB2312的标准。GBK的文字编码是用双字节来表示的,即不论中、英文字符均使用双字节来表示,为了区分中文,将其最高位都设定成1。GBK包含全部中文字符,是国家编码,通用性比UTF8差,不过UTF8占用的数据库比GBD大。 (Read More..)
十一月 29
新发现了这个python工具包,很方便,个人感觉比其他的操作excel表格的工具包都简单。
首先,下载xlwt。
第一个简单的例子,操作excel表格首先要创建一个Workbook对象,如下:

import xlwt
wbk = xlwt.Workbook()
sheet = wbk.add_sheet('sheet 1')
创建Workbook对象之后,操作就简单很多了:

# indexing is zero based, row then column
sheet.write(0,1,'test text')
wbk.save('test.xls') (Read More..)
十一月 26
Django中如何使用jquery和ajax可能不少有都有疑惑,下面的方法介绍了如何在django中使用jquery和ajax的技巧,让我们以blog为例,这个简单的blog只有一个model,一个view和一个template。
首先,是index页面的显示,如果用户点击了某一条post的title,那我们在显示这条post的全文,这里就需要用到ajax的相关技巧。 (Read More..)
十一月 26
Lots of APIs these days return JSON objects. I love JSON, but reading a raw JSON dump can be awkward. You can print the whole thing using pprint in Python (or your favorite language), but what if you want to grep out and print only parts of the JSON? I was thinking tonight that it would be easy and useful to write a recursive script to do that. It took about half an hour to arrive at this solution: (Read More..)
十一月 26
1、大学同寝打电话告诉我说破处了,终于结束了27年的处男生涯。
恭喜之后,我XE的打听了一下细节。
结果他说他女朋友也是处,然后下面引用原对话……

“一开始都找不到地方”
“不会吧,怎么可能找不到,你也没少看X片啊”
“真的,怎么找也找不到,她也不知道”
“那最后怎么破的处啊?”
“停下来先 Google 了一下……” (Read More..)
十一月 25
学习是每位专业人士生命中必不可少的过程。每一个公司都希望它的新进员工能够快速的学习,并尽快创造利润。那么一个人的学识总和他的工作经验成正比吗?还是他可以快速的学习而不受资历的束缚?让我们看一看可以让专业人士在工作中快速学习的5件事: (Read More..)
十一月 14
1.蝙蝠身上插鸡毛--你算什么鸟
2.苍蝇采蜜--装疯(蜂)
3.茶壶里的水--滚开
4.大火烧竹林--一片光棍
5.炊事员行军--替人背黑锅
6.从河南到湖南--难上加难
7.吃饱了的牛肚子--草包
8.裁缝不带尺--存心不量(良) (Read More..)