diff --git a/github-roam.md b/github-roam.md index 897b946..d17457e 100644 --- a/github-roam.md +++ b/github-roam.md @@ -1,7 +1,7 @@ #前言 -我的GitHub主页上写着加入的时间——``Joined on Nov 8, 2010``,那时才大一,在那之后的那长日子里我都没有过到。也许是因为我学的不是计算机,到了今天——``2015.3.9``,我也发现这其实是程序员的社交网站。 +我的GitHub主页上写着加入的时间——``Joined on Nov 8, 2010``,那时才大一,在那之后的那么长的日子里我都没有登录过。也许是因为我学的不是计算机,到了今天——``2015.3.9``,我才发现这其实是程序员的社交网站。 过去,曾经有很长的一些时间我试过在GitHub上连击,也试着去了解别人是如何用好这个工具的。当然粉丝在GitHub上也是很重要的。 @@ -9,9 +9,9 @@ ##我与GitHub的故事 -在我大四找工作的时候,试图去寻找一份硬件、物联网相关的工作(ps: 专业是电子信息工程)。尽管简历上写得满满的各种经历、经验,然而并没有卵用。跑了几场校园招聘会后,十份简历(ps: 事先已经有心里准备)一个也没有投出去——因为学校直接被拒。我对霸面什么的一点兴趣都没有,千里马需要伯乐。后来,我加入了Martin Flower所在的公司,当然这是后话了。 +在我大四找工作的时候,试图去寻找一份硬件、物联网相关的工作(ps: 专业是电子信息工程)。尽管简历上写得满满的各种经历、经验,然而并没有卵用。跑了几场校园招聘会后,十份简历(ps: 事先已经有心里准备)一个也没有投出去——因为学校直接被拒。我对霸面什么的一点兴趣都没有,千里马需要伯乐。后来,我加入了[Martin Flower](https://martinfowler.com/)所在的公司,当然这是后话了。 -这是一个残酷的世界,在学生时代,如果你长得不帅不高的话,那么多数的附加技能都是白搭(ps: 通常富的是看不到这篇文章的)。在工作时期,如果你上家没有名气,那么将会影响你下一份工作的待遇。而,很多东西却会改变这些,GitHub就是其中一个。 +这是一个残酷的世界,在学生时代,如果你长得不帅不高的话,那么多数的附加技能都是白搭(ps: 通常富的是看不到这篇文章的)。在工作时期,如果你上家没有名气,那么将会影响你下一份工作的待遇。而,很多东西却可以改变这些,GitHub就是其中一个。 注册GitHub的时候大概是大一的时候,我熟悉的时候已经是大四了,现在已经毕业一年了。在过去的近两年里,我试着以几个维度在GitHub上创建项目: @@ -47,7 +47,7 @@ 没有测试的项目是很扯淡的,除非你的项目只有一个函数,然后那个函数返回``Hello,World``。 -如果你的项目代码有上千行,如果你能保证测试覆盖率可以达到95%以的话,那么我想你的项目不会有太复杂的函数。假使有这样的函数,那么他也是被测试覆盖住的。 +如果你的项目代码有上千行,如果你能保证测试覆盖率可以达到95%以的话,那么我想你的项目不会有太复杂的函数。假使有这样的函数,那么它也是被测试覆盖住的。 如果你在用心做这个项目,那么你看到代码写得不好也会试着改进,即重构。当有了一些,你的技能会不断提升。你开始会试着接触更多的东西,如stub,如mock,如fakeserver。 @@ -61,7 +61,7 @@ ###方便工作 -我们可以从中获取到不同的知识、内容、信息。每个人都可以从别人的代码中学习,当我们需要构建一个库的时候我们可以在上面寻找不同的库和代码来实现我们的功能。如当我在实现一个库的时候,我会在GitHub上到相应的组件: +我们可以从中获取到不同的知识、内容、信息。每个人都可以从别人的代码中学习,当我们需要构建一个库的时候,我们可以在上面寻找不同的库和代码来实现我们的功能。如当我在实现一个库的时候,我会在GitHub上找到相应的组件: - Promise 支持 - Class类(ps:没有一个好的类使用的方式) @@ -1162,7 +1162,7 @@ req.end(); 或许你应该知道了,重构是怎样的,你也知道重构能带来什么。在我刚开始学重构和设计模式的时候,我需要去找一些好的示例,以便于我更好的学习。有时候不得不创造一些更好的场景,来实现这些功能。 -有一天,我发现当我需要我一次又一次地重复讲述某些内容,于是我就计划着把这些应该掌握的技能放到GitHub上,也就有了[Artisan Stack](https://github.com/artisanstack) 计划。 +有一天,我发现当我需要我一次又一次地重复讲述某些内容,于是我就计划着把这些应该掌握的技能放到GitHub上,也就有了[Artisan Stack](https://github.com/phodal-archive/artisanstack.github.io) 计划。 每个程序员都不可避免地是一个Coder,一个没有掌握好技能的Coder,算不上是手工艺人,但是是手工人。 @@ -1283,7 +1283,7 @@ str = tableHandler(str, execStr, strict); } ``` -然后你也看到了,上面有一堆重复的代码,接着让我们用JavaScript的``奇技浮巧``,即apply方法,把上面的重复代码变成。 +然后你也看到了,上面有一堆重复的代码,接着让我们用JavaScript的``奇技淫巧``,即apply方法,把上面的重复代码变成。 ```javascript ['code', 'headline', 'lists', 'tables', 'links', 'mail', 'url', 'smlinks', 'hr'].forEach(function (type) { @@ -1994,7 +1994,7 @@ if __name__ == '__main__': plt.show() ``` -蓝色的是第一周,绿色的是第二周,蓝色的是第三周就有了上面的结果。 +蓝色的是第一周,绿色的是第二周,红色的是第三周就有了上面的结果。 我们还需要优化方法,以及多线程的支持。 @@ -2446,7 +2446,7 @@ def get_points(usernames):  -``在停地造轮子的过程中,也不停地造车子。`` +``在不停地造轮子的过程中,也不停地造车子。`` 在那篇连续冲击365天的文章出现之前,我们公司的大大([https://github.com/dreamhead](https://github.com/dreamhead))也曾经在公司内部说过,天天commit什么的。当然这不是我的动力,在连击140天之前 @@ -2732,7 +2732,7 @@ def get_points(usernames): 组合相比于创造过程是一个更有挑战性的过程,我们需要在这过程去设计胶水来粘合这些代码,并在最终可以让他工作。这好比是我们在平时接触到的任务划分,每个人负责相应的模块,最后整合。 -想似的我在写[lan](https://github.com/phodal/lan)的时候,也是类似的,但是不同的是我已经设计了一个清晰的架构图。 +我在写[lan](https://github.com/phodal/lan)的时候,也是类似的,但是不同的是我已经设计了一个清晰的架构图。  diff --git a/index.html b/index.html index 3b883d6..2652c6f 100644 --- a/index.html +++ b/index.html @@ -208,12 +208,12 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
我的GitHub主页上写着加入的时间——Joined on Nov 8, 2010,那时才大一,在那之后的那长日子里我都没有过到。也许是因为我学的不是计算机,到了今天——2015.3.9,我也发现这其实是程序员的社交网站。
我的GitHub主页上写着加入的时间——Joined on Nov 8, 2010,那时才大一,在那之后的那么长的日子里我都没有登录过。也许是因为我学的不是计算机,到了今天——2015.3.9,我才发现这其实是程序员的社交网站。
过去,曾经有很长的一些时间我试过在GitHub上连击,也试着去了解别人是如何用好这个工具的。当然粉丝在GitHub上也是很重要的。
在这里,我会试着将我在GitHub上学到的东西一一分享出来。
在我大四找工作的时候,试图去寻找一份硬件、物联网相关的工作(ps: 专业是电子信息工程)。尽管简历上写得满满的各种经历、经验,然而并没有卵用。跑了几场校园招聘会后,十份简历(ps: 事先已经有心里准备)一个也没有投出去——因为学校直接被拒。我对霸面什么的一点兴趣都没有,千里马需要伯乐。后来,我加入了Martin Flower所在的公司,当然这是后话了。
-这是一个残酷的世界,在学生时代,如果你长得不帅不高的话,那么多数的附加技能都是白搭(ps: 通常富的是看不到这篇文章的)。在工作时期,如果你上家没有名气,那么将会影响你下一份工作的待遇。而,很多东西却会改变这些,GitHub就是其中一个。
+在我大四找工作的时候,试图去寻找一份硬件、物联网相关的工作(ps: 专业是电子信息工程)。尽管简历上写得满满的各种经历、经验,然而并没有卵用。跑了几场校园招聘会后,十份简历(ps: 事先已经有心里准备)一个也没有投出去——因为学校直接被拒。我对霸面什么的一点兴趣都没有,千里马需要伯乐。后来,我加入了Martin Flower所在的公司,当然这是后话了。
+这是一个残酷的世界,在学生时代,如果你长得不帅不高的话,那么多数的附加技能都是白搭(ps: 通常富的是看不到这篇文章的)。在工作时期,如果你上家没有名气,那么将会影响你下一份工作的待遇。而,很多东西却可以改变这些,GitHub就是其中一个。
注册GitHub的时候大概是大一的时候,我熟悉的时候已经是大四了,现在已经毕业一年了。在过去的近两年里,我试着以几个维度在GitHub上创建项目:
没有测试的项目是很扯淡的,除非你的项目只有一个函数,然后那个函数返回Hello,World。
如果你的项目代码有上千行,如果你能保证测试覆盖率可以达到95%以的话,那么我想你的项目不会有太复杂的函数。假使有这样的函数,那么他也是被测试覆盖住的。
+如果你的项目代码有上千行,如果你能保证测试覆盖率可以达到95%以的话,那么我想你的项目不会有太复杂的函数。假使有这样的函数,那么它也是被测试覆盖住的。
如果你在用心做这个项目,那么你看到代码写得不好也会试着改进,即重构。当有了一些,你的技能会不断提升。你开始会试着接触更多的东西,如stub,如mock,如fakeserver。
有一天,你会发现你离不开测试。
然后就会相信: 那些没有写测试的项目都是在耍流氓
上面我们说的都是我们可以收获到的东西,我们开始尝试就意味着我们知道它可能给我们带来好处。上面已经提到很多可以提升自己的例子了,这里再说说其他的。
我们可以从中获取到不同的知识、内容、信息。每个人都可以从别人的代码中学习,当我们需要构建一个库的时候我们可以在上面寻找不同的库和代码来实现我们的功能。如当我在实现一个库的时候,我会在GitHub上到相应的组件:
+我们可以从中获取到不同的知识、内容、信息。每个人都可以从别人的代码中学习,当我们需要构建一个库的时候,我们可以在上面寻找不同的库和代码来实现我们的功能。如当我在实现一个库的时候,我会在GitHub上找到相应的组件:
可是除了HTTP协议,还有MQTT和CoAP。对于MQTT协议来说,那还算好,毕竟自带授权,如:
-mosquitto_pub -u root -P root -h localhost -d -t lettuce -m "Hello, MQTT. This is my first message."mosquitto_pub -u root -P root -h localhost -d -t lettuce -m "Hello, MQTT. This is my first message."便可以让我们简单地完成这个功能,然而有的协议是没有这样的功能如CoAP协议中是用Option来进行授权的。现在的工具如libcoap只能有如下的简单功能
-coap-client -m get coap://127.0.0.1:5683/topics/zero -Tcoap-client -m get coap://127.0.0.1:5683/topics/zero -T于是,先写了个测试脚本来验证功能。
var coap = require('coap');
var request = coap.request;
@@ -1280,7 +1280,7 @@ beforeEach(function() {
重构
或许你应该知道了,重构是怎样的,你也知道重构能带来什么。在我刚开始学重构和设计模式的时候,我需要去找一些好的示例,以便于我更好的学习。有时候不得不创造一些更好的场景,来实现这些功能。
-有一天,我发现当我需要我一次又一次地重复讲述某些内容,于是我就计划着把这些应该掌握的技能放到GitHub上,也就有了Artisan Stack 计划。
+有一天,我发现当我需要我一次又一次地重复讲述某些内容,于是我就计划着把这些应该掌握的技能放到GitHub上,也就有了Artisan Stack 计划。
每个程序员都不可避免地是一个Coder,一个没有掌握好技能的Coder,算不上是手工艺人,但是是手工人。
艺,需要有创造性的方法。
为什么重构?
@@ -1358,7 +1358,7 @@ str = listHandler(strwhile ((execStr = regExpObject.tables.exec(str)) !== null) {
str = tableHandler(str, execStr, strict);
}然后你也看到了,上面有一堆重复的代码,接着让我们用JavaScript的奇技浮巧,即apply方法,把上面的重复代码变成。
然后你也看到了,上面有一堆重复的代码,接着让我们用JavaScript的奇技淫巧,即apply方法,把上面的重复代码变成。
['code', 'headline', 'lists', 'tables', 'links', 'mail', 'url', 'smlinks', 'hr'].forEach(function (type) {
while ((stra = regexobject[type].exec(str)) !== null) {
str = that[(type + 'Handler')].apply(that, [stra, str, strict]);
@@ -1381,16 +1381,16 @@ str = tableHandler(str编写测试->功能代码->修改测试->重构
上次在和buddy聊天的时候,才知道测试在功能简单的时候是后行的,在功能复杂不知道怎么下手的时候是先行的。
开始之前请原谅我对于Java语言的一些无知,然后,看一下我写的Main函数:
-package com.phodal.learing;
+package com.phodal.learing;
public class Main {
- public static void main(String[] args) {
+ public static void main(String[] args) {
int c=new Cal().add(1,2);
int d=new Cal2().sub(2,1);
- System.out.println("Hello,s");
- System.out.println(c);
- System.out.println(d);
+ System.out.println("Hello,s");
+ System.out.println(c);
+ System.out.println(d);
}
}
代码写得还好(自我感觉),先不管Cal和Cal2两个类。大部分都能看懂,除了c,d不知道他们表达的是什么意思,于是。
@@ -1402,16 +1402,16 @@ str = tableHandler(str把光标移到int d中的d,按下shift+f6,输入result_sub
于是就有
-package com.phodal.learing;
+package com.phodal.learing;
public class Main {
- public static void main(String[] args) {
+ public static void main(String[] args) {
int result_add=new Cal().add(1,2);
int result_sub=new Cal2().sub(2,1);
- System.out.println("Hello,s");
- System.out.println(result_add);
- System.out.println(result_sub);
+ System.out.println("Hello,s");
+ System.out.println(result_add);
+ System.out.println(result_sub);
}
}
Extract Method
@@ -1423,16 +1423,16 @@ str = tableHandler(str在弹出的窗口中输入mprint
于是有了
-public static void main(String[] args) {
+public static void main(String[] args) {
int result_add=new Cal().add(1,2);
int result_sub=new Cal2().sub(2,1);
- System.out.println("Hello,s");
+ System.out.println("Hello,s");
mprint(result_add);
mprint(result_sub);
}
private static void mprint(int result_sub) {
- System.out.println(result_sub);
+ System.out.println(result_sub);
}
似乎我们不应该这样对待System.out.println,那么让我们内联回去
Inline Method
@@ -1444,12 +1444,12 @@ str = tableHandler(str选中Inline all invocations and remove the method(2 occurrences) 点确定
然后我们等于什么也没有做了~~:
-public static void main(String[] args) {
+public static void main(String[] args) {
int result_add=new Cal().add(1,2);
int result_sub=new Cal2().sub(2,1);
- System.out.println("Hello,s");
- System.out.println(result_add);
- System.out.println(result_sub);
+ System.out.println("Hello,s");
+ System.out.println(result_add);
+ System.out.println(result_sub);
}
似乎这个例子不是很好,但是够用来说明了。
Pull Members Up
@@ -1489,7 +1489,7 @@ str = tableHandler(str重构之前
过多的临时变量会让我们写出更长的函数,函数不应该太多,以便使功能单一。这也是重构的另外的目的所在,只有函数专注于其功能,才会更容易读懂。
以书中的代码为例
-import java.lang.System;
+import java.lang.System;
public class replaceTemp {
public void count() {
@@ -1507,7 +1507,7 @@ str = tableHandler(strReplace Temp With Query
便会返回
-import java.lang.System;
+import java.lang.System;
public class replaceTemp {
public void count() {
@@ -1534,9 +1534,9 @@ str = tableHandler(strpublic class replaceTemp {
public void method() {
- String str = "str";
- String aString = returnString().concat(str);
- System.out.println(aString);
+ String str = "str";
+ String aString = returnString().concat(str);
+ System.out.println(aString);
}
}
@@ -1720,7 +1720,7 @@ public class replaceTemp {
2014年1月1日零时到一时,用户在github上的操作,这里的用户指的是很多。。一共有4814条数据,从commit、create到issues都有。
数据解析
import json
-for line in open(jsonfile):
+for line in open(jsonfile):
line = f.readline()
然后再解析json
import dateutil.parser
@@ -1733,23 +1733,23 @@ date = dateutil.parser.parse(lin["
dataarray = []
datacount = 0
- for line in open(jsonfile):
+ for line in open(jsonfile):
line = f.readline()
lin = json.loads(line)
date = dateutil.parser.parse(lin["created_at"])
datacount += 1
dataarray.append(date.minute)
- minuteswithcount = [(x, dataarray.count(x)) for x in set(dataarray)]
+ minuteswithcount = [(x, dataarray.count(x)) for x in set(dataarray)]
f.close()
return minuteswithcount
下面这句代码就是将上面的解析为
-minuteswithcount = [(x, dataarray.count(x)) for x in set(dataarray)]
+minuteswithcount = [(x, dataarray.count(x)) for x in set(dataarray)]
这样的数组以便于解析
[(0, 92), (1, 67), (2, 86), (3, 73), (4, 76), (5, 67), (6, 61), (7, 71), (8, 62), (9, 71), (10, 70), (11, 79), (12, 62), (13, 67), (14, 76), (15, 67), (16, 74), (17, 48), (18, 78), (19, 73), (20, 89), (21, 62), (22, 74), (23, 61), (24, 71), (25, 49), (26, 59), (27, 59), (28, 58), (29, 74), (30, 69), (31, 59), (32, 89), (33, 67), (34, 66), (35, 77), (36, 64), (37, 71), (38, 75), (39, 66), (40, 62), (41, 77), (42, 82), (43, 95), (44, 77), (45, 65), (46, 59), (47, 60), (48, 54), (49, 66), (50, 74), (51, 61), (52, 71), (53, 90), (54, 64), (55, 67), (56, 67), (57, 55), (58, 68), (59, 91)]
Matplotlib
开始之前需要安装``matplotlib
-sudo pip install matplotlib
+sudo pip install matplotlib
然后引入这个库
import matplotlib.pyplot as plt
如上面的那个结果,只需要
@@ -1775,14 +1775,14 @@ date = dateutil.parser.parse(lin["
dataarray = []
datacount = 0
- for line in open(jsonfile):
+ for line in open(jsonfile):
line = f.readline()
lin = json.loads(line)
date = dateutil.parser.parse(lin["created_at"])
datacount += 1
dataarray.append(date.minute)
- minuteswithcount = [(x, dataarray.count(x)) for x in set(dataarray)]
+ minuteswithcount = [(x, dataarray.count(x)) for x in set(dataarray)]
f.close()
return minuteswithcount
@@ -1791,7 +1791,7 @@ date = dateutil.parser.parse(lin["
x = []
y = []
mwcs = parse_data(files)
- for mwc in mwcs:
+ for mwc in mwcs:
x.append(mwc[0])
y.append(mwc[1])
@@ -1845,7 +1845,7 @@ draw_date("data/2014-01-01-0.json")重写了一个新的方法用于计算提交数,直至后面才意识到其实我们可以算行数就够了,但是方法上有点hack
def get_minutes_counts_with_id(jsonfile):
datacount, dataarray = handle_json(jsonfile)
- minuteswithcount = [(x, dataarray.count(x)) for x in set(dataarray)]
+ minuteswithcount = [(x, dataarray.count(x)) for x in set(dataarray)]
return minuteswithcount
@@ -1854,7 +1854,7 @@ draw_date("data/2014-01-01-0.json")= []
datacount = 0
- for line in open(jsonfile):
+ for line in open(jsonfile):
line = f.readline()
lin = json.loads(line)
date = dateutil.parser.parse(lin["created_at"])
@@ -1876,7 +1876,7 @@ draw_date("data/2014-01-01-0.json") :rtype : object
"""
monthdaycount = []
- for i in range(1, 20):
+ for i in range(1, 20):
if i < 10:
filename = 'data/2014-02-0' + i.__str__() + '-0.json'
else:
@@ -1896,7 +1896,7 @@ draw_date("data/2014-01-01-0.json")__getslice__(14, 21), label="third week")
plt.legend()
plt.show()
-蓝色的是第一周,绿色的是第二周,蓝色的是第三周就有了上面的结果。
+蓝色的是第一周,绿色的是第二周,红色的是第三周就有了上面的结果。
我们还需要优化方法,以及多线程的支持。
让我们分析之前的程序,然后再想办法做出优化。网上看到一篇文章http://www.huyng.com/posts/python-performance-analysis/讲的就是分析这部分内容的。
存储到数据库中
@@ -1911,43 +1911,43 @@ draw_date("data/2014-01-01-0.json")= 0
userinfo = []
condition = 'select * from userinfo where owener = \'' + str(username) + '\''
- for zero in c.execute(condition):
+ for zero in c.execute(condition):
count += 1
userinfo.append(zero)
return count, userinfo
当我查询gmszone的时候,也就是我自己就会有如下的结果
-(u'gmszone', u'ForkEvent', u'RESUME', u'TeX', u'https://github.com/gmszone/RESUME')
-(u'gmszone', u'WatchEvent', u'iot-dashboard', u'JavaScript', u'https://github.com/gmszone/iot-dashboard')
-(u'gmszone', u'PushEvent', u'wechat-wordpress', u'Ruby', u'https://github.com/gmszone/wechat-wordpress')
-(u'gmszone', u'WatchEvent', u'iot', u'JavaScript', u'https://github.com/gmszone/iot')
-(u'gmszone', u'CreateEvent', u'iot-doc', u'None', u'https://github.com/gmszone/iot-doc')
-(u'gmszone', u'CreateEvent', u'iot-doc', u'None', u'https://github.com/gmszone/iot-doc')
-(u'gmszone', u'PushEvent', u'iot-doc', u'TeX', u'https://github.com/gmszone/iot-doc')
-(u'gmszone', u'PushEvent', u'iot-doc', u'TeX', u'https://github.com/gmszone/iot-doc')
-(u'gmszone', u'PushEvent', u'iot-doc', u'TeX', u'https://github.com/gmszone/iot-doc')
-109
+(u'gmszone', u'ForkEvent', u'RESUME', u'TeX', u'https://github.com/gmszone/RESUME')
+(u'gmszone', u'WatchEvent', u'iot-dashboard', u'JavaScript', u'https://github.com/gmszone/iot-dashboard')
+(u'gmszone', u'PushEvent', u'wechat-wordpress', u'Ruby', u'https://github.com/gmszone/wechat-wordpress')
+(u'gmszone', u'WatchEvent', u'iot', u'JavaScript', u'https://github.com/gmszone/iot')
+(u'gmszone', u'CreateEvent', u'iot-doc', u'None', u'https://github.com/gmszone/iot-doc')
+(u'gmszone', u'CreateEvent', u'iot-doc', u'None', u'https://github.com/gmszone/iot-doc')
+(u'gmszone', u'PushEvent', u'iot-doc', u'TeX', u'https://github.com/gmszone/iot-doc')
+(u'gmszone', u'PushEvent', u'iot-doc', u'TeX', u'https://github.com/gmszone/iot-doc')
+(u'gmszone', u'PushEvent', u'iot-doc', u'TeX', u'https://github.com/gmszone/iot-doc')
+109
一共有109个事件,有Watch,Create,Push,Fork还有其他的, 项目主要有iot,RESUME,iot-dashboard,wechat-wordpress, 接着就是语言了,Tex,Javascript,Ruby,接着就是项目的url了。
值得注意的是。
--rw-r--r-- 1 fdhuang staff 905M Apr 12 14:59 userdata.db
+-rw-r--r-- 1 fdhuang staff 905M Apr 12 14:59 userdata.db
这个数据库文件有905M,不过查询结果相当让人满意,至少相对于原来的结果来说。
Python自带了对SQLite3的支持,然而我们还需要安装SQLite3
-brew install sqlite3
+brew install sqlite3
或者是
-sudo port install sqlite3
+sudo port install sqlite3
或者是Ubuntu的
-sudo apt-get install sqlite3
+sudo apt-get install sqlite3
openSUSE自然就是
-sudo zypper install sqlite3
+sudo zypper install sqlite3
不过,用yast2也很不错,不是么。。
数据导入
需要注意的是这里是需要python2.7,起源于对gzip的上下文管理器的支持问题
def handle_gzip_file(filename):
userinfo = []
with gzip.GzipFile(filename) as f:
- events = [line.decode("utf-8", errors="ignore") for line in f]
+ events = [line.decode("utf-8", errors="ignore") for line in f]
- for n, line in enumerate(events):
+ for n, line in enumerate(events):
try:
event = json.loads(line)
except:
@@ -1956,7 +1956,7 @@ draw_date("data/2014-01-01-0.json")= event["actor"]
attrs = event.get("actor_attributes", {})
- if actor is None or attrs.get("type") != "User":
+ if actor is None or attrs.get("type") != "User":
continue
key = actor.lower()
@@ -1976,7 +1976,7 @@ draw_date("data/2014-01-01-0.json")= 2014
month = 3
- for day in range(1,31):
+ for day in range(1,31):
date_re = re.compile(r"([0-9]{4})-([0-9]{2})-([0-9]{2})-([0-9]+)\.json.gz")
fn_template = os.path.join("march",
@@ -1984,7 +1984,7 @@ draw_date("data/2014-01-01-0.json")= {"year": year, "month": month, "day": day, "n": "*"}
filenames = glob.glob(fn_template.format(**kwargs))
- for filename in filenames:
+ for filename in filenames:
c.executemany('INSERT INTO userinfo VALUES (?,?,?,?,?)', handle_gzip_file(filename))
conn.commit()
@@ -2010,11 +2010,11 @@ pipe = pipe = r.pipeline()
pipe.zscore('osrc:user',"gmszone")
pipe.execute()
系统返回了227.0,试试别人。
->>> pipe.zscore('osrc:user',"dfm")
-<redis.client.StrictPipeline object at 0x104fa7f50>
->>> pipe.execute()
-[425.0]
->>>
+>>> pipe.zscore('osrc:user',"dfm")
+<redis.client.StrictPipeline object at 0x104fa7f50>
+>>> pipe.execute()
+[425.0]
+>>>
看看主要是在哪一天提交的
>>> pipe.hgetall('osrc:user:gmszone:day')
<redis.client.StrictPipeline object at 0x104fa7f50>
@@ -2041,7 +2041,7 @@ pipe.execute()
r = redis.StrictRedis(host='localhost', port=6379, db=0)
no_pipe = False
- if pipe is None:
+ if pipe is None:
pipe = pipe = r.pipeline()
no_pipe = True
@@ -2097,12 +2097,12 @@ pipe.execute()
points[0] = 1.0 / (total + 1)
# Week means.
- for k, v in results[1].iteritems():
+ for k, v in results[1].iteritems():
points[1 + int(k)] = float(v) / total
# Event types.
n = 8
- for k, v in results[2]:
+ for k, v in results[2]:
points[n + evttypes.index(k)] = float(v) / total
# Number of contributions, connections and languages.
@@ -2114,8 +2114,8 @@ pipe.execute()
# Top languages.
n += 4
- for k, v in results[7]:
- if k in langs:
+ for k, v in results[7]:
+ if k in langs:
points[n + langs.index(k)] = float(v) / total
else:
# Unknown language.
@@ -2212,7 +2212,7 @@ pipe.execute()

Longest Streak
-在停地造轮子的过程中,也不停地造车子。
+在不停地造轮子的过程中,也不停地造车子。
在那篇连续冲击365天的文章出现之前,我们公司的大大(https://github.com/dreamhead)也曾经在公司内部说过,天天commit什么的。当然这不是我的动力,在连击140天之前
- 给过google的
ngx_speed、node-coap等项目创建过pull request
@@ -2446,7 +2446,7 @@ pipe.execute()
创造是一种知识的再掌握过程。
回顾一下写echoesworks的过程,一开始我需要的是一个网页版的PPT,当然这类的东西已经有很多了,如impress.js、bespoke.js等等。分析一下所需要的功能:markdown解析器、键盘事件处理、Ajax、进度条显示、图片处理、Slide。我们可以在GitHub上找到各式各样的模块,我们所要做的就是将之结合在一样。在那之前,我试着用类似的原理写(组合)了Lettuce。
组合相比于创造过程是一个更有挑战性的过程,我们需要在这过程去设计胶水来粘合这些代码,并在最终可以让他工作。这好比是我们在平时接触到的任务划分,每个人负责相应的模块,最后整合。
-想似的我在写lan的时候,也是类似的,但是不同的是我已经设计了一个清晰的架构图。
+我在写lan的时候,也是类似的,但是不同的是我已经设计了一个清晰的架构图。

Lan IoT