diff --git a/chapters/01-start-project.md b/chapters/01-start-project.md index 95d3ea3..e8c1fbb 100644 --- a/chapters/01-start-project.md +++ b/chapters/01-start-project.md @@ -6,20 +6,51 @@ 取一个好的名字 --- +### 保持命令规则 +个性化,如同 ID 一般。 挑选好 LICENSE --- +事实上,在我们看到的一些外版书籍上,如果拥有代码。那么作者一般就会在前言或者类似的位置里,指明书中代码的版权所属。 + +如: + +> 也许你需要在自己的程序或文档中用到本书的代码,但除非大篇幅地使用,否则不必与我们联系取得授权。例如,用本书中的几段代码编写程序无需请求许可,blabla。 + ![License 使用情况](./img/permissive-vs-copylift-license-2.jpg) +### 公有领域 + +> WTFPL(Do What The Fuck You Want To Public License,中文译名:你他妈的想干嘛就干嘛公共许可证)是一种不太常用的、极度放任的自由软件许可证。它的条款基本等同于贡献到公有领域。[^wtfpl] + +[^wtfpl]: https://zh.wikipedia.org/wiki/WTFPL + +这取决于 + ### GPL -### BSD +由于 GPL 的传染性,便意味着,他人引用我们的代码时,其所写的代码也需要使用 GPL 开源。即:GPL 是有 “传染性” 的 “病毒” ,因为 GPL 条款规定演绎作品也必须是 GPL 的。 + +而如果我们只针对的是,他人可以使用库,而不开源,则可以用 LGPL。但是修改库则不适用。 ### MIT -### Creative Common +因此,一般而言,我使用的是 MIT 协议。至少我保留了一个署名权,即你可以修改我的代码,但是在 LICENSE 里必须加上我的名字。 + +### Creative Commons + +是的,当我写 Markdown 的时候,考虑到未来会以纸质书的形式出现,便会使用 CC-BY-NC-ND 协议: + + - cc -> Creative Commons + - by -> 署名(英语:Attribution,by) + - NC -> 非商业性使用(英语:NonCommercial) + - 禁止演绎 ->(英语:NoDerivs)。 + +即,任何人可以使用我写的电子书来自由复制、散布、展示及演出,但是不得用于商业用途(作者本人可以)。它可以随意地放在他的博客上,他的各个文章里。但是必须标明出自,并且不得改变、转变或更改本作品。 + +如果你不介意的话,你可以使用公有领域(Public Domain)。可是这样一来,万一有一天,别人直接拿的作品出书,你就骂爹了。 官方主页 --- diff --git a/chapters/10-git-tools.md b/chapters/10-git-tools.md index 543757f..6cb94c2 100644 --- a/chapters/10-git-tools.md +++ b/chapters/10-git-tools.md @@ -1,11 +1,7 @@ Git 与 GitHub 工具推荐 === -至于我的日常用的 Git 观看工具,一个是 WebStorm 和 Intellij IDEA 自带的,一个则是 SourceTree。 -由于日常用的开发工是 Intellij IDEA 企业版,所以就有点依赖于这个工具了。最常用的功能便是:**修复 Bug 时,对于文件修改的追溯**。了解某行代码修改的原因,对应的修改人等等。 - -而 SourceTree 则方便用来查看一些非我写的项目,寻找其中的一些问题。个中缘由便是:**Intelli IDEA 刚打开某个项目的时候,需要花费大量的时间 index**,只可惜现有的 SourceTree 客户端都需要登录 Atlassian 账户了。 Git 命令行增强 --- @@ -56,12 +52,17 @@ $ git-summary Intellij IDEA --- + +由于日常用的开发工是 Intellij IDEA 企业版,所以就有点依赖于这个工具了。最常用的功能便是:**修复 Bug 时,对于文件修改的追溯**。了解某行代码修改的原因,对应的修改人等等。 + Intellij IDEA Git、GitHub桌面增强 --- -### SourceTree +### SourceTree + +SourceTree 方便用来查看一些非我写的项目,寻找其中的一些问题。个中缘由便是:**Intelli IDEA 刚打开某个项目的时候,需要花费大量的时间 index**,只可惜现有的 SourceTree 客户端都需要登录 Atlassian 账户了。 gitflow 分支合并、查看 diff --git a/github-roam.md b/github-roam.md index e7a223f..32cd337 100644 --- a/github-roam.md +++ b/github-roam.md @@ -88,20 +88,51 @@ 取一个好的名字 --- +### 保持命令规则 +个性化,如同 ID 一般。 挑选好 LICENSE --- +事实上,在我们看到的一些外版书籍上,如果拥有代码。那么作者一般就会在前言或者类似的位置里,指明书中代码的版权所属。 + +如: + +> 也许你需要在自己的程序或文档中用到本书的代码,但除非大篇幅地使用,否则不必与我们联系取得授权。例如,用本书中的几段代码编写程序无需请求许可,blabla。 + ![License 使用情况](./img/permissive-vs-copylift-license-2.jpg) +### 公有领域 + +> WTFPL(Do What The Fuck You Want To Public License,中文译名:你他妈的想干嘛就干嘛公共许可证)是一种不太常用的、极度放任的自由软件许可证。它的条款基本等同于贡献到公有领域。[^wtfpl] + +[^wtfpl]: https://zh.wikipedia.org/wiki/WTFPL + +这取决于 + ### GPL -### BSD +由于 GPL 的传染性,便意味着,他人引用我们的代码时,其所写的代码也需要使用 GPL 开源。即:GPL 是有 “传染性” 的 “病毒” ,因为 GPL 条款规定演绎作品也必须是 GPL 的。 + +而如果我们只针对的是,他人可以使用库,而不开源,则可以用 LGPL。但是修改库则不适用。 ### MIT -### Creative Common +因此,一般而言,我使用的是 MIT 协议。至少我保留了一个署名权,即你可以修改我的代码,但是在 LICENSE 里必须加上我的名字。 + +### Creative Commons + +是的,当我写 Markdown 的时候,考虑到未来会以纸质书的形式出现,便会使用 CC-BY-NC-ND 协议: + + - cc -> Creative Commons + - by -> 署名(英语:Attribution,by) + - NC -> 非商业性使用(英语:NonCommercial) + - 禁止演绎 ->(英语:NoDerivs)。 + +即,任何人可以使用我写的电子书来自由复制、散布、展示及演出,但是不得用于商业用途(作者本人可以)。它可以随意地放在他的博客上,他的各个文章里。但是必须标明出自,并且不得改变、转变或更改本作品。 + +如果你不介意的话,你可以使用公有领域(Public Domain)。可是这样一来,万一有一天,别人直接拿的作品出书,你就骂爹了。 官方主页 --- @@ -1897,11 +1928,7 @@ Release Git 与 GitHub 工具推荐 === -至于我的日常用的 Git 观看工具,一个是 WebStorm 和 Intellij IDEA 自带的,一个则是 SourceTree。 -由于日常用的开发工是 Intellij IDEA 企业版,所以就有点依赖于这个工具了。最常用的功能便是:**修复 Bug 时,对于文件修改的追溯**。了解某行代码修改的原因,对应的修改人等等。 - -而 SourceTree 则方便用来查看一些非我写的项目,寻找其中的一些问题。个中缘由便是:**Intelli IDEA 刚打开某个项目的时候,需要花费大量的时间 index**,只可惜现有的 SourceTree 客户端都需要登录 Atlassian 账户了。 Git 命令行增强 --- @@ -1952,12 +1979,17 @@ $ git-summary Intellij IDEA --- + +由于日常用的开发工是 Intellij IDEA 企业版,所以就有点依赖于这个工具了。最常用的功能便是:**修复 Bug 时,对于文件修改的追溯**。了解某行代码修改的原因,对应的修改人等等。 + Intellij IDEA Git、GitHub桌面增强 --- -### SourceTree +### SourceTree + +SourceTree 方便用来查看一些非我写的项目,寻找其中的一些问题。个中缘由便是:**Intelli IDEA 刚打开某个项目的时候,需要花费大量的时间 index**,只可惜现有的 SourceTree 客户端都需要登录 Atlassian 账户了。 gitflow 分支合并、查看 diff --git a/index.html b/index.html index 974a1c5..8e11196 100644 --- a/index.html +++ b/index.html @@ -77,12 +77,14 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
  • 创建开源项目
  • @@ -311,14 +313,37 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf

    创建开源项目

    人们创建

    取一个好的名字

    +

    保持命令规则

    +

    个性化,如同 ID 一般。

    挑选好 LICENSE

    +

    事实上,在我们看到的一些外版书籍上,如果拥有代码。那么作者一般就会在前言或者类似的位置里,指明书中代码的版权所属。

    +

    如:

    +
    +

    也许你需要在自己的程序或文档中用到本书的代码,但除非大篇幅地使用,否则不必与我们联系取得授权。例如,用本书中的几段代码编写程序无需请求许可,blabla。

    +
    License 使用情况
    License 使用情况
    +

    公有领域

    +
    +

    WTFPL(Do What The Fuck You Want To Public License,中文译名:你他妈的想干嘛就干嘛公共许可证)是一种不太常用的、极度放任的自由软件许可证。它的条款基本等同于贡献到公有领域。1

    +
    +

    这取决于

    GPL

    -

    BSD

    +

    由于 GPL 的传染性,便意味着,他人引用我们的代码时,其所写的代码也需要使用 GPL 开源。即:GPL 是有 “传染性” 的 “病毒” ,因为 GPL 条款规定演绎作品也必须是 GPL 的。

    +

    而如果我们只针对的是,他人可以使用库,而不开源,则可以用 LGPL。但是修改库则不适用。

    MIT

    -

    Creative Common

    +

    因此,一般而言,我使用的是 MIT 协议。至少我保留了一个署名权,即你可以修改我的代码,但是在 LICENSE 里必须加上我的名字。

    +

    Creative Commons

    +

    是的,当我写 Markdown 的时候,考虑到未来会以纸质书的形式出现,便会使用 CC-BY-NC-ND 协议:

    + +

    即,任何人可以使用我写的电子书来自由复制、散布、展示及演出,但是不得用于商业用途(作者本人可以)。它可以随意地放在他的博客上,他的各个文章里。但是必须标明出自,并且不得改变、转变或更改本作品。

    +

    如果你不介意的话,你可以使用公有领域(Public Domain)。可是这样一来,万一有一天,别人直接拿的作品出书,你就骂爹了。

    官方主页

    一个好的例子是 GitHub Pages

    然后,创建

    @@ -1331,16 +1356,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不知道他们表达的是什么意思,于是。

    @@ -1352,16 +1377,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

    @@ -1373,16 +1398,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

    @@ -1394,12 +1419,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

    @@ -1439,7 +1464,7 @@ str = tableHandler(str重构之前

    过多的临时变量会让我们写出更长的函数,函数不应该太多,以便使功能单一。这也是重构的另外的目的所在,只有函数专注于其功能,才会更容易读懂。

    以书中的代码为例

    -
    import java.lang.System;
    +
    import java.lang.System;
     
     public class replaceTemp {
         public void count() {
    @@ -1457,7 +1482,7 @@ str = tableHandler(str
    Replace Temp With Query

    便会返回

    -
    import java.lang.System;
    +
    import java.lang.System;
     
     public class replaceTemp {
         public void count() {
    @@ -1484,9 +1509,9 @@ str = tableHandler(str
    public 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);
         }
     
     }
    @@ -1521,9 +1546,9 @@ public class replaceTemp { return res.end('Unauthorized'); }

    可是除了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 -T
    +
    coap-client -m get coap://127.0.0.1:5683/topics/zero -T

    于是,先写了个测试脚本来验证功能。

    var coap     = require('coap');
     var request  = coap.request;
    @@ -1817,9 +1842,6 @@ app.listen(3000);

    开源项目维护

    Release

    Git 与 GitHub 工具推荐

    -

    至于我的日常用的 Git 观看工具,一个是 WebStorm 和 Intellij IDEA 自带的,一个则是 SourceTree。

    -

    由于日常用的开发工是 Intellij IDEA 企业版,所以就有点依赖于这个工具了。最常用的功能便是:修复 Bug 时,对于文件修改的追溯。了解某行代码修改的原因,对应的修改人等等。

    -

    而 SourceTree 则方便用来查看一些非我写的项目,寻找其中的一些问题。个中缘由便是:Intelli IDEA 刚打开某个项目的时候,需要花费大量的时间 index,只可惜现有的 SourceTree 客户端都需要登录 Atlassian 账户了。

    Git 命令行增强

    diff-so-fancy

    @@ -1853,9 +1875,11 @@ app.listen(3000);
    1 oncealong 0.8% 1 zminds 0.8%

    Intellij IDEA

    +

    由于日常用的开发工是 Intellij IDEA 企业版,所以就有点依赖于这个工具了。最常用的功能便是:修复 Bug 时,对于文件修改的追溯。了解某行代码修改的原因,对应的修改人等等。

    Intellij IDEA

    Git、GitHub桌面增强

    SourceTree

    +

    SourceTree 方便用来查看一些非我写的项目,寻找其中的一些问题。个中缘由便是:Intelli IDEA 刚打开某个项目的时候,需要花费大量的时间 index,只可惜现有的 SourceTree 客户端都需要登录 Atlassian 账户了。

    gitflow 分支合并、查看

    SourceTree 截图
    SourceTree 截图
    @@ -1927,7 +1951,7 @@ Set up your git name and email, this is important so that your commits can be id

    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
    @@ -1940,23 +1964,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

    如上面的那个结果,只需要

    @@ -1982,14 +2006,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 @@ -1998,7 +2022,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]) @@ -2052,7 +2076,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
     
     
    @@ -2061,7 +2085,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"])
    @@ -2083,7 +2107,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:
    @@ -2118,43 +2142,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:
    @@ -2163,7 +2187,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()
    @@ -2183,7 +2207,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",
    @@ -2191,7 +2215,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()
    @@ -2217,11 +2241,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>
    @@ -2248,7 +2272,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 @@ -2304,12 +2328,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. @@ -2321,8 +2345,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. @@ -2989,5 +3013,11 @@ pipe.execute()

    不过,最好的开源项目就是自己平时用的。于是,我开始将写各种工作来提自己使用——如现在在用的这篇微信编辑工具:mdpub

    最后,我做了一个简单的 HTML 5 动画来记录这一时刻,作为这一个里程碑的记念:

    https://phodal.github.io/20k/

    +
    +
    +
      +
    1. https://zh.wikipedia.org/wiki/WTFPL

    2. +
    +