mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-28 23:20:10 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
a84c0cdecb
@ -1,24 +1,24 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (stevenzdg988)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-13012-1.html)
|
||||
[#]: subject: (Printing from the Linux command line)
|
||||
[#]: via: (https://www.networkworld.com/article/3373502/printing-from-the-linux-command-line.html)
|
||||
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
|
||||
|
||||
Linux 命令行打印
|
||||
从 Linux 命令行进行打印
|
||||
======
|
||||
|
||||
通过一些可用选项 Linux 命令行打印的内容比 `lp` 命令多得多。
|
||||
> 在 Linux 命令行进行打印的内容比单单一个 `lp` 命令多得多,让我们来看一些可用选项。
|
||||
|
||||
![Sherry \(CC BY 2.0\)][1]
|
||||
|
||||
Linux 命令行打印很容易。您可以使用 **lp** 命令来请求打印,并使用 **lpq** 命令来查看队列中有哪些打印作业,但是当您要双面打印或使用纵向模式时,这些会变得有些复杂。 您可能还需要做很多其他事情,例如打印多份文档副本或取消打印作业。 让我们通过某些选项以使打印输出的内容看起来像从命令行打印时的方式一样。
|
||||
Linux 命令行打印很容易。你可以使用 `lp` 命令来请求打印,并使用 `lpq` 命令来查看队列中有哪些打印作业,但是当你要双面打印或使用纵向模式时,这些会变得有些复杂。你可能还需要做很多其他事情,例如打印多份文档副本或取消打印作业。让我们来看看一些选项,当你从命令行打印时,如何让你的打印输出看起来如你所愿。
|
||||
|
||||
### 显示打印机配置
|
||||
|
||||
要从命令行查看打印机设置,请使用 **lpoptions** 命令。 输出应如下所示:
|
||||
要从命令行查看打印机设置,请使用 `lpoptions` 命令。 输出应如下所示:
|
||||
|
||||
```
|
||||
$ lpoptions
|
||||
@ -62,7 +62,7 @@ printer-uri-supported=ipp://localhost/printers/Color-LaserJet-CP2025dn
|
||||
sides=one-sided
|
||||
```
|
||||
|
||||
使用 **-v** 选项时,**lpinfo** 命令将列出驱动程序和相关信息。
|
||||
使用 `-v` 选项时,`lpinfo` 命令将列出驱动程序和相关信息:
|
||||
|
||||
```
|
||||
$ lpinfo -v
|
||||
@ -80,13 +80,13 @@ network dnssd://HP%20Color%20LaserJet%20CP2025dn%20(F47468)._pdl-datastream._tcp
|
||||
network socket://192.168.0.23 <== printer IP
|
||||
```
|
||||
|
||||
`lpoptions` 命令将显示默认打印机的设置。使用 **-p** 选项指定其中一个可用打印机代号。
|
||||
`lpoptions` 命令将显示默认打印机的设置。使用 `-p` 选项指定其中一个可用打印机代号:
|
||||
|
||||
```
|
||||
$ lpoptions -p LaserJet
|
||||
```
|
||||
|
||||
**lpstat -p** 命令显示打印机的状态,而 **lpstat -p -d** 列出可用打印机列表。
|
||||
`lpstat -p` 命令显示打印机的状态,而 `lpstat -p -d` 列出可用打印机列表。
|
||||
|
||||
```
|
||||
$ lpstat -p -d
|
||||
@ -96,14 +96,14 @@ system default destination: Color-LaserJet-CP2025dn
|
||||
|
||||
### 非常有用的命令
|
||||
|
||||
要在默认打印机上打印文档,只需使用 **lp** 命令,后跟要打印的文件名即可。 如果文件名包含空格(在 Linux 系统上很少见),请将该名称放在引号中或开始输入文件名并按 Tab 键调用空格的转义标志(如下面的第二个示例所示)。
|
||||
要在默认打印机上打印文档,只需使用 `lp` 命令,后跟要打印的文件名即可。 如果文件名包含空格(在 Linux 系统上很少见),请将该名称放在引号中或开始输入文件名并按 `Tab` 键调用空格的转义标志(如下面的第二个示例所示)。
|
||||
|
||||
```
|
||||
$ lp "never leave home angry"
|
||||
$ lp never\ leave\ home\ angry
|
||||
```
|
||||
|
||||
**lpq** 命令显示打印队列。
|
||||
`lpq` 命令显示打印队列:
|
||||
|
||||
```
|
||||
$ lpq
|
||||
@ -112,13 +112,13 @@ Rank Owner Job File(s) Total Size
|
||||
active shs 234 agenda 2048 bytes
|
||||
```
|
||||
|
||||
使用 **-n** 选项时,`lp` 命令可用来指定所需打印输出的份数。
|
||||
使用 `-n` 选项时,`lp` 命令可用来指定所需打印输出的份数:
|
||||
|
||||
```
|
||||
$ lp -n 11 agenda
|
||||
```
|
||||
|
||||
要取消打印作业,可以使用 **cancel** 或 **lprm** 命令。 如果没来得及执行,则可能会看到以下信息:
|
||||
要取消打印作业,可以使用 `cancel` 或 `lprm` 命令。如果没来得及执行,则可能会看到以下信息:
|
||||
|
||||
```
|
||||
$ cancel 229
|
||||
@ -127,13 +127,13 @@ cancel: cancel-job failed: Job #229 is already completed - can't cancel.
|
||||
|
||||
### 双面打印
|
||||
|
||||
要以双面模式打印,您可以在 **lp** 命令中使用 **sides** 选项,该选项表示既可以在纸张的正反面进行打印,又可以在纸张的其中一面进行打印。 通常此设置表示看起来像双面竖排格式文档方式。
|
||||
要以双面模式打印,你可以在 `lp` 命令中使用 `sides` 选项,该选项不但表示了在纸张的正反面进行打印,还表示了从纸张的哪个边开始打印。这个设置代表了你期望以双面纵向文档的正常方式打印。
|
||||
|
||||
```
|
||||
$ lp -o sides=two-sided-long-edge Notes.pdf
|
||||
```
|
||||
|
||||
如果要所有文档以双面模式打印,则可以使用 **lpoptions** 命令更改 `lp` 设置进而更改 **sides** 的设置。
|
||||
如果要所有文档以双面模式打印,则可以使用 `lpoptions` 命令更改 `sides` 设置以修改 `lp` 的设置。
|
||||
|
||||
```
|
||||
$ lpoptions -o sides=two-sided-short-edge
|
||||
@ -147,7 +147,7 @@ $ lpoptions -o sides=one-sided
|
||||
|
||||
#### 横向打印
|
||||
|
||||
要以横向模式打印,可以在 `lp` 命令中使用 **landscape** 选项。
|
||||
要以横向模式打印,可以在 `lp` 命令中使用 `landscape` 选项。
|
||||
|
||||
```
|
||||
$ lp -o landscape penguin.jpg
|
||||
@ -155,9 +155,7 @@ $ lp -o landscape penguin.jpg
|
||||
|
||||
### CUPS(Unix 通用打印系统)
|
||||
|
||||
Linux 系统上使用的打印系统是基于标准的开源打印系统,称为 **CUPS**,原本基于 **Unix 通用打印系统**。 它允许计算机充当打印服务器。
|
||||
|
||||
加入 Network World 社区的 [Facebook][2] 和 [LinkedIn][3],以评论最感兴趣的主题。
|
||||
Linux 系统上使用的打印系统是基于标准的开源打印系统,称为 **CUPS**,原意是<ruby>Unix 通用打印系统<rt>Common Unix Printing System</rt></ruby>。 它允许计算机充当打印服务器。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -165,8 +163,8 @@ via: https://www.networkworld.com/article/3373502/printing-from-the-linux-comman
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/stevenzdg988)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
译者:[stevenzdg988](https://github.com/stevenzdg988)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
150
published/20210106 Learn C by writing a simple game.md
Normal file
150
published/20210106 Learn C by writing a simple game.md
Normal file
@ -0,0 +1,150 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (qfzy1233)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-13013-1.html)
|
||||
[#]: subject: (Learn C by writing a simple game)
|
||||
[#]: via: (https://opensource.com/article/21/1/learn-c)
|
||||
[#]: author: (Jim Hall https://opensource.com/users/jim-hall)
|
||||
|
||||
通过编写一个简单的游戏学习 C 语言
|
||||
======
|
||||
|
||||
> 当你学习一门新的编程语言时,这个“猜数字”游戏是一个很好的入门程序。下面是如何用 C 语言来编写它。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202101/13/232713lh91stdahcxfyfhe.jpg)
|
||||
|
||||
我在小学时就开始 [自学编程][2]。我的第一个程序是在 Apple II 上编写的,但最终,我还是通过看书和编程练习学会了 C 语言。练习编程的最佳方法是编写示例程序,它能帮助你练习新知识。
|
||||
|
||||
在我学习一种新的编程语言时,我喜欢编写一个简单的“猜数字”游戏来练习。电脑从 1 到 100 中随机挑选一个数字,你必须通过猜测来算出来。在另一篇文章中,我展示了如何用 Bash 语言编写这个[“猜数字”游戏][3],我的同事也写了一些文章,介绍如何用 [Java][4]、[Julia][5] 和其他计算机语言编写它。
|
||||
|
||||
“猜数字”游戏的伟大之处在于它践行了几个编程概念:如何使用变量、如何比较值、如何打印输出以及如何读取输入。
|
||||
|
||||
整个夏天,我录制了[一个系列视频][6],教人们如何用 [C 语言][7]编写程序。从那以后,我听到了很多人都在跟着它学习 C 语言编程的消息。所以,我想接着用 C 语言写一个“猜数字”的游戏。
|
||||
|
||||
### 去取一个随机数
|
||||
|
||||
从写一个函数来选择一个随机数字来开始“猜数字”游戏。在编写函数时,优秀的程序员会尽量使它们具有灵活性,这样他们就可以重用它们来解决略有不同的问题。因此,与其硬编码函数来选择 1 到 100 之间的一个随机数,不如编写函数来选择 1 到某个整数 `maxval` 之间的一个随机数:
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
#include <sys/random.h>
|
||||
|
||||
int
|
||||
randnum(int maxval)
|
||||
{
|
||||
/* pick a random number from 1 to maxval */
|
||||
|
||||
int randval;
|
||||
|
||||
getrandom(&randval, sizeof(int), GRND_NONBLOCK);
|
||||
|
||||
/* could be negative, so ensure it's positive */
|
||||
|
||||
if (randval < 0) {
|
||||
return (-1 * randval % maxval + 1);
|
||||
}
|
||||
else {
|
||||
return (randval % maxval + 1);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
该函数使用 Linux 的系统调用 `getrandom` 来生成一系列随机数。你可以在手册页中了解关于这个系统调用的更多信息,但请注意,`getrandom` 将用随机的 0 和 1 填充变量。这意味着最终值可以是正的,也可以是负的,因此你需要在之后进行测试,以确保 `randnum` 函数的结果是正值。
|
||||
|
||||
### 编写程序
|
||||
|
||||
你可以用这个函数来写你的“猜数字”程序:
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
#include <sys/random.h>
|
||||
|
||||
int
|
||||
randnum(int maxval)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int number;
|
||||
int guess;
|
||||
|
||||
number = randnum(100);
|
||||
|
||||
puts("Guess a number between 1 and 100");
|
||||
|
||||
do {
|
||||
scanf("%d", &guess);
|
||||
|
||||
if (guess < number) {
|
||||
puts("Too low");
|
||||
}
|
||||
else if (guess > number) {
|
||||
puts("Too high");
|
||||
}
|
||||
} while (guess != number);
|
||||
|
||||
puts("That's right!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
程序首先使用 `randnum` 函数从 1 到 100 之间选择一个随机数。在向用户输出一个提示后,程序进入一个 `do-while` 循环,以便用户可以猜测数字。
|
||||
|
||||
在循环的每次迭代中,程序测试用户的猜测的数值。如果用户的猜测小于随机数,程序将输出“Too low”,如果猜测大于随机数,程序将输出“Too high”。循环继续,直到用户的猜测与随机数相同。
|
||||
|
||||
当循环退出时,程序输出 “That's right!”,然后立即结束:
|
||||
|
||||
```
|
||||
$ gcc -o guess -Wall guess.c
|
||||
|
||||
$ ./guess
|
||||
Guess a number between 1 and 100
|
||||
50
|
||||
Too high
|
||||
30
|
||||
Too low
|
||||
40
|
||||
Too low
|
||||
45
|
||||
Too high
|
||||
42
|
||||
Too low
|
||||
43
|
||||
Too low
|
||||
44
|
||||
That's right!
|
||||
```
|
||||
|
||||
### 尝试动手
|
||||
|
||||
在学习一门新的编程语言时,这个“猜数字”游戏是一个很好的入门程序,因为它以一种非常直接的方式练习了几个常见的编程概念。通过用不同的编程语言实现这个简单的游戏,你可以演示一些核心概念,并比较每种语言的细节。
|
||||
|
||||
你有最喜欢的编程语言吗?你会如何用它来编写“猜数字”游戏呢?关注本系列文章,查看你可能感兴趣的其他编程语言的示例。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/1/learn-c
|
||||
|
||||
作者:[Jim Hall][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[qfzy1233](https://github.com/qfzy1233)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jim-hall
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lenovo-thinkpad-laptop-concentration-focus-windows-office.png?itok=-8E2ihcF (Woman using laptop concentrating)
|
||||
[2]: https://opensource.com/article/20/8/learn-open-source
|
||||
[3]: https://linux.cn/article-12962-1.html
|
||||
[4]: https://opensource.com/article/20/12/learn-java
|
||||
[5]: https://opensource.com/article/20/12/julia
|
||||
[6]: https://opensource.com/article/20/8/teaching-c
|
||||
[7]: https://opensource.com/article/20/8/c-programming-cheat-sheet
|
||||
[8]: http://www.opengroup.org/onlinepubs/009695399/functions/puts.html
|
||||
[9]: http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html
|
@ -1,83 +0,0 @@
|
||||
Chao-zhi is translating
|
||||
|
||||
GCC: Optimizing Linux, the Internet, and Everything
|
||||
======
|
||||
|
||||
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gcc-paper.jpg?itok=QFNUZWsV)
|
||||
|
||||
Software is useless if computers can't run it. Even the most talented developer is at the mercy of the compiler when it comes to run-time performance - if you don’t have a reliable compiler toolchain you can’t build anything serious. The GNU Compiler Collection (GCC) provides a robust, mature and high performance partner to help you get the most out of your software. With decades of development by thousands of people GCC is one of the most respected compilers in the world. If you are building applications and not using GCC, you are missing out on the best possible solution.
|
||||
|
||||
GCC is the “de facto-standard open source compiler today” [1] according to LLVM.org and the foundation used to build complete systems - from the kernel upwards. GCC supports over 60 hardware platforms, including ARM, Intel, AMD, IBM POWER, SPARC, HP PA-RISC, and IBM Z, as well as a variety of operating environments, including GNU, Linux, Windows, macOS, FreeBSD, NetBSD, OpenBSD, DragonFly BSD, Solaris, AIX, HP-UX, and RTEMS. It offers highly compliant C/C++ compilers and support for popular C libraries, such as GNU C Library (glibc), Newlib, musl, and the C libraries included with various BSD operating systems, as well as front-ends for Fortran, Ada, and GO languages. GCC also functions as a cross compiler, creating executable code for a platform other than the one on which the compiler is running. GCC is the core component of the tightly integrated GNU toolchain, produced by the GNU Project, that includes glibc, Binutils, and the GNU Debugger (GDB).
|
||||
|
||||
"My all-time favorite GNU tool is GCC, the GNU Compiler Collection. At a time when developer tools were expensive, GCC was the second GNU tool and the one that enabled a community to write and build all the others. This tool single-handedly changed the industry and led to the creation of the free software movement, since a good, free compiler is a prerequisite to a community creating software." —Dave Neary, Open Source and Standards team at Red Hat. [2]
|
||||
|
||||
### Optimizing Linux
|
||||
|
||||
As the default compiler for the Linux kernel source, GCC delivers trusted, stable performance along with the additional extensions needed to correctly build the kernel. GCC is a standard component of popular Linux distributions, such as Arch Linux, CentOS, Debian, Fedora, openSUSE, and Ubuntu, where it routinely compiles supporting system components. This includes the default libraries used by Linux (such as libc, libm, libintl, libssh, libssl, libcrypto, libexpat, libpthread, and ncurses) which depend on GCC to provide correctness and performance and are used by applications and system utilities to access Linux kernel features. Many of the application packages included with a distribution are also built with GCC, such as Python, Perl, Ruby, nginx, Apache HTTP Server, OpenStack, Docker, and OpenShift. This combination of kernel, libraries, and application software translates into a large volume of code built with GCC for each Linux distribution. For the openSUSE distribution nearly 100% of native code is built by GCC, including 6,135 source packages producing 5,705 shared libraries and 38,927 executables. This amounts to about 24,540 source packages compiled weekly. [3]
|
||||
|
||||
The base version of GCC included in Linux distributions is used to create the kernel and libraries that define the system Application Binary Interface (ABI). User space developers have the option of downloading the latest stable version of GCC to gain access to advanced features, performance optimizations, and improvements in usability. Linux distributions offer installation instructions or prebuilt toolchains for deploying the latest version of GCC along with other GNU tools that help to enhance developer productivity and improve deployment time.
|
||||
|
||||
### Optimizing the Internet
|
||||
|
||||
GCC is one of the most widely adopted core compilers for embedded systems, enabling the development of software for the growing world of IoT devices. GCC offers a number of extensions that make it well suited for embedded systems software development, including fine-grained control using compiler built-ins, #pragmas, inline assembly, and application-focussed command-line options. GCC supports a broad base of embedded architectures, including ARM, AMCC, AVR, Blackfin, MIPS, RISC-V, Renesas Electronics V850, and NXP and Freescale Power-based processors, producing efficient, high quality code. The cross-compilation capability offered by GCC is critical to this community, and prebuilt cross-compilation toolchains [4] are a major requirement. For example, the GNU ARM Embedded toolchains are integrated and validated packages featuring the Arm Embedded GCC compiler, libraries, and other tools necessary for bare-metal software development. These toolchains are available for cross-compilation on Windows, Linux and macOS host operating systems and target the popular ARM Cortex-R and Cortex-M processors, which have shipped in tens of billions of internet capable devices. [5]
|
||||
|
||||
GCC empowers Cloud Computing, providing a reliable development platform for software that needs to directly manages computing resources, like database and web serving engines and backup and security software. GCC is fully compliant with C++11 and C++14 and offers experimental support for C++17 and C++2a [6], creating performant object code with a solid debugging information. Some examples of applications that utilize GCC include: MySQL Database Management System, which requires GCC for Linux [7]; the Apache HTTP Server, which recommends using GCC [8]; and Bacula, an enterprise ready network backup tool which require GCC. [9]
|
||||
|
||||
### Optimizing Everything
|
||||
|
||||
For the research and development of the scientific codes used in High Performance Computing (HPC), GCC offers mature C, C++, and Fortran front ends as well as support for OpenMP and OpenACC APIs for directive-based parallel programming. Because GCC offers portability across computing environments, it enables code to be more easily targeted and tested across a variety of new and legacy client and server platforms. GCC offers full support for OpenMP 4.0 for C, C++ and Fortran compilers and full support for OpenMP 4.5 for C and C++ compilers. For OpenACC, GCC supports most of the 2.5 specification and performance optimizations and is the only non-commercial, nonacademic compiler to provide [OpenACC][1] support.
|
||||
|
||||
Code performance is an important parameter to this community and GCC offers a solid performance base. A Nov. 2017 paper published by Colfax Research evaluates C++ compilers for the speed of compiled code parallelized with OpenMP 4.x directives and for the speed of compilation time. Figure 1 plots the relative performance of the computational kernels when compiled by the different compilers and run with a single thread. The performance values are normalized so that the performance of G++ is equal to 1.0.
|
||||
|
||||
![performance][3]
|
||||
|
||||
Figure 1. Relative performance of each kernel as compiled by the different compilers. (single-threaded, higher is better).
|
||||
|
||||
[Used with permission][4]
|
||||
|
||||
The paper summarizes “the GNU compiler also does very well in our tests. G++ produces the second fastest code in three out of six cases and is amongst the fastest compiler in terms of compile time.” [10]
|
||||
|
||||
### Who Is Using GCC?
|
||||
|
||||
In The State of Developer Ecosystem Survey in 2018 by JetBrains, out of 6,000 developers who took the survey GCC is regularly used by 66% of C++ programmers and 73% of C programmers. [11] Here is a quick summary of the benefits of GCC that make it so popular with the developer community.
|
||||
|
||||
* For developers required to write code for a variety of new and legacy computing platforms and operating environments, GCC delivers support for the broadest range of hardware and operating environments. Compilers offered by hardware vendors focus mainly on support for their products and other open source compilers are much more limited in the hardware and operating systems supported. [12]
|
||||
|
||||
* There is a wide variety of GCC-based prebuilt toolchains, which has particular appeal to embedded systems developers. This includes the GNU ARM Embedded toolchains and 138 pre-compiled cross compiler toolchains available on the Bootlin web site. [13] While other open source compilers, such as Clang/LLVM, can replace GCC in existing cross compiling toolchains, these would need to be completely rebuilt by the developer. [14]
|
||||
|
||||
* GCC delivers to application developers trusted, stable performance from a mature compiler platform. The GCC 8/9 vs. LLVM Clang 6/7 Compiler Benchmarks On AMD EPYC article provides results of 49 benchmarks ran across the four tested compilers at three optimization levels. Coming in first 34% of the time was GCC 8.2 RC1 using "-O3 -march=native" level, while at the same optimization level LLVM Clang 6.0 came in second with wins 20% of the time. [15]
|
||||
|
||||
* GCC delivers improved diagnostics for compile time debugging [16] and accurate and useful information for runtime debugging. GCC is tightly integrated with GDB, a mature and feature complete tool which offers ‘non-stop’ debugging that can stop a single thread at a breakpoint.
|
||||
|
||||
* GCC is a well supported platform with an active, committed community that supports the current and two previous releases. With releases schedule yearly this provides two years of support for a version.
|
||||
|
||||
|
||||
|
||||
|
||||
### GCC: Continuing to Optimize Linux, the Internet, and Everything
|
||||
|
||||
GCC continues to move forward as a world-class compiler. The most current version of GCC is 8.2, which was released in July 2018 and added hardware support for upcoming Intel CPUs, more ARM CPUs and improved performance for AMD’s ZEN CPU. Initial C17 support has been added along with initial work towards C++2A. Diagnostics have continued to be enhanced including better emitted diagnostics, with improved locations, location ranges, and fix-it hints, particularly in the C++ front end. A blog written by David Malcolm of Red Hat in March 2018 provides an overview of usability improvements in GCC 8. [17]
|
||||
|
||||
New hardware platforms continue to rely on the GCC toolchain for software development, such as RISC-V, a free and open ISA that is of interest to machine learning, Artificial Intelligence (AI), and IoT market segments. GCC continues to be a critical component in the continuing development of Linux systems. The Clear Linux Project for Intel Architecture, an emerging distribution built for cloud, client, and IoT use cases, provides a good example of how GCC compiler technology is being used and improved to boost the performance and security of a Linux-based system. GCC is also being used for application development for Microsoft's Azure Sphere, a Linux-based operating system for IoT applications that initially supports the ARM based MediaTek MT3620 processor. In terms of developing the next generation of programmers, GCC is also a core component of the Windows toolchain for Raspberry PI, the low-cost embedded board running Debian-based GNU/Linux that is used to promote the teaching of basic computer science in schools and developing countries.
|
||||
|
||||
GCC was first released on March 22, 1987 by Richard Stallman, the founder of the GNU Project and was considered a significant breakthrough since it was the first portable ANSI C optimizing compiler released as free software. GCC is maintained by a community of programmers from all over the world under the direction of a steering committee that ensures broad, representative oversight of the project. GCC’s community approach is one of its strengths, resulting in a large and diverse community of developers and users that contribute to and provide support for the project. According to Open Hub, GCC “is one of the largest open-source teams in the world, and is in the top 2% of all project teams on Open Hub.” [18]
|
||||
|
||||
There has been a lot of discussion about the licensing of GCC, most of which confuses rather than enlightens. GCC is distributed under the GNU General Public License version 3 or later with the Runtime Library Exception. This is a copyleft license, which means that derivative work can only be distributed under the same license terms. GPLv3 is intended to protect GCC from being made proprietary and requires that changes to GCC code are made available freely and openly. To the ‘end user’ the compiler is just the same as any other; using GCC makes no difference to any licensing choices you might make for your own code. [19]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/2018/10/gcc-optimizing-linux-internet-and-everything
|
||||
|
||||
作者:[Margaret Lewis][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://www.linux.com/users/margaret-lewis
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.openacc.org/tools
|
||||
[2]: /files/images/gccjpg-0
|
||||
[3]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gcc_0.jpg?itok=HbGnRqWX "performance"
|
||||
[4]: https://www.linux.com/licenses/category/used-permission
|
@ -0,0 +1,73 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Gain control of your calendar with this simple strategy)
|
||||
[#]: via: (https://opensource.com/article/21/1/calendar-time-boxing)
|
||||
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
|
||||
|
||||
Gain control of your calendar with this simple strategy
|
||||
======
|
||||
Time boxing is a time management strategy that helps protect your time
|
||||
so you can focus on the task at hand.
|
||||
![Calendar close up snapshot][1]
|
||||
|
||||
In prior years, this annual series covered individual apps. This year, we are looking at all-in-one solutions in addition to strategies to help in 2021. Welcome to day 3 of 21 Days of Productivity in 2021.
|
||||
|
||||
Before we had calendars on our computers, we often had to do a dance around scheduling a meeting. A time that was good for Alice and Bob might not be suitable for Carol and Dave, so there was a lot of talking about when the meeting could be held. When electronic calendars became generally available, it was a revolution. Alice could check to see when Bob, Carol, Dave, _and_ a meeting room were open, and send out an invitation asking for all of them to attend.
|
||||
|
||||
And, if you're looking for an open source calendar client, check [these alternatives][2] out.
|
||||
|
||||
![A typical day][3]
|
||||
|
||||
A typical day (Kevin Sonney, [CC BY-SA 4.0][4])
|
||||
|
||||
However, this led to problems where the only time available was when Carol, who is on the West Coast, is at lunch. Or Bob planned to use that big empty space on his calendar for writing a new function, but now has a meeting in the middle of it.
|
||||
|
||||
If Bob wants to avoid this, he creates an appointment with himself on his calendar to "Write Code," and Alice sees that block of time is not available.
|
||||
|
||||
This strategy is called _time boxing_ and is not only useful for preventing that meeting from being scheduled at a given time, but for giving a person the time to focus on a specific task. That task might be responding to email, writing code, or taking a break.
|
||||
|
||||
![An on-call week][5]
|
||||
|
||||
An on-call week (Kevin Sonney, [CC BY-SA 4.0][4])
|
||||
|
||||
Time boxing is very good for working on long projects with a deadline. With dedicated time set aside, it is easier to focus on individual steps and track progress. It also allows a person to say, "this is when I will be working on X," in a status update email or meeting.
|
||||
|
||||
[As discussed yesterday][6], assigning dedicated times to read and respond to email helps reduce stress and set expectations for when people might receive a response. Users can schedule time to work on more complex issues that may be brought up in email as well.
|
||||
|
||||
Taking breaks is one of the things I, at least, am _really bad_ at. After two hours of working on a problem, I know that my mind is going to be stuck in that space. For me, getting up and stepping away from my desk for a short while helps me clear my mind and focus on the next thing. In my case, this is very important after a meeting since what I may be working on next is not very likely to be directly related to the meeting I just attended.
|
||||
|
||||
I also block out time to eat lunch since I, like many people in technology, will get wrapped up in something and forget to eat lunch until late in the day or not have a meal at all, and just snack here and there.
|
||||
|
||||
![Blocked out time][7]
|
||||
|
||||
Blocked out time (Kevin Sonney, [CC BY-SA 4.0][4])
|
||||
|
||||
How do we deal with the person who schedules something in the middle of a block? There are a couple of ways. The easiest is to request a new time, just like any other meeting with a conflicting time. Sometimes, though, it can't be moved, and the meetings with myself must be moved around to accommodate.
|
||||
|
||||
Time boxing is an effective strategy for protecting time to work on specific things, take breaks, or process other tasks, and one I regularly use for both work and my hobbies (like writing articles for OpenSource.com 😄).
|
||||
|
||||
Need to keep your schedule straight? Learn how to do it using open source with these free...
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/1/calendar-time-boxing
|
||||
|
||||
作者:[Kevin Sonney][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/ksonney
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/calendar.jpg?itok=jEKbhvDT (Calendar close up snapshot)
|
||||
[2]: https://opensource.com/alternatives/google-calendar
|
||||
[3]: https://opensource.com/sites/default/files/pictures/a-typical-day.png (A typical day)
|
||||
[4]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[5]: https://opensource.com/sites/default/files/pictures/an-on-call-week.png (An on-call week)
|
||||
[6]: https://opensource.com/article/21/1/email-rules
|
||||
[7]: https://opensource.com/sites/default/files/pictures/oh-that-person.png (Blocked out time)
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (Chao-zhi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,381 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Integrate online documents editors, into a Python web app using ONLYOFFICE)
|
||||
[#]: via: (https://opensourceforu.com/2019/09/integrate-online-documents-editors-into-a-python-web-app-using-onlyoffice/)
|
||||
[#]: author: (Aashima Sharma https://opensourceforu.com/author/aashima-sharma/)
|
||||
|
||||
Integrate online documents editors, into a Python web app using ONLYOFFICE
|
||||
======
|
||||
|
||||
[![][1]][2]
|
||||
|
||||
_[ONLYOFFICE][3] is an open-source collaborative office suite distributed under the terms of GNU AGPL v.3 license. It contains three editors for text documents, spreadsheets, and presentations and features the following:_
|
||||
|
||||
* Viewing, editing and co-editing docx, .xlsx, pptx files. OOXML as a core format ensures high compatibility with Microsoft Word, Excel and PowerPoint files.
|
||||
* Editing other popular formats (.odt, .rtf, .txt, .html, .ods., .csv, .odp) with inner conversion to OOXML.
|
||||
* Familiar tabbed interface.
|
||||
* Collaboration tools: two co-editing modes (fast and strict), track changes, comments and integrated chat.
|
||||
* Flexible access rights management: full access, read only, review, form filling and comment.
|
||||
* Building your own add-ons using the API.
|
||||
* 250 languages available and hieroglyphic alphabets.
|
||||
|
||||
|
||||
|
||||
API allowing the developers integrate ONLYOFFICE editors into their own web sites and apps written in any programming language and setup and manage the editors.
|
||||
|
||||
To integrate ONLYOFFICE editors, we will need an integration app connecting the editors (ONLYOFFICE Document Server) and your service. To use editors within your interface, it should grant to ONLYOFFICE the following permissions :
|
||||
|
||||
* Adding and executing custom code.
|
||||
* Anonymous access for downloading and saving files. It means that the editors only communicate with your service on the server side without involving any user authorization data from the client side (browser cookies).
|
||||
* Adding new buttons to UI (for example, “Open in ONLYOFFICE”, “Edit in ONLYOFFICE”).
|
||||
* Оpening a new page where ONLYOFFICE can execute the script to add an editor.
|
||||
* Ability to specify Document Server connection settings.
|
||||
|
||||
|
||||
|
||||
There are several cases of successful integration with popular collaboration solutions such as Nextcloud, ownCloud, Alfresco, Confluence and SharePoint, via official ready-to-use connectors offered by ONLYOFFICE.
|
||||
|
||||
One of the most actual integration cases is the integration of ONLYOFFICE editors with its open-source collaboration platform written in C#. This platform features document and project management, CRM, email aggregator, calendar, user database, blogs, forums, polls, wiki, and instant messenger.
|
||||
|
||||
Integrating online editors with CRM and Projects modules, you can:
|
||||
|
||||
* Attach documents to CRM opportunities and cases, or to project tasks and discussions, or even create a separate folder with documents, spreadsheets, and presentations related to the project.
|
||||
* Create new docs, sheets, and presentations right in CRM or in the Project module.
|
||||
* Open and edit attached documents, or download and delete them.
|
||||
* Import contacts to your CRM in bulk from a CSV file as well as export the customer database as a CSV file.
|
||||
|
||||
|
||||
|
||||
In the Mail module, you can attach files stored in the Documents module or insert a link to the needed document into the message body. When ONLYOFFICE users receive a message with an attached document, they are able to: download the attachment, view the file in the browser, open the file for editing or save it to the Documents module. As mentioned above, if the format differs from OOXML, the file will be automatically converted to .docx/.xlsx/.pptx and its copy will be saved in the original format as well.
|
||||
|
||||
In this article, you will see the integration process of ONLYOFFICE into the Document Management System written in Python, one of the most popular programming languages. The following steps will show you how to create all the necessary elements to make possible work and collaboration on documents within DMS interface: viewing, editing, co-editing, saving files and users access management and may serve as an example of integration into your Python app.
|
||||
|
||||
**1\. What you will need**
|
||||
|
||||
Let’s start off by creating key components of the integration process: [_ONLYOFFICE Document Server_][4] and DMS written in Python.
|
||||
|
||||
1.1 To install ONLYOFFICE Document Server you can choose from multiple installation options: compile the source code available on GitHub, use .deb or .rpm packages or the Docker image.
|
||||
We recommend installing Document Server and all the necessary dependencies with only one command using the Docker image. Please note, that choosing this method, you need the latest Docker version installed.
|
||||
|
||||
```
|
||||
docker run -itd -p 80:80 onlyoffice/documentserver-de
|
||||
```
|
||||
|
||||
1.2 We need to develop DMS in Python. If you have one already, please, check if it meets the following conditions:
|
||||
|
||||
* Has a list of files you need to open for viewing/editing
|
||||
* Allows downloading files
|
||||
|
||||
|
||||
|
||||
For the app, we will use a Bottle framework. We will install it in the working directory using the following command:
|
||||
|
||||
```
|
||||
pip install bottle
|
||||
```
|
||||
|
||||
Then we create the app’s code * main.py* and the template _index.tpl_ .
|
||||
We add the following code into this * main.py* file:
|
||||
|
||||
```
|
||||
from bottle import route, run, template, get, static_file # connecting the framework and the necessary components
|
||||
@route('/') # setting up routing for requests for /
|
||||
def index():
|
||||
return template('index.tpl') # showing template in response to request
|
||||
run(host="localhost", port=8080) # running the application on port 8080
|
||||
```
|
||||
|
||||
Once we run the app, an empty page will be rendered on <http://localhost:8080 >.
|
||||
|
||||
In order, the Document Server to be able to create new docs, add default files and form a list of their names in the template, we should create a folder _files_ , and put 3 files (.docx, .xlsx and .pptx) in there.
|
||||
|
||||
To read these files’ names, we use the _listdir_ component.
|
||||
|
||||
```
|
||||
from os import listdir
|
||||
```
|
||||
|
||||
Now let’s create a variable for all the file names from the files folder:
|
||||
|
||||
```
|
||||
sample_files = [f for f in listdir('files')]
|
||||
```
|
||||
|
||||
To use this variable in the template, we need to pass it through the _template_ method:
|
||||
|
||||
```
|
||||
def index():
|
||||
return template('index.tpl', sample_files=sample_files)
|
||||
|
||||
Here’s this variable in the template:
|
||||
%for file in sample_files:
|
||||
<div>
|
||||
<span>{{file}}</span>
|
||||
</div>
|
||||
% end
|
||||
```
|
||||
|
||||
We restart the application to see the list of filenames on the page.
|
||||
Here’s the method to make these files available for all the app users:
|
||||
|
||||
```
|
||||
@get("/files/<filepath:re:.*\.*>")
|
||||
def show_sample_files(filepath):
|
||||
return static_file(filepath, root="files")
|
||||
```
|
||||
|
||||
**2\. How to view docs in ONLYOFFICE within the Python App**
|
||||
Once all the components are ready, let’s add functions to make editors operational within the app interface.
|
||||
|
||||
The first option enables users to open and view docs. Connect document editors API in the template:
|
||||
|
||||
```
|
||||
<script type="text/javascript" src="editor_url/web-apps/apps/api/documents/api.js"></script>
|
||||
```
|
||||
|
||||
_editor_url_ is a link to document editors.
|
||||
|
||||
A button to open each file for viewing:
|
||||
|
||||
```
|
||||
<button onclick="view('files/{{file}}')">view</button>
|
||||
```
|
||||
|
||||
Now we need to add a div with _id_ , in which the document editor will be opened:
|
||||
|
||||
```
|
||||
<div id="editor"></div>
|
||||
```
|
||||
|
||||
To open the editor, we have to call a function:
|
||||
|
||||
```
|
||||
<script>
|
||||
function view(filename) {
|
||||
if (/docx$/.exec(filename)) {
|
||||
filetype = "text"
|
||||
}
|
||||
if (/xlsx$/.exec(filename)) {
|
||||
filetype = "spreadsheet"
|
||||
}
|
||||
if (/pptx$/.exec(filename)) {
|
||||
filetype = "presentation",
|
||||
title: filename
|
||||
}
|
||||
new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: filetype,
|
||||
document: {
|
||||
url: "host_url" + '/' + filename,
|
||||
title: filename
|
||||
},
|
||||
editorConfig: {mode: 'view'}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
There are two arguments for the DocEditor function: id of the element where the editors will be opened and a JSON with the editors’ settings.
|
||||
In this example, the following mandatory parameters are used:
|
||||
|
||||
* _documentType_ is identified by its format (.docx, .xlsx, .pptx for texts, spreadsheets and presentations accordingly)
|
||||
* _document.url_ is the link to the file you are going to open.
|
||||
* _editorConfig.mode_.
|
||||
|
||||
|
||||
|
||||
We can also add _title_ that will be displayed in the editors.
|
||||
|
||||
So, now we have everything to view docs in our Python app.
|
||||
|
||||
**3\. How to edit docs in ONLYOFFICE within the Python App**
|
||||
First of all, add the “Edit” button:
|
||||
|
||||
```
|
||||
<button onclick="edit('files/{{file}}')">edit</button>
|
||||
```
|
||||
|
||||
Then create a new function that will open files for editing. It is similar to the View function.
|
||||
Now we have 3 functions:
|
||||
|
||||
```
|
||||
<script>
|
||||
var editor;
|
||||
function view(filename) {
|
||||
if (editor) {
|
||||
editor.destroyEditor()
|
||||
}
|
||||
editor = new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: get_file_type(filename),
|
||||
document: {
|
||||
url: "host_url" + '/' + filename,
|
||||
title: filename
|
||||
},
|
||||
editorConfig: {mode: 'view'}
|
||||
});
|
||||
}
|
||||
function edit(filename) {
|
||||
if (editor) {
|
||||
editor.destroyEditor()
|
||||
}
|
||||
editor = new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: get_file_type(filename),
|
||||
document: {
|
||||
url: "host_url" + '/' + filename,
|
||||
title: filename
|
||||
}
|
||||
});
|
||||
}
|
||||
function get_file_type(filename) {
|
||||
if (/docx$/.exec(filename)) {
|
||||
return "text"
|
||||
}
|
||||
if (/xlsx$/.exec(filename)) {
|
||||
return "spreadsheet"
|
||||
}
|
||||
if (/pptx$/.exec(filename)) {
|
||||
return "presentation"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
_destroyEditor_ is called to close an open editor.
|
||||
As you might notice, the _editorConfig_ parameter is absent from the _edit()_ function, because it has by default the value * {“mode”: “edit”}.*
|
||||
|
||||
Now we have everything to open docs for co-editing in your Python app.
|
||||
|
||||
**4\. How to co-edit docs in ONLYOFFICE within the Python App**
|
||||
Co-editing is implemented by using the same document.key for the same document in the editors’ settings. Without this key, the editors will create the editing session each time you open the file.
|
||||
|
||||
Set unique keys for each doc to make users connect to the same editing session for co-editing. The format of the key should be the following: _filename + “_key”_. The next step is to add it to all of the configs where document is present.
|
||||
|
||||
```
|
||||
document: {
|
||||
url: "host_url" + '/' + filepath,
|
||||
title: filename,
|
||||
key: filename + '_key'
|
||||
},
|
||||
```
|
||||
|
||||
**5\. How to save docs in ONLYOFFICE within the Python App**
|
||||
Every time we change and save the file, ONLYOFFICE stores all its versions. Let’s see closely how it works. After we close the editor, Document Server builds the file version to be saved and sends the request to callbackUrl address. This request contains document.key and the link to the just built file.
|
||||
document.key is used to find the old version of the file and replace it with the new one. As we do not have any database here, we just send the filename using callbackUrl.
|
||||
Specify _callbackUrl_ parameter in the setting in _editorConfig.callbackUrl_ and add it to the _edit()method_:
|
||||
|
||||
```
|
||||
function edit(filename) {
|
||||
const filepath = 'files/' + filename;
|
||||
if (editor) {
|
||||
editor.destroyEditor()
|
||||
}
|
||||
editor = new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: get_file_type(filepath),
|
||||
document: {
|
||||
url: "host_url" + '/' + filepath,
|
||||
title: filename,
|
||||
key: filename + '_key'
|
||||
}
|
||||
,
|
||||
editorConfig: {
|
||||
mode: 'edit',
|
||||
callbackUrl: "host_url" + '/callback' + '&filename=' + filename // add file name as a request parameter
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
Write a method that will save file after getting the POST request to* /callback* address:
|
||||
|
||||
```
|
||||
@post("/callback") # processing post requests for /callback
|
||||
def callback():
|
||||
if request.json['status'] == 2:
|
||||
file = requests.get(request.json['url']).content
|
||||
with open('files/' + request.query['filename'], 'wb') as f:
|
||||
f.write(file)
|
||||
return "{\"error\":0}"
|
||||
```
|
||||
|
||||
* # status 2* is the built file.
|
||||
|
||||
When we close the editor, the new version of the file will be saved to storage.
|
||||
|
||||
**6\. How to manage users in ONLYOFFICE within the Python App**
|
||||
If there are users in your app, and you need to see who exactly is editing a doc, write their identifiers (id and name) in the editors’ configuration.
|
||||
Add the ability to select a user in the interface:
|
||||
|
||||
```
|
||||
<select id="user_selector" onchange="pick_user()">
|
||||
<option value="1" selected="selected">JD</option>
|
||||
<option value="2">Turk</option>
|
||||
<option value="3">Elliot</option>
|
||||
<option value="4">Carla</option>
|
||||
</select>
|
||||
```
|
||||
|
||||
If you add the call of the function *pick_user()*at the beginning of the tag _<script>_, it will initialize, in the function itself, the variables responsible for the id and the user name.
|
||||
|
||||
```
|
||||
function pick_user() {
|
||||
const user_selector = document.getElementById("user_selector");
|
||||
this.current_user_name = user_selector.options[user_selector.selectedIndex].text;
|
||||
this.current_user_id = user_selector.options[user_selector.selectedIndex].value;
|
||||
}
|
||||
```
|
||||
|
||||
Make use of _editorConfig.user.id_ and _editorConfig.user.name_ to configure user’s settings. Add these parameters to the editors’ configuration in the file editing function.
|
||||
|
||||
```
|
||||
function edit(filename) {
|
||||
const filepath = 'files/' + filename;
|
||||
if (editor) {
|
||||
editor.destroyEditor()
|
||||
}
|
||||
editor = new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: get_file_type(filepath),
|
||||
document: {
|
||||
url: "host_url" + '/' + filepath,
|
||||
title: filename
|
||||
},
|
||||
editorConfig: {
|
||||
mode: 'edit',
|
||||
callbackUrl: "host_url" + '/callback' + '?filename=' + filename,
|
||||
user: {
|
||||
id: this.current_user_id,
|
||||
name: this.current_user_name
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
Using this approach, you can integrate ONLYOFFICE editors into your app written in Python and get all the necessary tools for working and collaborating on docs. For more integration examples (Java, Node.js, PHP, Ruby), please, refer to the official [_API documentation_][5].
|
||||
|
||||
**By: Maria Pashkina**
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensourceforu.com/2019/09/integrate-online-documents-editors-into-a-python-web-app-using-onlyoffice/
|
||||
|
||||
作者:[Aashima Sharma][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://opensourceforu.com/author/aashima-sharma/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i1.wp.com/opensourceforu.com/wp-content/uploads/2016/09/Typist-composing-text-in-laptop.jpg?resize=696%2C420&ssl=1 (Typist composing text in laptop)
|
||||
[2]: https://i1.wp.com/opensourceforu.com/wp-content/uploads/2016/09/Typist-composing-text-in-laptop.jpg?fit=900%2C543&ssl=1
|
||||
[3]: https://www.onlyoffice.com/en/
|
||||
[4]: https://www.onlyoffice.com/en/developer-edition.aspx
|
||||
[5]: https://api.onlyoffice.com/editors/basic
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (stevenzdg988)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (stevenzdg988)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,120 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Homura: A WINE-based Game Launcher for BSD)
|
||||
[#]: via: (https://itsfoss.com/homura-game-launcher-bsd/)
|
||||
[#]: author: (John Paul https://itsfoss.com/author/john/)
|
||||
|
||||
Homura: A WINE-based Game Launcher for BSD
|
||||
======
|
||||
|
||||
BSD isn’t just for servers. People use it for desktop as well and perform common tasks including casual gaming. To help make that possible, we are going to look at an app that allows you to run Windows games on FreeBSD.
|
||||
|
||||
### What is Homura?
|
||||
|
||||
![][1]
|
||||
|
||||
[Homura][2] is a tool that allows you to play Windows games on FreeBSD. It was inspired by [Lutris][3]. It allows you to install and manage several Windows game and game store launchers. It mainly uses Wine, but also comes with a number of fixes and workarounds to get the games working.
|
||||
|
||||
Homura’s creator, [Alexander Vereeken][4], said that he created the application because “when I started using FreeBSD, there was no useful utility to set up games or launcher in wine, so I created one myself.” At the time, Wine was the only option. The Linux version of Steam did not exist.
|
||||
|
||||
![Homura install list][5]
|
||||
|
||||
Here is a list of the things you can install with Homura:
|
||||
|
||||
* Anarchy Online
|
||||
* Arc
|
||||
* Bethesda launcher
|
||||
* Blizzard launcher
|
||||
* Diablo II
|
||||
* Discord
|
||||
* Drakensang Online
|
||||
* GOG
|
||||
|
||||
|
||||
* Growtopia
|
||||
* League of Legends
|
||||
* Origin launcher
|
||||
* PokeMMO
|
||||
* Pokemon Uranium
|
||||
* RuneScape
|
||||
* Steam
|
||||
|
||||
|
||||
* Subway Surfers
|
||||
* Teamspeak
|
||||
* Tropix 2
|
||||
* UC Browser
|
||||
* Uplay
|
||||
* Wargaming Game Center
|
||||
* Itch.io
|
||||
|
||||
|
||||
|
||||
Homura is named after a character in an anime named [Madoka Magica][6]. It was originally hosted on GitHub before the creator moved to GitLab. It is currently hosted on Codeberg. Hopefully, it will stay there for now.
|
||||
|
||||
![Homura][7]
|
||||
|
||||
### Installing Homura Game Launcher on BSD
|
||||
|
||||
You can install Homura from the FreeBSD repo with this command:
|
||||
|
||||
```
|
||||
pkg install games/homura
|
||||
```
|
||||
|
||||
You can also build and install it from the ports collection using this command.
|
||||
|
||||
```
|
||||
cd /usr/ports/games/homura/ && make install clean
|
||||
```
|
||||
|
||||
Once it is installed, you can run Homura by selecting it from the menu or typing `Homura` in the command line. (The name must be capitalized in the terminal or it will not work.)
|
||||
|
||||
If you install Steam via Homura, you need to launch it from Homura. If you launch it from the operating system’s menu, it won’t display currently.
|
||||
|
||||
Steam’s library and store tabs are displayed by a built-in web browser. For some reason, that does not work on FreeBSD. But if you launch Steam from Homura’s menu, it will use a list mode that works without issue.
|
||||
|
||||
### Experience
|
||||
|
||||
I installed Homura on GhostBSD and used it to install Steam. Afterward, I installed a couple of games to test it out. Not all of the games I tried worked, mainly because they tried to use or install a Windows-specific piece of software that was unavailable. However, I was able to play one of my favorite games, Microsoft’s Rise of Nations, without any issue. (My test turned into a couple of hours of gameplay.)
|
||||
|
||||
![Homura Main Menu][8]
|
||||
|
||||
I also tried to install the GOG launcher. For some reason, it didn’t work for me. The loading screen would pop up and nothing would happen. I’m planning to file an issue. I didn’t test any of the installer/launchers because I don’t use them.
|
||||
|
||||
### Final Thoughts
|
||||
|
||||
Not everything worked smoothly with Homura, but I could play some of my favorite games.
|
||||
|
||||
![Rise of Nation on BSD][9]
|
||||
|
||||
This app is the classic case of a user who had a need and decided to fill it. In doing so, he makes life easier for others. Hopefully, this application will make it a little easier for people to start using FreeBSD as their operating system.
|
||||
|
||||
If you found this article interesting, please take a minute to share it on social media, Hacker News, or [Reddit][10].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/homura-game-launcher-bsd/
|
||||
|
||||
作者:[John Paul][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://itsfoss.com/author/john/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/01/homura.jpg?resize=800%2C450&ssl=1
|
||||
[2]: https://codeberg.org/Alexander88207/Homura
|
||||
[3]: https://lutris.net/
|
||||
[4]: https://codeberg.org/Alexander88207
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/01/homura-install.jpg?resize=800%2C421&ssl=1
|
||||
[6]: https://madoka.fandom.com/wiki/Puella_Magi_Madoka_Magica
|
||||
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/01/homura-about.jpg?resize=800%2C411&ssl=1
|
||||
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/01/homura-main-menu.jpg?resize=500%2C776&ssl=1
|
||||
[9]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/01/rise-of-nation-bsd.jpg?resize=800%2C450&ssl=1
|
||||
[10]: https://%0Areddit.com/r/linuxusersgroup
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -0,0 +1,309 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Analyze Kubernetes files for errors with KubeLinter)
|
||||
[#]: via: (https://opensource.com/article/21/1/kubelinter)
|
||||
[#]: author: (Jessica Cherry https://opensource.com/users/cherrybomb)
|
||||
|
||||
Analyze Kubernetes files for errors with KubeLinter
|
||||
======
|
||||
Find and fix errors in your Helm charts and Kubernetes configuration
|
||||
files with KubeLinter.
|
||||
![magnifying glass on computer screen, finding a bug in the code][1]
|
||||
|
||||
[KubeLinter][2] is an open source project released by Stackrox to analyze Kubernetes YAML files for security issues and errant code. The tool covers Helm charts and Kubernetes configuration files, including [Knative][3] files. Using it can improve cloud-native development, reduce development time, and encourage DevOps best practices.
|
||||
|
||||
### Download and install
|
||||
|
||||
For this tutorial, I used Pop_OS! 20.10, Helm 3, Go 1.13.8, and Minikube with Kubernetes 1.19.
|
||||
|
||||
You have several options to install KubeLinter.
|
||||
|
||||
You can install manually from the Git repository:
|
||||
|
||||
|
||||
```
|
||||
$ git clone [git@github.com][4]:stackrox/kube-linter.git
|
||||
$ cd kube-linter && make build
|
||||
$ .gobin/kube-linter version
|
||||
```
|
||||
|
||||
If you use [Homebrew][5], you can install it with the `brew` command:
|
||||
|
||||
|
||||
```
|
||||
`$ brew install kube-linter`
|
||||
```
|
||||
|
||||
You can also install it with Go (as I did):
|
||||
|
||||
|
||||
```
|
||||
$ GO111MODULE=on go get golang.stackrox.io/kube-linter/cmd/kube-linter
|
||||
go: finding golang.stackrox.io/kube-linter latest
|
||||
go: downloading golang.stackrox.io/kube-linter v0.0.0-20201204022312-475075c74675
|
||||
go: extracting golang.stackrox.io/kube-linter v0.0.0-20201204022312-475075c74675
|
||||
[...]
|
||||
```
|
||||
|
||||
After installing, you must make an alias in your `~/.bashrc`:
|
||||
|
||||
|
||||
```
|
||||
$ echo "alias kube-linter=$HOME/go/bin/kube-linter" >> ~/.bashrc
|
||||
$ source ~/.bashrc
|
||||
```
|
||||
|
||||
### Helm with KubeLinter
|
||||
|
||||
Now that the tool is installed, try it out on a Helm chart. First, start Minikube with a clean build and some small configuration changes:
|
||||
|
||||
|
||||
```
|
||||
$ minikube config set kubernetes-version v1.19.0
|
||||
$ minikube config set memory 8000
|
||||
❗ These changes will take effect upon a minikube delete and then a minikube start
|
||||
$ minikube config set cpus 12
|
||||
❗ These changes will take effect upon a minikube delete and then a minikube start
|
||||
$ minikube delete
|
||||
🔥 Deleting "minikube" in docker ...
|
||||
🔥 Deleting container "minikube" ...
|
||||
🔥 Removing /home/jess/.minikube/machines/minikube ...
|
||||
💀 Removed all traces of the "minikube" cluster.
|
||||
|
||||
$ minikube start
|
||||
😄 minikube v1.14.2 on Debian bullseye/sid
|
||||
✨ Using the docker driver based on user configuration
|
||||
👍 Starting control plane node minikube in cluster minikube
|
||||
🎉 minikube 1.15.1 is available! Download it: <https://github.com/kubernetes/minikube/releases/tag/v1.15.1>
|
||||
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
|
||||
|
||||
💾 Downloading Kubernetes v1.19.0 preload ...
|
||||
```
|
||||
|
||||
Once everything is running, create an example Helm chart called `first_test`:
|
||||
|
||||
|
||||
```
|
||||
$ helm create first_test
|
||||
Creating first_test
|
||||
$ ls
|
||||
first_test
|
||||
```
|
||||
|
||||
Test KubeLinter against the new, unedited chart. Run the `kube-linter` command to see the available commands and flags:
|
||||
|
||||
|
||||
```
|
||||
$ kube-linter
|
||||
Usage:
|
||||
/home/jess/go/bin/kube-linter [command]
|
||||
|
||||
Available Commands:
|
||||
checks View more information on lint checks
|
||||
help Help about any command
|
||||
lint Lint Kubernetes YAML files and Helm charts
|
||||
templates View more information on check templates
|
||||
version Print version and exit
|
||||
|
||||
Flags:
|
||||
-h, --help help for /home/jess/go/bin/kube-linter
|
||||
|
||||
Use "/home/jess/go/bin/kube-linter [command] --help" for more information about a command.
|
||||
```
|
||||
|
||||
Then test what the basic `lint` command does to your example chart. You'll end up with many errors, so I'll grab a snippet of some issues:
|
||||
|
||||
|
||||
```
|
||||
$ kube-linter lint first_test/
|
||||
|
||||
first_test/first_test/templates/deployment.yaml: (object: <no namespace>/test-release-first_test apps/v1, Kind=Deployment) container "first_test" does not have a read-only root file system (check: no-read-only-root-fs, remediation: Set readOnlyRootFilesystem to true in your container's securityContext.)
|
||||
|
||||
first_test/first_test/templates/deployment.yaml: (object: <no namespace>/test-release-first_test apps/v1, Kind=Deployment) container "first_test" is not set to runAsNonRoot (check: run-as-non-root, remediation: Set runAsUser to a non-zero number, and runAsNonRoot to true, in your pod or container securityContext. See <https://kubernetes.io/docs/tasks/configure-pod-container/security-context/> for more details.)
|
||||
[...]
|
||||
Error: found 12 lint errors
|
||||
```
|
||||
|
||||
For the sake of brevity, I picked two security issues that are easy for me to fix. Over time, as you test more, you'll be able to fix any issues you find.
|
||||
|
||||
The `kube-linter` output provides hints about the required fixes. For instance, the first error ends with:
|
||||
|
||||
|
||||
```
|
||||
`remediation: Set readOnlyRootFilesystem to true in your container's securityContext.`
|
||||
```
|
||||
|
||||
The next step is clear: Open the `values.yaml` file in a text editor (I use Vi, but you can use whatever you like) and locate the `securityContext` section:
|
||||
|
||||
|
||||
```
|
||||
securityContext: {}
|
||||
# capabilities:
|
||||
# drop:
|
||||
# - ALL
|
||||
# readOnlyRootFilesystem: true
|
||||
# runAsNonRoot: true
|
||||
# runAsUser: 1000
|
||||
```
|
||||
|
||||
Uncomment the section and remove the braces:
|
||||
|
||||
|
||||
```
|
||||
securityContext:
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
readOnlyRootFilesystem: true
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000
|
||||
```
|
||||
|
||||
Save the file and rerun the linter. Those errors no longer show up in the list, and the error count changes.
|
||||
|
||||
|
||||
```
|
||||
`Error: found 10 lint errors`
|
||||
```
|
||||
|
||||
Congratulations! You have resolved security issues!
|
||||
|
||||
### Kubernetes with KubeLinter
|
||||
|
||||
This example uses an app file from my [previous article on Knative][6] to test against Kubernetes config files. I already have Knative up and running, so you may want to review that article if it's not running on your system.
|
||||
|
||||
I downloaded the Kourier service YAML file for this example:
|
||||
|
||||
|
||||
```
|
||||
$ ls
|
||||
kourier.yaml first_test
|
||||
```
|
||||
|
||||
Start by running the linter against `kourier.yaml`. Again, there are several issues. I'll focus on resource problems:
|
||||
|
||||
|
||||
```
|
||||
$ kube-linter lint kourier.yaml
|
||||
|
||||
kourier.yaml: (object: kourier-system/3scale-kourier-gateway apps/v1, Kind=Deployment) container "kourier-gateway" has cpu limit 0 (check: unset-cpu-requirements, remediation: Set your container's CPU requests and limits depending on its requirements. See <https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/\#requests-and-limits> for more details.)
|
||||
|
||||
kourier.yaml: (object: kourier-system/3scale-kourier-gateway apps/v1, Kind=Deployment) container "kourier-gateway" has memory request 0 (check: unset-memory-requirements, remediation: Set your container's memory requests and limits depending on its requirements. See <https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/\#requests-and-limits> for more details.)
|
||||
|
||||
Error: found 12 lint errors
|
||||
```
|
||||
|
||||
Since this is a single deployment file, you can edit it directly. Open it in a text editor and change the values in the file. The file is long, so I'll include only the parts that need to change.
|
||||
|
||||
Start with deployment:
|
||||
|
||||
|
||||
```
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: 3scale-kourier-gateway
|
||||
namespace: kourier-system
|
||||
labels:
|
||||
networking.knative.dev/ingress-provider: kourier
|
||||
[...]
|
||||
```
|
||||
|
||||
The containers section has some problems:
|
||||
|
||||
|
||||
```
|
||||
spec:
|
||||
containers:
|
||||
- args:
|
||||
- --base-id 1
|
||||
- -c /tmp/config/envoy-bootstrap.yaml
|
||||
- --log-level info
|
||||
command:
|
||||
- /usr/local/bin/envoy
|
||||
image: docker.io/maistra/proxyv2-ubi8:1.1.5
|
||||
imagePullPolicy: Always
|
||||
name: kourier-gateway
|
||||
ports:
|
||||
- name: http2-external
|
||||
containerPort: 8080
|
||||
protocol: TCP
|
||||
- name: http2-internal
|
||||
containerPort: 8081
|
||||
protocol: TCP
|
||||
- name: https-external
|
||||
containerPort: 8443
|
||||
protocol: TCP
|
||||
```
|
||||
|
||||
Add some specs to the container configuration:
|
||||
|
||||
|
||||
```
|
||||
spec:
|
||||
containers:
|
||||
- args:
|
||||
- --base-id 1
|
||||
- -c /tmp/config/envoy-bootstrap.yaml
|
||||
- --log-level info
|
||||
command:
|
||||
- /usr/local/bin/envoy
|
||||
image: docker.io/maistra/proxyv2-ubi8:1.1.5
|
||||
imagePullPolicy: Always
|
||||
name: kourier-gateway
|
||||
ports:
|
||||
- name: http2-external
|
||||
containerPort: 8080
|
||||
protocol: TCP
|
||||
- name: http2-internal
|
||||
containerPort: 8081
|
||||
protocol: TCP
|
||||
- name: https-external
|
||||
containerPort: 8443
|
||||
protocol: TCP
|
||||
resources:
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
```
|
||||
|
||||
When you rerun the linter, you'll notice these issues no longer show in the output, and the error count changes:
|
||||
|
||||
|
||||
```
|
||||
`Error: found 8 lint errors`
|
||||
```
|
||||
|
||||
Congratulations! You have fixed resource issues in your Kubernetes file!
|
||||
|
||||
### Final thoughts
|
||||
|
||||
KubeLinter is a great tool and a great opportunity to start a new DevOps process to secure and resource-manage all of your Kubernetes' and applications' configurations. Adding this function to automated testing steps up your environment and DevOps cycle.
|
||||
|
||||
I think KubeLinter's best part is that each error message includes documentation, so even if you don't know what the error linting output means, the documentation helps you learn and plan ahead. I recommend this tool for everyday use and working with retroactive code.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/1/kubelinter
|
||||
|
||||
作者:[Jessica Cherry][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/cherrybomb
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/mistake_bug_fix_find_error.png?itok=PZaz3dga (magnifying glass on computer screen, finding a bug in the code)
|
||||
[2]: https://github.com/stackrox/kube-linter
|
||||
[3]: https://knative.dev/
|
||||
[4]: mailto:git@github.com
|
||||
[5]: https://opensource.com/article/20/6/homebrew-linux
|
||||
[6]: https://opensource.com/article/20/11/knative
|
@ -0,0 +1,84 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Turn your Raspberry Pi into a HiFi music system)
|
||||
[#]: via: (https://opensource.com/article/21/1/raspberry-pi-hifi)
|
||||
[#]: author: (Peter Czanik https://opensource.com/users/czanik)
|
||||
|
||||
Turn your Raspberry Pi into a HiFi music system
|
||||
======
|
||||
Play music for your friends, family, co-workers, or anyone else with an
|
||||
inexpensive audiophile setup.
|
||||
![HiFi vintage stereo][1]
|
||||
|
||||
For the past 10 years, I've worked remotely most of the time, but when I go into the office, I sit in a room full of fellow introverts who are easily disturbed by ambient noise and talking. We discovered that listening to music can suppress office noise, make voices less distracting, and provide a pleasant working environment with enjoyable music.
|
||||
|
||||
Initially, one of our colleagues brought in some old powered computer speakers, connected them to his desktop, and asked us what we wanted to listen to. It did its job, but the sound quality wasn't great, and it only worked when he was in the office. Next, we bought a pair of Altec Lansing speakers. The sound quality improved, but flexibility did not.
|
||||
|
||||
Not much later, we got a generic Arm single-board computer (SBC). This meant anyone could control the playlist and the speakers over the network using a web interface. But a random Arm developer board meant we could not use popular music appliance software. Updating the operating system was a pain due to a non-standard kernel, and the web interface broke frequently.
|
||||
|
||||
When the team grew and moved into a larger room, we started dreaming about better speakers and an easier way to handle the software and hardware combo.
|
||||
|
||||
To solve our issue in a way that is relatively inexpensive, flexible, and has good sound quality, we developed an office HiFi with a Raspberry Pi, speakers, and open source software.
|
||||
|
||||
### HiFi hardware
|
||||
|
||||
Having a dedicated PC for background music is overkill. It's expensive, noisy (unless it's silent, but then it's even more expensive), and not environmentally friendly. Even the cheapest Arm boards are up to the job, but they're often problematic from the software point of view. The Raspberry Pi is still on the cheap end and, while not standards-compliant, is well-supported on the hardware and the software side.
|
||||
|
||||
The next question was: what speakers to use. Good-quality, powered speakers are expensive. Passive speakers cost less but need an amplifier, and that would add another box to the setup. They would also have to use the Pi's audio output; while it works, it's not exactly the best, especially when you're already spending money on quality speakers and an amplifier.
|
||||
|
||||
Luckily, among the thousands of Raspberry Pi hardware extensions are amplifiers with built-in digital-analog converters (DAC). We selected [HiFiBerry's Amp][2]. It was discontinued soon after we bought it (replaced by an Amp+ model with a better sample rate), but it's good enough for our purposes. With air conditioning on, I don't think you can hear the difference between a DAC capable of 48kHz or 192kHz anyway.
|
||||
|
||||
For speakers, we chose the [Audioengine P4][3], which we bought when a shop had a clearance sale with extra-low prices. It easily fills our office room with sound without distortion (and fills much more than our room with some distortion, but neighboring engineers tend to dislike that).
|
||||
|
||||
### HiFi software
|
||||
|
||||
Maintaining Ubuntu on our old generic Arm SBC with a fixed, ancient, out-of-packaging system kernel was problematic. The Raspberry Pi OS includes a well-maintained kernel package, making it a stable and easily updated base system, but it still required us to regularly update a Python script to access Spotify and YouTube. That was a little too high-maintenance for our purposes.
|
||||
|
||||
Luckily, using the Raspberry Pi as a base means there are many ready-to-use software appliances available.
|
||||
|
||||
We settled on [Volumio][4], an open source project that turns a Pi into a music-playing appliance. Installation is a simple _next-next-finish_ process. Instead of painstakingly installing and maintaining an operating system and regularly debugging broken Python code, installation and upgrades are completely pain-free. Configuring the HiFiBerry amplifier doesn't require editing any configuration files; you can just select it from a list. Of course, getting used to a new user interface takes some time, but the stability and ease of maintenance made this change worthwhile.
|
||||
|
||||
![Volumio interface][5]
|
||||
|
||||
Screenshot courtesy of [Volumeio][4] (© Michelangelo Guarise)
|
||||
|
||||
### Playing music and experimenting
|
||||
|
||||
While we're all working from home during the pandemic, the office HiFi is installed in my home office, which means I have free reign over what it runs. A constantly changing user interface would be a pain for a team, but for someone with an R&D background, playing with a device on my own, change is fun.
|
||||
|
||||
I'm not a programmer, but I have a strong Linux and Unix sysadmin background. That means that while I find fixing broken Python code tiresome, Volumio is just perfect enough to be boring for me (a great "problem" to have). Luckily, there are many other possibilities to play music on a Raspberry Pi.
|
||||
|
||||
As a terminal maniac (I even start LibreOffice from a terminal window), I mostly use Music on Console ([MOC][6]) to play music from my network-attached storage (NAS). I have hundreds of CDs, all turned into [FLAC][7] files. And I've also bought many digital albums from sources like [BandCamp][8] or [Society of Sound][9].
|
||||
|
||||
Another option is the [Music Player Daemon (MPD)][10]. With it running on the Raspberry Pi, I can interact with my music remotely over the network using any of the many clients available for Linux and Android.
|
||||
|
||||
### Can't stop the music
|
||||
|
||||
As you can see, the possibilities for creating an inexpensive HiFi system are almost endless on both the software and the hardware side. Our solution is just one of many, and I hope it inspires you to build something that fits your environment.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/1/raspberry-pi-hifi
|
||||
|
||||
作者:[Peter Czanik][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/czanik
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/hi-fi-stereo-vintage.png?itok=KYY3YQwE (HiFi vintage stereo)
|
||||
[2]: https://www.hifiberry.com/products/amp/
|
||||
[3]: https://audioengineusa.com/shop/passivespeakers/p4-passive-speakers/
|
||||
[4]: https://volumio.org/
|
||||
[5]: https://opensource.com/sites/default/files/uploads/volumeio.png (Volumio interface)
|
||||
[6]: https://en.wikipedia.org/wiki/Music_on_Console
|
||||
[7]: https://xiph.org/flac/
|
||||
[8]: https://bandcamp.com/
|
||||
[9]: https://realworldrecords.com/news/society-of-sound-statement/
|
||||
[10]: https://www.musicpd.org/
|
@ -0,0 +1,78 @@
|
||||
GCC:优化 Linux、互联网和一切
|
||||
======
|
||||
|
||||
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gcc-paper.jpg?itok=QFNUZWsV)
|
||||
|
||||
软件如果不能被电脑运行,那么它就是无用的。而在处理 run-time 性能的问题上,即使是最有才华的开发人员也会受编译器的支配——因为如果没有可靠的编译器工具链,就无法构建任何重要的东西。GNU Compiler Collection(GCC)提供了一个健壮、成熟和高性能的工具,帮助您充分发挥你代码的潜能。经过几十年成千上万人的开发,GCC 成为了世界上最受尊敬的编译器之一。如果您正在构建应用程序而不使用 GCC,那么您可能错过了最佳解决方案。
|
||||
|
||||
根据 LLVM.org 的说法,GCC 是“如今事实上的标准开源编译器”[1],它可以从内核开始的构建完整的系统。GCC 支持超过 60 种硬件平台,包括 ARM、Intel、AMD、IBM POWER、SPARC、HP PA-RISC 和 IBM Z,以及各种操作环境,包括 GNU、Linux、Windows、macOS、FreeBSD、NetBSD、OpenBSD、DragonFly BSD、Solaris、AIX、HP- ux 和 RTEMS。它提供了高度兼容的 C/C++ 编译器,并支持流行的 C 库,如 GNU C Library(glibc)、Newlib、musl 和各种 BSD 操作系统中包含的 C 库,以及 Fortran、Ada 和 GO 语言的前端。GCC 还可以作为一个交叉编译器,为运行编译器的平台以外的其他平台创建可执行代码。GCC 是紧密集成的 GNU 工具链的核心组件,由 GNU 项目产生,包括 glibc、Binutils 和 GNU 调试器(GDB)。
|
||||
|
||||
“一直以来我最喜欢的 GNU 工具是 GCC。在开发工具非常昂贵的时候,GCC 是第二个 GNU 工具,它使一个社区能够编写和构建所有其他工具。这个工具一手改变了行业,导致了自由软件运动的诞生,因为一个好的、自由的编译器是一个社区软件的先决条件。”—— Red Hat 开源和标准团队的 Dave Neary。[2]
|
||||
|
||||
### 优化 Linux
|
||||
|
||||
作为 Linux 内核源代码的默认编译器,GCC 提供了可靠、稳定的性能以及正确构建内核所需的扩展。GCC 是流行的 Linux 发行版的标准组件,比如 ArchLinux、CentOS、Debian、Fedora、openSUSE 和 Ubuntu,在这些发行版中,GCC 通常用来编译支持系统的组件。这包括 Linux 使用的默认库(如 libc、libm、libintl、libssh、libssl、libcrypto、libexpat、libpthread 和 ncurses),这些库依赖于 GCC 来提供可靠性和高性能,并且使应用程序和系统程序可以访问 Linux 内核功能。发行版中包含的许多应用程序包也是用 GCC 构建的,例如 Python、Perl、Ruby、nginx、Apache HTTP 服务器、OpenStack、Docker 和 OpenShift。各个 Linux 发行版使用 GCC 构建的大量代码组成了内核、库和应用程序软件。对于 openSUSE 发行版,几乎 100% 的本机代码是由 GCC 构建的,包括 6135 个源程序包,5705 个共享库和 38927 个可执行文件。这相当于每周编译 24540 个源代码包。[3]
|
||||
|
||||
Linux 发行版中包含的 GCC 的基本版本用于创建定义系统应用程序二进制接口(ABI)的内核和库。用户空间开发者可以选择下载 GCC 的最新稳定版本,以获得高级功能、性能优化和可用性改进。Linux 发行版提供安装说明或预构建的工具链,用于部署最新版本的 GCC 以及其他 GNU 工具,这些工具有助于提高开发人员的工作效率和缩短部署时间。
|
||||
|
||||
### 优化互联网
|
||||
|
||||
GCC 是嵌入式系统中被广泛采用的核心编译器之一,支持为日益增长的物联网设备开发软件。GCC 提供了许多扩展,使其非常适合嵌入式系统软件开发,包括使用编译器内置的细粒度控制、#pragmas、内联汇编和以应用程序为中心的命令行选项。GCC 支持广泛的嵌入式体系结构,包括 ARM、AMCC、AVR、Blackfin、MIPS、RISC-V、Renesas Electronics V850、NXP 和 Freescale Power 处理器,可以生成高效、高质量的代码。GCC 提供的交叉编译功能是开源社区至关重要的功能,预构建的交叉编译工具链[4]是被广泛运用的工具。例如,GNU ARM 嵌入式工具链是集成和已被验证的软件包,具有 ARM 嵌入式 GCC 编译器、库和裸机软件开发所需的其他工具。这些工具链可用于在 Windows、Linux 和 macOS 主机操作系统上对流行的 ARM Cortex-R 和 Cortex-M 处理器进行交叉编译,这些处理器已在数百亿台支持互联网的设备中发布。[5]
|
||||
|
||||
GCC 支持云计算,为需要直接管理计算资源的软件提供可靠的开发平台,如数据库和 web 服务引擎以及备份和安全软件。GCC 完全兼容 C++ 11 和 C++ 14,为 C++ 17 和 C++ 2a [6] 提供实验支持,创建具有可靠调试信息的性能目标代码。使用 GCC 的应用程序的一些例子包括:MySQL 数据库管理系统,它依赖于 Linux 的 GCC [7];Apache HTTP 服务器,它建议使用 GCC [8];Bacula,一个企业级网络备份工具,它依赖于 GCC。[9]
|
||||
|
||||
### 优化一切
|
||||
|
||||
为了研究和开发用于高性能计算(HPC)的科学代码,GCC 提供了成熟的 C、C++ 和 Fortran 前端,并支持基于指令的并行编程的 OpenMP 和 OpenACC api。因为 GCC 提供了跨计算环境的可移植性,它使得代码能够更容易地在各种新的和遗留的客户机和服务器平台上进行测试。GCC 为 C, C++ 和 Fortran 编译器提供了 OpenMP 4.0 的完整支持,为 C 和 C++ 编译器提供了 OpenMP 4.5 完整支持。对于 OpenACC, GCC 支持大多数 2.5 规范和性能优化,并且是唯一提供 [OpenACC][1] 支持的非商业、非学术编译器。
|
||||
|
||||
代码性能是这个社区的一个重要参数,GCC 提供了一个坚实的性能基础。Colfax Research 于 2017 年 11 月发表的一篇论文评估了 C++ 编译器在 OpenMP 4.x 指令下并行编译代码的速度和代码运行速度。图 1 描绘了不同编译器编译并使用单个线程运行时计算内核的相对性能。使 G++ 的性能标定为 1.0,将其他编译器性能值规范化处理。
|
||||
|
||||
![performance][3]
|
||||
|
||||
图1 为由不同编译器编译的每个内核的相对性能。(单线程,越高越好)。
|
||||
|
||||
[Used with permission][4]
|
||||
|
||||
论文总结道:“GNU 编译器在我们的测试中也做得很好。G++ 在六种情况中的三种情况下生成的代码速度是第二快的,并且在编译时间方面是最快的编译器之一。”[10]
|
||||
|
||||
### 谁在用 GCC?
|
||||
|
||||
在 JetBrains 2018 年的开发者生态状况调查中,在接受调查的 6000 名开发者中,66% 的 C++ 程序员和 73% 的 C 程序员经常使用 GCC。[11] 以下简要介绍 GCC 的优点,正是这些优点使它在开发人员社区中如此受欢迎。
|
||||
|
||||
* 对于需要为各种新的和遗留的计算平台和操作环境编写代码的开发人员,GCC 提供了对最广泛的硬件和操作环境的支持。硬件供应商提供的编译器主要侧重于对其产品的支持,而其他开源编译器在所支持的硬件和操作系统方面则受到很大限制。[12]
|
||||
|
||||
* 有各种各样的基于 GCC 的预构建工具链,这对嵌入式系统开发人员特别有吸引力。这包括 GNU ARM 嵌入式工具链和 Bootlin 网站上提供的 138 个预编译交叉编译器工具链。[13] 虽然其他开源编译器(如 Clang/LLVM)可以取代现有交叉编译工具链中的 GCC,但开发人员需要完全重建这些工具链。[14]
|
||||
|
||||
* GCC 通过成熟的编译器平台向应用程序开发人员提供可靠、稳定的性能。在 AMD EPYC 平台上用 GCC 8/9 与 LLVM Clang 6/7 编译器基准测试的文章提供了 49 个基准测试的结果,这些测试的编译器在三个优化级别上运行。使用 “-O3 -march=native”级别的 GCC 8.2 RC1 在 34% 的时间里排在第一位,而在相同的优化级别 LLVM Clang 6.0 在 20% 的时间里赢得了第二位。[15]
|
||||
|
||||
* GCC 为编译调试 [16] 提供了改进的诊断,并为运行调试提供了准确而有用的信息。GCC 与 GDB 紧密集成,GDB 是一个成熟且功能齐全的工具,它提供“不间断”调试,可以在断点处停止单个线程。
|
||||
|
||||
* GCC 是一个受良好支持的平台,它有一个活跃的、承诺的社区,支持当前版本和以前的两个版本。对于每年发布一次的计划,这为一个版本提供了两年的支持。
|
||||
|
||||
### GCC:仍然在继续优化 Linux,互联网和所有事情
|
||||
|
||||
GCC 作为世界级的编译器继续向前发展。GCC 的最新版本是 8.2,于 2018 年 7 月发布,增加了对即将推出的 Intel CPU、更多 ARM CPU 的硬件支持,并提高了 AMD 的 ZEN CPU 的性能。初始 C17 支持已经添加到 C++ 2A 的初始工作中。诊断继续得到改进,包括更好的发射诊断,改进的定位、定位范围,并修复提示,特别是在 C++ 前端。Red Hat 的 David Malcolm 在 2018 年 3 月撰写的博客概述了 GCC 8 中的可用性改进。[17]
|
||||
|
||||
新的硬件平台继续依赖 GCC 工具链进行软件开发,例如 RISC-V,这是一种对机器学习、人工智能(AI)和物联网细分市场感兴趣的免费开放 ISA。GCC 仍然是 Linux 系统持续开发的关键组件。Clear Linux Project for Intel Architecture 是一个针对云、客户端和物联网用例构建的新兴发行版,它提供了一个很好的示例,说明如何使用和改进 GCC 编译器技术来提高基于 Linux 的系统的性能和安全性。GCC 还被用于微软 Azure Sphere 的应用程序开发,这是一个基于 Linux 的物联网应用程序操作系统,最初支持基于 ARM 的联发科 MT3620 处理器。在开发下一代程序员方面,GCC 也是树莓派的 Windows 工具链的核心组件,树莓派是一种运行基于 Debian 的 GNU/Linux 的低成本嵌入式板,用于促进学校和发展中国家的基础计算机科学教学。
|
||||
|
||||
GCC 于 1987 年 3 月 22 日由 GNU 项目的创始人 richardstallman 首次发布,它被认为是一个重大突破,因为它是第一个作为自由软件发布的可移植的 ANSI C 优化编译器。GCC 由来自世界各地的程序员组成的社区在指导委员会的指导下维护,该指导委员会确保对项目进行广泛的、有代表性的监督。GCC 的社区方法是它的优势之一,它形成了一个由开发人员和用户组成的庞大而多样化的社区,为项目做出贡献并提供支持。根据 Open Hub,“GCC 是世界上最大的开源团队之一,在 Open Hub 上的所有项目团队中排名前 2%。”[18]
|
||||
|
||||
关于 GCC 的许可问题,人们进行了大量的讨论,其中大多数是混淆而不是启发。GCC 在 GNU 通用公共许可证版本 3 或更高版本下发布,但运行时库例外。这是一个 copyleft 许可,这意味着衍生作品只能在相同的许可条款下分发。GPLv3 旨在保护 GCC 不被私有化,并要求对 GCC 代码的更改可以自由公开地进行。对于“最终用户”来说,编译器与其他编译器完全相同;使用 GCC 对您自己的代码所做的任何许可选择都没有区别。[19]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/2018/10/gcc-optimizing-linux-internet-and-everything
|
||||
|
||||
作者:[Margaret Lewis][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[Chao-zhi](https://github.com/Chao-zhi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linux.com/users/margaret-lewis
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.openacc.org/tools
|
||||
[2]: /files/images/gccjpg-0
|
||||
[3]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/gcc_0.jpg?itok=HbGnRqWX "performance"
|
||||
[4]: https://www.linux.com/licenses/category/used-permission
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (Chao-zhi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
@ -7,12 +7,12 @@
|
||||
[#]: via: (https://www.linuxtechi.com/monitor-manage-docker-containers-portainer-io-part-2/)
|
||||
[#]: author: (Shashidhar Soppin https://www.linuxtechi.com/author/shashidhar/)
|
||||
|
||||
Monitor and Manage Docker Containers with Portainer.io (GUI tool) – Part-2
|
||||
用 Portainer.io 来监控和管理 Docker 容器(2)
|
||||
======
|
||||
|
||||
As a continuation of Part-1, this part-2 has remaining features of Portainer covered and as explained below.
|
||||
作为第 1 部分的延续,本第 2 部分将介绍 Portainer 的其余功能。
|
||||
|
||||
### Monitoring docker container images
|
||||
### 监控 docker 容器镜像
|
||||
|
||||
```
|
||||
root@linuxtechi ~}$ docker ps -a
|
||||
@ -22,19 +22,18 @@ CONTAINER ID IMAGE COMMAND CREATED
|
||||
9a669f3dc4f6 portainer/portainer "/portainer" 7 minutes ago Up 7 minutes 0.0.0.0:9000->9000/tcp trusting_keller
|
||||
```
|
||||
|
||||
Including the portainer(which is a docker container image), all the exited and present running docker images are displayed. Below screenshot from Portainer GUI displays the same.
|
||||
包括 portainer(docker 容器镜像),所有已退出和当前正在运行的 docker 镜像都会显示出来。下面的 Portainer GUI 屏幕截图显示了相同的情况。
|
||||
|
||||
[![Docker_status][1]][2]
|
||||
|
||||
### Monitoring events
|
||||
### 监视事件
|
||||
|
||||
Click on the “Events” option from the portainer webpage as shown below.
|
||||
|
||||
Various events that are generated and created based on docker-container activity, are captured and displayed in this page
|
||||
单击 portainer 网页中的“Events”选项,如下所示。
|
||||
基于 docker 容器活动生成和创建的各种事件将被提取并显示在此页面中
|
||||
|
||||
[![Container-Events-Poratiner-GUI][3]][4]
|
||||
|
||||
Now to check and validate how the “ **Events** ” section works. Create a new docker-container image redis as explained below, check the docker ps –a status at docker command-line.
|
||||
现在检查并验证“**Events**”部分是如何工作的。创建一个新的 docker 容器映像 redis,如下所述,在 docker 命令行检查状态:docker ps –a。
|
||||
|
||||
```
|
||||
root@linuxtechi ~}$ docker ps -a
|
||||
@ -45,35 +44,37 @@ cdbfbef59c31 redis "docker-entrypoint.s…" About a min
|
||||
9a669f3dc4f6 portainer/portainer "/portainer" 17 minutes ago Up 17 minutes 0.0.0.0:9000->9000/tcp trusting_keller
|
||||
```
|
||||
|
||||
Click the “Event List” on the top to refresh the events list,
|
||||
单击顶部的“Event List”刷新事件列表,
|
||||
|
||||
[![events_updated][5]][6]
|
||||
|
||||
Now the event’s page also updated with this change,
|
||||
现在事件的页面也更新了这个变化,
|
||||
|
||||
### Host status
|
||||
### 主机状态
|
||||
|
||||
Below is the screenshot of the portainer displaying the host status. This is a simple window showing-up. This shows the basic info like “CPU”, “hostname”, “OS info” etc of the host linux machine. Instead of logging- into the host command-line, this page provides very useful info on for quick glance.
|
||||
下面是 portainer 显示主机状态的屏幕截图。这是一个简单的窗口。这显示了主机 linux 机器的基本信息,如“CPU”、“主机名”、“操作系统信息”等。这个页面在不需要登录主机命令行的情况下提供了非常有用的信息,以便快速浏览。
|
||||
|
||||
[![Host-names-Portainer][7]][8]
|
||||
|
||||
### Dashboard in Portainer
|
||||
|
||||
Until now we have seen various features of portainer based under “ **Local”** section. Now jump on to the “ **Dashboard** ” section of the selected Docker Container image.
|
||||
Portainer 中的仪表板
|
||||
|
||||
When “ **EndPoint** ” option is clicked in the GUI of Portainer, the following window appears,
|
||||
到目前为止,我们已经在“**Local**”部分看到了基于 portainer 的各种特性。现在跳到所选 Docker 容器镜像的“**Dashboard**”部分。
|
||||
|
||||
在 Portainer 的网页中单击“**EndPoint**”选项时,会出现以下窗口:
|
||||
|
||||
[![End_Point_Settings][9]][10]
|
||||
|
||||
This Dashboard has many statuses and options, for a host container image.
|
||||
对于主机容器镜像,此仪表板有许多状态和选项。
|
||||
|
||||
**1) Stacks:** Clicking on this option, provides status of any stacks if any. Since there are no stacks, this displays zero.
|
||||
**1)Stacks:** 单击此选项,提供任何堆栈(如果有的话)的状态。因为没有堆栈,所以显示为零。
|
||||
|
||||
**2) Images:** Clicking on this option provides host of container images that are available. This option will display all the live and exited container images
|
||||
**2) Images:** 单击此选项可提供主机中可用的容器镜像。此选项将显示所有活动和退出的容器镜像
|
||||
|
||||
[![Docker-Container-Images-Portainer][11]][12]
|
||||
|
||||
For example create one more “ **Nginx”** container and refresh this list to see the updates.
|
||||
例如,再创建一个“**Nginx**”容器并刷新此列表以查看更新。
|
||||
|
||||
```
|
||||
root@linuxtechi ~}$ sudo docker run nginx
|
||||
@ -86,51 +87,51 @@ Digest: sha256:e71b1bf4281f25533cf15e6e5f9be4dac74d2328152edf7ecde23abc54e16c1c
|
||||
Status: Downloaded newer image for nginx:latest
|
||||
```
|
||||
|
||||
The following is the image after refresh,
|
||||
下面是刷新后的镜像界面:
|
||||
|
||||
[![Nginx_Image_creation][13]][14]
|
||||
|
||||
Once the Nginx image is stopped/killed and docker container image will be moved to unused status.
|
||||
当 Nginx 镜像处于 stopped/killed 时,docker 的容器镜像会改变为 unused 状态
|
||||
|
||||
**Note** :-One can see all the image details here are very clear with memory usage, creation date and time. As compared to command-line option, maintaining and monitoring containers from here it will be very easy.
|
||||
**注**:-你可以看到这里所有的镜像的细节都非常清楚,比如内存使用,创建日期和时间。与命令行选项相比,从这里维护和监视容器将非常容易。
|
||||
|
||||
**3) Networks:** this option is used for network operations. Like assigning IP address, creating subnets, providing IP address range, access control (admin and normal user) . The following window provides the details of various options possible. Based on your need these options can be explored further.
|
||||
**3) Networks:** 此选项用于网络操作。例如分配 IP 地址、创建子网、提供 IP 地址范围、访问控制(管理员和普通用户)。下面的窗口提供了各种可能选项的详细信息。根据您的需要,可以进一步去自行研究这些选项。
|
||||
|
||||
[![Conatiner-Network-Portainer][15]][16]
|
||||
|
||||
Once all the various networking parameters are entered, “ **create network** ” button is clicked for creating the network.
|
||||
输入所有各种网络参数后,单击“**创建网络**”按钮即可创建网络。
|
||||
|
||||
**4) Container:** (click on container) This option will provide the container status. This list will provide details on live and not running container statuses. This output is similar to docker ps command option.
|
||||
**4) Container:** 此选项将提供容器状态。此列表将提供有关活动的和未运行的容器状态的详细信息。此输出类似于 docker ps 命令选项。
|
||||
|
||||
[![Containers-Status-Portainer][17]][18]
|
||||
|
||||
From this window only the containers can be stopped and started as need arises by checking the check box and selecting the above buttons. One example is provided as below,
|
||||
在该窗口中,通过选中复选框并选择上述按钮可以根据需要控制容器停止和启动。一个例子如下:
|
||||
|
||||
Example, Both “CentOS” and “Ubuntu” containers which are in stopped state, they are started now by selecting check boxes and hitting “Start” button.
|
||||
例如,“CentOS”和“Ubuntu”容器都处于停止状态,现在可以通过选中复选框并点击“Start”按钮来启动它们。
|
||||
|
||||
[![start_containers1][19]][20]
|
||||
|
||||
[![start_containers2][21]][22]
|
||||
|
||||
**Note:** Since both are Linux container images, they will not be started. Portainer tries to start and stops later. Try “Nginx” instead and you can see it coming to “running”status.
|
||||
**注意:** 因为这两个都是 Linux 容器映像,所以不会被启动。Portainer 尝试启动,但稍后又停止。试试启动“Nginx”,你会看到它变成了“running”状态。
|
||||
|
||||
[![start_containers3][23]][24]
|
||||
|
||||
**5) Volume:** Described in Part-I of Portainer Article
|
||||
**5) Volume:** 本文章第一部分
|
||||
|
||||
### Setting option in Portainer
|
||||
### Portainer 中的设置选项
|
||||
|
||||
Until now we have seen various features of portainer based under “ **Local”** section. Now jump on to the “ **Setting”** section of the selected Docker Container image.
|
||||
到目前为止,我们已经在“**Local**”部分看到了基于 portainer 的各种特性。现在跳到所选 Docker 容器图像的“**设置**”部分。
|
||||
|
||||
When “Settings” option is clicked in the GUI of Portainer, the following further configuration options are available,
|
||||
在 Portainer 的网页中单击“**Settings**”选项时,可以使用以下的配置选项:
|
||||
|
||||
**1) Extensions** : This is a simple Portainer CE subscription process. The details and uses can be seen from the attached window. This is mainly used for maintaining the license and subscription of the respective version.
|
||||
**1) Extensions**:这是一个简单的 Portainer CE 订阅程序。详细信息和用途可以从附加的窗口中看到。这主要用于维护相应版本的许可证和订阅。
|
||||
|
||||
[![Extensions][25]][26]
|
||||
|
||||
**2) Users:** This option is used for adding “users” with or without administrative privileges. Following example provides the same.
|
||||
**2) Users:** 此选项用于添加具有或不具有管理权限的“用户”。下面的示例提供了相同的示例。
|
||||
|
||||
Enter the selected user name “shashi” in this case and your choice of password and hit “ **Create User** ” button below.
|
||||
在本例中输入你的想好的用户名比如“shashi”和您选择的密码,然后点击下面的“**Create User**”按钮。
|
||||
|
||||
[![create_user_portainer][27]][28]
|
||||
|
||||
@ -138,50 +139,48 @@ Enter the selected user name “shashi” in this case and your choice of passwo
|
||||
|
||||
[![Internal-user-Portainer][31]][32]
|
||||
|
||||
Similarly the just now created user “shashi” can be removed by selecting the check box and hitting remove button.
|
||||
类似地,可以通过选中复选框并点击 remove 按钮来删除刚刚创建的用户“shashi”。
|
||||
|
||||
[![user_remove_portainer][33]][34]
|
||||
|
||||
**3) Endpoints:** this option is used for Endpoint management. Endpoints can be added and removed as shown in the attached windows.
|
||||
**3) Endpoints:** 此选项用于端点终端管理。终端可以添加和删除,如附加窗口中所示。
|
||||
|
||||
[![Endpoint-Portainer-GUI][35]][36]
|
||||
|
||||
The new endpoint “shashi” is created using the various default parameters as shown below,
|
||||
新终端“shashi”是使用如下所示的各种默认参数创建的,
|
||||
|
||||
[![Endpoint2-Portainer-GUI][37]][38]
|
||||
|
||||
Similarly this endpoint can be removed by clicking the check box and hitting remove button.
|
||||
类似地,可以通过单击复选框并单击移除按钮来移除此端点。
|
||||
|
||||
**4) Registries:** this option is used for registry management. As docker hub has registry of various images, this feature can be used for similar purposes.
|
||||
**4) Registries:** 此选项用于注册的管理。由于 docker hub 有各种镜像的注册,因此此功能可用于类似的目的。
|
||||
|
||||
[![Registry-Portainer-GUI][39]][40]
|
||||
|
||||
With the default options the “shashi-registry” can be created.
|
||||
使用默认选项就可以创建“shashi-registry”。
|
||||
|
||||
[![Registry2-Portainer-GUI][41]][42]
|
||||
|
||||
Similarly this can be removed if not required.
|
||||
同样,如果不需要了,就可以移除它。
|
||||
|
||||
**5) Settings:** This option is used for the following various options,
|
||||
**5) Settings:** 此选项用于设置以下各种选项,
|
||||
|
||||
* Setting-up snapshot interval
|
||||
* For using custom logo
|
||||
* To create external templates
|
||||
* Security features like- Disable and enable bin mounts for non-admins, Disable/enable privileges for non-admins, Enabling host management features
|
||||
* 设置快照间隔
|
||||
* 设置自定义徽标
|
||||
* 创建外部模板
|
||||
* 安全功能,如:为非管理员禁用和启用 bin 挂载,为非管理员禁用/启用权限,启用主机管理功能
|
||||
|
||||
|
||||
|
||||
Following screenshot shows some options enabled and disabled for demonstration purposes. Once all done hit on “Save Settings” button to save all these options.
|
||||
下面的屏幕截图显示了出于演示目的启用和禁用的一些选项。一旦全部完成点击“保存设置”按钮保存所有这些选项。
|
||||
|
||||
[![Portainer-GUI-Settings][43]][44]
|
||||
|
||||
Now one more option pops-up on “Authentication settings” for LDAP, Internal or OAuth extension as shown below”
|
||||
现在点开“Authentication settings”就会弹出 LDAP、Internal 和 OAuth(extension)选项,如下所示:
|
||||
|
||||
[![Authentication-Portainer-GUI-Settings][45]][46]
|
||||
|
||||
Based on what level of security features we want for our environment, respective option is chosen.
|
||||
根据我们想要的环境安全特性级别,选择相应的选项。
|
||||
|
||||
That’s all from this article, I hope these Portainer GUI articles helps you to manage and monitor containers more efficiently. Please do share your feedback and comments.
|
||||
以上就是本文的内容,我希望这些介绍 portainer 的文章能帮助您更有效地管理和监视容器。请分享您的反馈和意见。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -189,7 +188,7 @@ via: https://www.linuxtechi.com/monitor-manage-docker-containers-portainer-io-pa
|
||||
|
||||
作者:[Shashidhar Soppin][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[Chao-zhi]](https://github.com/Chao-zhi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
@ -0,0 +1,365 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (stevenzdg988)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Integrate online documents editors, into a Python web app using ONLYOFFICE)
|
||||
[#]: via: (https://opensourceforu.com/2019/09/integrate-online-documents-editors-into-a-python-web-app-using-onlyoffice/)
|
||||
[#]: author: (Aashima Sharma https://opensourceforu.com/author/aashima-sharma/)
|
||||
|
||||
利用 **ONLYOFFICE** 将在线文档编辑器集成到 Python Web 应用程序中
|
||||
======
|
||||
|
||||
[![][1]][2]
|
||||
|
||||
_[ONLYOFFICE][3]是根据 GNU AGPL v.3 许可条款分发的开源协作办公套件。它包含三个用于文本文档,电子表格和演示文稿的编辑器,并具有以下功能:_
|
||||
|
||||
* 查看,编辑和协同编辑 `.docx, .xlsx , .pptx` 文件。 OOXML作为一种核心格式,可确保与 Microsoft Word,Excel 和 PowerPoint 文件的高度兼容性。
|
||||
* 通过内部转换为 OOXML,编辑其他流行格式(`.odt,.rtf,.txt,.html,.ods,.csv,.odp`)。
|
||||
* 熟悉的选项卡式界面。
|
||||
* 协作工具:两种协同编辑模式(快速和严谨),跟踪更改,评论和集成聊天。
|
||||
* 灵活的访问权限管理:完全访问权限,只读,审阅,表单填写和评论。
|
||||
* 使用 API ( 应用程序接口:Application Programming Interface ) 构建附加组件。
|
||||
* 250 种可用语言和象形字母表。
|
||||
|
||||
通过 API ( 应用程序接口:Application Programming Interface ) ,开发人员可以将 ONLYOFFICE 编辑器集成到网站和利用程序设计语言编写的应用程序中,并能配置和管理编辑器。
|
||||
|
||||
要集成 ONLYOFFICE 编辑器,我们需要一个集成应用程序来连接编辑器( ONLYOFFICE 文档服务器)和服务。 要在您的界面中使用编辑器,因该授予 ONLYOFFICE 以下权限:
|
||||
|
||||
* 添加并执行自定义代码。
|
||||
* 用于下载和保存文件的匿名访问权限。这意味着编辑器仅与服务器端的服务通信,而不包括客户端的任何用户授权数据(浏览器cookies)。
|
||||
* 在 UI(用户界面) 添加新按钮(例如,“在 ONLYOFFICE 中打开”,“在 ONLYOFFICE 中编辑”)。
|
||||
* 开启一个新页面,ONLYOFFICE 可以在其中执行脚本以添加编辑器。
|
||||
* 能够指定文档服务器连接设置。
|
||||
|
||||
流行的协作解决方案的成功集成案例有很多,如 Nextcloud,ownCloud,Alfresco,Confluence和SharePoint,都是通过 ONLYOFFICE 提供的官方即用型连接器实现的。
|
||||
|
||||
实际的集成案例之一是 ONLYOFFICE 编辑器与以 C# 编写的开源协作平台的集成。 该平台具有文档和项目管理,CRM (客户关系管理) ,电子邮件聚合器,日历,用户数据库,博客,论坛,民意调查,Wiki和即时通讯程序的功能。
|
||||
|
||||
将在线编辑器与 CRM 和项目模块集成,您可以:
|
||||
|
||||
* 文档关联到 CRM 时机和容器,项目任务和讨论,甚至创建一个单独的文件夹,其中包含与项目相关的文档,电子表格和演示文稿。
|
||||
* 直接在 CRM 或项目模块中创建新的文档,工作表和演示文稿。
|
||||
* 打开和编辑关联的文档,或者下载和删除。
|
||||
* 将联系人从 CSV 文件批量导入到 CRM 中,并将客户数据库导出为 CSV 文件。
|
||||
|
||||
在“邮件”模块中,您可以关联存储在“文档模块”中的文件,或者将指向所需文档的链接插入到邮件正文中。 当 ONLYOFFICE 用户收到带有附件的文档的消息时,他们可以:下载附件,在浏览器中查看文件,打开文件进行编辑或将其保存到“文档模块”。 如上所述,如果格式不同于 OOXML ,则文件将自动转换为 `.docx / .xlsx / .pptx`,并且其副本也将以原始格式保存。
|
||||
|
||||
在本文中,您将看到ONLYOFFICE 与最流行的编程语言之一的 Python 编写的文档管理系统的集成过程。 以下步骤将向您展示如何创建所有必要的部分,以使在 DMS(Document Management System)界面内的文档中可以进行协同工作成为可能:查看,编辑,协同编辑,保存文件和用户访问管理,并可以作为服务的示例集成到 Python 应用程序中。
|
||||
|
||||
**1\. What you will need 你需要什么**
|
||||
|
||||
首先,创建集成过程的关键组件:[_ONLYOFFICE 文档服务器_][4] 和用 Python 编写的文件管理系统。
|
||||
|
||||
1.1 要安装 ONLYOFFICE 文档服务器,您可以从多个安装选项中进行选择:编译 GitHub 上可用的源代码,使用 `.deb` 或 `.rpm` 软件包亦或 Docker 映像。
|
||||
我们推荐使用下面这条命令利用 Docker 映像安装文档服务器和所有必需的依赖。请注意,选择此方法,您需要安装最新的 Docker 版本。
|
||||
|
||||
```
|
||||
docker run -itd -p 80:80 onlyoffice/documentserver-de
|
||||
```
|
||||
|
||||
1.2我们需要利用 Python 开发 DMS。 如果已经拥有一个,请检查它是否满足以下条件:
|
||||
|
||||
* 包含需要打开以查看/编辑的保留文件
|
||||
* 允许下载文件
|
||||
|
||||
对于该应用程序,我们将使用 Bottle 框架。我们将使用以下命令将其安装在工作目录中:
|
||||
|
||||
```
|
||||
pip install bottle
|
||||
```
|
||||
|
||||
然后我们创建应用程序代码 *main.py* 和模板 _index.tpl_。
|
||||
我们将以下代码添加到 *main.py* 文件中:
|
||||
|
||||
```
|
||||
from bottle import route, run, template, get, static_file # connecting the framework and the necessary components
|
||||
@route('/') # setting up routing for requests for /
|
||||
def index():
|
||||
return template('index.tpl') # showing template in response to request
|
||||
run(host="localhost", port=8080) # running the application on port 8080
|
||||
```
|
||||
|
||||
一旦我们运行该应用程序,点击 <http://localhost:8080> 就会在浏览器上呈现一个空白页面 。
|
||||
为了使文档服务器能够创建新文档,添加默认文件并在模板中生成其名称列表,我们应该创建一个文件夹 _files_ 并将3种类型文件(.docx,.xlsx 和 .pptx)放入其中。
|
||||
|
||||
要读取这些文件的名称,我们使用 _listdir_ 组件(模块)。
|
||||
|
||||
```
|
||||
from os import listdir
|
||||
```
|
||||
|
||||
现在让我们为文件夹中的所有文件名创建一个变量:
|
||||
|
||||
```
|
||||
sample_files = [f for f in listdir('files')]
|
||||
```
|
||||
|
||||
要在模板中使用此变量,我们需要通过 _template_ 方法传递它:
|
||||
|
||||
```
|
||||
def index():
|
||||
return template('index.tpl', sample_files=sample_files)
|
||||
|
||||
Here’s this variable in the template:
|
||||
%for file in sample_files:
|
||||
<div>
|
||||
<span>{{file}}</span>
|
||||
</div>
|
||||
% end
|
||||
```
|
||||
|
||||
我们重新启动应用程序以查看页面上的文件名列表。
|
||||
使这些文件可用于所有应用程序用户的方法如下:
|
||||
|
||||
```
|
||||
@get("/files/<filepath:re:.*\.*>")
|
||||
def show_sample_files(filepath):
|
||||
return static_file(filepath, root="files")
|
||||
```
|
||||
|
||||
**2\. 如何利用 Python 应用程序在ONLYOFFICE中查看文档**
|
||||
所有组件准备就绪后,让我们添加函数以使编辑者可以利用应用接口操作。
|
||||
第一个选项使用户可以打开和查看文档。连接模板中的文档编辑器 API :
|
||||
```
|
||||
<script type="text/javascript" src="editor_url/web-apps/apps/api/documents/api.js"></script>
|
||||
```
|
||||
|
||||
_editor_url_ 是文档编辑器的链接接口。
|
||||
打开每个文件以供查看的按钮:
|
||||
|
||||
```
|
||||
<button onclick="view('files/{{file}}')">view</button>
|
||||
```
|
||||
|
||||
现在我们需要添加带有 _id_ 的 `div` 标签,打开文档编辑器:
|
||||
|
||||
```
|
||||
<div id="editor"></div>
|
||||
```
|
||||
|
||||
要打开编辑器,必须调用调用一个函数:
|
||||
|
||||
```
|
||||
<script>
|
||||
function view(filename) {
|
||||
if (/docx$/.exec(filename)) {
|
||||
filetype = "text"
|
||||
}
|
||||
if (/xlsx$/.exec(filename)) {
|
||||
filetype = "spreadsheet"
|
||||
}
|
||||
if (/pptx$/.exec(filename)) {
|
||||
filetype = "presentation",
|
||||
title: filename
|
||||
}
|
||||
new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: filetype,
|
||||
document: {
|
||||
url: "host_url" + '/' + filename,
|
||||
title: filename
|
||||
},
|
||||
editorConfig: {mode: 'view'}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
DocEditor 函数有两个参数:将在其中打开编辑器的元素 `id` 和带有编辑器设置的 `JSON`。
|
||||
在此示例中,使用了以下必需参数:
|
||||
|
||||
* _documentType_ 由其格式标识(`.docx,.xlsx,.pptx` 用于相应的文本,电子表格和演示文稿)
|
||||
* _document.url_ 是您要打开的文件链接。
|
||||
* _editorConfig.mode_。
|
||||
|
||||
我们还可以添加将在编辑器中显示的 _title_。
|
||||
接下来,我们可以在 Python 应用程序中查看文档。
|
||||
|
||||
**3\. 如何在 Python 应用中利用 ONLYOFFICE 编辑文档**
|
||||
首先,添加 “Edit”(编辑) 按钮:
|
||||
|
||||
```
|
||||
<button onclick="edit('files/{{file}}')">edit</button>
|
||||
```
|
||||
|
||||
然后创建一个新功能,打开文件进行编辑。类似于查看功能。
|
||||
现在创建3个函数:
|
||||
|
||||
```
|
||||
<script>
|
||||
var editor;
|
||||
function view(filename) {
|
||||
if (editor) {
|
||||
editor.destroyEditor()
|
||||
}
|
||||
editor = new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: get_file_type(filename),
|
||||
document: {
|
||||
url: "host_url" + '/' + filename,
|
||||
title: filename
|
||||
},
|
||||
editorConfig: {mode: 'view'}
|
||||
});
|
||||
}
|
||||
function edit(filename) {
|
||||
if (editor) {
|
||||
editor.destroyEditor()
|
||||
}
|
||||
editor = new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: get_file_type(filename),
|
||||
document: {
|
||||
url: "host_url" + '/' + filename,
|
||||
title: filename
|
||||
}
|
||||
});
|
||||
}
|
||||
function get_file_type(filename) {
|
||||
if (/docx$/.exec(filename)) {
|
||||
return "text"
|
||||
}
|
||||
if (/xlsx$/.exec(filename)) {
|
||||
return "spreadsheet"
|
||||
}
|
||||
if (/pptx$/.exec(filename)) {
|
||||
return "presentation"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
_destroyEditor_ 被调用以关闭一个打开的编辑器。
|
||||
您可能会注意到,_edit()_ 函数中缺少 _editorConfig_ 参数,因为默认情况下它的值是 **{"mode":"edit"}.*
|
||||
|
||||
现在,我们拥有了打开文档以在 Python 应用程序中进行协同编辑的所有功能。
|
||||
|
||||
**4\. 如何在 Python 应用中利用 ONLYOFFICE 协同编辑文档**
|
||||
通过在编辑器中设置对同一文档使用相同的 `document.key` 来实现协同编辑。 如果没有此键,则每次打开文件时,编辑器都会创建编辑会话。
|
||||
|
||||
为每个文档设置唯一键,以使用户连接到同一编辑会话时进行协同编辑。 密钥格式应为以下格式:_filename +"_key"_。下一步是将其添加到当前文档的所有配置中。
|
||||
|
||||
```
|
||||
document: {
|
||||
url: "host_url" + '/' + filepath,
|
||||
title: filename,
|
||||
key: filename + '_key'
|
||||
},
|
||||
```
|
||||
|
||||
**5\. 如何在 Python 应用中利用 ONLYOFFICE 保存文档**
|
||||
每次我们更改并保存文件时,ONLYOFFICE 都会存储其所有版本。 让我们仔细看看它是如何工作的。 关闭编辑器后,文档服务器将构建要保存的文件版本并将请求发送到 `callbackUrl` 地址。 该请求包含 `document.key`和指向刚刚构建的文件的链接。
|
||||
`document.key` 用于查找文件的旧版本并将其替换为新版本。 由于这里没有任何数据库,因此仅使用 `callbackUrl` 发送文件名。
|
||||
在 _editorConfig.callbackUrl_ 的设置中指定 _callbackUrl_ 参数并将其添加到 _edit()method_ 中:
|
||||
|
||||
```
|
||||
function edit(filename) {
|
||||
const filepath = 'files/' + filename;
|
||||
if (editor) {
|
||||
editor.destroyEditor()
|
||||
}
|
||||
editor = new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: get_file_type(filepath),
|
||||
document: {
|
||||
url: "host_url" + '/' + filepath,
|
||||
title: filename,
|
||||
key: filename + '_key'
|
||||
}
|
||||
,
|
||||
editorConfig: {
|
||||
mode: 'edit',
|
||||
callbackUrl: "host_url" + '/callback' + '&filename=' + filename // add file name as a request parameter
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
编写一种方法,在获取到 POST 请求发送到 */callback* 地址后将保存文件:
|
||||
|
||||
```
|
||||
@post("/callback") # processing post requests for /callback
|
||||
def callback():
|
||||
if request.json['status'] == 2:
|
||||
file = requests.get(request.json['url']).content
|
||||
with open('files/' + request.query['filename'], 'wb') as f:
|
||||
f.write(file)
|
||||
return "{\"error\":0}"
|
||||
```
|
||||
|
||||
*# status 2* 是已生成的文件
|
||||
当我们关闭编辑器时,新版本的文件将保存到存储器中。
|
||||
|
||||
**6\. 如何在 Python 应用中利用 ONLYOFFICE 管理用户**
|
||||
如果应用中有用户,并且您需要查看谁在编辑文档,请在编辑器的配置中输入其标识符(`id`和`name`)。
|
||||
在界面中添加选择用户的功能:
|
||||
|
||||
```
|
||||
<select id="user_selector" onchange="pick_user()">
|
||||
<option value="1" selected="selected">JD</option>
|
||||
<option value="2">Turk</option>
|
||||
<option value="3">Elliot</option>
|
||||
<option value="4">Carla</option>
|
||||
</select>
|
||||
```
|
||||
|
||||
如果在标记 _&lt;script&gt;_ 的开头添加对函数 *pick_user()* 的调用,负责初始化函数自身 `id`和`name`变量。
|
||||
|
||||
```
|
||||
function pick_user() {
|
||||
const user_selector = document.getElementById("user_selector");
|
||||
this.current_user_name = user_selector.options[user_selector.selectedIndex].text;
|
||||
this.current_user_id = user_selector.options[user_selector.selectedIndex].value;
|
||||
}
|
||||
```
|
||||
|
||||
使用 _editorConfig.user.id_ 和 _editorConfig.user.name_ 来配置用户设置。将这些参数添加到文件编辑函数中的编辑器配置中。
|
||||
|
||||
```
|
||||
function edit(filename) {
|
||||
const filepath = 'files/' + filename;
|
||||
if (editor) {
|
||||
editor.destroyEditor()
|
||||
}
|
||||
editor = new DocsAPI.DocEditor("editor",
|
||||
{
|
||||
documentType: get_file_type(filepath),
|
||||
document: {
|
||||
url: "host_url" + '/' + filepath,
|
||||
title: filename
|
||||
},
|
||||
editorConfig: {
|
||||
mode: 'edit',
|
||||
callbackUrl: "host_url" + '/callback' + '?filename=' + filename,
|
||||
user: {
|
||||
id: this.current_user_id,
|
||||
name: this.current_user_name
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
使用这种方法,您可以将 ONLYOFFICE 编辑器集成到用 Python 编写的应用程序中,并获得用于在文档上进行协同工作的所有必要工具。有关更多集成示例(Java,Node.js,PHP,Ruby),请参考官方的 [_API文档_][5]。
|
||||
|
||||
**By: Maria Pashkina**
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensourceforu.com/2019/09/integrate-online-documents-editors-into-a-python-web-app-using-onlyoffice/
|
||||
|
||||
作者:[Aashima Sharma][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/stevenzdg988)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensourceforu.com/author/aashima-sharma/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i1.wp.com/opensourceforu.com/wp-content/uploads/2016/09/Typist-composing-text-in-laptop.jpg?resize=696%2C420&ssl=1 (Typist composing text in laptop)
|
||||
[2]: https://i1.wp.com/opensourceforu.com/wp-content/uploads/2016/09/Typist-composing-text-in-laptop.jpg?fit=900%2C543&ssl=1
|
||||
[3]: https://www.onlyoffice.com/en/
|
||||
[4]: https://www.onlyoffice.com/en/developer-edition.aspx
|
||||
[5]: https://api.onlyoffice.com/editors/basic
|
@ -1,151 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (qfzy1233 )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Learn C by writing a simple game)
|
||||
[#]: via: (https://opensource.com/article/21/1/learn-c)
|
||||
[#]: author: (Jim Hall https://opensource.com/users/jim-hall)
|
||||
|
||||
通过编写一个简单的游戏学习C语言
|
||||
======
|
||||
当你学习一门新的编程语言时,这个“猜数字”游戏是一个很好的入门程序。下面是如何用C语言来编写它。
|
||||
![Business woman on laptop sitting in front of window][1]
|
||||
|
||||
我在小学时就开始 [自学编程][2] 。 我的第一个程序是在Apple II上编写的,但最终,我通过阅读和编程练习来学习C语言。练习编程的最佳方法是编写示例程序,他能帮助你练习新知识。
|
||||
|
||||
在我学习一种新的编程语言时,我喜欢编写一个简单的“猜数字”游戏来练习。电脑从1到100中随机挑选一个数字,你必须通过猜测来算出来。在另一篇文章中,我展示了如何用 Bash 语言编写这个[“猜数字”游戏][3],我的 Opensource.com 的同伴同事也写了一些文章,介绍如何用[Java][4]、[Julia][5]和其他计算机语言编写它。
|
||||
|
||||
“猜数字”游戏的伟大之处在于它践行了几个编程概念:如何使用变量、如何比较值、如何打印输出以及如何读取输入。
|
||||
|
||||
整个夏天,我录制了[一个系列视频][6],教人们如何用[C语言][7]编写程序。从那以后,我收到了许多通过学习C语言的订阅观众的来信。所以,我想接着用 C 语言写一个“猜数字”的游戏。
|
||||
|
||||
### 去取一个随机数
|
||||
|
||||
从写一个函数来选择一个随机数字来开始“猜数字”游戏。在编写函数时,优秀的程序员会尽量使它们具有灵活性,这样他们就可以重用它们来解决略有不同的问题。因此,与其硬编码函数来选择1到100之间的一个随机数,不如编写函数来选择1到某个整数' maxval '之间的一个随机数:开始“猜数字”游戏,写一个函数来选择一个随机数字。在编写函数时,优秀的程序员会尽量使它们具有灵活性,这样他们就可以重用它们来解决略有不同的问题。因此,与其硬编码函数来选择1到100之间的一个随机数,不如编写函数来选择1到某个整数' maxval '之间的一个随机数:
|
||||
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
#include <sys/random.h>
|
||||
|
||||
int
|
||||
randnum(int maxval)
|
||||
{
|
||||
/* 从 1 到 maxval 之前取一个随机数 */
|
||||
|
||||
int randval;
|
||||
|
||||
getrandom(&randval, sizeof(int), GRND_NONBLOCK);
|
||||
|
||||
/* 可能是负值,所以要确保改数值为正值 */
|
||||
|
||||
if (randval < 0) {
|
||||
return (-1 * randval % maxval + 1);
|
||||
}
|
||||
else {
|
||||
return (randval % maxval + 1);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
该函数使用 Linux 系统调用 `getrandom` 来生成一系列随机数。你可以在 man 中了解关于这个系统调用的更多信息,但请注意,`getrandom` 将用随机的0和1填充变量。这意味着最终值可以是正的,也可以是负的,因此您需要在之后进行测试,以确保 `randnum` 函数的结果是正值。
|
||||
|
||||
### 编写程序
|
||||
|
||||
你可以用这个函数来写你的“猜数字”程序:
|
||||
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
#include <sys/random.h>
|
||||
|
||||
int
|
||||
randnum(int maxval)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int number;
|
||||
int guess;
|
||||
|
||||
number = randnum(100);
|
||||
|
||||
[puts][8]("Guess a number between 1 and 100");
|
||||
|
||||
do {
|
||||
[scanf][9]("%d", &guess);
|
||||
|
||||
if (guess < number) {
|
||||
[puts][8]("Too low");
|
||||
}
|
||||
else if (guess > number) {
|
||||
[puts][8]("Too high");
|
||||
}
|
||||
} while (guess != number);
|
||||
|
||||
[puts][8]("That's right!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
程序首先使用 `randnum` 函数从1到100之间选择一个随机数。在向用户输出一个提示后,程序进入一个 `do-while` 循环,以便用户可以猜测数字。
|
||||
|
||||
在循环的每次迭代中,程序测试用户的猜测的数值。如果用户的猜测小于随机数,程序将输出“太低”,如果猜测大于随机数,程序将输出“太高”。循环继续,直到用户的猜测与随机数相同。
|
||||
|
||||
当循环退出时,程序输出“That's right!”,然后立即结束。
|
||||
|
||||
|
||||
```
|
||||
$ gcc -o guess -Wall guess.c
|
||||
|
||||
$ ./guess
|
||||
Guess a number between 1 and 100
|
||||
50
|
||||
Too high
|
||||
30
|
||||
Too low
|
||||
40
|
||||
Too low
|
||||
45
|
||||
Too high
|
||||
42
|
||||
Too low
|
||||
43
|
||||
Too low
|
||||
44
|
||||
That's right!
|
||||
```
|
||||
|
||||
### 尝试动手
|
||||
|
||||
在学习一门新的编程语言时,这个“猜数字”游戏是一个很好的入门程序,因为它以一种非常直接的方式练习了几个常见的编程概念。通过用不同的编程语言实现这个简单的游戏,您可以演示一些核心概念,并比较每种语言的细节。
|
||||
|
||||
你有最喜欢的编程语言吗?你怎么用该语言编写“猜数字”游戏?跟随本系列文章,查看您可能感兴趣的其他编程语言的示例。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/1/learn-c
|
||||
|
||||
作者:[Jim Hall][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/jim-hall
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lenovo-thinkpad-laptop-concentration-focus-windows-office.png?itok=-8E2ihcF (Woman using laptop concentrating)
|
||||
[2]: https://opensource.com/article/20/8/learn-open-source
|
||||
[3]: https://opensource.com/article/20/12/learn-bash
|
||||
[4]: https://opensource.com/article/20/12/learn-java
|
||||
[5]: https://opensource.com/article/20/12/julia
|
||||
[6]: https://opensource.com/article/20/8/teaching-c
|
||||
[7]: https://opensource.com/article/20/8/c-programming-cheat-sheet
|
||||
[8]: http://www.opengroup.org/onlinepubs/009695399/functions/puts.html
|
||||
[9]: http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html
|
@ -0,0 +1,120 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Homura: A WINE-based Game Launcher for BSD)
|
||||
[#]: via: (https://itsfoss.com/homura-game-launcher-bsd/)
|
||||
[#]: author: (John Paul https://itsfoss.com/author/john/)
|
||||
|
||||
Homura:基于 WINE 的 BSD 游戏启动器
|
||||
======
|
||||
|
||||
BSD 不只是用于服务器。人们也将其用于桌面,并执行通常任务,包括休闲游戏。为了帮助实现这一点,我们将看看一个能让你在 FreeBSD 上运行 Windows 游戏的应用。
|
||||
|
||||
### 什么是 Homura?
|
||||
|
||||
![][1]
|
||||
|
||||
[Homura][2] 是一个能让你在 FreeBSD 上玩 Windows 游戏的工具。它的灵感来自于 [Lutris][3]。它允许你安装和管理多个 Windows 游戏和游戏商店启动器。它主要使用 Wine,但也附带了一些修复和变通的方法来让游戏工作。
|
||||
|
||||
Homura 的创建者 [Alexander Vereeken][4] 说,他创建这个应用是因为“当我开始使用 FreeBSD 时,没有有用的程序在 Wine 中安装游戏或启动器,所以我自己创建了一个”。当时,Wine 是唯一的选择。Linux 版本的 Steam 并不存在。
|
||||
|
||||
![Homura install list][5]
|
||||
|
||||
以下是你可以用 Homura 安装的清单:
|
||||
|
||||
* Anarchy Online
|
||||
* Arc
|
||||
* Bethesda 启动器
|
||||
* 暴雪启动器
|
||||
* 暗黑破坏神 II
|
||||
* Discord
|
||||
* 龙歌 OL
|
||||
* GOG
|
||||
|
||||
|
||||
* 建造乌托邦
|
||||
* 英雄联盟
|
||||
* Origin 启动器
|
||||
* PokeMMO
|
||||
* 精灵宝可梦绿铀
|
||||
* RuneScape
|
||||
* Steam
|
||||
|
||||
|
||||
* 地铁跑酷
|
||||
* Teamspeak
|
||||
* 猴岛大冒险 2
|
||||
* UC 浏览器
|
||||
* 育碧
|
||||
* 战游游戏中心
|
||||
* Itch.io
|
||||
|
||||
|
||||
|
||||
Homura 是以动画 [Madoka Magica][6] 中的一个角色命名的。在创建者转移到 GitLab 之前,它最初托管在 GitHub 上。目前它被托管在 Codeberg 上。希望它能暂时留在那里。
|
||||
|
||||
![Homura][7]
|
||||
|
||||
### 在 BSD 上安装 Homura 游戏启动器
|
||||
|
||||
你可以用这个命令从 FreeBSD 仓库中安装 Homura:
|
||||
|
||||
```
|
||||
pkg install games/homura
|
||||
```
|
||||
|
||||
你也可以使用这个命令从 ports 构建并安装它:
|
||||
|
||||
```
|
||||
cd /usr/ports/games/homura/ && make install clean
|
||||
```
|
||||
|
||||
安装完成后,你可以从菜单中选择 Homura,或在命令行中输入 `Homura` 来运行它。(在终端中名字必须大写,否则将无法运行。)
|
||||
|
||||
如果你通过 Homura 安装 Steam,你需要从 Homura 启动它。如果你从操作系统的菜单中启动它,它目前不会显示。
|
||||
|
||||
Steam 的库和商店标签由内置的网络浏览器显示。由于某些原因,这在 FreeBSD 上是不行的。但如果你从 Homura 的菜单中启动 Steam,它将使用列表模式,工作没有问题。
|
||||
|
||||
### 体验
|
||||
|
||||
我在 GhostBSD 上安装了 Homura,并用它来安装 Steam。之后,我安装了几个游戏来测试它。并不是所有的游戏都能正常运行,主要是因为它们试图使用或安装一个不可用的 Windows 专用软件。然而,我能够玩我最喜欢的游戏之一,微软的“国家的崛起”,没有任何问题。(我的测试变成了几个小时的游戏。)
|
||||
|
||||
![Homura Main Menu][8]
|
||||
|
||||
我也尝试安装 GOG 启动器。由于某些原因,它对我不起作用。加载页面会弹出,但什么都不会发生。我打算提交一个问题。我没有测试任何安装程序/启动器,因为我没有使用它们。
|
||||
|
||||
### 最后想法
|
||||
|
||||
并不是所有的东西都能顺利地与 Homura 一起使用,但我可以玩一些我最喜欢的游戏。
|
||||
|
||||
![Rise of Nation on BSD][9]
|
||||
|
||||
这款应用是一个典型的用户有了需求,并决定去填补它的案例。通过这样做,他让其他人的生活变得更轻松。希望这个应用能让人们更容易地开始使用 FreeBSD 作为他们的操作系统。
|
||||
|
||||
如果你觉得这篇文章有趣,请花点时间在社交媒体、Hacker News 或 [Reddit][10] 上分享。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/homura-game-launcher-bsd/
|
||||
|
||||
作者:[John Paul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/john/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/01/homura.jpg?resize=800%2C450&ssl=1
|
||||
[2]: https://codeberg.org/Alexander88207/Homura
|
||||
[3]: https://lutris.net/
|
||||
[4]: https://codeberg.org/Alexander88207
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/01/homura-install.jpg?resize=800%2C421&ssl=1
|
||||
[6]: https://madoka.fandom.com/wiki/Puella_Magi_Madoka_Magica
|
||||
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/01/homura-about.jpg?resize=800%2C411&ssl=1
|
||||
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/01/homura-main-menu.jpg?resize=500%2C776&ssl=1
|
||||
[9]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/01/rise-of-nation-bsd.jpg?resize=800%2C450&ssl=1
|
||||
[10]: https://%0Areddit.com/r/linuxusersgroup
|
Loading…
Reference in New Issue
Block a user