mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-27 02:30:10 +08:00
commit
9ac7a32420
@ -1,256 +1,189 @@
|
||||
如何使用 Emacs 创建 LaTeX 文档
|
||||
======
|
||||
> 这篇教程将带你遍历在 Emacs 使用强大的开源排版系统 LaTex 来创建文档的全过程。
|
||||
|
||||

|
||||
|
||||
一篇由 Aaron Cocker 写的很棒的文章 [An introduction to creating documents in LaTeX][1] 中,介绍了 LaTeX 排版系统 [LaTeX typesetting system][3] 并描述了如何使用 [TeXstudio][4] 来创建 LaTeX 文档。同时,他也列举了一些很多用户觉得创建 LaTeX 文档很方便的编辑器。
|
||||
一篇由 Aaron Cocker 写的很棒的文章 “[在 LaTeX 中创建文件的介绍][1]” 中,介绍了 [LaTeX 排版系统][3] 并描述了如何使用 [TeXstudio][4] 来创建 LaTeX 文档。同时,他也列举了一些很多用户觉得创建 LaTeX 文档很方便的编辑器。
|
||||
|
||||
[Greg Pittman][5] 对这篇文章的评论吸引了我:“当你第一次开始使用 LaTeX 时,他似乎是个和差劲的排版。。。” 事实也确实如此。LaTeX 包含了多种排版字体和调试,如果你漏了一个特殊的字符比如说感叹号,这会阻碍很多用户,尤其是新手。在本文中,我将介绍如何使用 [GNU Emacs][6] 来创建 LaTeX 文档。
|
||||
[Greg Pittman][5] 对这篇文章的评论吸引了我:“当你第一次开始使用 LaTeX 时,他似乎是个很差劲的排版……” 事实也确实如此。LaTeX 包含了多种排版字体和调试,如果你漏了一个特殊的字符比如说感叹号,这会让很多用户感到沮丧,尤其是新手。在本文中,我将介绍如何使用 [GNU Emacs][6] 来创建 LaTeX 文档。
|
||||
|
||||
### 创建你的第一个文档
|
||||
启动 Emacs:
|
||||
|
||||
启动 Emacs:
|
||||
|
||||
```
|
||||
emacs -q --no-splash helloworld.org
|
||||
```
|
||||
参数 `-q` 确保 Emacs 不会加载其他的初始化配置。参数 `--no-splash-screen` 防止 emacs 打开多个窗口,确保只打开一个窗口,最后的参数 `helloworld.org` 表示你要创建的文件名为 `helloworld.org` 。
|
||||
|
||||
参数 `-q` 确保 Emacs 不会加载其他的初始化配置。参数 `--no-splash-screen` 防止 Emacs 打开多个窗口,确保只打开一个窗口,最后的参数 `helloworld.org` 表示你要创建的文件名为 `helloworld.org` 。
|
||||
|
||||
![Emacs startup screen][8]
|
||||
|
||||
GNU Emacs 打开文件名为 helloworld.org 的窗口时的样子。
|
||||
*GNU Emacs 打开文件名为 helloworld.org 的窗口时的样子。*
|
||||
|
||||
现在让我们用 Emacs 添加一些 LaTeX 的标题吧: 在菜单栏找到 **Org** 选项并选择 **Export/Publish**.
|
||||
现在让我们用 Emacs 添加一些 LaTeX 的标题吧:在菜单栏找到 “Org” 选项并选择 “Export/Publish”。
|
||||
|
||||
![template_flow.png][10]
|
||||
|
||||
导入一个默认的模板:
|
||||
*导入一个默认的模板*
|
||||
|
||||
在下一个窗口中,Emacs 同时提供了导入和导出一个模板。使用 #([#] Insert template)来导入一个模板。这将会是光标跳转到一个带有 **Options category:** 提示的 mini-buffer 中。第一次你可能不知道这个类型的名字,但是你可以使用 Tab 键来查看所有的补全。输入 “default” 然后按回车,之后你就能看到如下的内容被插入了:
|
||||
在下一个窗口中,Emacs 同时提供了导入和导出一个模板。输入 `#`(“[#] Insert template”)来导入一个模板。这将会使光标跳转到一个带有 “Options category:” 提示的 mini-buffer 中。第一次你可能不知道这个类型的名字,但是你可以使用 `Tab` 键来查看所有的补全。输入 “default” 然后按回车,之后你就能看到如下的内容被插入了:
|
||||
|
||||
```
|
||||
#+TITLE: helloworld
|
||||
|
||||
#+DATE: <2018-03-12 Mon>
|
||||
|
||||
#+AUTHOR:
|
||||
|
||||
#+EMAIL: makerpm@nubia
|
||||
|
||||
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
|
||||
|
||||
#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
|
||||
|
||||
#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
|
||||
|
||||
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
|
||||
|
||||
#+CREATOR: Emacs 25.3.1 (Org mode 8.2.10)
|
||||
|
||||
#+DESCRIPTION:
|
||||
|
||||
#+EXCLUDE_TAGS: noexport
|
||||
|
||||
#+KEYWORDS:
|
||||
|
||||
#+LANGUAGE: en
|
||||
|
||||
#+SELECT_TAGS: export
|
||||
|
||||
```
|
||||
|
||||
根据自己的需求修改标题,日期,作者和 email。我自己的话是下面这样的:
|
||||
根据自己的需求修改标题、日期、作者和 email。我自己的话是下面这样的:
|
||||
|
||||
```
|
||||
#+TITLE: Hello World! My first LaTeX document
|
||||
|
||||
#+DATE: \today
|
||||
|
||||
#+AUTHOR: Sachin Patil
|
||||
|
||||
#+EMAIL: psachin@redhat.com
|
||||
|
||||
```
|
||||
|
||||
我们目前还不想创建一个目录,所以要将 `toc` 的值由 `t` 改为 `nil`,具体如下:
|
||||
|
||||
```
|
||||
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:nil todo:t |:t
|
||||
|
||||
```
|
||||
|
||||
现在让我们添加一个章节和段落吧。章节是由一个星号(*)开头。我们从 Aaron 的贴子([Lipsum Lorem Ipsum generator][11])复制一些文本过来:
|
||||
现在让我们添加一个章节和段落吧。章节是由一个星号(`*`)开头。我们从 Aaron 的贴子(来自 [Lipsum Lorem Ipsum 生成器][11])复制一些文本过来:
|
||||
|
||||
```
|
||||
* Introduction
|
||||
|
||||
\paragraph{}
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem
|
||||
nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in
|
||||
diam libero. Nunc tristique ex a nibh egestas sollicitudin.
|
||||
|
||||
|
||||
\paragraph{}
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem
|
||||
|
||||
nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in
|
||||
|
||||
diam libero. Nunc tristique ex a nibh egestas sollicitudin.
|
||||
|
||||
|
||||
|
||||
\paragraph{}
|
||||
|
||||
Mauris efficitur vitae ex id egestas. Vestibulum ligula felis,
|
||||
|
||||
pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non
|
||||
|
||||
elementum leo. Nullam molestie congue placerat. Phasellus tempor et
|
||||
|
||||
libero maximus commodo.
|
||||
|
||||
\paragraph{}
|
||||
Mauris efficitur vitae ex id egestas. Vestibulum ligula felis,
|
||||
pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non
|
||||
elementum leo. Nullam molestie congue placerat. Phasellus tempor et
|
||||
libero maximus commodo.
|
||||
```
|
||||
|
||||
|
||||
![helloworld_file.png][13]
|
||||
|
||||
helloworld.org 文件
|
||||
*helloworld.org 文件*
|
||||
|
||||
|
||||
将内容修改好后,我们要把它导出为 PDF 格式。再次在 **Org** 的菜单选项中选择 **Export/Publish**,但是这次,要输入 **l**(export to LaTeX),紧跟着输入 **o**(as PDF file and open)。这次操作不止会打开 PDF 文件让你浏览,同时也会将文件保存为 `helloworld.pdf`,并保存在与 `helloworld.org` 的同一个目录下。
|
||||
将内容修改好后,我们要把它导出为 PDF 格式。再次在 “Org” 的菜单选项中选择 “Export/Publish”,但是这次,要输入 `l`(“export to LaTeX”),紧跟着输入 `o`(“as PDF file and open”)。这次操作不止会打开 PDF 文件让你浏览,同时也会将文件保存为 `helloworld.pdf`,并保存在与 `helloworld.org` 的同一个目录下。
|
||||
|
||||
![org_to_pdf.png][15]
|
||||
|
||||
将 helloworld.org 导出为 helloworld.pdf
|
||||
*将 helloworld.org 导出为 helloworld.pdf*
|
||||
|
||||
![org_and_pdf_file.png][17]
|
||||
|
||||
打开 helloworld.pdf 文件
|
||||
*打开 helloworld.pdf 文件*
|
||||
|
||||
你也可以按下 `Alt + x` 键,然后输入 “org-latex-export-to-pdf” 来将 org 文件导出为 PDF 文件。可以使用 Tab 键来自动补全命令。
|
||||
你也可以按下 `Alt + x` 键,然后输入 `org-latex-export-to-pdf` 来将 org 文件导出为 PDF 文件。可以使用 `Tab` 键来自动补全命令。
|
||||
|
||||
Emacs 也会创建 `helloworld.tex` 文件来让你控制具体的内容。
|
||||
|
||||
![org_tex_pdf.png][19]
|
||||
|
||||
Emacs 在三个不同的窗口中分别打开 LaTeX,org 和 PDF 文档。
|
||||
*Emacs 在三个不同的窗口中分别打开 LaTeX,org 和 PDF 文档。*
|
||||
|
||||
你可以使用命令来将 `.tex` 文件转换为 `.pdf` 文件:
|
||||
|
||||
```
|
||||
pdflatex helloworld.tex
|
||||
|
||||
```
|
||||
|
||||
你也可以将 `.org` 文件输出问HTML或是一个简单的文本格式的文件。我最喜欢 .org 文件的原因是他们可以被 push 到 [GitHub][20] 上,然后被渲染的同 markdown 的一样的格式。
|
||||
你也可以将 `.org` 文件输出为 HTML 或是一个简单的文本格式的文件。我最喜欢 `.org` 文件的原因是他们可以被推送到 [GitHub][20] 上,然后同 markdown 一样被渲染。
|
||||
|
||||
### 创建一个 LaTeX 的 Beamer presentation
|
||||
### 创建一个 LaTeX 的 Beamer 简报
|
||||
|
||||
现在让我们更进一步,通过少量的修改上面的文档来创建一个 LaTeX [Beamer][21] 简报,如下所示:
|
||||
|
||||
现在让我们更进一步,通过少量的修改上面的文档来创建一个 LaTeX [Beamer][21]的 presentation,如下所示:
|
||||
```
|
||||
#+TITLE: LaTeX Beamer presentation
|
||||
|
||||
#+DATE: \today
|
||||
|
||||
#+AUTHOR: Sachin Patil
|
||||
|
||||
#+EMAIL: psachin@redhat.com
|
||||
|
||||
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
|
||||
|
||||
#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
|
||||
|
||||
#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
|
||||
|
||||
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:nil todo:t |:t
|
||||
|
||||
#+CREATOR: Emacs 25.3.1 (Org mode 8.2.10)
|
||||
|
||||
#+DESCRIPTION:
|
||||
|
||||
#+EXCLUDE_TAGS: noexport
|
||||
|
||||
#+KEYWORDS:
|
||||
|
||||
#+LANGUAGE: en
|
||||
|
||||
#+SELECT_TAGS: export
|
||||
|
||||
#+LATEX_CLASS: beamer
|
||||
|
||||
#+BEAMER_THEME: Frankfurt
|
||||
|
||||
#+BEAMER_INNER_THEME: rounded
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
* Introduction
|
||||
|
||||
*** Programming
|
||||
|
||||
- Python
|
||||
|
||||
- Ruby
|
||||
|
||||
|
||||
- Python
|
||||
- Ruby
|
||||
|
||||
*** Paragraph one
|
||||
|
||||
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing
|
||||
|
||||
elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat
|
||||
|
||||
ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas
|
||||
|
||||
sollicitudin.
|
||||
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing
|
||||
elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat
|
||||
ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas
|
||||
sollicitudin.
|
||||
|
||||
*** Paragraph two
|
||||
|
||||
|
||||
|
||||
Mauris efficitur vitae ex id egestas. Vestibulum
|
||||
|
||||
ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac
|
||||
|
||||
imperdiet orci, non elementum leo. Nullam molestie congue
|
||||
|
||||
placerat. Phasellus tempor et libero maximus commodo.
|
||||
|
||||
|
||||
Mauris efficitur vitae ex id egestas. Vestibulum
|
||||
ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac
|
||||
imperdiet orci, non elementum leo. Nullam molestie congue
|
||||
placerat. Phasellus tempor et libero maximus commodo.
|
||||
|
||||
* Thanks
|
||||
|
||||
*** Links
|
||||
|
||||
- Link one
|
||||
|
||||
- Link two
|
||||
|
||||
- Link one
|
||||
- Link two
|
||||
```
|
||||
|
||||
We have added three more lines to the header:
|
||||
我们给标题增加了三行:
|
||||
|
||||
```
|
||||
#+LATEX_CLASS: beamer
|
||||
|
||||
#+BEAMER_THEME: Frankfurt
|
||||
|
||||
#+BEAMER_INNER_THEME: rounded
|
||||
|
||||
```
|
||||
|
||||
导出为 PDF,按下 `Alt + x` 键后输入 “org-beamer-export-to-pdf”
|
||||
导出为 PDF,按下 `Alt + x` 键后输入 `org-beamer-export-to-pdf`。
|
||||
|
||||
![latex_beamer_presentation.png][23]
|
||||
|
||||
用 Emacs 和 Org mode 创建的 Latex Beamer persentation
|
||||
*用 Emacs 和 Org 模式创建的 Latex Beamer 简报*
|
||||
|
||||
希望你会爱上使用 Emacs 来创建 LaTex 和 Beamer 文档(注意:使用快捷键比用鼠标更快些)。Emacs 的 Org-mode 提供了比我在这篇文章中说的更多的功能,你可以在 [orgmode.org][24] 获取更多的信息.
|
||||
希望你会爱上使用 Emacs 来创建 LaTex 和 Beamer 文档(注意:使用快捷键比用鼠标更快些)。Emacs 的 Org 模式提供了比我在这篇文章中说的更多的功能,你可以在 [orgmode.org][24] 获取更多的信息.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/4/how-create-latex-documents-emacs
|
||||
|
||||
作者:[Sachin Patil][a]
|
||||
译者:[oneforalone](https://github.com/oneforalone)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[oneforalone](https://github.com/oneforalone)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,17 +1,17 @@
|
||||
将 Grails 与 jQuery 和 DataTables 一起使用
|
||||
在 Grails 中使用 jQuery 和 DataTables
|
||||
======
|
||||
|
||||
本文介绍如何构建一个基于 Grails 的数据浏览器来可视化复杂的表格数据。
|
||||
> 本文介绍如何构建一个基于 Grails 的数据浏览器来可视化复杂的表格数据。
|
||||
|
||||

|
||||
|
||||
我是 [Grails][1] 的忠实粉丝。当然,我主要是热衷于利用命令行工具来探索和分析数据的数据人。数据人经常需要_查看_数据,这也意味着他们通常拥有优秀的数据浏览器。利用 Grails,[jQuery][2],以及 [DataTables jQuery 插件][3],我们可以制作出非常友好的表格数据浏览器。
|
||||
我是 [Grails][1] 的忠实粉丝。当然,我主要是热衷于利用命令行工具来探索和分析数据的数据从业人员。数据从业人员经常需要*查看*数据,这也意味着他们通常拥有优秀的数据浏览器。利用 Grails、[jQuery][2],以及 [DataTables jQuery 插件][3],我们可以制作出非常友好的表格数据浏览器。
|
||||
|
||||
[DataTables 网站][3]提供了许多“食谱风格”的教程文档,展示了如何组合一些优秀的示例应用程序,这些程序包含了完成一些非常漂亮的东西所必要的 JavaScript,HTML,以及偶尔出现的 [PHP][4]。但对于那些宁愿使用 Grails 作为后端的人来说,有必要进行一些说明示教。此外,样本程序中使用的数据是虚构公司的员工的单个平面表数据,因此处理这些复杂的表关系可以作为读者的一个练习项目。
|
||||
[DataTables 网站][3]提供了许多“食谱式”的教程文档,展示了如何组合一些优秀的示例应用程序,这些程序包含了完成一些非常漂亮的东西所必要的 JavaScript、HTML,以及偶尔出现的 [PHP][4]。但对于那些宁愿使用 Grails 作为后端的人来说,有必要进行一些说明示教。此外,样本程序中使用的数据是一个虚构公司的员工的单个平面表格数据,因此处理这些复杂的表关系可以作为读者的一个练习项目。
|
||||
|
||||
本文中,我们将创建具有略微复杂的数据结构和 DataTables 浏览器的 Grails 应用程序。我们将介绍 Grails 标准 [Groovy][5]-fied Java Hibernate 标准。我已将代码托管在 [GitHub][6] 上方便大家访问,因此本文主要是对代码细节的解读。
|
||||
本文中,我们将创建具有略微复杂的数据结构和 DataTables 浏览器的 Grails 应用程序。我们将介绍 Grails 标准,它是 [Groovy][5] 式的 Java Hibernate 标准。我已将代码托管在 [GitHub][6] 上方便大家访问,因此本文主要是对代码细节的解读。
|
||||
|
||||
首先,你需要配置 Java,Groovy,Grails 的使用环境。对于 Grails,我倾向于使用终端窗口和 [Vim][7],本文也使用它们。为获得现代 Java,建议下载并安装 Linux 发行版提供的 [Open Java Development Kit][8] (OpenJDK)(应该是 Java 8,9,10或11,撰写本文时,我正在使用 Java 8)。从我的角度来看,获取最新的 Groovy 和 Grails 的最佳方法是使用 [SKDMAN!][9]。
|
||||
首先,你需要配置 Java、Groovy、Grails 的使用环境。对于 Grails,我倾向于使用终端窗口和 [Vim][7],本文也使用它们。为获得现代的 Java 环境,建议下载并安装 Linux 发行版提供的 [Open Java Development Kit][8] (OpenJDK)(应该是 Java 8、9、10 或 11 之一,撰写本文时,我正在使用 Java 8)。从我的角度来看,获取最新的 Groovy 和 Grails 的最佳方法是使用 [SDKMAN!][9]。
|
||||
|
||||
从未尝试过 Grails 的读者可能需要做一些背景资料阅读。作为初学者,推荐文章 [创建你的第一个 Grails 应用程序][10]。
|
||||
|
||||
@ -34,7 +34,7 @@ grails create-domain-class com.nuevaconsulting.embrow.Employeecd embrowgrails cr
|
||||
|
||||
这种方式构建的域类没有属性,因此必须按如下方式编辑它们:
|
||||
|
||||
Position 域类:
|
||||
`Position` 域类:
|
||||
|
||||
```
|
||||
package com.nuevaconsulting.embrow
|
||||
@ -51,7 +51,7 @@ class Position {
|
||||
}com.Stringint startingstatic constraintsnullableblankstarting nullable
|
||||
```
|
||||
|
||||
Office 域类:
|
||||
`Office` 域类:
|
||||
|
||||
```
|
||||
package com.nuevaconsulting.embrow
|
||||
@ -72,7 +72,7 @@ class Office {
|
||||
}
|
||||
```
|
||||
|
||||
Enployee 域类:
|
||||
`Enployee` 域类:
|
||||
|
||||
```
|
||||
package com.nuevaconsulting.embrow
|
||||
@ -98,7 +98,7 @@ class Employee {
|
||||
}
|
||||
```
|
||||
|
||||
请注意,虽然 Position 和 Office 域类使用了预定义的 Groovy 类型 String 以及 int,但 Employee 域类定义了 Position 和 Office 字段(以及预定义的 Date)。这会导致创建数据库表,其中存储的 Employee 实例中包含了指向存储 Position 和 Office 实例表的引用或者外键。
|
||||
请注意,虽然 `Position` 和 `Office` 域类使用了预定义的 Groovy 类型 `String` 以及 `int`,但 `Employee` 域类定义了 `Position` 和 `Office` 字段(以及预定义的 `Date`)。这会导致创建数据库表,其中存储的 `Employee` 实例中包含了指向存储 `Position` 和 `Office` 实例表的引用或者外键。
|
||||
|
||||
现在你可以生成控制器,视图,以及其他各种测试组件:
|
||||
|
||||
@ -108,7 +108,7 @@ grails generate-all com.nuevaconsulting.embrow.Office
|
||||
grails generate-all com.nuevaconsulting.embrow.Employeegrails generateall com.grails generateall com.grails generateall com.
|
||||
```
|
||||
|
||||
此时,你已经准备好基本的 create-read-update-delete(CRUD)应用程序。我在**grails-app/init/com/nuevaconsulting/BootStrap.groovy**中包含了一些基础数据来填充表格。
|
||||
此时,你已经准备好了一个基本的增删改查(CRUD)应用程序。我在 `grails-app/init/com/nuevaconsulting/BootStrap.groovy` 中包含了一些基础数据来填充表格。
|
||||
|
||||
如果你用如下命令来启动应用程序:
|
||||
|
||||
@ -116,43 +116,44 @@ grails generate-all com.nuevaconsulting.embrow.Employeegrails generateall com.gr
|
||||
grails run-app
|
||||
```
|
||||
|
||||
在浏览器输入**<http://localhost:8080/:>**,你将会看到如下界面:
|
||||
在浏览器输入 `http://localhost:8080/`,你将会看到如下界面:
|
||||
|
||||
![Embrow home screen][12]
|
||||
|
||||
Embrow 应用程序主界面。
|
||||
*Embrow 应用程序主界面。*
|
||||
|
||||
单击 OfficeController,会跳转到如下界面:
|
||||
单击 “OfficeController” 链接,会跳转到如下界面:
|
||||
|
||||
![Office list][14]
|
||||
|
||||
Office 列表
|
||||
*Office 列表*
|
||||
|
||||
注意,此表由 **OfficeController index** 生成,并由视图 `office/index.gsp` 显示。
|
||||
注意,此表由 `OfficeController` 的 `index` 方式生成,并由视图 `office/index.gsp` 显示。
|
||||
|
||||
同样,单击 **EmployeeController** 跳转到如下界面:
|
||||
同样,单击 “EmployeeController” 链接 跳转到如下界面:
|
||||
|
||||
![Employee controller][16]
|
||||
|
||||
employee controller
|
||||
*employee 控制器*
|
||||
|
||||
好吧,这很丑陋: Position 和 Office 链接是什么?
|
||||
|
||||
上面的命令 `generate-all` 生成的视图创建了一个叫 **index.gsp** 的文件,它使用 Grails <f:table/> 标签,该标签默认会显示类名(**com.nuevaconsulting.embrow.Position**)和持久化示例标识符(**30**)。这个操作可以自定义用来产生更好看的东西,并且自动生成链接,自动生成分页以及自动生成可拍序列的一些非常简洁直观的东西。
|
||||
上面的命令 `generate-all` 生成的视图创建了一个叫 `index.gsp` 的文件,它使用 Grails `<f:table/>` 标签,该标签默认会显示类名(`com.nuevaconsulting.embrow.Position`)和持久化示例标识符(`30`)。这个操作可以自定义用来产生更好看的东西,并且自动生成链接,自动生成分页以及自动生成可排序列的一些非常简洁直观的东西。
|
||||
|
||||
但该员工信息浏览器功能也是有限的。例如,如果想查找 position 信息中包含 “dev” 的员工该怎么办?如果要组合排序,以姓氏为主排序关键字,office 为辅助排序关键字,该怎么办?或者,你需要将已排序的数据导出到电子表格或 PDF 文档以便通过电子邮件发送给无法访问浏览器的人,该怎么办?
|
||||
但该员工信息浏览器功能也是有限的。例如,如果想查找 “position” 信息中包含 “dev” 的员工该怎么办?如果要组合排序,以姓氏为主排序关键字,“office” 为辅助排序关键字,该怎么办?或者,你需要将已排序的数据导出到电子表格或 PDF 文档以便通过电子邮件发送给无法访问浏览器的人,该怎么办?
|
||||
|
||||
jQuery DataTables 插件提供了这些所需的功能。允许你创建一个完成的表格数据浏览器。
|
||||
|
||||
### 创建员工信息浏览器视图和控制器的方法
|
||||
|
||||
要基于 jQuery DataTables 创建员工信息浏览器,你必须先完成以下两个任务:
|
||||
1. 创建 Grails 视图,其中包含启用 DataTable 所需的 HTML 和 JavaScript
|
||||
|
||||
1. 创建 Grails 视图,其中包含启用 DataTable 所需的 HTML 和 JavaScript
|
||||
2. 给 Grails 控制器增加一个方法来控制新视图。
|
||||
|
||||
#### 员工信息浏览器视图
|
||||
|
||||
在目录 **embrow/grails-app/views/employee** 中,首先复制 **index.gsp** 文件,重命名为 **browser.gsp**:
|
||||
在目录 `embrow/grails-app/views/employee` 中,首先复制 `index.gsp` 文件,重命名为 `browser.gsp`:
|
||||
|
||||
```
|
||||
cd Projects
|
||||
@ -160,7 +161,7 @@ cd embrow/grails-app/views/employee
|
||||
cp gsp browser.gsp
|
||||
```
|
||||
|
||||
此刻,你自定义新的 **browser.gsp** 文件来添加相关的 jQuery DataTables 代码。
|
||||
此刻,你自定义新的 `browser.gsp` 文件来添加相关的 jQuery DataTables 代码。
|
||||
|
||||
通常,在可能的时候,我喜欢从内容提供商处获得 JavaScript 和 CSS;在下面这行后面:
|
||||
|
||||
@ -185,7 +186,7 @@ cp gsp browser.gsp
|
||||
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js "></script>
|
||||
```
|
||||
|
||||
然后删除 **index.gsp** 中提供数据分页的代码:
|
||||
然后删除 `index.gsp` 中提供数据分页的代码:
|
||||
|
||||
```
|
||||
<div id="list-employee" class="content scaffold-list" role="main">
|
||||
@ -253,7 +254,7 @@ $(this).html('<input type="text" size="15" placeholder="' + title + '?" />');
|
||||
});titletitletitletitletitle
|
||||
```
|
||||
|
||||
接下来,定义表模型。 这是提供所有表选项的地方,包括界面的滚动,而不是分页,根据 dom 字符串提供的装饰,将数据导出为 CSV 和其他格式的能力,以及建立与服务器的 Ajax 连接。 请注意,使用 Groovy GString 调用 Grails **createLink()** 的方法创建 URL,在 **EmployeeController** 中指向 **browserLister** 操作。同样有趣的是表格列的定义。此信息将发送到后端,后端查询数据库并返回相应的记录。
|
||||
接下来,定义表模型。这是提供所有表选项的地方,包括界面的滚动,而不是分页,根据 DOM 字符串提供的装饰,将数据导出为 CSV 和其他格式的能力,以及建立与服务器的 AJAX 连接。 请注意,使用 Groovy GString 调用 Grails `createLink()` 的方法创建 URL,在 `EmployeeController` 中指向 `browserLister` 操作。同样有趣的是表格列的定义。此信息将发送到后端,后端查询数据库并返回相应的记录。
|
||||
|
||||
```
|
||||
var table = $('#employee_dt').DataTable( {
|
||||
@ -302,7 +303,7 @@ that.search(this.value).draw();
|
||||
|
||||

|
||||
|
||||
这是另一个屏幕截图,显示了过滤和多列排序(寻找 position 包括字符 “dev” 的员工,先按 office 排序,然后按姓氏排序):
|
||||
这是另一个屏幕截图,显示了过滤和多列排序(寻找 “position” 包括字符 “dev” 的员工,先按 “office” 排序,然后按姓氏排序):
|
||||
|
||||

|
||||
|
||||
@ -314,37 +315,37 @@ that.search(this.value).draw();
|
||||
|
||||

|
||||
|
||||
好的,视图部分看起来非常简单; 因此,控制器必须做所有繁重的工作,对吧? 让我们来看看…
|
||||
好的,视图部分看起来非常简单;因此,控制器必须做所有繁重的工作,对吧? 让我们来看看……
|
||||
|
||||
#### 控制器 browserLister 操作
|
||||
|
||||
回想一下,我们看到过这个字符串
|
||||
回想一下,我们看到过这个字符串:
|
||||
|
||||
```
|
||||
"${createLink(controller: 'employee', action: 'browserLister')}"
|
||||
```
|
||||
|
||||
对于从 DataTables 模型中调用 Ajax 的 URL,是在 Grails 服务器上动态创建 HTML 链接,其 Grails 标记背后通过调用 [createLink()][17] 的方法实现的。这会最终产生一个指向 **EmployeeController** 的链接,位于:
|
||||
对于从 DataTables 模型中调用 AJAX 的 URL,是在 Grails 服务器上动态创建 HTML 链接,其 Grails 标记背后通过调用 [createLink()][17] 的方法实现的。这会最终产生一个指向 `EmployeeController` 的链接,位于:
|
||||
|
||||
```
|
||||
embrow/grails-app/controllers/com/nuevaconsulting/embrow/EmployeeController.groovy
|
||||
```
|
||||
|
||||
特别是控制器方法 **browserLister()**。我在代码中留了一些 print 语句,以便在运行时能够在终端看到中间结果。
|
||||
特别是控制器方法 `browserLister()`。我在代码中留了一些 `print` 语句,以便在运行时能够在终端看到中间结果。
|
||||
|
||||
```
|
||||
def browserLister() {
|
||||
// Applies filters and sorting to return a list of desired employees
|
||||
```
|
||||
|
||||
首先,打印出传递给 **browserLister()** 的参数。我通常使用此代码开始构建控制器方法,以便我完全清楚我的控制器正在接收什么。
|
||||
首先,打印出传递给 `browserLister()` 的参数。我通常使用此代码开始构建控制器方法,以便我完全清楚我的控制器正在接收什么。
|
||||
|
||||
```
|
||||
println "employee browserLister params $params"
|
||||
println()
|
||||
```
|
||||
|
||||
接下来,处理这些参数以使它们更加有用。首先,jQuery DataTables 参数,一个名为 **jqdtParams**的 Groovy 映射:
|
||||
接下来,处理这些参数以使它们更加有用。首先,jQuery DataTables 参数,一个名为 `jqdtParams` 的 Groovy 映射:
|
||||
|
||||
```
|
||||
def jqdtParams = [:]
|
||||
@ -363,7 +364,7 @@ println "employee dataTableParams $jqdtParams"
|
||||
println()
|
||||
```
|
||||
|
||||
接下来,列数据,一个名为 **columnMap**的 Groovy 映射:
|
||||
接下来,列数据,一个名为 `columnMap` 的 Groovy 映射:
|
||||
|
||||
```
|
||||
def columnMap = jqdtParams.columns.collectEntries { k, v ->
|
||||
@ -386,7 +387,7 @@ println "employee columnMap $columnMap"
|
||||
println()
|
||||
```
|
||||
|
||||
接下来,从 **columnMap** 中检索的所有列表,以及在视图中应如何排序这些列表,Groovy 列表分别称为 **allColumnList**和 **orderList**:
|
||||
接下来,从 `columnMap` 中检索的所有列表,以及在视图中应如何排序这些列表,Groovy 列表分别称为 `allColumnList` 和 `orderList` :
|
||||
|
||||
```
|
||||
def allColumnList = columnMap.keySet() as List
|
||||
@ -395,7 +396,7 @@ def orderList = jqdtParams.order.collect { k, v -> [allColumnList[v.column as In
|
||||
println "employee orderList $orderList"
|
||||
```
|
||||
|
||||
我们将使用 Grails 的 Hibernate 标准实现来实际选择要显示的元素以及它们的排序和分页。标准要求过滤器关闭; 在大多数示例中,这是作为标准实例本身的创建的一部分给出的,但是在这里我们预先定义过滤器闭包。请注意,在这种情况下,“date hired” 过滤器的相对复杂的解释被视为一年并应用于建立日期范围,并使用 **createAlias** 以允许我们进入相关类别 Position 和 Office:
|
||||
我们将使用 Grails 的 Hibernate 标准实现来实际选择要显示的元素以及它们的排序和分页。标准要求过滤器关闭;在大多数示例中,这是作为标准实例本身的创建的一部分给出的,但是在这里我们预先定义过滤器闭包。请注意,在这种情况下,“date hired” 过滤器的相对复杂的解释被视为一年并应用于建立日期范围,并使用 `createAlias` 以允许我们进入相关类别 `Position` 和 `Office`:
|
||||
|
||||
```
|
||||
def filterer = {
|
||||
@ -424,14 +425,14 @@ def filterer = {
|
||||
}
|
||||
```
|
||||
|
||||
是时候应用上述内容了。第一步是获取分页代码所需的所有 Employee 实例的总数:
|
||||
是时候应用上述内容了。第一步是获取分页代码所需的所有 `Employee` 实例的总数:
|
||||
|
||||
```
|
||||
def recordsTotal = Employee.count()
|
||||
println "employee recordsTotal $recordsTotal"
|
||||
```
|
||||
|
||||
接下来,将过滤器应用于 Employee 实例以获取过滤结果的计数,该结果将始终小于或等于总数(同样,这是针对分页代码):
|
||||
接下来,将过滤器应用于 `Employee` 实例以获取过滤结果的计数,该结果将始终小于或等于总数(同样,这是针对分页代码):
|
||||
|
||||
```
|
||||
def c = Employee.createCriteria()
|
||||
@ -467,7 +468,7 @@ def filterer = {
|
||||
|
||||
要完全清楚,JTable 中的分页代码管理三个计数:数据集中的记录总数,应用过滤器后得到的数字,以及要在页面上显示的数字(显示是滚动还是分页)。 排序应用于所有过滤的记录,并且分页应用于那些过滤的记录的块以用于显示目的。
|
||||
|
||||
接下来,处理命令返回的结果,在每行中创建指向 Employee,Position 和 Office 实例的链接,以便用户可以单击这些链接以获取相关实例的所有详细信息:
|
||||
接下来,处理命令返回的结果,在每行中创建指向 `Employee`、`Position` 和 `Office` 实例的链接,以便用户可以单击这些链接以获取相关实例的所有详细信息:
|
||||
|
||||
```
|
||||
def dollarFormatter = new DecimalFormat('$##,###.##')
|
||||
@ -490,14 +491,15 @@ def filterer = {
|
||||
}
|
||||
```
|
||||
|
||||
大功告成
|
||||
大功告成。
|
||||
|
||||
如果你熟悉 Grails,这可能看起来比你原先想象的要多,但这里没有火箭式的一步到位方法,只是很多分散的操作步骤。但是,如果你没有太多接触 Grails(或 Groovy),那么需要了解很多新东西 - 闭包,代理和构建器等等。
|
||||
|
||||
在那种情况下,从哪里开始? 最好的地方是了解 Groovy 本身,尤其是 [Groovy closures][18] 和 [Groovy delegates and builders][19]。然后再去阅读上面关于 Grails 和 Hibernate 条件查询的建议阅读文章。
|
||||
|
||||
### 结语
|
||||
|
||||
jQuery DataTables 为 Grails 制作了很棒的表格数据浏览器。对视图进行编码并不是太棘手,但DataTables 文档中提供的 PHP 示例提供的功能仅到此位置。特别是,它们不是用 Grails 程序员编写的,也不包含探索使用引用其他类(实质上是查找表)的元素的更精细的细节。
|
||||
jQuery DataTables 为 Grails 制作了很棒的表格数据浏览器。对视图进行编码并不是太棘手,但 DataTables 文档中提供的 PHP 示例提供的功能仅到此位置。特别是,它们不是用 Grails 程序员编写的,也不包含探索使用引用其他类(实质上是查找表)的元素的更精细的细节。
|
||||
|
||||
我使用这种方法制作了几个数据浏览器,允许用户选择要查看和累积记录计数的列,或者只是浏览数据。即使在相对适度的 VPS 上的百万行表中,性能也很好。
|
||||
|
||||
@ -512,7 +514,7 @@ via: https://opensource.com/article/18/9/using-grails-jquery-and-datatables
|
||||
作者:[Chris Hermansen][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[jrg](https://github.com/jrglinux)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@ -528,11 +530,11 @@ via: https://opensource.com/article/18/9/using-grails-jquery-and-datatables
|
||||
[9]: http://sdkman.io/
|
||||
[10]: http://guides.grails.org/creating-your-first-grails-app/guide/index.html
|
||||
[11]: https://opensource.com/file/410061
|
||||
[12]: https://opensource.com/sites/default/files/uploads/screen_1.png "Embrow home screen"
|
||||
[12]: https://opensource.com/sites/default/files/uploads/screen_1.png
|
||||
[13]: https://opensource.com/file/410066
|
||||
[14]: https://opensource.com/sites/default/files/uploads/screen_2.png "Office list screenshot"
|
||||
[14]: https://opensource.com/sites/default/files/uploads/screen_2.png
|
||||
[15]: https://opensource.com/file/410071
|
||||
[16]: https://opensource.com/sites/default/files/uploads/screen3.png "Employee controller screenshot"
|
||||
[16]: https://opensource.com/sites/default/files/uploads/screen3.png
|
||||
[17]: https://gsp.grails.org/latest/ref/Tags/createLink.html
|
||||
[18]: http://groovy-lang.org/closures.html
|
||||
[19]: http://groovy-lang.org/dsls.html
|
80
published/20181113 4 tips for learning Golang.md
Normal file
80
published/20181113 4 tips for learning Golang.md
Normal file
@ -0,0 +1,80 @@
|
||||
学习 Golang 的 4 个技巧
|
||||
======
|
||||
|
||||
> 到达 Golang 大陆:一位资深开发者之旅。
|
||||
|
||||

|
||||
|
||||
2014 年夏天……
|
||||
|
||||
> IBM:“我们需要你弄清楚这个 Docker。”
|
||||
|
||||
> 我:“没问题。”
|
||||
|
||||
> IBM:“那就开始吧。”
|
||||
|
||||
> 我:“好的。”(内心声音):”Docker 是用 Go 编写的。是吗?“(Google 一下)“哦,一门编程语言。我在我的岗位上已经学习了很多了。这不会太难。”
|
||||
|
||||
我的大学新生编程课是使用 VAX 汇编程序教授的。在数据结构课上,我们使用 Pascal —— 在图书馆计算机中心的旧电脑上使用软盘加载。在一门更高一级的课程中,我的教授教授喜欢用 ADA 去展示所有的例子。在我们的 Sun 工作站上,我通过各种 UNIX 的实用源代码学到了一点 C。在 IBM,OS/2 源代码中我们使用了 C 和一些 x86 汇编程序;在一个与 Apple 合作的项目中我们大量使用 C++ 的面向对象功能。不久后我学到了 shell 脚本,开始是 csh,但是在 90 年代中期发现 Linux 后就转到了 Bash。在 90 年代后期,我在将 IBM 的定制的 JVM 代码中的即时(JIT)编译器移植到 Linux 时,我不得不开始学习 m4(与其说是编程语言,不如说是一种宏处理器)。
|
||||
|
||||
一晃 20 年……我从未因为学习一门新的编程语言而焦灼。但是 [Go][1] 让我感觉有些不同。我打算公开贡献,上传到 GitHub,让任何有兴趣的人都可以看到!作为一个 40 多岁的资深开发者的 Go 新手,我不想成为一个笑话。我们都知道程序员的骄傲,不想丢人,不论你的经验水平如何。
|
||||
|
||||
我早期的调研显示,Go 似乎比某些语言更 “地道”。它不仅仅是让代码可以编译;也需要让代码可以 “Go Go Go”。
|
||||
|
||||
现在,我的个人的 Go 之旅四年间有了几百个拉取请求(PR),我不是致力于成为一个专家,但是现在我觉得贡献和编写代码比我在 2014 年的时候更舒服了。所以,你该怎么教一个老人新的技能或者一门编程语言呢?以下是我自己在前往 Golang 大陆之旅的四个步骤。
|
||||
|
||||
### 1、不要跳过基础
|
||||
|
||||
虽然你可以通过复制代码来进行你早期的学习(谁还有时间阅读手册!?),Go 有一个非常易读的 [语言规范][2],它写的很易于理解,即便你在语言或者编译理论方面没有取得硕士学位。鉴于 Go 的 **参数:类型** 顺序的特有习惯,以及一些有趣的语言功能,例如通道和 go 协程,搞定这些新概念是非常重要的是事情。阅读这个附属的文档 [高效 Go 编程][3],这是 Golang 创造者提供的另一个重要资源,它将为你提供有效和正确使用语言的准备。
|
||||
|
||||
### 2、从最好的中学习
|
||||
|
||||
有许多宝贵的资源可供挖掘,可以将你的 Go 知识提升到下一个等级。最近在 [GopherCon][4] 上的所有讲演都可以在网上找到,如这个 [GopherCon US 2018][5] 的详尽列表。这些讲演的专业知识和技术水平各不相同,但是你可以通过它们轻松地找到一些你所不了解的事情。[Francesc Campoy][6] 创建了一个名叫 [JustForFunc][7] 的 Go 编程视频系列,其不断增多的剧集可以用来拓宽你的 Go 知识和理解。直接搜索 “Golang" 可以为那些想要了解更多信息的人们展示许多其它视频和在线资源。
|
||||
|
||||
想要看代码?在 GitHub 上许多受欢迎的云原生项目都是用 Go 写的:[Docker/Moby][8]、[Kubernetes][9]、[Istio][10]、[containerd][11]、[CoreDNS][12],以及许多其它的。语言纯粹主义者可能会认为一些项目比另外一些更地道,但这些都是很好的起点,可以看到在高度活跃的项目的大型代码库中使用 Go 的程度。
|
||||
|
||||
### 3、使用优秀的语言工具
|
||||
|
||||
你会很快了解到 [gofmt][13] 的宝贵之处。Go 最漂亮的一个地方就在于没有关于每个项目代码格式的争论 —— **gofmt** 内置在语言的运行环境中,并且根据一系列可靠的、易于理解的语言规则对 Go 代码进行格式化。我不知道有哪个基于 Golang 的项目会在持续集成中不坚持使用 **gofmt** 检查拉取请求。
|
||||
|
||||
除了直接构建于运行环境和 SDK 中的一系列有价值的工具之外,我强烈建议使用一个对 Golang 的特性有良好支持的编辑器或者 IDE。由于我经常在命令行中进行工作,我依赖于 Vim 加上强大的 [vim-go][14] 插件。我也喜欢微软提供的 [VS Code][15],特别是它的 [Go 语言][16] 插件。
|
||||
|
||||
想要一个调试器?[Delve][17] 项目在不断的改进和成熟,它是在 Go 二进制文件上进行 [gdb][18] 式调试的强有力的竞争者。
|
||||
|
||||
### 4、写一些代码
|
||||
|
||||
你要是不开始尝试使用 Go 写代码,你永远不知道它有什么好的地方。找一个有 “需要帮助” 问题标签的项目,然后开始贡献代码。如果你已经使用了一个用 Go 编写的开源项目,找出它是否有一些可以用初学者方式解决的 Bug,然后开始你的第一个拉取请求。与生活中的大多数事情一样,实践出真知,所以开始吧。
|
||||
|
||||
事实证明,你可以教会一个资深的老开发者一门新的技能甚至编程语言。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/11/learning-golang
|
||||
|
||||
作者:[Phill Estes][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[dianbanjiu](https://github.com/dianbanjiu)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/estesp
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://golang.org/
|
||||
[2]: https://golang.org/ref/spec
|
||||
[3]: https://golang.org/doc/effective_go.html
|
||||
[4]: https://www.gophercon.com/
|
||||
[5]: https://tqdev.com/2018-gophercon-2018-videos-online
|
||||
[6]: https://twitter.com/francesc
|
||||
[7]: https://www.youtube.com/channel/UC_BzFbxG2za3bp5NRRRXJSw
|
||||
[8]: https://github.com/moby/moby
|
||||
[9]: https://github.com/kubernetes/kubernetes
|
||||
[10]: https://github.com/istio/istio
|
||||
[11]: https://github.com/containerd/containerd
|
||||
[12]: https://github.com/coredns/coredns
|
||||
[13]: https://blog.golang.org/go-fmt-your-code
|
||||
[14]: https://github.com/fatih/vim-go
|
||||
[15]: https://code.visualstudio.com/
|
||||
[16]: https://code.visualstudio.com/docs/languages/go
|
||||
[17]: https://github.com/derekparker/delve
|
||||
[18]: https://www.gnu.org/software/gdb/
|
@ -1,56 +0,0 @@
|
||||
HankChow translating
|
||||
|
||||
What you need to know about the GPL Cooperation Commitment
|
||||
======
|
||||
|
||||
The GPL Cooperation Commitment fosters innovation by freeing developers from fear of license termination.
|
||||
|
||||

|
||||
|
||||
Imagine what the world would look like if growth, innovation, and development were free from fear. Innovation without fear is fostered by consistent, predictable, and fair license enforcement. That is what the [GPL Cooperation Commitment][1] aims to accomplish.
|
||||
|
||||
Last year, I wrote an article about licensing effects on downstream users of open source software. As I was conducting research for that article, it became apparent that license enforcement is infrequent and often unpredictable. In that article, I offered potential solutions to the need to make open source license enforcement consistent and predictable. However, I only considered "traditional" methods (e.g., through the court system or some form of legislative action) that a law student might consider.
|
||||
|
||||
In November 2017, Red Hat, IBM, Google, and Facebook proposed the the "non-traditional" solution I had not considered: the GPL Cooperation Commitment, which provides for fair and consistent enforcement of the GPL. I believe the GPL Cooperation Commitment is critical for two reasons: First, consistent and fair license enforcement is crucial for growth in the open source community; second, unpredictability is undesirable in the legal community.
|
||||
|
||||
### Understanding the GPL
|
||||
|
||||
To understand the GPL Cooperation Commitment, you must first understand the GPL's history. GPL is short for [GNU General Public License][2]. The GPL is a "copyleft" open source license, meaning that a software's distributor must make the source code available to downstream users. The GPL also prohibits placing restrictions on downstream use. These requirements keep individual users from denying freedoms (to use, study, share, and improve the software) to others. Under the GPL, a license to use the code is granted to all downstream users, provided they meet the requirements and conditions of the license. If a licensee does not meet the license's requirements, they are non-compliant.
|
||||
|
||||
Under the second version of the GPL (GPLv2), a license automatically terminates upon any non-compliance, which causes some software developers to shy away from using the GPL. However, the third version of the GPL (GPLv3) [added a "cure provision"][3] that gives a 30-day period for a licensee to remediate any GPL violation. If the violation is cured within 30 days following notification of non-compliance, the license is not terminated.
|
||||
|
||||
This provision eliminates the fear of termination due to an innocent mistake, thus fostering development and innovation by bringing peace of mind to users and distributors of the software.
|
||||
|
||||
### What the GPL Cooperation Commitment does
|
||||
|
||||
The GPL Cooperation Commitment applies the GPLv3's cure provisions to GPLv2-licensed software, thereby protecting licensees of GPLv2 code from the automatic termination of their license, consistent with the protections afforded by the GPLv3.
|
||||
|
||||
The GPL Cooperation Commitment is important because, while software engineers typically want to do the right thing and maintain compliance, they sometimes misunderstand how to do so. This agreement enables developers to avoid termination when they are non-compliant due to confusion or simple mistakes.
|
||||
|
||||
The GPL Cooperation Commitment spawned from an announcement in 2017 by the Linux Foundation Technical Advisory Board that the Linux kernel project would [adopt the cure provision from GPLv3][4]. With the GPL Cooperation Commitment, many major technology companies and individual developers made the same commitment and expanded it by applying the cure period to all of their software licensed under GPLv2 (and LGPLv2.1), not only to contributions to the Linux kernel.
|
||||
|
||||
Broad adoption of the GPL Cooperation Commitment will have a positive impact on the open source community because a significant amount of software is licensed under GPLv2. An increasing number of companies and individuals are expected to adopt the GPL Cooperation Commitment, which will lead to a significant amount of GPLv2 (and LGPLv2.1) code under license terms that promote fair and predictable approaches to license enforcement.
|
||||
|
||||
In fact, as of November 2018, more than 40 companies, including industry leaders IBM, Google, Amazon, Microsoft, Tencent, Intel, and Red Hat, have [signed onto the GPL Cooperation Commitment][5] and are working collaboratively to create a standard of fair and predictable enforcement within the open source community. The GPL Cooperation Commitment is just one example of how the community comes together to ensure the future of open source.
|
||||
|
||||
The GPL Cooperation Commitment tells downstream licensees that you respect their good intentions and that your GPLv2 code is safe for them to use. More information, including about how you can add your name to the commitment, is available on the [GPL Cooperation Commitment website][6].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/11/gpl-cooperation-commitment
|
||||
|
||||
作者:[Brooke Driver][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/bdriver
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://gplcc.github.io/gplcc/
|
||||
[2]: https://www.gnu.org/licenses/licenses.en.html
|
||||
[3]: https://opensource.com/article/18/6/gplv3-anniversary
|
||||
[4]: https://www.kernel.org/doc/html/v4.16/process/kernel-enforcement-statement.html
|
||||
[5]: https://gplcc.github.io/gplcc/Company/Company-List.html
|
||||
[6]: http://gplcc.github.io/gplcc
|
@ -1,72 +0,0 @@
|
||||
Emacs #4: Automated emails to org-mode and org-mode syncing
|
||||
======
|
||||
This is fourth in [a series on Emacs and org-mode][1].
|
||||
|
||||
Hopefully by now you’ve started to see how powerful and useful org-mode is. If you’re like me, you’re thinking:
|
||||
|
||||
“I’d really like to have this in sync across all my devices.”
|
||||
|
||||
and, perhaps:
|
||||
|
||||
“Can I forward emails into org-mode?”
|
||||
|
||||
This being Emacs, the answers, of course, are “Yes.”
|
||||
|
||||
### Syncing
|
||||
|
||||
Since org-mode just uses text files, syncing is pretty easily accomplished using any number of tools. I use git with git-remote-gcrypt. Due to some limitations of git-remote-gcrypt, each machine tends to push to its own branch, and to master on command. Each machine merges from all the other branches and pushes the result to master after a merge. A cron job causes pushes to the machine’s branch to happen, and a bit of elisp coordinates it all — making sure to save buffers before a sync, refresh them from disk after, etc.
|
||||
|
||||
The code for this post is somewhat more extended, so I will be linking to it on github rather than posting inline.
|
||||
|
||||
I have a directory $HOME/org where all my org-stuff lives. In ~/org lives [a Makefile][2] that handles the syncing. It defines these targets:
|
||||
|
||||
* push: adds, commits, and pushes to a branch named after the machine’s hostname
|
||||
* fetch: does a simple git fetch
|
||||
* sync: adds, commits, pulls remote changes, merges, and (assuming the merge was successful) pushes to the branch named after the machine’s hostname plus master
|
||||
|
||||
|
||||
|
||||
Now, in my user’s crontab, I have this:
|
||||
```
|
||||
*/15 * * * * make -C $HOME/org push fetch 2>&1 | logger --tag 'orgsync'
|
||||
|
||||
```
|
||||
|
||||
The [accompanying elisp code][3] defines a shortcut (C-c s) to cause a sync to occur. Thanks to the cronjob, as long as files were saved — even if I didn’t explicitly sync on the other boxen — they’ll be pulled in.
|
||||
|
||||
I have found this setup to work really well.
|
||||
|
||||
### Emailing to org-mode
|
||||
|
||||
Before going down this path, one should ask the question: do you really need it? I use org-mode with mu4e, and the integration is excellent; any org task can link to an email by message-id, and this is ideal — it lets a person do things like make a reminder to reply to a message in a week.
|
||||
|
||||
However, org is not just about reminders. It’s also a knowledge base, authoring system, etc. And, not all of my mail clients use mu4e. (Note: things like MobileOrg exist for mobile devices). I don’t actually use this as much as I thought I would, but it has its uses and I thought I’d document it here too.
|
||||
|
||||
Now I didn’t want to just be able to accept plain text email. I wanted to be able to handle attachments, HTML mail, etc. This quickly starts to sound problematic — but with tools like ripmime and pandoc, it’s not too bad.
|
||||
|
||||
The first step is to set up some way to get mail into a specific folder. A plus-extension, special user, whatever. I then use a [fetchmail configuration][4] to pull it down and run my [insorgmail][5] script.
|
||||
|
||||
This script is where all the interesting bits happen. It starts with ripmime to process the message. HTML bits are converted from HTML to org format using pandoc. an org hierarchy is made to represent the structure of the email as best as possible. emails can get pretty complicated, with HTML and the rest, but I have found this does an acceptable job with my use cases.
|
||||
|
||||
### Up next…
|
||||
|
||||
My last post on org-mode will talk about using it to write documents and prepare slides — a use for which I found myself surprisingly pleased with it, but which needed a bit of tweaking.
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://changelog.complete.org/archives/9898-emacs-4-automated-emails-to-org-mode-and-org-mode-syncing
|
||||
|
||||
作者:[John Goerzen][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://changelog.complete.org/
|
||||
[1]:https://changelog.complete.org/archives/tag/emacs2018
|
||||
[2]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/Makefile
|
||||
[3]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/emacs-config.org
|
||||
[4]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/fetchmailrc.orgmail
|
||||
[5]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/insorgmail
|
@ -1,177 +0,0 @@
|
||||
Emacs #5: Documents and Presentations with org-mode
|
||||
======
|
||||
|
||||
### 1 About org-mode exporting
|
||||
|
||||
#### 1.1 Background
|
||||
|
||||
org-mode isn't just an agenda-making program. It can also export to lots of formats: LaTeX, PDF, Beamer, iCalendar (agendas), HTML, Markdown, ODT, plain text, man pages, and more complicated formats such as a set of web pages.
|
||||
|
||||
This isn't just some afterthought either; it's a core part of the system and integrates very well.
|
||||
|
||||
One file can be source code, automatically-generated output, task list, documentation, and presentation, all at once.
|
||||
|
||||
Some use org-mode as their preferred markup format, even for things like LaTeX documents. The org-mode manual has an extensive [section on exporting][13].
|
||||
|
||||
#### 1.2 Getting started
|
||||
|
||||
From any org-mode document, just hit C-c C-e. From there will come up a menu, letting you choose various export formats and options. These are generally single-key options so it's easy to set and execute. For instance, to export a document to a PDF, use C-c C-e l p or for HTML export, C-c C-e h h.
|
||||
|
||||
There are lots of settings available for all of these export options; see the manual. It is, in fact, quite possible to use LaTeX-format equations in both LaTeX and HTML modes, to insert arbitrary preambles and settings for different modes, etc.
|
||||
|
||||
#### 1.3 Add-on packages
|
||||
|
||||
ELPA containts many addition exporters for org-mode as well. Check there for details.
|
||||
|
||||
### 2 Beamer slides with org-mode
|
||||
|
||||
#### 2.1 About Beamer
|
||||
|
||||
[Beamer][14] is a LaTeX environment for making presentations. Its features include:
|
||||
|
||||
* Automated generating of structural elements in the presentation (see, for example, [the Marburg theme][1]). This provides a visual reference for the audience of where they are in the presentation.
|
||||
|
||||
* Strong help for structuring the presentation
|
||||
|
||||
* Themes
|
||||
|
||||
* Full LaTeX available
|
||||
|
||||
#### 2.2 Benefits of Beamer in org-mode
|
||||
|
||||
org-mode has a lot of benefits for working with Beamer. Among them:
|
||||
|
||||
* org-mode's very easy and strong support for visualizing and changing the structure makes it very quick to reorganize your material.
|
||||
|
||||
* Combined with org-babel, live source code (with syntax highlighting) and results can be embedded.
|
||||
|
||||
* The syntax is often easier to work with.
|
||||
|
||||
I have completely replaced my usage of LibreOffice/Powerpoint/GoogleDocs with org-mode and beamer. It is, in fact, rather frustrating when I have to use one of those tools, as they are nowhere near as strong as org-mode for visualizing a presentation structure.
|
||||
|
||||
#### 2.3 Headline Levels
|
||||
|
||||
org-mode's Beamer export will convert sections of your document (defined by headings) into slides. The question, of course, is: which sections? This is governed by the H [export setting][15] (org-export-headline-levels).
|
||||
|
||||
There are many ways to go, which suit people. I like to have my presentation like this:
|
||||
|
||||
```
|
||||
#+OPTIONS: H:2
|
||||
#+BEAMER_HEADER: \AtBeginSection{\frame{\sectionpage}}
|
||||
```
|
||||
|
||||
This gives a standalone section slide for each major topic, to highlight major transitions, and then takes the level 2 (two asterisks) headings to set the slide. Many Beamer themes expect a third level of indirection, so you would set H:3 for them.
|
||||
|
||||
#### 2.4 Themes and settings
|
||||
|
||||
You can configure many Beamer and LaTeX settings in your document by inserting lines at the top of your org file. This document, for instance, defines:
|
||||
|
||||
```
|
||||
#+TITLE: Documents and presentations with org-mode
|
||||
#+AUTHOR: John Goerzen
|
||||
#+BEAMER_HEADER: \institute{The Changelog}
|
||||
#+PROPERTY: comments yes
|
||||
#+PROPERTY: header-args :exports both :eval never-export
|
||||
#+OPTIONS: H:2
|
||||
#+BEAMER_THEME: CambridgeUS
|
||||
#+BEAMER_COLOR_THEME: default
|
||||
```
|
||||
|
||||
#### 2.5 Advanced settings
|
||||
|
||||
I like to change some colors, bullet formatting, and the like. I round out my document with:
|
||||
|
||||
```
|
||||
# We can't just +BEAMER_INNER_THEME: default because that picks the theme default.
|
||||
# Override per https://tex.stackexchange.com/questions/11168/change-bullet-style-formatting-in-beamer
|
||||
#+BEAMER_INNER_THEME: default
|
||||
#+LaTeX_CLASS_OPTIONS: [aspectratio=169]
|
||||
#+BEAMER_HEADER: \definecolor{links}{HTML}{0000A0}
|
||||
#+BEAMER_HEADER: \hypersetup{colorlinks=,linkcolor=,urlcolor=links}
|
||||
#+BEAMER_HEADER: \setbeamertemplate{itemize items}[default]
|
||||
#+BEAMER_HEADER: \setbeamertemplate{enumerate items}[default]
|
||||
#+BEAMER_HEADER: \setbeamertemplate{items}[default]
|
||||
#+BEAMER_HEADER: \setbeamercolor*{local structure}{fg=darkred}
|
||||
#+BEAMER_HEADER: \setbeamercolor{section in toc}{fg=darkred}
|
||||
#+BEAMER_HEADER: \setlength{\parskip}{\smallskipamount}
|
||||
```
|
||||
|
||||
Here, aspectratio=169 sets a 16:9 aspect ratio, and the remaining are standard LaTeX/Beamer configuration bits.
|
||||
|
||||
#### 2.6 Shrink (to fit)
|
||||
|
||||
Sometimes you've got some really large code examples and you might prefer to just shrink the slide to fit.
|
||||
|
||||
Just type C-c C-x p, set the BEAMER_opt property to shrink=15\.
|
||||
|
||||
(Or a larger value of shrink). The previous slide uses this here.
|
||||
|
||||
#### 2.7 Result
|
||||
|
||||
Here's the end result:
|
||||
|
||||
[][16]
|
||||
|
||||
### 3 Interactive Slides
|
||||
|
||||
#### 3.1 Interactive Emacs Slideshows
|
||||
|
||||
With the [org-tree-slide package][17], you can display your slideshow from right within Emacs. Just run M-x org-tree-slide-mode. Then, use C-> and C-< to move between slides.
|
||||
|
||||
You might find C-c C-x C-v (which is org-toggle-inline-images) helpful to cause the system to display embedded images.
|
||||
|
||||
#### 3.2 HTML Slideshows
|
||||
|
||||
There are a lot of ways to export org-mode presentations to HTML, with various levels of JavaScript integration. See the [non-beamer presentations section][18] of the org-mode wiki for details.
|
||||
|
||||
### 4 Miscellaneous
|
||||
|
||||
#### 4.1 Additional resources to accompany this post
|
||||
|
||||
* [orgmode.org beamer tutorial][2]
|
||||
|
||||
* [LaTeX wiki][3]
|
||||
|
||||
* [Generating section title slides][4]
|
||||
|
||||
* [Shrinking content to fit on slide][5]
|
||||
|
||||
* A great resource: refcard-org-beamer See its [Github repo][6] Make sure to check out both the PDF and the .org file
|
||||
|
||||
* A nice [Theme matrix][7]
|
||||
|
||||
#### 4.2 Up next in my Emacs series…
|
||||
|
||||
mu4e for email!
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://changelog.complete.org/archives/9900-emacs-5-documents-and-presentations-with-org-mode
|
||||
|
||||
作者:[John Goerzen][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://changelog.complete.org/archives/author/jgoerzen
|
||||
[1]:https://hartwork.org/beamer-theme-matrix/all/beamer-albatross-Marburg-1.png
|
||||
[2]:https://orgmode.org/worg/exporters/beamer/tutorial.html
|
||||
[3]:https://en.wikibooks.org/wiki/LaTeX/Presentations
|
||||
[4]:https://tex.stackexchange.com/questions/117658/automatically-generate-section-title-slides-in-beamer/117661
|
||||
[5]:https://tex.stackexchange.com/questions/78514/content-doesnt-fit-in-one-slide
|
||||
[6]:https://github.com/fniessen/refcard-org-beamer
|
||||
[7]:https://hartwork.org/beamer-theme-matrix/
|
||||
[8]:https://changelog.complete.org/archives/tag/emacs2018
|
||||
[9]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/emacs-org-beamer/emacs-org-beamer.org
|
||||
[10]:http://changelog.complete.org/archives/9900-emacs-5-documents-and-presentations-with-org-mode
|
||||
[11]:https://github.com/jgoerzen/public-snippets/raw/master/emacs/emacs-org-beamer/emacs-org-beamer.pdf
|
||||
[12]:https://github.com/jgoerzen/public-snippets/raw/master/emacs/emacs-org-beamer/emacs-org-beamer-document.pdf
|
||||
[13]:https://orgmode.org/manual/Exporting.html#Exporting
|
||||
[14]:https://en.wikipedia.org/wiki/Beamer_(LaTeX)
|
||||
[15]:https://orgmode.org/manual/Export-settings.html#Export-settings
|
||||
[16]:https://www.flickr.com/photos/jgoerzen/26366340577/in/dateposted/
|
||||
[17]:https://orgmode.org/worg/org-tutorials/non-beamer-presentations.html#org-tree-slide
|
||||
[18]:https://orgmode.org/worg/org-tutorials/non-beamer-presentations.html
|
@ -1,147 +0,0 @@
|
||||
Translating by Jamskr
|
||||
|
||||
How to install a device driver on Linux
|
||||
======
|
||||
Learn how Linux drivers work and how to use them.
|
||||

|
||||
|
||||
One of the most daunting challenges for people switching from a familiar Windows or MacOS system to Linux is installing and configuring a driver. This is understandable, as Windows and MacOS have mechanisms that make this process user-friendly. For example, when you plug in a new piece of hardware, Windows automatically detects it and shows a pop-up window asking if you want to continue with the driver's installation. You can also download a driver from the internet, then just double-click it to run a wizard or import the driver through Device Manager.
|
||||
|
||||
This process isn't as easy on a Linux operating system. For one reason, Linux is an open source operating system, so there are [hundreds of Linux distribution variations][1] . This means it's impossible to create one how-to guide that works for all Linux distros. Each Linux operating system handles the driver installation process a different way.
|
||||
|
||||
Second, most default Linux drivers are open source and integrated into the system, which makes installing any drivers that are not included quite complicated, even though most hardware devices can be automatically detected. Third, license policies vary among the different Linux distributions. For example, [Fedora prohibits][2] including drivers that are proprietary, legally encumbered, or that violate US laws. And Ubuntu asks users to [avoid using proprietary or closed hardware][3].
|
||||
|
||||
To learn more about how Linux drivers work, I recommend reading [An Introduction to Device Drivers][4] in the book Linux Device Drivers.
|
||||
|
||||
### Two approaches to finding drivers
|
||||
|
||||
#### 1\. User interfaces
|
||||
|
||||
If you are new to Linux and coming from the Windows or MacOS world, you'll be glad to know that Linux offers ways to see whether a driver is available through wizard-like programs. Ubuntu offers the [Additional Drivers][5] option. Other Linux distributions provide helper programs, like [Package Manager for GNOME][6], that you can check for available drivers.
|
||||
|
||||
#### 2\. Command line
|
||||
|
||||
What if you can't find a driver through your nice user interface application? Or you only have access through the shell with no graphic interface whatsoever? Maybe you've even decided to expand your skills by using a console. You have two options:
|
||||
|
||||
A. **Use a repository**
|
||||
This is similar to the [**homebrew**][7] command in MacOS.** ** By using **yum** , **dnf** , **apt-get** , etc., you're basically adding a repository and updating the package cache.
|
||||
|
||||
|
||||
B. **Download, compile, and build it yourself**
|
||||
This usually involves downloading a package directly from a website or using the **wget** command and running the configuration file and Makefile to install it. This is beyond the scope of this article, but you should be able to find online guides if you choose to go this route.
|
||||
|
||||
|
||||
|
||||
### Check if a driver is already installed
|
||||
|
||||
Before jumping further into installing a driver in Linux, let's look at some commands that will determine whether the driver is already available on your system.
|
||||
|
||||
The [**lspci**][8] command shows detailed information about all PCI buses and devices on the system:
|
||||
|
||||
```
|
||||
$ lscpci
|
||||
```
|
||||
|
||||
Or with **grep** :
|
||||
|
||||
```
|
||||
$ lscpci | grep SOME_DRIVER_KEYWORD
|
||||
```
|
||||
|
||||
For example, you can type **lspci | grep SAMSUNG** if you want to know if a Samsung driver is installed.
|
||||
|
||||
The [**dmesg**][9] command shows all device drivers recognized by the kernel:
|
||||
|
||||
```
|
||||
$ dmesg
|
||||
```
|
||||
|
||||
Or with **grep** :
|
||||
|
||||
```
|
||||
$ dmesg | grep SOME_DRIVER_KEYWORD
|
||||
```
|
||||
|
||||
Any driver that's recognized will show in the results.
|
||||
|
||||
If nothing is recognized by the **dmesg** or **lscpi** commands, try these two commands to see if the driver is at least loaded on the disk:
|
||||
|
||||
```
|
||||
$ /sbin/lsmod
|
||||
```
|
||||
|
||||
and
|
||||
|
||||
```
|
||||
$ find /lib/modules
|
||||
```
|
||||
|
||||
Tip: As with **lspci** or **dmesg** , append **| grep** to either command above to filter the results.
|
||||
|
||||
If a driver is recognized by those commands but not by **lscpi** or **dmesg** , it means the driver is on the disk but not in the kernel. In this case, load the module with the **modprobe** command:
|
||||
|
||||
```
|
||||
$ sudo modprobe MODULE_NAME
|
||||
```
|
||||
|
||||
Run as this command as **sudo** since this module must be installed as a root user.
|
||||
|
||||
### Add the repository and install
|
||||
|
||||
There are different ways to add the repository through **yum** , **dnf** , and **apt-get** ; describing them all is beyond the scope of this article. To make it simple, this example will use **apt-get** , but the idea is similar for the other options.
|
||||
|
||||
**1\. Delete the existing repository, if it exists.**
|
||||
|
||||
```
|
||||
$ sudo apt-get purge NAME_OF_DRIVER*
|
||||
```
|
||||
|
||||
where **NAME_OF_DRIVER** is the probable name of your driver. You can also add pattern match to your regular expression to filter further.
|
||||
|
||||
**2\. Add the repository to the repolist, which should be specified in the driver guide.**
|
||||
|
||||
```
|
||||
$ sudo add-apt-repository REPOLIST_OF_DRIVER
|
||||
```
|
||||
|
||||
where **REPOLIST_OF_DRIVER** should be specified from the driver documentation (e.g., **epel-list** ).
|
||||
|
||||
**3\. Update the repository list.**
|
||||
|
||||
```
|
||||
$ sudo apt-get update
|
||||
```
|
||||
|
||||
**4\. Install the package.**
|
||||
|
||||
```
|
||||
$ sudo apt-get install NAME_OF_DRIVER
|
||||
```
|
||||
|
||||
**5\. Check the installation.**
|
||||
|
||||
Run the **lscpi** command (as above) to check that the driver was installed successfully.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/11/how-install-device-driver-linux
|
||||
|
||||
作者:[Bryant Son][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/brson
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/List_of_Linux_distributions
|
||||
[2]: https://fedoraproject.org/wiki/Forbidden_items?rd=ForbiddenItems
|
||||
[3]: https://www.ubuntu.com/licensing
|
||||
[4]: https://www.xml.com/ldd/chapter/book/ch01.html
|
||||
[5]: https://askubuntu.com/questions/47506/how-do-i-install-additional-drivers
|
||||
[6]: https://help.gnome.org/users/gnome-packagekit/stable/add-remove.html.en
|
||||
[7]: https://brew.sh/
|
||||
[8]: https://en.wikipedia.org/wiki/Lspci
|
||||
[9]: https://en.wikipedia.org/wiki/Dmesg
|
@ -1,3 +1,5 @@
|
||||
heguangzhi Translating
|
||||
|
||||
9 obscure Python libraries for data science
|
||||
======
|
||||
Go beyond pandas, scikit-learn, and matplotlib and learn some new tricks for doing data science in Python.
|
||||
|
@ -1,3 +1,5 @@
|
||||
HankChow translating
|
||||
|
||||
How To Customize Bash Prompt In Linux
|
||||
======
|
||||

|
||||
|
@ -1,3 +1,4 @@
|
||||
Translating by Guevaraya
|
||||
How To Change GDM Login Screen Background In Ubuntu
|
||||
======
|
||||
Whenever you log in or lock and unlock your Ubuntu 18.04 LTS desktop, you will be greeted with a plain purple-colored screen. It is the default GDM (GNOME Display Manager) background since Ubuntu version 17.04. Some of you may feel boring to look at this plain background and want to make the Login screen something cool and eye-candy! If so, you’re on the right track. This brief guide describes how to change GDM Login screen background in Ubuntu 18.04 LTS desktop.
|
||||
|
@ -0,0 +1,56 @@
|
||||
GPL 合作承诺的发展历程
|
||||
======
|
||||
|
||||
GPL 合作承诺消除了开发者对许可证失效的顾虑,从而达到促进技术创新的目的。
|
||||
|
||||

|
||||
|
||||
假如没有任何顾虑,技术创新和发展将会让世界发生天翻地覆的改变。[GPL 合作承诺][1]就这样应运而生,只为通过公平、一致、可预测的许可证来让科技创新无后顾之忧。
|
||||
|
||||
去年,我曾经写过一篇文章,讨论了许可证对开源软件下游用户的影响。在进行研究的时候,我就发现许可证的约束力并不强,而且很多情况下是不可预测的。因此,我在文章中提出了一个能使开源许可证具有一致性和可预测性的潜在解决方案。但我只考虑到了诸如通过法律系统立法的传统方法。
|
||||
|
||||
2017 年 11 月,RedHat、IBM、Google 和 Facebook 提出了这种我从未考虑过的非传统的解决方案:GPL 合作承诺。GPL 合作承诺规定了 GPL 公平一致执行的方式。我认为,GPL 合作承诺之所以有这么深刻的意义,有以下两个原因:一是许可证的公平性和一致性对于开源社区的发展来说至关重要,二是法律对不可预测性并不容忍。
|
||||
|
||||
### 了解 GPL
|
||||
|
||||
要了解 GPL 合作承诺,首先要了解什么是 GPL。GPL 是 <ruby>[GNU 通用许可证][2]<rt>GNU General Public License</rt></ruby>的缩写,它是一个公共版权的开源许可证,这就意味着开源软件的分发者必须向下游用户公开源代码。GPL 还禁止对下游用户作出限制,要求个人用户不得拒绝他人对开源软件的使用自由、研究自由、共享自由和改进自由。GPL 规定,只要下游用户满足了许可证的要求和条件,就可以使用该许可证。如果被许可人出现了不符合许可证的情况,则视为违规。
|
||||
|
||||
按照第二版 GPL(GPLv2)的描述,许可证会在任何违规的情况下自动终止,这就导致了部分开发者对 GPL 有所抗拒。而在第三版 GPL(GPLv3)中则引入了“[<ruby>治愈条款<rt>cure provision</rt></ruby>][3]”,这一条款规定,被许可人可以在 30 天内对违反 GPL 的行为进行改正,如果在这个缓冲期内改正完成,许可证就不会被终止。
|
||||
|
||||
这一规定消除了许可证被无故终止的顾虑,从而让软件的开发者和用户专注于开发和创新。
|
||||
|
||||
### GPL 合作承诺做了什么
|
||||
|
||||
GPL 合作承诺将 GPLv3 的治愈条款应用于使用 GPLv2 的软件上,让使用 GPLv2 许可证的开发者避免许可证无故终止的窘境,并与 GPLv3 许可证保持一致。
|
||||
|
||||
|
||||
很多软件开发者都希望正确合规地做好一件事情,但有时候却不了解具体的实施细节。因此,GPL 合作承诺的重要性就在于能够对软件开发者们做出一些引导,让他们避免因一些简单的错误导致许可证违规终止。
|
||||
|
||||
Linux 基金会技术顾问委员会在 2017 年宣布,Linux 内核项目将会[采用 GPLv3 的治愈条款][4]。在 GPL 合作承诺的推动下,很多大型科技公司和个人开发者都承诺,会将自己的开源软件和 Linux 内核贡献在 30 天缓冲期内从 GPLv2 或 LGPLv2.1 扩展到 GPLv3。
|
||||
|
||||
GPL 合作承诺的广泛采用将会对开源社区产生非常积极的影响。如果更多的公司和个人开始采用 GPL 合作承诺,就能让大量正在使用 GPLv2 或 LGPLv2.1 许可证的软件以更公平和更可预测的形式履行许可证中的条款。
|
||||
|
||||
截至 2018 年 11 月,包括 IBM、Google、亚马逊、微软、腾讯、英特尔、RedHat 在内的 40 余家行业巨头公司都已经[签署了 GPL 合作承诺][5],以期为开源社区创立公平的标准以及提供可预测的执行力。GPL 合作承诺是开源社区齐心协力引领开源未来发展方向的一个成功例子。
|
||||
|
||||
GPL 合作承诺能够让下游用户了解到开发者对他们的尊重,同时也表示了开发者使用了 GPLv2 许可证的代码是安全的。如果你想查阅更多信息,包括如何将自己的名字添加到 GPL 合作承诺中,可以访问 [GPL 合作承诺的网站][6]。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/11/gpl-cooperation-commitment
|
||||
|
||||
作者:[Brooke Driver][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[HankChow](https://github.com/HankChow)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/bdriver
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://gplcc.github.io/gplcc/
|
||||
[2]: https://www.gnu.org/licenses/licenses.en.html
|
||||
[3]: https://opensource.com/article/18/6/gplv3-anniversary
|
||||
[4]: https://www.kernel.org/doc/html/v4.16/process/kernel-enforcement-statement.html
|
||||
[5]: https://gplcc.github.io/gplcc/Company/Company-List.html
|
||||
[6]: http://gplcc.github.io/gplcc
|
||||
|
@ -0,0 +1,71 @@
|
||||
Emacs #4:使用org-mode自动管理邮件及同步文档
|
||||
======
|
||||
这是 [Emacs 和 org-mode 系类][4]的第四篇。
|
||||
|
||||
至今为止,你已经见识到了 org-mode 的强大和高效,如果你像我一样,你可能会想:
|
||||
|
||||
“我真的很想让它在我所有的设备上同步。”
|
||||
|
||||
或者是说:
|
||||
|
||||
“我能在 org-mode 中转发邮件吗?”
|
||||
|
||||
答案当然是肯定的,因为这就是 Emacs。
|
||||
|
||||
### 同步
|
||||
|
||||
由于 org-mode 只使用文本文件,所以使用任意工具都可以很容易地实现同步。我使用的是 git 的 git-remote-gcrypt。由于 git-remote-gcrypt 的一些限制,每台机器都倾向于推到自己的分支,并使用命令来控制。每台机子都会先合并其他所有的 branch 然后再将合并后的结果 push 到 master 上。cron 作业可以实现将机器上的 branch push 上去,而 elisp 会协调这一切--确保在同步之前保存缓冲区,在同步之后从磁盘刷新缓冲区,等等。
|
||||
|
||||
这篇文章的代码有点多,所以我将把它链接到 github 上,而不是写在这里。
|
||||
|
||||
|
||||
我有一个用来存放我所有的 org-stuff 的目录 $HOME/org,在 ~/org 目录下有个 [Makefile][2] 文件来处理同步。该文件定义了一下目标:
|
||||
* push: 添加,提交和 push 到以主机命名的 branch 上
|
||||
* fetch: 一个简单的 git fetch
|
||||
* sync: 添加,提交和 pull 远程的修改,合并并将其 push 到以主机命名的 branch 和 master 上(假设合并成功)
|
||||
|
||||
|
||||
现在,在我的用户 crontab 中有这个:
|
||||
```
|
||||
*/15 * * * * make -C $HOME/org push fetch 2>&1 | logger --tag 'orgsync'
|
||||
|
||||
```
|
||||
[accompanying elisp code][3] 定义了一个快捷键(C-c s)来调用同步。多亏了 cronjob,只要文件被保存 -- 即使我没有在另一个 boxen 上同步 -- 它们也会被 pull 进来。
|
||||
|
||||
我发现这个设置非常好用。
|
||||
|
||||
### 用 org-mode 发邮件
|
||||
|
||||
在继续下去之前,首先要问自己一下:你真的需要它吗? 我用的是带有 [mu4e][4] 的 org-mode,而且它集成的也很好;任何组织任务都可以通过 message-id 链接到电子邮件,这很理想 -- 它可以让一个人做一些事情,比如提醒他在一周内回复一条消息。
|
||||
|
||||
然而,org 不仅仅只有提醒。它还是一个知识库、创作系统等,但是并不是我所有的邮件客户端都使用 mu4e。(注意:像 MobileOrg 是存在于移动设备中)。我并没有像我想的那样经常使用它,但是它有它的用途,所以我认为我也应该在这里记录它。
|
||||
|
||||
现在我不仅想处理纯文本电子邮件。我希望能够处理附件、HTML 邮件等。这听起来很快就有问题了 -- 但是通过使用 ripmime 和 pandoc 这样的工具,情况还不错。
|
||||
|
||||
第一步就是要用某些方法将获取到的邮件放入指定的文件夹下。扩展名,特殊用户等。然后我用 [fetchmail configuration][5] 来将它 pull 下来并运行我自己的 [insorgmail][6] 脚本。
|
||||
|
||||
这个脚本就是处理所有有趣的部分了。它从 ripmime 开始处理消息,用 pandoc 将HTML 的部分转换为 org 格式。 org 的层次结构是用来尽可能最好地表示 email 的结构。使用HTML和其他工具时,email 可能会变得相当复杂,但我发现这对于我来说是可以接受的。
|
||||
|
||||
### 下一篇
|
||||
|
||||
我最后一篇关于 org-mode 的文章将讨论如何使用它来编写文档和准备幻灯片 -- 我发现自己对 org-mode 的使用非常满意,但这需要一些调整。
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://changelog.complete.org/archives/9898-emacs-4-automated-emails-to-org-mode-and-org-mode-syncing
|
||||
|
||||
作者:[John Goerzen][a]
|
||||
译者:[oneforalone](https://github.com/oneforalone)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://changelog.complete.org/
|
||||
[1]:https://changelog.complete.org/archives/tag/emacs2018
|
||||
[2]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/Makefile
|
||||
[3]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/emacs-config.org
|
||||
[4]:https://www.emacswiki.org/emacs/mu4e
|
||||
[5]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/fetchmailrc.orgmail
|
||||
[6]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/insorgmail
|
@ -0,0 +1,176 @@
|
||||
Emacs #5: org-mode 之文档与 Presentations
|
||||
======
|
||||
|
||||
### 1 org-mode 的输出
|
||||
|
||||
#### 1.1 背景
|
||||
|
||||
org-mode 不仅仅只是一个议程生成程序, 它也能输出许多不同的格式: LaTeX,PDF,Beamer,iCalendar(议程),HTML,Markdown,ODT,普通文本,帮助页面(man pages)和其它更多的复杂的格式,比如说网页文件。
|
||||
|
||||
这也不只是一些事后的想法,这是 org-mode 的设计核心部分并且集成的很好。
|
||||
|
||||
一个文件可以同时是源代码,自动生成的输出,任务列表,文档和 presentation。
|
||||
|
||||
有些人将 org-mode 作为他们首选的标记格式,甚至对于 LaTeX 文档也是如此。org-mode 手册中的 [section on exporting][13] 有更详细的介绍。
|
||||
|
||||
#### 1.2 开始
|
||||
|
||||
对于任意的 org-mode 的文档,只要按下 C-c C-e键,就会弹出一个让你选择多种输出格式和选项的菜单。这些选项通常是次键选择,所以很容易设置和执行。例如:要输出一个 PDF 文档,按 C-c C-e l p,要输出 HMTL 格式的, 按 C-c C-e h h。
|
||||
|
||||
对于所有的输出选项,都有许多可用的设置;详情参见手册。事实上,使用 LaTeX 格式相当于同时使用 LaTeX 和 HTML 模式,在不同的模式中插入任意的前言和设置等。
|
||||
|
||||
#### 1.3 第三方插件
|
||||
|
||||
[ELPA][19] 中也包含了许多额外的输出格式,详情参见 [ELPA][19].
|
||||
|
||||
### 2 org-mode 的 Beamer 演示
|
||||
|
||||
#### 2.1 关于 Beamer
|
||||
|
||||
[Beamer][14] 是一个生成 presentation 的 LaTeX 环境. 它包括了一下特性:
|
||||
|
||||
* 在 presentation 中自动生成结构化的元素(例如 [the Marburg theme][1])。 在 presentation 时,这个特性可以为观众提供了视觉参考。
|
||||
|
||||
* 对组织 presentation 有很大的帮助。
|
||||
|
||||
* 主题
|
||||
|
||||
* 完全支持 LaTeX
|
||||
|
||||
#### 2.2 org-mode 中 Beamer 的优点
|
||||
|
||||
在 org-mode 中用 Beamer 有很多好处,总的来说:
|
||||
|
||||
* org-mode 很简单而且对可视化支持的很好,同时改变结构可以快速的重组你的材料。
|
||||
|
||||
* 与 org-babel 绑定在一起,实时语法高亮源码和内嵌结果。
|
||||
|
||||
* 语法通常更容易使用。
|
||||
|
||||
我已经完全用 org-mode 和 beamer 替换掉 LibreOffice/Powerpoint/GoogleDocs 的使用。事实上,当我必须使用其中一种工具时,这是相当令人沮丧的,因为它们在可视化表示结构方面远远比不上 org-mode。
|
||||
|
||||
#### 2.3 标题层次
|
||||
|
||||
org-mode 的 Beamer 会将你文档中的部分(文中定义了标题的)转换成幻灯片。当然,问题是:哪些部分?这是由 H [export setting][15](org-export-headline-levels)决定的。
|
||||
|
||||
针对不同的人,有许多不同的方法。我比较喜欢我的 presentation 这样:
|
||||
|
||||
```
|
||||
#+OPTIONS: H:2
|
||||
#+BEAMER_HEADER: \AtBeginSection{\frame{\sectionpage}}
|
||||
```
|
||||
|
||||
这将为每个主题提供了独立部分,以突出主题的改变然后使用级别 2(两个星号)的标题来设置幻灯片。许多 Beamer 主题也有第三个间接层次,所以你可以将 H 设为 3。
|
||||
|
||||
#### 2.4 主题和配置
|
||||
|
||||
你可以在 org 文件的顶部来插入几行来配置 Beamer 和 LaTeX。在本文中,例如,你可以这样定义:
|
||||
|
||||
```
|
||||
#+TITLE: Documents and presentations with org-mode
|
||||
#+AUTHOR: John Goerzen
|
||||
#+BEAMER_HEADER: \institute{The Changelog}
|
||||
#+PROPERTY: comments yes
|
||||
#+PROPERTY: header-args :exports both :eval never-export
|
||||
#+OPTIONS: H:2
|
||||
#+BEAMER_THEME: CambridgeUS
|
||||
#+BEAMER_COLOR_THEME: default
|
||||
```
|
||||
|
||||
#### 2.5 高级设置
|
||||
|
||||
我比教喜欢修改颜色、项目符号样式等。我的配置如下:
|
||||
|
||||
```
|
||||
# We can't just +BEAMER_INNER_THEME: default because that picks the theme default.
|
||||
# Override per https://tex.stackexchange.com/questions/11168/change-bullet-style-formatting-in-beamer
|
||||
#+BEAMER_INNER_THEME: default
|
||||
#+LaTeX_CLASS_OPTIONS: [aspectratio=169]
|
||||
#+BEAMER_HEADER: \definecolor{links}{HTML}{0000A0}
|
||||
#+BEAMER_HEADER: \hypersetup{colorlinks=,linkcolor=,urlcolor=links}
|
||||
#+BEAMER_HEADER: \setbeamertemplate{itemize items}[default]
|
||||
#+BEAMER_HEADER: \setbeamertemplate{enumerate items}[default]
|
||||
#+BEAMER_HEADER: \setbeamertemplate{items}[default]
|
||||
#+BEAMER_HEADER: \setbeamercolor*{local structure}{fg=darkred}
|
||||
#+BEAMER_HEADER: \setbeamercolor{section in toc}{fg=darkred}
|
||||
#+BEAMER_HEADER: \setlength{\parskip}{\smallskipamount}
|
||||
```
|
||||
|
||||
在这里, aspectratio=169 将纵横比设为 16:9, 其它部分都是标准的 LaTeX/Beamer 配置。
|
||||
|
||||
#### 2.6 缩小 (适应屏幕)
|
||||
|
||||
有时你会遇到一些非常大的代码示例,你可能更倾向与将幻灯片缩小以适应它们。
|
||||
|
||||
只要按下 C-c C-c p 将 BEAMER_opt属性设为 shrink=15\.(或者设为更大的 shrink 值)。上一张幻灯片就用到了这个。
|
||||
|
||||
#### 2.7 效果
|
||||
|
||||
这就是最终的效果:
|
||||
|
||||
[][16]
|
||||
|
||||
### 3 幻灯片之间的交互
|
||||
|
||||
#### 3.1 交互式的 Emacs 幻灯片
|
||||
|
||||
使用 [org-tree-slide package][17] 这个插件的话, 就可以在 Emacs 的右侧显示幻灯片了。 只要按下 M-x,然后输入 org-tree-slide-mode,回车,然后你就可以用 C-> 和 C-< 在幻灯片之间切换了。
|
||||
|
||||
你可能会发现 C-c C-x C-v (即 org-toggle-inline-images)有助于使系统显示内嵌的图像。
|
||||
|
||||
#### 3.2 HTML 幻灯片
|
||||
|
||||
有许多方式可以将 org-mode 的 presentation 导出为 HTML,并有不同级别的 JavaScript 集成。有关详细信息,请参见 org-mode 的 wiki 中的 [non-beamer presentations section][18]。
|
||||
|
||||
### 4 更多
|
||||
|
||||
#### 4.1 本文中的附加资源
|
||||
|
||||
* [orgmode.org beamer tutorial][2]
|
||||
|
||||
* [LaTeX wiki][3]
|
||||
|
||||
* [Generating section title slides][4]
|
||||
|
||||
* [Shrinking content to fit on slide][5]
|
||||
|
||||
* 很棒的资源: refcard-org-beamer 详情参见其 [Github repo][6] 中的 PDF 和 .org 文件。
|
||||
|
||||
* 很漂亮的主题: [Theme matrix][7]
|
||||
|
||||
#### 4.2 下一个 Emacs 系列
|
||||
|
||||
mu4e 邮件!
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://changelog.complete.org/archives/9900-emacs-5-documents-and-presentations-with-org-mode
|
||||
|
||||
作者:[John Goerzen][a]
|
||||
译者:[oneforalone](https://github.com/oneforalone)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://changelog.complete.org/archives/author/jgoerzen
|
||||
[1]:https://hartwork.org/beamer-theme-matrix/all/beamer-albatross-Marburg-1.png
|
||||
[2]:https://orgmode.org/worg/exporters/beamer/tutorial.html
|
||||
[3]:https://en.wikibooks.org/wiki/LaTeX/Presentations
|
||||
[4]:https://tex.stackexchange.com/questions/117658/automatically-generate-section-title-slides-in-beamer/117661
|
||||
[5]:https://tex.stackexchange.com/questions/78514/content-doesnt-fit-in-one-slide
|
||||
[6]:https://github.com/fniessen/refcard-org-beamer
|
||||
[7]:https://hartwork.org/beamer-theme-matrix/
|
||||
[8]:https://changelog.complete.org/archives/tag/emacs2018
|
||||
[9]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/emacs-org-beamer/emacs-org-beamer.org
|
||||
[10]:http://changelog.complete.org/archives/9900-emacs-5-documents-and-presentations-with-org-mode
|
||||
[11]:https://github.com/jgoerzen/public-snippets/raw/master/emacs/emacs-org-beamer/emacs-org-beamer.pdf
|
||||
[12]:https://github.com/jgoerzen/public-snippets/raw/master/emacs/emacs-org-beamer/emacs-org-beamer-document.pdf
|
||||
[13]:https://orgmode.org/manual/Exporting.html#Exporting
|
||||
[14]:https://en.wikipedia.org/wiki/Beamer_(LaTeX)
|
||||
[15]:https://orgmode.org/manual/Export-settings.html#Export-settings
|
||||
[16]:https://www.flickr.com/photos/jgoerzen/26366340577/in/dateposted/
|
||||
[17]:https://orgmode.org/worg/org-tutorials/non-beamer-presentations.html#org-tree-slide
|
||||
[18]:https://orgmode.org/worg/org-tutorials/non-beamer-presentations.html
|
||||
[19]:https://www.emacswiki.org/emacs/ELPA
|
@ -1,76 +0,0 @@
|
||||
学习 Golang 的 4 个技巧
|
||||
======
|
||||
到达 Golang 大陆:一个高级开发者的日记。
|
||||

|
||||
|
||||
2014 年夏天...
|
||||
|
||||
> IBM:“我们需要你弄清楚这个 Docker。”
|
||||
> Me:“没问题。”
|
||||
> IBM:“那就开始吧。”
|
||||
> Me:“好的。”(内心声音):”Docker 是用 Go 编写的。是吗?“(Googles)“哦,一门编程语言。我在我的岗位上已经学习了很多了。这不会太难。”
|
||||
|
||||
|
||||
我的大学新生编程课是使用 VAX 汇编程序教授的。在数据结构课上,我们在图书馆计算机中心的旧电脑上使用 Pascal 加载的软盘。在一门更上一级的课程中,我有一个教授喜欢用 ADA 去展示所有的例子。我在我们的 Sun 工作站上通过各种的 UNIX 的实用源代码学到了一点 C。在 IBM,我们使用 C 和一些 x86 汇编程序来获取 OS/2 源代码,我们大量使用 C++ 的面向对象功能与 Apple 合作。不久后我学到了 shell 脚本,并开始使用 csh,但是在 90 年代中期发现 Linux 后就转到了 Bash。在 90 年代后期将其移植到 Linux 时,我正在研究 IBM 的自定义 JVM 代码中的即时(JIT)编译器,因此我开始学习 m4(可以说是宏编程器而不是编程语言)。
|
||||
|
||||
快进 20 年... 我从未因为学习一门新的编程语言而焦灼。但是 [Go][1] 感觉有些不同。我打算在 GitHub 上游公开贡献,让任何有兴趣的人都可以看到!作为一个 40 多岁高级开发者的 Go 新手,我不想成为一个笑话。我们都知道程序员的骄傲是不想受伤,不论你的经验水平如何。
|
||||
|
||||
我早期的调查显示,Go 似乎比某些语言更倾向于 “惯用语”。它不仅仅是编译代码; 我需要能够用 “Go 的方式” 写代码。
|
||||
|
||||
现在在我的私人 Go 日志上,四年有上百个 pull requests,我不是致力于成为一个专家,但是我觉得贡献和编写代码比我在 2014 年的时候更舒服了。所以,你该怎么教一个老人新的技能或者至少一门编程语言?以下是我自己在前往 Golang 大陆的四个步骤。
|
||||
|
||||
### 1. 不要跳过基础
|
||||
|
||||
虽然你可以通过复制代码来进行你早期的学习(还有谁有时间阅读手册!?),Go 有一个非常易读的 [语言规范][2],它写的很清楚,即便你在语言或者编译理论方面没有硕士学位。鉴于 Go 在 **参数:类型** 的顺序做的独特决定,在使用有趣的语言功能,例如 通道和 goroutines 时,搞定这些新概念是非常重要的是事情。阅读文档 [高效 Go 编程][3],这是 Golang 创作者的另一个重要资源,它将为你提供有效和正确使用语言的准备。
|
||||
|
||||
### 2. 从最好的中学习
|
||||
|
||||
有许多宝贵的资源可供挖掘,并将你的 Go 知识提升到下一个等级。最近在 [GopherCon][4] 上的所有谈话都可以在网上找到,就像 [GopherCon US 在 2018][5] 中的详尽列表一样。谈话的专业知识和技术水平各不相同,但是你可以通过谈话轻松地找到一些你不了解的事情。[Francesc Campoy][6] 创建了一个名叫 [JustForFunc][7] 的 Go 编程视频系列,其中有越来越多的剧集来拓宽你的 Go 知识和理解。快速搜索 “Golang" 可以为那些想要了解更多信息的人们展示许多其他视频和在线资源。
|
||||
|
||||
想要看代码?在 GitHub 上许多受欢迎的云原生项目都是用 Go 写的:[Docker/Moby][8],[Kubernetes][9],[Istio][10],[containerd][11],[CoreDNS][12],以及许多其他的。语言纯粹者可能会评价一些项目的惯用语优于其他的,但是这些都是在了解大型代码在高度活跃的项目中开始使用 Go 的大好起点。
|
||||
|
||||
### 3. 使用优秀的语言工具
|
||||
|
||||
你将要快速了解有关 [gofmt][13] 的宝贵之处。Go 最漂亮的一个地方就在于没有关于每个项目代码格式的争论 —— **gofmt** 内置在语言的运行库中,并且根据一系列稳固、易于理解的语言规则对 Go 代码进行格式化。我不理解任何基于 Golang 不坚持使用 **gofmt** 检查 pull requests 作为持续集成一部分的项目。
|
||||
|
||||
除了直接构建在 runtime/SDK 有价值的工具之外,我强烈建议使用一个对 Golang 的特性有良好支持的编辑器或者 IDE。由于我经常在命令行中进行工作,我依赖于 Vim 加上强大的 [vim-go][14] 插件。我也喜欢微软提供的 [VS Code][15],特别是它的 [Go language][16] 插件。
|
||||
|
||||
想要一个调试器?[Delve][17] 项目在不断的改进和成熟,而且是在 Go 二进制文件上进行 [gdb][18] 式调试的强有力的竞争者。
|
||||
|
||||
### 4. 写一些代码
|
||||
|
||||
你要是不开始尝试使用 Go 写代码,你永远不知道它有什么好的地方。找一个有 “需要帮助” 问题标签的项目,然后开始贡献代码。如果你已经使用了一个用 Go 编写的开源项目,找出它是否有一些用初学者方式解决的 Bugs,然后开始你的第一个 pull request。与生活中的大多数事情一样,唯一真正的改进方法就是通过实践,所以开始吧。
|
||||
|
||||
事实证明,你似乎可以教一个老高级开发者至少一门新的技能或者编程语言。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/11/learning-golang
|
||||
|
||||
作者:[Phill Estes][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[dianbanjiu](https://github.com/dianbanjiu)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/estesp
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://golang.org/
|
||||
[2]: https://golang.org/ref/spec
|
||||
[3]: https://golang.org/doc/effective_go.html
|
||||
[4]: https://www.gophercon.com/
|
||||
[5]: https://tqdev.com/2018-gophercon-2018-videos-online
|
||||
[6]: https://twitter.com/francesc
|
||||
[7]: https://www.youtube.com/channel/UC_BzFbxG2za3bp5NRRRXJSw
|
||||
[8]: https://github.com/moby/moby
|
||||
[9]: https://github.com/kubernetes/kubernetes
|
||||
[10]: https://github.com/istio/istio
|
||||
[11]: https://github.com/containerd/containerd
|
||||
[12]: https://github.com/coredns/coredns
|
||||
[13]: https://blog.golang.org/go-fmt-your-code
|
||||
[14]: https://github.com/fatih/vim-go
|
||||
[15]: https://code.visualstudio.com/
|
||||
[16]: https://code.visualstudio.com/docs/languages/go
|
||||
[17]: https://github.com/derekparker/delve
|
||||
[18]: https://www.gnu.org/software/gdb/
|
@ -0,0 +1,143 @@
|
||||
如何在 Linux 上安装设备驱动程序
|
||||
======
|
||||
学习 Linux 设备驱动如何工作,并知道如何使用它们。
|
||||
|
||||

|
||||
|
||||
对于一个熟悉 Windows 或者 MacOS 的人,想要切换到 Linux,它们都会面临一个艰巨的问题就是怎么安装和配置设备驱动。这是可以理解的,因为 Windows 和 MacOS 都有一套机制把这个过程做得非常的友好。比如说,当你插入一个新的硬件设备, Windows 能够自动检测并会弹出一个窗口询问你是否要继续驱动程序。你也可以从网络上下载驱动程序,仅仅需要双击解压或者是通过设备管理器导入驱动程序即可。
|
||||
|
||||
而这在 Linux 操作系统上并非这么简单。第一个原因是, Linux 是一个开源的操作系统,所以有 [数百种 Linux 发行版的变体][1]。也就是说不可能做一个指南来适应所有的 Linux 发行版。因为每种 Linux 安装驱动程序的过程都有差异。
|
||||
|
||||
第二,大多数默认的 Linux 驱动程序也都是开源的,并被集成到了系统中,这使得安装一些并未包含的驱动程序变得非常复杂,即使已经可以检测大多数的硬件设备。第三,不同发行版的许可也有差异。例如,[Fedora 禁止事项][2] 禁止包含专有的,受法律保护,或者是违反美国法律的驱动程序。而 Ubuntu 则让用户[避免使用受法律保护或闭源的硬件设备][3]。
|
||||
|
||||
为了更好的学习 Linux 驱动程序是如何工作的,我建议阅读 Linux 设备驱动程序一书中的 [设备驱动程序简介][4]。
|
||||
|
||||
### 两种方式来寻找驱动程序
|
||||
|
||||
#### 1\. 用户界面
|
||||
|
||||
如果是一个刚从 Windows 或 MacOS 转过来的 Linux 新手,那你会很高兴知道 Linux 也提供了一个通过向导式的程序来查看驱动程序是否可用的方法。 Ubuntu 提供了一个 [附加驱动程序][5] 选项。其它的 Linux 发行版也提供了帮助程序,像 [GNOME 的包管理器][6],你可以使用它来检查驱动程序是否可用。
|
||||
|
||||
#### 2\. 命令行
|
||||
|
||||
如果你通过漂亮的用户界面找到驱动程序,那又该怎么办呢?或许你只能通过没有任何图形界面的 shell?甚至你可以使用控制台来展现你的技能。你有两个选择:
|
||||
|
||||
A. **通过一个仓库**
|
||||
这和 MacOS 中的 [**homebrew**][7] 命令行很像。通过使用 `yum` , `dnf` , `apt-get` , 等等。你基本可以通过添加仓库,并更新包缓存。
|
||||
|
||||
B. **下载, 编译, 然后自己构建**
|
||||
这通常包括直接从网络,或通过 `wget` 命令下载源码包,然后运行配置和编译、安装。这超出了本文的范围,但是你可以在网络上找到很多在线指南,如果你选择的是这条路的话。
|
||||
|
||||
### 检查是否已经安装了这个驱动程序
|
||||
|
||||
在进一步学习安装 Linux 驱动程序之前,让我们来学习几条命令,用来检测驱动程序是否已经在你的系统上可用。
|
||||
|
||||
[`lspci`][8] 命令显示了系统上所有 PCI 总线和设备驱动程序的详细信息。
|
||||
|
||||
```
|
||||
$ lscpci
|
||||
```
|
||||
|
||||
或者使用 `grep`:
|
||||
|
||||
```
|
||||
$ lscpci | grep SOME_DRIVER_KEYWORD
|
||||
```
|
||||
|
||||
例如,你可以使用 `lspci | grep SAMSUNG` 命令,如果你想知道是否安装过三星的驱动。
|
||||
|
||||
[`dmesg`][9] 命令显示了所有内核识别的驱动程序。
|
||||
|
||||
```
|
||||
$ dmesg
|
||||
```
|
||||
|
||||
或配合 `grep` 使用
|
||||
|
||||
```
|
||||
$ dmesg | grep SOME_DRIVER_KEYWORD
|
||||
```
|
||||
|
||||
任何识别到的驱动程序都会显示在结果中。
|
||||
|
||||
如果通过 `dmesg` 或者 `lscpi` 命令没有识别到任何驱动程序,尝试下这两个命令,看看驱动程序至少是否加载到硬盘。
|
||||
|
||||
```
|
||||
$ /sbin/lsmod
|
||||
```
|
||||
|
||||
和
|
||||
|
||||
```
|
||||
$ find /lib/modules
|
||||
```
|
||||
|
||||
小贴士:和`lspci` 或 `dmesg` 一样,通过在上面的命令后面加上 `| grep` 来过滤结果。
|
||||
|
||||
如果一个驱动程序已经被识别到了,但是通过 `lscpi` 或 `dmesg` 并没有找到,这意味着驱动程序已经存在于硬盘上,但是并没有加载到内核中,这种情况,你可以通过 `modprobe` 命令来加载这个模块。
|
||||
|
||||
```
|
||||
$ sudo modprobe MODULE_NAME
|
||||
```
|
||||
|
||||
使用 `sudo` 来运行这个命令,因为这个模块要使用 root 权限来安装。
|
||||
|
||||
### 添加仓库并安装
|
||||
|
||||
可以通过 `yum` , `dnf` , 和 `apt-get` 几种不同的方式来添加一个仓库;一个个介绍完它们并不在本文的范围。简单一点来说,这个示例将会使用 `apt-get` ,但是这个命令和其它的几个都是很类似的。
|
||||
|
||||
**1\. 删除存在的仓库,如果它存在.**
|
||||
|
||||
```
|
||||
$ sudo apt-get purge NAME_OF_DRIVER*
|
||||
```
|
||||
|
||||
其中 `NAME_OF_DRIVER` 是你的驱动程序的可能的名称。你还可以将模式匹配加到正则表达式中来进一步过滤。
|
||||
|
||||
**2\. 将仓库加入到仓库表中,这应该在驱动程序指南中有指定**
|
||||
|
||||
```
|
||||
$ sudo add-apt-repository REPOLIST_OF_DRIVER
|
||||
```
|
||||
|
||||
其中 `REPOLIST_OF_DRIVER` 应该从驱动文档中有指定(例如:`epel-list`)。
|
||||
|
||||
**3\. 更新仓库列表。**
|
||||
|
||||
```
|
||||
$ sudo apt-get update
|
||||
```
|
||||
|
||||
**4\. 安装驱动程序。**
|
||||
|
||||
```
|
||||
$ sudo apt-get install NAME_OF_DRIVER
|
||||
```
|
||||
|
||||
**5\. 检查安装状态.**
|
||||
|
||||
像上面说的一样,通过 `lscpi` 命令来检查驱动程序是否已经安装成功。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/11/how-install-device-driver-linux
|
||||
|
||||
作者:[Bryant Son][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[Jamskr](https://github.com/Jamskr)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/brson
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/List_of_Linux_distributions
|
||||
[2]: https://fedoraproject.org/wiki/Forbidden_items?rd=ForbiddenItems
|
||||
[3]: https://www.ubuntu.com/licensing
|
||||
[4]: https://www.xml.com/ldd/chapter/book/ch01.html
|
||||
[5]: https://askubuntu.com/questions/47506/how-do-i-install-additional-drivers
|
||||
[6]: https://help.gnome.org/users/gnome-packagekit/stable/add-remove.html.en
|
||||
[7]: https://brew.sh/
|
||||
[8]: https://en.wikipedia.org/wiki/Lspci
|
||||
[9]: https://en.wikipedia.org/wiki/Dmesg
|
Loading…
Reference in New Issue
Block a user