Merge pull request #1 from LCTT/master

Merge
This commit is contained in:
tendertime 2022-05-05 10:08:23 +08:00 committed by GitHub
commit f293f88fbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 1576 additions and 625 deletions

View File

@ -0,0 +1,105 @@
[#]: subject: "Documentation Isnt Just Another Aspect of Open Source Development"
[#]: via: "https://www.opensourceforu.com/2022/04/documentation-isnt-just-another-aspect-of-open-source-development/"
[#]: author: "Harsh Bardhan Mishra https://www.opensourceforu.com/author/harsh-bardhan-mishra/"
[#]: collector: "lkxed"
[#]: translator: "lkxed"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-14545-1.html"
文档并不是开源项目开发的附属品
======
有些项目长期保持活跃,有些项目却过早消亡 —— 这两者的区别往往在于它们的文档。严谨、聪明的文档可以给你的项目带来它所需要的动力。你应该把文档工作视为一项主要工作,把它与开发相提并论,下面我将说明这么做的理由和正确的做法。
![](https://img.linux.net.cn/data/attachment/album/202205/05/090003l7xrtrwszw6u4wqu.jpg)
经常会有开发者简单地认为他们的代码的“<ruby>自我描述<rt>self-documented</rt></ruby>”已经足够了,继而认为额外的文档是没有必要的。这种过度的自信会让项目付出很大的代价。匮乏或差劲的文档会扼杀你的项目。没有适当的文档,用户将无法理解项目的目标以及正确的工作流程。这可能会导致人们对采用你的开源产品产生一些疑虑。
### 撰写文档,从项目第一天就开始
文档不应该是次要的工作,它应该是与代码开发和管理同等的主要任务。随着内容以 Community Threads、Stack Overflow 和 Quora 问答等形式的广泛传播,文档承担了“<ruby>信息源<rt>source of truth</rt></ruby>”的角色。它应该满足那些想参考一手资料的贡献者的需要,并给工程师提供必要的参考支持。它还应该与利益相关者沟通基本计划。一个好的文档可以确保产品的持续改进和发展。
当发布一个软件产品时,我们不仅要发布代码,还要发布好的文档。这给我们带来了一个最重要的概念,大多数良好维护了文档的开源项目都遵循这个概念 —— “<ruby>文档即代码<rt>Documentation as code</rt></ruby>”。
### 文档及代码
今天,文档不再被存储为微软 Word 或 PDF 文件。新的需求是版本控制文档,其中所有的文档都是通过版本控制系统添加的,并持续发布。这个概念因 Read the DocsLCTT 译注:一个文档创建、托管和浏览的平台)而流行,现在已经成为大多数文档团队的内容策略的重要组成部分。
像 Bugzilla 和 GitHub <ruby>议题<rt>Issue</rt></ruby>这样的工具可以用来跟踪待处理的文档工作,并从维护者和用户那里获得反馈以验证文档的发布。外部审查可以用来验证文档作品,并持续发布文档。这就保证了除代码外,文档也能不断改进并快速发布。
请记住,如果不遵循规范化的实践,每个文档都会不同。这可能会导致一些混乱,使人们难以获取正确的信息。
哪些东西会被归类为混乱呢?当大多数文件都不遵循规范实践时,不一致就会产生,从而导致更大的混乱!那么,如何整理混乱的开源文档呢?
### 整理混乱的开源文档
遵循一个“文档风格指南”是很重要的。风格指南是创建和展示内容的指导方针的集合。无论你是一个独立的作家还是一个大型文档团队的成员,它都有助于在你的文档中保持一致的风格、口音和语气。
有几个流行的风格指南,如《红帽风格指南》、《谷歌文档风格指南》和《苹果风格指南》。如何选用?首先要从定义你的需求开始。如果你的要求与其他开源项目没有太大区别,你可以遵循一个现成的风格指南,或者你也可以先选一个,然后在它的基础上根据自身需要做一些修改。大多数与语法有关的准则和内容规则可能是通用的,但整体术语可能会有所不同。
你还需要在你的项目中自动采用这些风格指南。为此,你可以使用 Vale它集成了本地的持续集成CI服务该服务能帮助你确保文档严格遵循风格指南。
> **文档类型**
>
> * *自述文件*:包含基本的安装和使用说明,这也是任何开源文档中最重要的部分之一。它是潜在的用户/开发者与项目之间的第一个连接点。
> * *参考指南*:可能包括一些基本的参考资料,以便帮助你快速上手,或者是与项目贡献相关的文档。
> * *用户文档*:是最基本的文档,它描述了项目的使用方式。如果没有用户文档,大多数人就会对如何使用该项目感到迷茫。
> * *开发文档*:旨在支持开发团队在项目中不断取得新的进展。它还应该为内部开发工作提供一个良好的途径,并确保功能被很好地传达给股东。
> * *社区内容*:包括基本的博客、视频和外部内容,旨在为那些想进一步了解项目的社区成员提供支持。
通过使用风格指南,文件的整体前提将以统一的语言风格传达给用户。但是,这些文件毕竟是由一个技术作家团队准备的,它们的写作风格可能会冲突,因为写作风格是因人而异的。那么,如何才能使文档规范化呢?
### 规范化文档
当涉及到规范化文档时,有许多方法可以采取。第一个方法显然是创建适用于各种角色的预定义模板。这些模板可以用来记录新的功能、识别错误和问题,以及更新变更日志以适应正在增加的新内容。
如果你采用的是基于 Git 的工作流,试着开发一个规范的工作流程来发布你的文档。最规范的工作流是:<ruby>复刻<rt>fork</rt></ruby> 发布文档的仓库,在本地分支上添加你的修改,推送这些修改,提出请求并要求对其进行审查。规范化文档的一个好处就是带来更好的反馈和审查过程。
### 反馈和自动审查
规范化使得你能够得到用户的反馈并生成自动的审查,可以参考这些反馈来改进项目和文档。通过这些反馈,你也可以评估所分享的信息对用户是否有意义。像 GitBook 这样的文档平台会提供合适的反馈服务,这有助于验证文档是否有用。
始终寻求<ruby>主题专家<rt>subject matter expert</rt></ruby>SME对文档的反馈他们可以是利益相关者、开发者、工程师甚至是外部贡献者。你也可以使用自动测试和 CI 来验证你的文档是否遵循风格指南。
### 文档众包
如果你想开源你的文档,最好的方法也许是提供一个快速入门指南。它可以像 `CONTRIBUTING.md` 那样简单,基本上只要说明该如何设置项目并为其作出贡献/单纯使用它即可。
始终开发以用户为中心的文档,标明每个项目的目的。同时,打造学习课程来帮助新的贡献者。
> **带着目的编写文档**
>
> 始终带着目的编写文档。它是最基本的写作策略之一,它定义了你编写某个特定文档的理由,而非方式。首先回答以下问题:
>
> * 这个文档的目标是什么?
> * 需要传递的信息是什么?
> * 你希望用户在这之后采取什么行动?
> * 我与读者分享的价值观是什么?
> * 我的文档风格是否简洁、一致?
### 定义一致的内容策略
一致的内容策略有助于确保文档工作和项目基础设施的长期愿景。它可以围绕以下两个主要方面:
1. 资源:包括项目文档、案例研究和白皮书、项目架构等
2. 品牌内容:博客和特邀帖子、新闻和社区故事、学习课程等
每个开源项目都应该有适当的文档,以说明它能为用户提供的功能,这样用户就可以选择最合适的解决方案。适当的文档可以传达正确的信息,也可以让其他开发者贡献力量来进一步加强和改进项目。虽然听起来很简单,但只有做对了,文档才能成功。而你的项目,反过来,只有在你的文档正确的情况下才能成功,所以永远不要低估它的目标或过程!
策划Laveesh Kocher
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/04/documentation-isnt-just-another-aspect-of-open-source-development/
作者:[Harsh Bardhan Mishra][a]
选题:[lkxed][b]
译者:[lkxed](https://github.com/lkxed)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/harsh-bardhan-mishra/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/03/Importance-of-documentation-696x477.jpg

View File

@ -0,0 +1,38 @@
[#]: subject: "Microsoft Joins The Open 3D Foundation For Open Source 3D Development"
[#]: via: "https://www.opensourceforu.com/2022/05/microsoft-joins-the-open-3d-foundation-for-open-source-3d-development-promotion/"
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
[#]: collector: "lkxed"
[#]: translator: "lkxed"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-14544-1.html"
微软加入开放 3D 基金会,参与开源 3D 开发
======
![微软][1]
微软已经以首席成员的身份加入了<ruby>开放 3D 基金会<rt>Open 3D Foundation</rt></ruby>O3DF其他首席成员是 Adobe、AWS、华为、英特尔和 Niantic。微软的参与为该项目带来了大量的知识和思想引领这表明了通过行业合作创造一个高保真、功能齐全、不受商业条件限制的开源 3D 引擎是多么的关键。
微软首席集团项目经理 Paul Oliver 将加入 O3DF 管理委员会,这表明他将致力于实现基金会的目标,即确保符合开放 3D 社区保持需求与输入的平衡。基金会的战略方向和对 3D 可视化、仿真计划的管理,是由理事会与股东的创新互动来指导的。
“微软在创意方面的根基很深我们希望帮助所有的创作者无论他们是谁、在哪里、为哪个平台创作”Oliver 如是说,“由 Linux 基金会创建的开放 3D 基金会,是朝着帮助更多世界各地的创作者迈出的美妙一步,我们很高兴能成为其中的一员。”
微软不断致力于使游戏制作民主化,并向全世界的游戏创作者提供其工具和技术。加入开放 3D 基金会也反映出这一点。微软去年通过 GitHub 向所有开发者发布了其游戏开发工具包,并正在通过与 O3DF 的新伙伴关系,扩大其向所有人开放技术的承诺。
O3DF 执行董事,兼 Linux 基金会的游戏和数字媒体部总经理 Royal O'Brien 说:“我们很高兴微软以首席成员的身份加入开放 3D 基金会。有像微软这样杰出的行业资深公司做出贡献,并帮助社区推动 3D 引擎的创新,这对开源社区和使用它的公司都是巨大的好处。”
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/05/microsoft-joins-the-open-3d-foundation-for-open-source-3d-development-promotion/
作者:[Laveesh Kocher][a]
选题:[lkxed][b]
译者:[lkxed](https://github.com/lkxed)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/05/microsoft-696x464.jpg

View File

@ -1,37 +0,0 @@
[#]: subject: "Microsoft Joins The Open 3D Foundation For Open Source 3D Development"
[#]: via: "https://www.opensourceforu.com/2022/05/microsoft-joins-the-open-3d-foundation-for-open-source-3d-development-promotion/"
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Microsoft Joins The Open 3D Foundation For Open Source 3D Development
======
![microsoft][1]
Microsoft has joined the Open 3D Foundation (O3DF) as a Premier member, joining Adobe, AWS, Huawei, Intel, and Niantic. Microsofts involvement in the project adds a lot of knowledge and thought leadership to the project, demonstrating how crucial it is for the industry to work together to create a high-fidelity, fully-featured open source 3D engine that is free of commercial conditions.
Paul Oliver, Microsofts Principal Group Program Manager, will join the O3DF Governing Board, demonstrating his commitment to the Foundations goal of ensuring balanced collaboration and input that fits the needs of the Open 3D community. The Foundations strategic direction and stewardship of 3D visualisation and simulation initiatives are guided by the Governing Boards innovative interactions with stakeholders.
“Microsofts roots in creativity run deep and we want to help creators wherever they are, whoever they are, and whatever platform theyre creating for,” said Oliver. “Having the Linux Foundation create the Open 3D Foundation is a fantastic step towards helping more creators everywhere and we are excited to be a part of it.”
Microsofts continuous commitment to democratising game production and making its tools and technology available to game creators all over the world is reflected in this step. The company released its Game Development Kit to all developers via GitHub last year. Microsoft is extending its commitment to open up technology to everyone with its new partnership with O3DF.
“We are elated to have Microsoft join the Open 3D Foundation as a Premier member,” said Royal OBrien, Executive Director of O3DF and General Manager of Games and Digital Media at the Linux Foundation. “Having incredible industry veterans like Microsoft contributing and helping drive innovation with the community for 3D engines is a huge benefit to the open source community and the companies that use it alike.”
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/05/microsoft-joins-the-open-3d-foundation-for-open-source-3d-development-promotion/
作者:[Laveesh Kocher][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/05/microsoft-696x464.jpg

View File

@ -0,0 +1,43 @@
[#]: subject: "Nvidia Begins To Set The Foundation For Future Open And Parallel Coding"
[#]: via: "https://www.opensourceforu.com/2022/05/nvidia-begins-to-set-the-foundation-for-future-open-and-parallel-coding/"
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Nvidia Begins To Set The Foundation For Future Open And Parallel Coding
======
![Nvidia_logo_angled_shutterstock][1]
As graphics processors become more common in computers, Nvidia is expanding its collaboration with standards and open source communities to include downstream technologies that were previously limited to the companys development tools. A lot of effort is being put into programming languages like C++ and Fortran, which are thought to lag behind native implementation when it comes to executing code on highly parallel computers.
Nvidias CUDA parallel programming framework, which combines open and proprietary libraries, is responsible for many of the technologies being opened up and mainstreamed. In 2007, CUDA was introduced as a set of programming tools and frameworks for programmers to develop GPU-based systems. However, as GPU utilisation grew in more applications and sectors, the CUDA philosophy shifted.
Nvidia is best recognised for its GPU dominance, but CUDA is at the heart of the companys rebranding as a software and services supplier targeting a $1 trillion market cap. Nvidias long-term ambition is to become a full-stack provider with a focus on specific fields such as autonomous driving, quantum computing, health care, robotics, cybersecurity, and quantum computing.
Nvidia has created dedicated CUDA libraries in certain domains, as well as the hardware and services that businesses can use. The concept of a “AI factory,” announced by CEO Jensen Huang at the recent GPU Technology Conference, best exemplifies the full-stack strategy. Customers can drop applications into Nvidias mega datacenters, with the result being a customised AI model tailored to specific industry or application needs.
Nvidia may profit from AI factory principles in two ways: by utilising GPU capacity or by utilising domain-specific CUDA libraries. On Nvidia GPUs, programmers can use open source parallel programming frameworks such as OpenCL. CUDA, on the other hand, will deliver that extra last-mile increase for those willing to invest because it is tuned to operate closely with Nvidias GPU.
While parallel programming is common in high-performance computing, Nvidias goal is to make it a norm in mainstream computing. The company is assisting in the standardisation of best-in-class tools for writing parallel code that is portable across hardware platforms regardless of brand, accelerator type, or parallel programming framework.
For one thing, Nvidia is a member of a C++ group that is building the groundwork for simultaneous execution of portable code across hardware. A context could be a CPU thread that primarily performs IO or a CPU or GPU thread that does demanding computation. Nvidia is particularly engaged in delivering C++ programmers a standard language and infrastructure for asynchrony and parallelism.
The first work focused on the memory model, which was incorporated in C++ 11, but had to be updated when parallelism and concurrency became more prevalent. C++ 11s memory model emphasised concurrent execution across multicore CPUs, but it lacked parallel programming hooks. The C++ 17 standard laid the foundation for higher-level parallelism features, but real portability will have to wait for future standards. C++ 20 is the current standard, with C++ 23 on the horizon.
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/05/nvidia-begins-to-set-the-foundation-for-future-open-and-parallel-coding/
作者:[Laveesh Kocher][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/05/Nvidia_logo_angled_shutterstock.jpg

View File

@ -0,0 +1,39 @@
[#]: subject: "ESI Group Collaborates With ENSAM, Open Sources Its “Inspector” Software"
[#]: via: "https://www.opensourceforu.com/2022/05/esi-group-collaborates-with-ensam-open-sources-its-inspector-software/"
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
ESI Group Collaborates With ENSAM, Open Sources Its “Inspector” Software
======
![software][1]
Inspector is a visual and interactive data exploration software that can analyse massive amounts of data and extract relevant information for applications such as predictive maintenance, cybersecurity, control, and machine learning algorithm analysis.
ESI Group extends its commitment to the industrial and academic ecosystems by making Inspector software available to as many individuals as possible, allowing them to collaborate on a dependable and flexible solution to address the technological problems and special needs of the community.
Inspectors growth and extension will be led by ENSAM (Ecole Nationale Supérieure dArts et Métiers), as part of an ongoing sponsorship and co-creation partnership between ESI Group and ENSAM. Their joint participation in the DesCartes initiative, coordinated by the CNRS in Singapore, the CREATE-ID international research chair, and the ESI ENSAM virtual engineering laboratory has strengthened their relationship.
There are numerous advantages to using an open source strategy. First, it lets the community to use the programme in the most efficient and effective manner possible, allowing the scientific community to benefit from new functionality tailored to each users needs, as well as security enhancements. Second, ESI Group hopes to provide an opportunity to profit from software whose dependability has been demonstrated over time by its clients in a variety of industries, including automotive and aeronautics. Thanks to the involvement of many stakeholders, “Inspector” will continue to evolve and adapt to the demands of the community.
ESI Groups intention to release its data analysis software as open source has received interest and support from a number of industry leaders and “Inspector” users. This is the case with CNS, for example.
Stephane Perrin, Managing Director of CNS says: “The decision taken by ESI Group is a great illustration of the Groups dedication to the innovation and scientific ecosystem with its cutting-edge technologies. At CNS, a Network and Security expertise company, we are mobilized to ensure the future of Inspector. In addition to integrating Inspector into our continuous network auditing software suite, we will also soon offer support for the software via our business unit dedicated to innovative solutions.”
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/05/esi-group-collaborates-with-ensam-open-sources-its-inspector-software/
作者:[Laveesh Kocher][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/05/software-696x371.jpg

View File

@ -0,0 +1,108 @@
[#]: subject: "Firefox 100 Marks 17 Years of Development with Interesting Upgrades"
[#]: via: "https://news.itsfoss.com/firefox-100-release/"
[#]: author: "Ankush Das https://news.itsfoss.com/author/ankush/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Firefox 100 Marks 17 Years of Development with Interesting Upgrades
======
Mozilla Firefox 100 is a significant release, marking 17 years of development, and all the exciting feature additions over the years.
![firefox 100][1]
Firefox is arguably the most popular open-source browser thats not based on Chrome, available for Linux, Windows, and Mac.
While we know that Chrome-based browsers dominate the market share, Firefox was introduced way before Google Chrome came into existence.
To be accurate, Firefox 100 release marks 17 years of development effort since 2004.
It still feels like yesterday, right?
### Firefox 100: Whats New?
![firefox 100][2]
It does not matter whether you love/hate Firefoxs new development plans, the fact that it introduced numerous industry-leading features/technology over the years is impressive.
Firefox 100 release hits an important milestone. But, it is not a massive upgrade.
Here, I shall highlight the key improvements with this release:
#### Improvements to Picture-in-Picture Mode
![firefox 100][3]
Whenever you watch anything on YouTube, Prime Video, and Netflix in Picture-in-Picture mode, Firefox now supports captions/subtitles for it.
You just need to enable the captions/subtitles for the video in the respective platform and it will continue to appear in PiP.
The support for captions in PiP is not limited to mainstream platforms but also on websites like Coursera that use WebVTT format.
#### Language Detection
To improve the user experience, Firefox now detects when the language does not match the operating system preferences.
This only happens when you first run the browser after installation. So, you can choose between the systems language or the browsers default.
#### Scrollbars Dont Take Space by Default
The scrollbars on Linux and Windows 11 wont take your precious screen space by default. In other words, they will be responsive and collapse when youre focused on scrolling or navigating.
![firefox 100][4]
You can change this in the Settings (for Linux users). Firefox follows your system setting for visual effects if you are on Windows. So, you would need to tweak that for Firefox to honor your preferences.
#### Control Website Appearance
![firefox 100][5]
For some websites, your browser preferences influence the color/appearance of the web page.
To tweak the experience for such websites, you now can set a website appearance preference in the Settings to choose light/dark, system, or Firefox theme.
#### HDR Video and Hardware Accelerated AV1 Video Decoding
HDR Video support may not be a big deal for everyone. But, it is now supported in Firefox on Mac.
The official support exists for YouTube as of now with macOS 11+. Of course, you need an HDR-compatible screen as well.
The hardware-accelerated AV1 video decoding is finally supported on Windows with compatible GPUs (including Intels 11th Gen, AMD RDNA 2, and GeForce 30 series). In addition to this, video overlay is also enabled on Windows, reducing power usage.
Unfortunately, these arent Linux-specific updates but should help the Firefox users across multiple platforms.
#### Other Improvements
In addition to the major highlights, the changes include:
* Support for profiling multiple java threads has been added.
* Soft-reloading a web page will no longer cause revalidation for all resources.
* Firefox has a new focus indicator for links, which replaces the old dotted outline with a solid blue outline.
You can learn more about the technical changes in the [official release notes][6].
### Get Firefox 100
You can download it from its official website or look for an update available, it should be a quick download.
--------------------------------------------------------------------------------
via: https://news.itsfoss.com/firefox-100-release/
作者:[Ankush Das][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://news.itsfoss.com/author/ankush/
[b]: https://github.com/lkxed
[1]: https://news.itsfoss.com/wp-content/uploads/2022/05/firefox-100-release.jpg
[2]: https://news.itsfoss.com/wp-content/uploads/2022/05/firefox-100-about.jpg
[3]: https://news.itsfoss.com/wp-content/uploads/2022/05/firefox-captions-100.jpg
[4]: https://news.itsfoss.com/wp-content/uploads/2022/05/scrollbars.jpg
[5]: https://news.itsfoss.com/wp-content/uploads/2022/05/firefox-appearance-tweak.jpg
[6]: https://www.mozilla.org/en-US/firefox/100.0/releasenotes/

View File

@ -0,0 +1,46 @@
[#]: subject: "Microsofts 3D Movie Maker, First Released In 1995, Is Now Open Source"
[#]: via: "https://www.opensourceforu.com/2022/05/microsofts-3d-movie-maker-first-released-in-1995-is-now-open-source/"
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Microsofts 3D Movie Maker, First Released In 1995, Is Now Open Source
======
![windows movie maker logo][1]
Microsoft has released a number of open source tools over the years, and today it is digging deep into its archives to make 3D Movie Maker available to everyone. 3D Movie Maker, which was first launched in 1995, allows you to create animated scenarios with 3D characters, props, backgrounds, text, sound, and special effects. This version also includes an Argonaut software build of BRender. While this is a positive step, you shouldnt get too enthusiastic because there is a catch.
“This project is unlikely to build successfully under modern hardware/software, but you can get started with compilation and get partial completed binaries.”
It includes the following construction instructions.
Make sure this repository is checked out to a folder with a brief name, preferably near the drives root (i.e. C:\3d).
On your route, youll need the dev tools for Visual C++ 2.0 (found under MSVC20BIN on the installer disc). Some pre-C++98 norms are disliked by modern compilers.
Run setvars.bat from the root of this repository. You can alter the values in this script to change the target of your build.
Find and install font files (see FONTS.md)
Run nmake to get started with 3D Movie Maker.
The code was recovered from the Microsoft corporate archives, third-party authorization (for products like BRender) was gained, and developer identities and aliases were deleted in order to make the software open source (with the exception of current Microsoft employees who worked on the original release and agreed to keep their names in place). It can be downloaded from [here][2].
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/05/microsofts-3d-movie-maker-first-released-in-1995-is-now-open-source/
作者:[Laveesh Kocher][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/05/windows-movie-maker-logo-696x392.png
[2]: https://github.com/microsoft/Microsoft-3D-Movie-Maker

View File

@ -0,0 +1,58 @@
[#]: subject: "elementary OS 7 Code Name Revealed. Here are the Details"
[#]: via: "https://www.debugpoint.com/2022/05/elementary-os-7-announcement/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
elementary OS 7 Code Name Revealed. Here are the Details
======
In a blog post earlier today, Daniella Fore (Founder & CEO) announced the elementary OS 7 release details and its expected features.
**In a blog post earlier today, Daniella Fore (Founder & CEO) announced the elementary OS 7 release details and its expected features.**
![elementary OS 6 ODIN Desktop][1]
### elementary OS 7 Announcement
The elementary OS 7 code name is “**Horus**“, and it will be based on [Ubuntu 22.04 LTS][2]. The development is near the finishing line of this release while the team is fixing some critical regression test problems dealing with the window manager and other areas.
Firstly, features wise, elementary OS 7 gets the latest packages and upgrades from **Ubuntu 22.04 LTS**. In addition, the **Flatpak runtime updates, Granite 7, stylesheet and icon updates** are expected in version 7 of this release. The Linux Kernel should be [Kernel 5.15.x][3].
Secondly, the App Store applications should get the **automatic application update feature** and new **power profile options** for laptops. The power profile is expected to follow the traditional “Balanced”, “Performance”, and “Power Saver” options like other Linux distros out there.
Moreover, a **new sleek Music application** is ready to debut in this release with a few redesigned icons and visual uplift across the desktop. The native App Store applications that have already migrated to Gtk4 tech should give a smooth performant experience to the users while using elementary OS 7.
#### A New Upgrade tool
But thats not all. The team is also excited to announce that a working prototype for the elementary **version upgrade tool** is ready and being tested at the moment. So, post the eOS 7 release, it should debut officially to enable eOS 6 to 7 migration.
The elementary version upgrades are the biggest challenges today without any official upgrade path. And it is exciting news and attracts more users to this beautiful Linux distribution.
However, the Wayland migration is still on the cards and has not been prioritised yet. It would be an exciting experience with the elementary OS when Wayland support is fully developed.
### Release Date?
Perhaps the most frequently asked question of any elementary OS release is the release date. Well, the release date is not final yet. The elementary OS 7 “Horus” will be released when ready. My optimistic guess is by the end of this year, after the first point release of Ubuntu 22.04 (due in July 2022).
Finally, read the official elementary OS 7 [announcement][4] for more about this release and many updates on elementary OS 6 “Odin” (point release 6.1).
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2022/05/elementary-os-7-announcement/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed
[1]: https://www.debugpoint.com/wp-content/uploads/2021/08/elementary-OS-6-ODIN-Desktop-1024x576.jpeg
[2]: https://www.debugpoint.com/2022/01/ubuntu-22-04-lts/
[3]: https://www.debugpoint.com/2021/11/linux-kernel-5-15/
[4]: https://blog.elementary.io/updates-for-april-2022/

View File

@ -1,112 +0,0 @@
[#]: subject: "How I use open source to design my own card games"
[#]: via: "https://opensource.com/article/21/12/open-source-card-game"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "hadisi1993"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How I use open source to design my own card games
======
Open source isn't just about software. It's a cultural phenomenon, a
natural fit for tabletop games.
![Deck of playing cards][1]
I love a good game, and I particularly enjoy tabletop games because they have many of the same traits that open source has. When you're playing a card game in real life with friends sitting around a table, you can as a group decide that Jokers are wild. Alternately, you could arbitrarily decide that should a Joker come into play, anyone holding an Ace must discard that Ace. Or when a Queen of Diamonds comes into play, everyone must pass their hand to the player on their right. In other words, you can reprogram the rules on a whim because a game is nothing but a mutually agreed-upon set of conditions. To me, what's even better is that you can invent your own games instead of hacking the rules of somebody else's game. From time to time, I do this as a hobbyist, and because I like to combine my hobbies, I tend to design games with only open source and open culture resources.
First of all, it's important to understand that there are, broadly, two facets of a game: _flavor_ and _mechanics_. The flavor is the story and theme of the game. The mechanics of a game are the rules and the condition of play. The two aren't always completely separate from one another, and there's an elegance to designing a game themed around race cars, for instance, with rules that demand players to perform actions very quickly. However, the flavor and mechanics are just as often treated separately, and it's entirely reasonable to invent a game that _could_ be played with a standard deck of poker cards, but that's themed around space llamas, just for the fun of it.
### Open source artwork
If you've ever gone to a museum of modern art, you've probably found yourself standing in front of a canvas painted solid blue and overheard somebody utter this time-honored phrase: "Heck, I could make that!" But the truth is, artwork is hard work. Making art that's pleasing to the eye takes a lot of thought, time, confidence, and skill, so it makes sense that the art is one of the most difficult things to procure for a game you're designing.
I have a few "hacks" on dealing with this classic snag.
#### 1\. Find common ground
There's free and open art out there, and a lot of it is very good. The problem is that games usually need more than one art piece. If you're designing a card game, you probably need at least four or six distinct elements (assuming your cards follow the foundations laid out by the Tarot deck) and possibly more. If you spend enough time on it, you can find [Creative Commons and Public Domain][2] artwork online on sites like [OpenGameArt.org][3], [FreeSVG.org][4], [ArtStation.com][5], [DeviantArt.com][6], and many others.
If the site you're using doesn't have a Creative Commons search, enter the following words into any search engine, "This work is licensed under a Creative Commons" (the quotes are important, so don't leave those off) and whatever syntax your favorite search engine uses to limit the search to just one site (for example, **site:deviantart.com**).
Once you have a pool of art to choose from, sort the art that you've found by identifying common themes in the artwork. Two pictures of robots by two different people might look nothing alike, but they're still both robots. Provided you have enough robot-themed art, you can structure the flavor of your game around robots.
#### 2\. Commission Creative Commons art
You can hire artists to make custom art for you. I work with artists who use open source paint programs like [Krita][7] and Mypaint, and as part of the contract, I specify that the art must be licensed under a Creative Commons Attribution Share-alike (CC BY-SA) license. I've only ever had one artist decline the offer because of the license restriction, and most are happy for their artwork to have a potentially larger life than just as part of a hobbyist's self-published game.
#### 3\. Make your own
As a trip to the museum of modern art reveals, art is a very flexible term. I've found that as long as I give myself a goal of how many cards or tokens for a game I need to create, I can usually produce something with one of the many graphical creative tools available on Linux. It doesn't have to be anything fancy. Just like modern art, you can paint a card with blue and yellow stripes, another with red and white polka-dots, another with green and purple zig-zags, and nobody but you will ever know that you secretly meant for them to be the lords and ladies of the fairy court, except that you don't know how to draw those. Think about all the simple things you can create in a graphics application, or by tracing photographs of everyday objects, or by remixing classic Poker suits, or Tarot themes, and so on.
### Layout
I use [Inkscape][8], Scribus, or [GIMP][9] for layout, depending on what my assets are and what manner of design I'm after.
For cards, I find that a simple layout is easy to do and look at, solid colors tend to print better than gradients, and intuitive iconography is best.
![layout in Inkscape][10]
(Seth Kenlon, CC BY-SA 4.0)
I did the layout in a single Inkscape file for my latest game, which uses just nine images from three or four different artists on OpenGameArt.com. I design the layout of each card in its own file for games with a more extensive set of art and card variety.
Know your target output before you do any layout for your game assets. If you're going to print your game at home, then do the math and figure out how many cards or tokens or tiles you can fit on your default paper size (US Letter for some, A4 for everybody else). If you're printing with a game printer like [TheGameCrafter][11], download the template files.
![printed cards][12]
(Seth Kenlon, CC BY-SA 4.0)
### Mechanics
Game mechanics are the most important part of a game. They're what makes the game a game. Developing rules for a game doesn't have to be a formal process. You can come up with a game on a whim, or take a game that exists and remix its rules until it's something different, fix a game that just doesn't work for you, or mash two different games together. Start simple, using index cards, standard playing cards, or a Tarot deck to mock up how you think your game will work. You can play early game ideas by yourself, but eventually, getting a friend to help is a great way to introduce surprise glitches and optimizations.
Playtest often. Play your game with a diverse set of players, and listen to their feedback. Your game might inspire many players to invent new rules and ideas, so separate feedback about what's _broken_ from feedback about what _could be different_. You don't have to implement feedback that just iterates your idea, but give careful thoughts to the bug reports.
Once you've decided how you want your rules to work, write them down to make them [short and easy to parse][13]. Your rules don't have to convince players to play the game, you don't have to explain the strategy to them, nor do you need to give permission to players to remix the rules. Just tell the players the sequence of steps they need to take in order to make the game work.
Most importantly, consider making your rules open source. Gaming is all about shared experiences, and that ought to include the rules. A Creative Commons or Open Game License ruleset allows other gamers to iterate, remix, and build upon your work. You never know, somebody might come up with a variant that you enjoy more than your own!
### Open source gaming
Open source isn't just about software. It's a cultural phenomenon, a natural fit for tabletop games. Take a few evenings to experiment with creating a game. If you're new to it, start with something simple, like this blank card activity:
1. Gather up some friends.
2. Give each person a few blank index cards, and tell them to write a rule on each card. The rule can be anything ("If you're wearing something red, you win" or "The first person to stand up wins," and so on.)
3. On your own index cards, write _and_, _but_, _or_, _but not_, _and not_, _except_, and other conditional phrases.
4. Shuffle your deck and deal the cards to all players.
5. Each player may play one card per turn.
6. The goal is to win, but players may play the _and_, _but_, and _or_ cards to modify the conditions of what determines the winner.
It's a fun party game and a nice introduction to thinking like a game designer because it helps you recognize what tends to work as a game mechanic and what doesn't.
And, of course, it's open source.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/12/open-source-card-game
作者:[Seth Kenlon][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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rich-smith-unsplash.jpg?itok=uzzS0gRa (Deck of playing cards)
[2]: https://opensource.com/article/20/1/what-creative-commons
[3]: https://opensource.com/article/21/12/opengameart.org/
[4]: http://freesvg.org
[5]: http://artstation.com
[6]: http://deviantart.com
[7]: https://opensource.com/article/21/12/krita-digital-paint
[8]: https://opensource.com/article/21/12/linux-draw-inkscape
[9]: https://opensource.com/content/cheat-sheet-gimp
[10]: https://opensource.com/sites/default/files/inkscape-layout.jpg (Layout in Inkscape)
[11]: https://www.thegamecrafter.com/
[12]: https://opensource.com/sites/default/files/cards-printed_0.jpg (Printed cards)
[13]: https://opensource.com/life/16/11/software-documentation-tabletop-gaming

View File

@ -1,329 +0,0 @@
[#]: subject: "Learn Rust in 2022"
[#]: via: "https://opensource.com/article/22/1/rust-cheat-sheet"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Learn Rust in 2022
======
If you're going to explore Rust this year, download our free Rust cheat
sheet, so you have a quick reference for the basics.
![Cheat Sheet cover image][1]
Rust is a relatively new programming language, and it's already a popular one [winning over programmers][2] from all industries. Still, it's also a language that builds on everything that's come before. Rust wasn't made in a day, after all, so even though there are concepts in Rust that seem wildly different from what you might have learned from Python, Java, C++, and so on, they all have a foundation in the same CPU and NUMA architecture you've always been (whether you know it or not) interacting with, and so some of what's new in Rust feels somehow familiar.
Now, I'm not a programmer by trade. I'm impatient yet obsessive. If a language doesn't help me get the results I want relatively quickly, I rarely find myself inspired to use it when I need to get something done. Rust tries to bring into balance two conflicting things: The modern computer's need for secure and structured code, and the modern programmer's desire to do less work while attaining more success.
### Install Rust
The [rust-lang.org][3] website has great documentation on installing Rust, but usually, it's as simple as downloading the `sh.rustup.rs` script and running it.
```
$ curl --proto '=https' --tlsv1.2 -sSf <https://sh.rustup.rs>
$ less sh.rustup.sh
$ sh ./sh.rustup.rs
```
### No classes
Rust doesn't have classes and does not use the `class` keyword. Rust does have the `struct` data type, however, its purpose is to serve as a kind of template for a collection of data. So instead of creating a class to represent a virtual object, you can use a struct:
```
struct Penguin {
    genus: String,
    species: String,
    extinct: bool,
    classified: u64,
}
```
You can use this similar to how a class is used. For instance, once a `Penguin` struct is defined, you can create instances of it, and interact with that instance:
```
struct Penguin {
    genus: String,
    species: String,
    extinct: bool,
    classified: u64,
}
fn main() {
    let p = Penguin { genus: "Pygoscelis".to_owned(),
         species: "R adeliæ".to_owned(), 
         extinct: false, 
         classified: 1841 };
    println!("Species: {}", p.species);    
    println!("Genus: {}", p.genus);
    println!("Classified in {}", p.classified);
    if p.extinct == true {
        println!("Sadly this penguin has been made extinct.");
    }
    
}
```
Using the `impl` data type in conjunction with the `struct` data type, you can implement a struct containing functions, and you can add inheritance and other class-like features.
### Functions
Functions in Rust are a lot like functions in other languages. Each one represents a discreet set of tasks that you can call upon when needed. The primary function must be called `main`.
Functions are declared using the `fn` keyword, followed by the function's name and any parameters the function accepts.
```
fn foo() {
  let n = 8;
  println!("Eight is written as {}", n);
}
```
Passing information from one function to another gets done with parameters. For instance, I've already created a `Penguin` class, and I've got an instance of a penguin as `p`, so passing the attributes of `p` from one function to another requires me to specify `p` as an accepted `Penguin` type for its destination function.
```
fn main() {
  let p = Penguin { genus: "Pygoscelis".to_owned(), 
    species: "R adeliæ".to_owned(), 
    extinct: false, classified: 1841 };
  printer(p);
}
fn printer(p: Penguin) {
  println!("Species: {}", p.species);    
  println!("Genus: {}", p.genus);
  println!("Classified in {}", p.classified);
  if p.extinct == true {
      println!("Sadly this penguin has been made extinct.");
  }
}
```
### Variables 
Rust creates immutable variables by default. That means that a variable you create cannot be changed later. This code, humble though it may be, cannot be compiled:
```
fn main() {
 let n = 6;
 let n = 5;
 }
```
However, you can declare a mutable variable with the keyword `mut`, so this code compiles successfully:
```
fn main() {
 let mut n = 6;
 println!("Value is {}", n);
 n = 5;
 println!("Value is {}", n);
}
```
### Compiler 
The Rust compiler, at least in terms of its error messages, is one of the nicest compilers available. When you get something wrong in Rust, the compiler makes a sincere effort to tell you what you did wrong. I've actually learned many nuances of Rust (insofar as I understand any nuance of Rust) just by learning from compiler error messages. Even when an error message is too obscure to learn from directly, it's almost always enough for an internet search to explain.
The easiest way to start a Rust program is to use `cargo`, the Rust package management and build system.
```
$ mkdir myproject
$ cd myproject
$ cargo init 
```
This creates the basic infrastructure for a project, most notably a `main.rs` file in the `src` subdirectory. Open this file and paste in the example code I've generated for this article:
```
struct Penguin {
    genus: String,
    species: String,
    extinct: bool,
    classified: u64,
}
fn main() {
    let p = Penguin { genus: "Pygoscelis".to_owned(), species: "R adeliæ".to_owned(), extinct: false, classified: 1841 };
    printer(p);
    foo();
}
fn printer(p: Penguin) {
    println!("Species: {}", p.species);    
    println!("Genus: {}", p.genus);
    println!("Classified in {}", p.classified);
    if p.extinct == true {
        println!("Sadly this penguin has been made extinct.");
    }
}
fn foo() {
     let mut n = 6;
 println!("Value is {}", n);
 n = 8;
  println!("Eight is written as {}", n);
}
```
To compile, use the `cargo build` command:
```
`$ cargo build`
```
To run your project, execute the binary in the `target` subdirectory, or else just use `cargo run`: 
```
$ cargo run
Species: R adeliæ
Genus: Pygoscelis
Classified in 1841
Value is 6
Eight is written as 8
```
### Crates
Much of the convenience of any language comes from its libraries or modules. In Rust, libraries get distributed and tracked as "crates". The [crates.io][4] website is a good registry of community crates.
To add a crate to your Rust project, list them in the `Cargo.toml` file. For instance, to install a random number function, I use the `rand` crate, with `*` serving as a wildcard to ensure that I get the latest version at compile time:
```
[package]
name = "myproject"
version = "0.1.0"
authors = ["Seth &lt;[seth@opensource.com][5]&gt;"]
edition = "2022"
[dependencies]
rand = "*"
```
Using it in Rust code requires a `use` statement at the top:
```
`use rand::Rng;`
```
Some sample code that creates a random seed and then a random range:
```
fn foo() {
    let mut rng = rand::thread_rng();
    let mut n = rng.gen_range(1..99);
    println!("Value is {}", n);
    n = rng.gen_range(1..99);
    println!("Value is {}", n);
}
```
You can use `cargo run` to run it, which detects the code change and triggers a new build. The build process downloads the `rand` crate and all the crates that it, in turn, depends upon, compiles the code, and then runs it:
```
$ cargo run
Updating crates.io index
Downloaded ppv-lite86 v0.2.16
Downloaded 1 crate (22.2 KB) in 1.40s
 Compiling libc v0.2.112
 Compiling cfg-if v1.0.0
 Compiling ppv-lite86 v0.2.16
 Compiling getrandom v0.2.3
 Compiling rand_core v0.6.3
 Compiling rand_chacha v0.3.1
 Compiling rand v0.8.4
 Compiling rustpenguin v0.1.0 (/home/sek/Demo/rustpenguin)
 Finished dev [unoptimized + debuginfo] target(s) in 13.97s
 Running `target/debug/rustpenguin`
Species: R adeliæ
Genus: Pygoscelis
Classified in 1841
Value is 70
Value is 35
```
### Rust cheat sheet
Rust is a supremely pleasant language. Thanks to its integration with online registries, its helpful compiler, and its almost intuitive syntax, it feels appropriately modern.
Make no mistake, though, it's also a complex language, with strict data types, strongly scoped variables, and many built-in methods. Rust is worth looking at, and if you're going to explore Rust, then you should download our free **[Rust cheat sheet][6]**, so you have a quick reference for the basics. The sooner you get started, the sooner you'll know Rust. And, of course, you should practice often to avoid getting rusty.
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/1/rust-cheat-sheet
作者:[Seth Kenlon][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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coverimage_cheat_sheet.png?itok=lYkNKieP (Cheat Sheet cover image)
[2]: https://opensource.com/article/20/5/rust-java
[3]: http://rust-lang.org
[4]: https://crates.io/
[5]: mailto:seth@opensource.com
[6]: https://opensource.com/downloads/rust-cheat-sheet

View File

@ -1,42 +0,0 @@
[#]: subject: "Bloomberg Open Sources Memray, A Python Memory Profiler"
[#]: via: "https://www.opensourceforu.com/2022/04/bloomberg-open-sources-memray-a-python-memory-profiler/"
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Bloomberg Open Sources Memray, A Python Memory Profiler
======
![soft][1]
Memray is a memory profiler that was developed at Bloomberg and is now open source. It can track memory allocations in Python code, including native extensions and the Python interpreter itself. Memory profiling is a strong tool for understanding how a program utilises memory and, as a result, detecting memory leaks or determining which areas of the program consume the most memory.
In contrast to sampling memory profilers like py-spy, Memray can track every function call, including calls into C/C++ libraries, and display the call stack in detail. Bloomberg claims that this does not come at the sacrifice of performance, with profiling only slowing down interpreted code by a little amount. However, native code profiling is slower and must be enabled directly.
Memray may generate a variety of reports based on the acquired memory consumption data, including flame graphs, which are valuable for rapidly and precisely identifying the most common code-paths.
According to Yury Selivanov, co-founder and CEO of EgdeDB, the tool gives previously unavailable insights into Python applications. Memray can be used to execute and profile a Python application from the command line:
```python
$ python3 -m memray run -o output.bin my_script.py
$ python3 -m memray flamegraph output.bin
```
Alternatively, you can use pytest-memray to integrate Memray into your test suite. You can also profile all C/C++ calls with the —native command line option, or analyse memory allocation in real time while a programme is executing with the —live command line option. Memray can be installed with python3 -m pip install memray on a Linux x86/64 system.
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/04/bloomberg-open-sources-memray-a-python-memory-profiler/
作者:[Laveesh Kocher][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/04/soft-1-696x363.jpg

View File

@ -0,0 +1,66 @@
[#]: subject: "Automate and manage multiple devices with Remote Home Assistant"
[#]: via: "https://opensource.com/article/22/5/remote-home-assistant"
[#]: author: "Kevin Sonney https://opensource.com/users/ksonney"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Automate and manage multiple devices with Remote Home Assistant
======
Link together multiple Home Assistant devices with this centralized control panel.
![Houses in a row][1]
(Image by: [27707][2] via [Pixabay][3], CC0. Modified by Jen Wike Huger.)
Automation is a hot topic right now. In my day job as an SRE part of my remit is to automate as many repeating tasks as possible. But how many of us do that in our daily, not-work, lives? This year, I am focused on automating away the toil so that we can focus on the things that are important.
There are a lot of guides out there on [Setting Up Home Assistant][4], but what if you have multiple Home Assistant installations (like I do), and want to display and control them all from a single, central Home Assistant?
There is an amazing add-on called Remote Home Assistant ([https://github.com/custom-components/remote_homeassistant][5]) that makes this an absolute breeze. And it really helps me manage and automate things without having to set up any complex software (although I have done this with MQTT in the past — it was a challenge).
![Image of Remote Home Assistant][6]
(Image by: Kevin Sonney, CC BY-SA 40)
The easiest way to set up Remote Home Assistant is to install the [Home Assistant Community Store][7] (HACS) on both HASS installations. HACS is an absolutely massive collection of third-party add-ons for Home Assistant. The instructions are very straight forward, and cover most use cases — including using  Home Assistant OS (which is my central node), and Home Assistant Core (one of my remote nodes). It installs as a new Integration, so you can add it like any other integration. You must be able to log into GitHub for HACS to work, but HACS walks you through that as part of the configuration flow. After it's complete, it loads all the known add-on repositories. To see the status of it, click the new **HACS** option in the navigation menu on the left.
![Image of HACS Main Page][8]
(Image by: Kevin Sonney, CC BY-SA 40)
Select **Integrations** and search for **Remote Home Assistant** when it has completed loading all the store information. Install the add-on with the **Install** button, and restart Home Assistant. When the restart is complete, you have a new custom integration available, which can be added like any other.
On the remote node (“lizardhaus”), you need to [generate a long-lived token][9], and then add the **Remote Home Assistant** integration. Select **Setup as remote node** and that's all you need to do.
On the central node (“homeassistant”), the configuration flow is different. Add the integration as before, but do not create an access token. Select **Add a remote node** and click **Submit**. You are asked for the site name, the address (which can be a name or an IP address), the port, and the access token generated on the remote node. You can enable or disable SSL (and I STRONGLY recommend setting up SSL on the remote if it's exposed to the internet). After it connects, it prompts you for additional information, such as a prefix for the entities from the remote node (I like to include a trailing "_" character), what entities to fetch, and what to include and exclude. You can get events that can be triggered remotely, like turning on and off switches.
![Image of Remote Home Assistant Setup Step 2][10]
(Image by: Kevin Sonney, CC BY-SA 40)
After that, the remote items appear to home assistant like any other item. And you can control them in the same way, as long as you added the correct triggers and entities.
Remote Home Assistant is really useful if you have devices like Bluetooth Low Energy plant sensors that are too far away from the main HASS machine. You can place a Raspberry Pi with HassOS near the plants then use Remote Home Assistant to put them in your central dashboard, and get an alert when they need watering, and so on. Overall, linking together multiple Home Assistant configurations is surprisingly easy, and VERY helpful.
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/5/remote-home-assistant
作者:[Kevin Sonney][a]
选题:[lkxed][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/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/house_home_colors_live_building.jpg
[2]: https://pixabay.com/en/users/27707-27707/
[3]: https://pixabay.com/en/buildings-houses-cliff-top-home-1008677/
[4]: https://opensource.com/article/20/12/home-assistant
[5]: https://github.com/custom-components/remote_homeassistant
[6]: https://opensource.com/sites/default/files/2022-04/CronyDay03-1.png
[7]: https://hacs.xyz
[8]: https://opensource.com/sites/default/files/2022-04/CronyDay03-2.png
[9]: https://www.atomicha.com/home-assistant-how-to-generate-long-lived-access-token-part-1/
[10]: https://opensource.com/sites/default/files/2022-04/CronyDay03-3_0.png

View File

@ -0,0 +1,223 @@
[#]: subject: "How I use the Bacula GUI for backup and recovery"
[#]: via: "https://opensource.com/article/22/5/baculum-open-source-backup"
[#]: author: "Rob Morrison https://opensource.com/users/robmorrison"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How I use the Bacula GUI for backup and recovery
======
Baculum is an open source web application for using Bacula's range of backup and restore jobs.
![Text editor on a browser, in blue][1]
Today, when best practices for backup and recovery are more important than ever before, it's good to know that high-end fully open source enterprise backup solutions exist for even the largest organizations. Perhaps the most powerful open source solution in its class is Bacula, a highly scalable software for backup, recovery, and data verification. It is a mature yet still significantly developing project used by MSPs, defense organizations, ISVs, and e-commerce companies worldwide and runs on many different Linux flavors. Bacula has a thriving community, and many Linux enthusiasts use it to provide a strong level of data protection.
With the many severe disruptions that ransomware causes today, it's critical that the client system being backed up is never aware of storage targets and has no credentials for accessing them. This is true in Bacula's case, and in addition:
* Storage and Storage Deamon hosts are dedicated systems, strictly secured, allowing only Bacula-related traffic and admin access and nothing else.
* Bacula's "Director" (core management module) is a dedicated system with the same restrictive access.
Bacula has plenty of additional configuration options to tune backups to user needs. It functions in networks and can back up both remote and local hosts. For first-time users, it can look complex, but fortunately, the Bacula Project also provides the [Baculum][2] web interface to ease administration. Many Linux users are more than happy to rely on Bacula's command-line interface to exploit its considerable range of capabilities, but sometimes it's good to have an effective GUI, too. That's where the open source Baculum comes in.
### Baculum
Baculum's installation process is reasonably simple because its repositories provide binary packages for popular Linux distributions. After installation, you have access to two wizards:
* The Baculum API - a REST API component for working with Bacula data.
* The Baculum Web component - the web interface itself.
The Baculum API is installed on hosts with Bacula components which you manage from the web interface level. Baculum Web is usually one instance that connects all Baculum API hosts and makes it possible to manage all of them. This architecture fits well with the Bacula network architecture because you can manage all Bacula hosts from one interface. It's important to know that the web interface does not store any Bacula-specific configuration from any host but manages them by sending API requests instead. When you modify the interface or run Bacula actions, they are done in real-time. When you click on the save configuration button, the modification is done simultaneously on the targeted hosts.
Below is a sample Bacula and Baculum topology.
![Baculum API][3]
One disadvantage of this approach is that you need to install one Baculum API instance on each Bacula host that you want to manage. If there are many servers to back up, it is possible to automate the installation process using an application-deployment tool like Ansible.
In my case, I have a much simpler topology with only one host managed by Baculum. My topology looks like the one below.
![Baculum web interface topology][4]
You can decide what Bacula resources to share on each Baculum API host. You can set the API hosts to do configuration work, access the Bacula catalog database, run Bacula console commands, or any combination.
After installing the web interface in the Bacula environment, you see a dashboard page like this:
![Baculum dashboard][5]
### Create a backup job
To define a new backup job, go to the job page to see some wizards for creating backup, copy, or migrate jobs using a custom job form. For this demonstration, I chose the **backup job**, which displays the first wizard step:
![New backup job wizard][6]
First, type the new job name and optional description. In the second step, decide what to backup. For this example, I chose a Bacula client and FileSet, which defines the paths to be backed up. Usually, in this window, there aren't any FileSet options to choose from yet, but you can create one with the **Add new fileset** button in the wizard. To define paths, I decided to browse the client filesystem and select paths in the drag and drop browser, as in the image below.
![Select file set][7]
Once the FileSet is ready, the next step is to select where to save the backed-up data for this job. Select a storage location and a volume pool.
![select storage and pool][8]
As with FileSets, you have an option to create a new pool. In this example, I chose an existing volume pool.
In the next step are job-specific options like choosing the job level (full, incremental, differential, etc.), job priority, and a few other settings.
![select job objectives][9]
On the next wizard page, specify when to run this backup job. Backups are usually run periodically, and here you can choose a schedule for this job. If you don't have a schedule, you can create it in this interface:
![Define a schedule][10]
The last wizard step is just a summary of all values selected in the previous steps.
![job summary][11]
Review all the values, and if they look correct, create the new job.
### Run the backup
OK, you have a new backup job. To run the initial backup, you may choose to start it manually using the **Run job** button. There is a useful capability in the **Run job** window to estimate a job before running it. Run this estimation to know in advance how many files and how many bytes will be backed up by this job.
![manually run the job][12]
After running the job, you move to a job view page where you can see backup progress from the client's perspective.
![Job page][13]
You can track job status from three places on the interface:
* The Bacula client (shown above).
* The Bacula director component side.
* The storage daemon perspective.
Here you can see the job progress on the director and storage daemon side:
![job progress][14]
![job progress][15]
The backup job completes.
### Restore data
Of course, you must be able to restore the backed-up data. Baculum provides a **Restore wizard** in the primary sidebar menu. After opening it, you see a backup client selection to which you can restore the data.
![Restore job wizard][16]
Select the client and go to the second step. Here you see all backups from that client. Your backup is at the top, so it is easy to choose. However, if you want to find a past backup, search the backups data grid. There is also an option to find a backup by filename, with or without a path.
![Select backup job][17]
Select the backup and go to file selection on the third restore wizard step. Here, in the file browser, choose directories and files to restore. The browser also has an area to select a specific file version if it exists in other backups.
![Select files to restore][18]
The next wizard step defines the destination where the restore will save the data. By default, the client from which the backup originates is selected, but you can change that to restore to a different host than the original. You can also define an absolute path on the client to restore the data. The media required to complete this restore is displayed. This is very useful for a backup tape device operator to prepare for the restore job. Personally, I use disk media, and my volumes are available for the storage daemon all the time.
![Select restore destination][19]
The next step offers the restore options, such as replacing a policy for existing files on the filesystem or file relocation fields. I keep them untouched and go to the summary step before running the restore.
![Restore job summary][20]
In the restore job—just like in the backup job—you see the running restore job's progress. After completion, there is a summary of the entire process.
![Restore job summary details][21]
That's just about it. The backup and a restore are done. The process may be a little simpler with other tools, but Bacula offers Linux enthusiasts hundreds of very useful options. This limits how much you can simplify the interface, and most users of Bacula don't want that.
### Copy jobs
Besides doing traditional backup and restore jobs, Bacula also provides a few other job types. One of them is **Copy job**, which copies backups between storage devices from one pool of volumes to another. One storage device can be a disk, and another can be a tape or tape library. Copy job reads data from file volumes and sends it to tape devices for saving on magnetic tapes. Bacula users can configure a backup D2D2T strategy (disk-to-disk-to-tape). Source and destination storage can be of different types (disk and tape), but it works just as well when copying backup jobs between the same device types.
Baculum has full support for copy jobs, including configuring copy jobs and ending with restoring data directly from copy jobs. Configure a copy job using the copy job wizard visible in the image below.
![Copy job wizard][22]
After typing the new copy job name, choose the source storage and source volume pool. This is the storage that reads data when the copy job runs.
![Copy job source][23]
The third wizard step specifies how to copy jobs. In other words, you can define the selection criteria used for choosing the backups that will be copied. You can select backups by patterns like:
* Job name
* Client
* Volume
* Smallest volume in the pool
* Oldest volume in the pool
* SQL query
* Copy all uncopied jobs so far from the pool
In this example, I chose a selection by job name.
![Copy job selection][24]
Select the destination storage and pool in the next step. This storage writes backups to the destination pool when you run the copy job.
![Copy job destination][25]
In the penultimate step are a couple of options, such as the maximum number of spawned jobs. You can also set a schedule to run the copy job periodically.
![Copy job options][26]
After saving the wizard, run the copy job in the same place where you started the backup job. You can see the live updated job log output.
![Copy job history][27]
### Wrap up
Done! You have performed a backup job, restored a job, and created a copy job.
There are two Baculum functions that I think many folks will find useful.
First, its simple interface enables the user to administer Bacula from any mobile device. This can be crucial for cases when you are outside the office and somebody from the organization sends a text message like: "Hey! I accidentally deleted an important report file and need it urgently. Are you able to restore it to my computer?" You could do this restore using a mobile phone and the same wizard steps described above.
The second important function is its multi-user interface with several authentication methods (local user, basic authentication, LDAP, etc.). It enables company employees to use Baculum to backup and restore their own resources without requiring access to any other utilities. You can customize the role-based access control interface for each group of users.
Of course, these options are just the tip of the iceberg regarding Bacula's capabilities with Baculum. Baculum really is about being configurable. I hope you can enjoy its benefits and the empowerment it brings you to make your data safer and your life easier!
(Image by: Rob Morrison, CC BY-SA 4.0)
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/5/baculum-open-source-backup
作者:[Rob Morrison][a]
选题:[lkxed][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/robmorrison
[b]: https://github.com/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/browser_blue_text_editor_web.png
[2]: https://baculum.app/
[3]: https://opensource.com/sites/default/files/2022-04/1baculumAPI.png
[4]: https://opensource.com/sites/default/files/2022-04/2baculumwebinterface.png
[5]: https://opensource.com/sites/default/files/2022-04/3dashboard.png
[6]: https://opensource.com/sites/default/files/2022-04/4newBUwizard.png
[7]: https://opensource.com/sites/default/files/2022-04/5FileSet.png
[8]: https://opensource.com/sites/default/files/2022-04/6storage-and-pool.png
[9]: https://opensource.com/sites/default/files/2022-04/7job-directives.png
[10]: https://opensource.com/sites/default/files/2022-04/8schedule.png
[11]: https://opensource.com/sites/default/files/2022-04/9summary.png
[12]: https://opensource.com/sites/default/files/2022-04/10runjob.png
[13]: https://opensource.com/sites/default/files/2022-04/11jobhistory.png
[14]: https://opensource.com/sites/default/files/2022-04/12job-from-daemon.png
[15]: https://opensource.com/sites/default/files/2022-04/13jobstoragedaemon.png
[16]: https://opensource.com/sites/default/files/2022-04/14restorewizard.png
[17]: https://opensource.com/sites/default/files/2022-04/15selectjobtorestore.png
[18]: https://opensource.com/sites/default/files/2022-04/16selectfilestorestore.png
[19]: https://opensource.com/sites/default/files/2022-04/17selectstoragedestination.png
[20]: https://opensource.com/sites/default/files/2022-04/18restoresummary.png
[21]: https://opensource.com/sites/default/files/2022-04/19restorehistory.png
[22]: https://opensource.com/sites/default/files/2022-04/20copyjobwizard.png
[23]: https://opensource.com/sites/default/files/2022-04/21copysource.png
[24]: https://opensource.com/sites/default/files/2022-04/22copy-files.png
[25]: https://opensource.com/sites/default/files/2022-04/23copydestination.png
[26]: https://opensource.com/sites/default/files/2022-04/24copyoptions.png
[27]: https://opensource.com/sites/default/files/2022-04/25copyhistory.png

View File

@ -0,0 +1,282 @@
[#]: subject: "PHP MySQL WHERE Clause"
[#]: via: "https://ostechnix.com/php-mysql-where-clause/"
[#]: author: "Sravan Kumar https://ostechnix.com/author/sravankumar/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
PHP MySQL WHERE Clause
======
How To Select And Filter Data From A MySQL Database Using PHP In XAMPP
In this guide, we will discuss how to select the records from a MySQL database based on specific conditions with the WHERE clause and the SELECT command using PHP in XAMPP stack.
### Prerequisites
Make sure you've created a database and table in XAMPP stack as described in the following guide.
* Create MySQL Database And Table Using PHP In XAMPP
For demonstration purpose, I've created a table named **"sales"** in a MySQL database called **"my_company"** with the below schema and records.
![Database Schema And Records][1]
### Filtering Data From MySQL Table With WHERE Clause Using PHP
The WHERE clause is used to extract only the records that matches a specific condition. The WHERE clause will check the condition by taking an operator followed by a value.
**WHERE Clause Syntax:**
```
SELECT column1,column2,.,column n from table_name WHERE column_name operator value;
```
Where,
* column_name - the column on which condition is applied.
* operator - It is used to check the condition.
* value - It is the string/numeric value compared with each and every column values present in the table.
```
column_name
```
```
operator
```
```
value
```
### Steps
**1.** Specify the servername (E.g. localhost), database username (E.g. `root` ), root user password and the database name (E.g. my_company). Here, my `root` user's password is empty.
**2.** Establish a connection using the `mysqli_connect()` function. It will take servername, username and password as parameters.
**Code:**
```
$connection = mysqli_connect($server_name, $user_name, $password, $database_name);
```
**3.** Specify the SQL Query to select a particular column or all columns' records from the table by a condition. In this step, we can specify the SQL query to select columns from the table into a variable.
For example, I am going to use the database name called **my_company** and I am storing it in a variable named **query**. The table name is **sales** that has three columns.
**Code:**
```
$query = "SELECT column1,…. from sales where column_name operator value";
```
**4.** Store the selected results into a variable called **"final"** using the `mysqli_query()` function. It will take "connection" and "query" as parameters.
**Code:**
```
mysqli_query($connection, $query);
```
**5.** Get the rows one by one from the "final" variable using the `mysqli_num_rows()` function. After that fetch the results by iterating through a **while** loop using `mysqli_fetch_assoc()` function. It will take the "`final` " variable as a parameter.
**Code:**
```
if (mysqli_num_rows($final) > 0) {
//get the output of each row
while($i = mysqli_fetch_assoc($final)) {
echo $i["column1”],…………..;
}
} else {
echo "No results";
}
```
**6.** Finally, close the connection by using the `mysqli_close()` function.
**Code:**
```
mysqli_close($connection);
```
Now, let us write a sample PHP code based on the above steps.
### PHP code To Select Data From MySQL Database Using WHERE Clause
**Example Code 1:**
In this example, we will select all columns from the "sales" table where the **id value is greater than 4** and display the result in a PHP page.
So our operator will be greater than (**">"**) and the value is **4** by specifying the **column_name** as **id**.
Create a new file named `select.php` under the `/htdocs` folder with the following contents in it.
**Heads Up:** If you use Linux, the **htdocs** folder will be under **/opt/lampp/** directory. If you're on Windows, the **htdocs** will be usually in **C:\xampp**\ folder.
```
<?php
//specify the server name and here it is localhost
$server_name = "localhost";
//specify the username - here it is root
$user_name = "root";
//specify the password - it is empty
$password = "";
//specify the database name - "my_company"
$database_name = "my_company";
// Creating the connection by specifying the connection details
$connection = mysqli_connect($server_name, $user_name, $password, $database_name);
//sql query to select particular columns
//select all columns such that id is greater than 4
$query = "SELECT * from sales where id>4";
#get the result
$final = mysqli_query($connection, $query);
if (mysqli_num_rows($final) > 0) {
//get the output of each row
while($i = mysqli_fetch_assoc($final)) {
//get all columns
echo "id: " . $i["id"]. " ----> name: " . $i["name"]." ----> count: " . $i["count"]. "<br>";
}
} else {
echo "No results";
}
//close the connection
mysqli_close($connection);
?>
```
Open your web browser and point it to **http://localhost/select.php** URL. You can see that data is selected where **id is greater than 4** and the result is displayed in the browser window.
![Select Data From MySQL Database Using WHERE Clause][2]
**Example Code 2:**
In this example, we will select all columns from the "sales" table with the name as "Eggs" and display the result in the PHP page.
So our operator will be equal to (**"="**) and the value is "Eggs" by specifying the `column_name` as **name**.
```
<?php
//specify the server name and here it is localhost
$server_name = "localhost";
//specify the username - here it is root
$user_name = "root";
//specify the password - it is empty
$password = "";
//specify the database name
$database_name = "my_company";
// Creating the connection by specifying the connection details
$connection = mysqli_connect($server_name, $user_name, $password, $database_name);
//sql query to select particular columns
//select all columns such that name equals to Eggs
$query = "SELECT * from sales where name ='Eggs'";
#get the result
$final = mysqli_query($connection, $query);
if (mysqli_num_rows($final) > 0) {
//get the output of each row
while($i = mysqli_fetch_assoc($final)) {
//get all columns
echo "id: " . $i["id"]. " ----> name: " . $i["name"]." ----> count: " . $i["count"]. "<br>";
}
} else {
echo "No results";
}
//close the connection
mysqli_close($connection);
?>
```
Open your web browser and point it to **http://localhost/select.php** URL. You can see that data is selected where name ='Eggs' and displayed.
![Select Columns That Contains The Name Eggs][3]
**Example Code 3:**
In this example, we will select all columns from the "sales" table with **count as 45** and display the result in the PHP page.
So our operator will be equal to (**"="**) and the value is 45 by specifying the column_name as **count**.
```
<?php
//specify the server name and here it is localhost
$server_name = "localhost";
//specify the username - here it is root
$user_name = "root";
//specify the password - it is empty
$password = "";
//specify the database name
$database_name = "my_company";
// Creating the connection by specifying the connection details
$connection = mysqli_connect($server_name, $user_name, $password, $database_name);
//sql query to select particular columns
//select all columns such that count is 45
$query = "SELECT * from sales where count =45";
#get the result
$final = mysqli_query($connection, $query);
if (mysqli_num_rows($final) > 0) {
//get the output of each row
while($i = mysqli_fetch_assoc($final)) {
//get all columns
echo "id: " . $i["id"]. " ----> name: " . $i["name"]." ----> count: " . $i["count"]. "<br>";
}
} else {
echo "No results";
}
//close the connection
mysqli_close($connection);
?>
```
Open your web browser and point it to **http://localhost/select.php** URL. You can see that data is selected where **count = 45** and the resulting column is displayed.
![Select Columns That Contains The Count 45][4]
### Conclusion
In this tutorial, we've discussed three different ways to select data from a MySQL database based on particular conditions using PHP with WHERE clause. The first example showed you how to filter the data by using the numeric value "id". The second and third examples explained how to select data by using the string value "name" and the numeric value "count" respectively.
--------------------------------------------------------------------------------
via: https://ostechnix.com/php-mysql-where-clause/
作者:[Sravan Kumar][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://ostechnix.com/author/sravankumar/
[b]: https://github.com/lkxed
[1]: https://ostechnix.com/wp-content/uploads/2022/05/Database-Schema-And-Records.png
[2]: https://ostechnix.com/wp-content/uploads/2022/05/Select-Data-From-MySQL-Database-Using-WHERE-Clause.png
[3]: https://ostechnix.com/wp-content/uploads/2022/05/Select-Columns-That-Contains-The-Name-Eggs.png
[4]: https://ostechnix.com/wp-content/uploads/2022/05/Select-Columns-That-Contains-The-Count-45.png

View File

@ -2,7 +2,7 @@
[#]: via: "https://www.opensourceforu.com/2022/05/package-analysis-examines-packages-in-open-source-repositories-in-real-time/"
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "

View File

@ -0,0 +1,89 @@
[#]: subject: "How I manage my own virtual network with ZeroTier"
[#]: via: "https://opensource.com/article/22/5/zerotier-network"
[#]: author: "Kevin Sonney https://opensource.com/users/ksonney"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How I manage my own virtual network with ZeroTier
======
ZeroTier is an encrypted virtual network backbone, allowing multiple machines to communicate as if they were on a single network.
![Person drinking a hat drink at the computer][1]
(Image by: [Jonas Leupe][2] on [Unsplash][3])
*Automation is a hot topic right now. In my day job as a site reliability engineer (SRE), part of my remit is to automate as many repeating tasks as possible. But how many of us do that in our daily, not-work, lives? This year, I am focused on automating away the toil so that we can focus on the things that are important.*
While automating everything, I ran into some difficulty with remote sites. I'm not a networking person so I started to look at my options. After researching the various virtual private networks (VPN), hardware endpoints, firewall rules, and everything that goes into supporting multiple remote sites, I was confused, grumpy, and frustrated with the complexity of it all.
Then I found [ZeroTier][4]. ZeroTier is an encrypted virtual network backbone, allowing multiple machines to communicate as if they were on a single network. The code is all open source, and you can self-host the controller or use the [ZeroTierOne][5] service with either free or paid plans. I'm using their free plan right now, and it is robust, solid, and very consistent.
Because I'm using the web service, I'm not going to go into detail about running the controller and root services. ZeroTier has a complete reference on how to do that in their [documentation][6], and it's very good.
After creating my own virtual network in the web user interface, the client installation is almost trivial. ZeroTier has packages for APT, RPM, FreeBSD, and many other platforms, so getting the first node online takes little effort.
Once installed, the client connects to the controller service and generates a unique ID for the node. On Linux, you use the `zerotier-cli` command to join a network, using the `zerotier-cli join NETWORKID` command.
```
$ sudo zerotier-cli info
200 info 469584783a 1.x.x ONLINE
```
You can also use `zerotier-cli` to get a listing of connected and available nodes, change network settings, and leave networks.
![Image of Setting up a New Node][7]
(Image by: Kevin Sonney, CC BY-SA 4.0)
After joining a network, you do have to approve access for the node, either through the web console or by making a call to the application programming interface (API). Both methods are documented on the ZeroTier site. After you have two nodes connected, connecting to each other — no matter where you are or what side of any firewalls you may be on — is exactly what you would expect if you were in the same building on the same network. One of my primary use cases is for [remote access to my Home Assistant setup][8] without needing to open up firewall ports or expose it to the internet (more on my Home Assistant setup and related services later).
One thing I did set up myself is a [Beta ZeroNDS Service][9] for internal DNS. This saved me a lot of complexity for managing my own name service or having to create public records for all my private hosts and IP addresses. I found the instructions to be very straight forward, and was able to have a DNS server for my private network up in about 5 minutes. Each client has to allow Zerotier to set the DNS, which is very simple in the GUI clients. To enable it for use on Linux clients, use:
```
$ sudo zerotier-cli setNETWORKID allowDNS=1
```
No other updates are needed as you add and remove hosts, and it "just works."
```
$ sudo zerotier-cli info
200 info 469584845a 1.x.y ONLINE
$ sudo zerotier-cli join
93afae596398153a 200 join OK
$ sudo zerotier-cli peers
200 peers
<ztaddr> <ver> <role> <lat> <link> <TX> <RX> <path>
61d294b9cb - PLANET 112 DIRECT 7946 2812 50.7.73.34/9993
62f865ae71 - PLANET 264 DIRECT 7946 2681 50.7.76.38/9993
778cde7190 - PLANET 61 DIRECT 2944 2901 103.195.13.66/9993
93afae5963 1.x LEAF 77 DIRECT 2945 2886 35.188.31.177/41848
992fcf1db7 - PLANET RECT 79124 DI47 2813 195. 181.173.159/9993
```
I've barely scratched the surface of the features here. ZeroTier also allows for bridging between ZeroTier networks, advanced routing rules, and a whole lot more. They even have a [Terraform provider][10] and a listing of [Awesome Zerotier Things][11]. As of today, I'm using ZeroTier to connect machines across four physical sites, three of which are behind NAT firewalls. Zerotier is simple to set up, and almost completely painless to manage.
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/5/zerotier-network
作者:[Kevin Sonney][a]
选题:[lkxed][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/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/coffee_tea_laptop_computer_work_desk.png
[2]: https://unsplash.com/@jonasleupe?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[3]: https://unsplash.com/s/photos/tea-cup-computer?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[4]: https://github.com/zerotier
[5]: https://www.zerotier.com/pricing
[6]: https://docs.zerotier.com
[7]: https://opensource.com/sites/default/files/2022-04/SecondDay02-2.png
[8]: https://opensource.com/article/22/5/remote-home-assistant
[9]: https://github.com/zerotier/zeronsd
[10]: https://github.com/zerotier/terraform-provider-zerotier
[11]: https://github.com/zerotier/awesome-zerotier

View File

@ -0,0 +1,107 @@
[#]: subject: "How I use open source to design my own card games"
[#]: via: "https://opensource.com/article/21/12/open-source-card-game"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "hadisi1993"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
我如何利用开源设计自己的卡牌游戏
======
开源并不仅仅关于软件。开源是一种文化现象,天然适用于桌上游戏。
![Deck of playing cards][1]
我喜欢优秀的游戏,尤其是桌游,因为桌游的很多特性都和开源相同。在现实生活中,当你和朋友坐在桌子旁一起玩卡牌游戏时,作为一个团队,你们可以一起决定小丑牌是不是万能的。还有,你们可以随意地决定当出了小丑牌后,手上有 Ace 牌的人的要不要舍弃 Ace 牌,或者出了方块皇后以后,每个人是不是都要把手上的牌传给右手边的人。换句话说,一心血来潮你们就可以重新制定规则,因为游戏不过是参与者们一致认同的条件集合罢了。对我来说,更棒的是你可以发明自己的游戏而不用破坏别人的游戏规则。有时候,我会作为一个业余爱好者来开发桌游。因为我喜欢结合自己的爱好,所以我倾向于只使用开源和公共的文化资源来设计游戏。
首先,游戏有大致有两个关键特征,风格和机制,理解这一点非常重要。游戏风格指的是游戏的故事或者主题,游戏机制指的是游戏的规则和条件。这两者并不总是完全脱离的,举个例子,在设计一款以赛车为主题的游戏时,要求玩家迅速进行操作是非常巧妙的。然而,风格和机制通常是被分开对待的,所以我们完全可以为了好玩就去创造一款使用标准扑克牌,却以太空羊驼为主题的游戏。
### 开源美术
如果你去过现代艺术博物馆,你可能会发现自己站在一幅纯蓝色的画布前,无意中听到有人说起老话:“见鬼,这我也能做!”。但事实是,艺术是一项艰巨的工作。让艺术赏心悦目需要付出大量的思考,时间,自信和技巧。这也意味着艺术是你在设计游戏时中最困难的部分之一。
我有一些“技巧”来解决这个典型的麻烦。
#### 1\. 寻找共同点
现在有很多免费开放的艺术作品而且大部分质量上佳。问题在于游戏通常需要不止一件作品。如果你正在设计一款纸牌游戏你大概至少需要4或6个不同的元素(假设你的纸牌遵循塔罗牌),有可能还需要更多。如果你花足够多的时间在这上面,你可以在 [OpenGameArt.org][3] , [FreeSVG.org][4] , [ArtStation.com][5] , [DeviantArt.com][6]等网站上找到知识共享和公共领域([Creative Commons and Public Domain][2])的艺术作品。
如果你使用的网站没有知识共享(Creative Commons)搜索,输入以下文字到任何搜索引擎当中,“本工作处于知识共享许可协议之下”(引号很重要,所以不要把它们漏了),以及你常用的搜索引擎要求语法,以便将搜索限制到一个具体的站点当中(举个例子,**站点deviantart.com**)。
一旦你有了一个美术库可供挑选素材,那就去辨别这些作品的主题,并根据主题分类。两个不同的人拍摄的机器人的照片可能看起来一点都不像,但它们的主题都是机器人。如果提供给你足够多机器人相关的美术素材,你可以围绕机器人这个主题构建你的游戏风格。
#### 2\. 委托他人定制共享艺术
你可以雇艺术家来为你定制艺术作品。我与使用开源绘画程序(如[Krita][7]和Mypaint)的艺术家一起合作。同时,我指定定制的艺术作品必须在知识共享署名份额许可证(Creative Commons Attribution - share - like,CC BY-SA)下授权,以作为合同的一部分。迄今为止,只有一位艺术家因为许可证的限制拒绝了我的提议,并且大多数人都很高兴自己的美术作品能够拥有更广阔的图景,而不仅仅是作为业余爱好者自己发行的游戏的一部分。
#### 3\. 创作自己的艺术
就像现代艺术馆之旅展示的那样艺术是一个非常灵活的词。我发现只要我给自己设定一个目标也就是我需要为一款游戏创造多少纸牌或令牌我便能够从Linux上的丰富图像创造工具中选择一种去创作。这并不需要什么高难度的东西。就像现代艺术一样,你可以用蓝色和黄色的条纹,或者红色和白色的圆点花纹,或者绿色和紫色的锯齿线来涂一张卡片,只要你能把它们画出来,那么除了你以外,其他人永远不会知道你秘密地把它们当做仙宫里的贵族和小姐。想想通过运用图形应用程序,描摹日常物品的照片,重组经典的扑克花色和塔罗牌主题等一系列方式,你可以创造出的简单作品吧。
### 布局
我用 [Inkscape][8] Scribus或者 [GIMP][9] 来布局,这取决与我有什么素材以及我追求的设计方式是什么。
对于卡片,我发现简单的布局很容易实现,看上去也更轻松,纯色比渐变设打印的效果更好,还有,直观的图像是最棒的。
![layout in Inkscape][10]
(Seth Kenlon, CC BY-SA 4.0)
我在一个单独的Inkscape文件中为我最新的游戏做了布局这个游戏只使用了来自OpenGameArt.com上三四个不同艺术家的九张图片。在有着更大的美工集更好的卡牌多样性的游戏中我会为游戏中的每一种卡片在它们自己的文件中设计布局。
在为你的游戏素材做任何布局之前,要先了解你的目标输出是什么。如果你打算在家里打印游戏,那就做一些计算,搞清楚默认的纸张大小(有些是US Letter,或者是A4)可以容纳多少卡片、令牌或卡牌。如果你使用 [TheGameCrafter][11] 之类的桌游打印机打印,请下载好模板文件。
![printed cards][12]
(Seth Kenlon, CC BY-SA 4.0)
### 机制
游戏机制是游戏中最重要的部分。它们使一款游戏成为游戏。开发游戏规则并不一定是一个正式的过程。你可以一时兴起地创造了一款游戏,可以拿一块现有的游戏重组它的规则,直到它和原来不同,可以修改一款你不喜欢的游戏,也可以将两款不同的游戏组合在一起。从简单容易的地方做起,拿索引卡,标准扑克牌,或塔罗牌去试着模拟你的想象中游戏是如何工作的。你可以自己尝试早期的游戏想法,但最终,让朋友来帮忙是找出意外故障和进行优化的好方法。
经常测试游戏。与不同类型的玩家一起玩游戏,并听取他们的反馈。你的游戏可能会激发许多玩家去创造新的规则和想法,因此要将关于 _哪些内容搞砸了_ 的反馈与关于 _哪些内容可以做修改_ 的反馈分开。你不一定要去真的实践这些反馈意见,只需迭代你的想法,但还是要仔细考虑错误报告。
一旦确定了你想要让你的规则如何运作,就把它们写下来,使它们简短且容易分析( [short and easy to parse][13] )。你定的规则不必说服玩家去玩这款游戏,不必向他们解释策略,你也不必允许玩家重新设置规则,只要告诉玩家为了让游戏玩起来,他们应该采取的步骤就可以了。
最重要的是,考虑一下,将您的规则开源。分享经验是游戏的一切,这其中也应该包括规则。知识共享(Creative Commons)或打开游戏许可证(Open Gaming License)的规则集合允许其他玩家在你的作品上进行迭代、混合和创建。你永远不会知道,有人可能会因此想出一个变种游戏,让你喜欢它更胜过原来的版本!
### 开源游戏
开源不仅仅关于软件。开源是一种文化现象,天然适用于桌游。花几个晚上的时间实验制作游戏。如果你刚刚入门,那就从一些简单的开始,比如下面的这个空白卡牌游戏:
1. 找来一些朋友。
2. 给每个人几张空白的索引卡,告诉他们在每张卡片上写一条规则。规则可以是任何的(“如果你穿着红色衣服,你就赢了”或“第一个站起来的人赢”等等)。
3. 在你自己的索引卡片上,写上 _和_ _但是__但是不要_ _而且不要_ _除了_ ,以及其他的条件短语。
4. 洗牌并将牌发给所有玩家。
5. 每个玩家轮到的时候出一张牌。
6. 最终目标是赢,但是玩家可以通过出 _和_, _但是_, _或者_ 卡片来修改决定赢家的条件。
这是一个有趣的聚会游戏,同时是一份很好的介绍,告诉你如何像游戏设计者一样思考,它帮助你认识到什么适合作为游戏机制,什么不适合。
还有,当然的,这是开源的。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/12/open-source-card-game
作者:[Seth Kenlon][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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rich-smith-unsplash.jpg?itok=uzzS0gRa (Deck of playing cards)
[2]: https://opensource.com/article/20/1/what-creative-commons
[3]: https://opensource.com/article/21/12/opengameart.org/
[4]: http://freesvg.org
[5]: http://artstation.com
[6]: http://deviantart.com
[7]: https://opensource.com/article/21/12/krita-digital-paint
[8]: https://opensource.com/article/21/12/linux-draw-inkscape
[9]: https://opensource.com/content/cheat-sheet-gimp
[10]: https://opensource.com/sites/default/files/inkscape-layout.jpg (Layout in Inkscape)
[11]: https://www.thegamecrafter.com/
[12]: https://opensource.com/sites/default/files/cards-printed_0.jpg (Printed cards)
[13]: https://opensource.com/life/16/11/software-documentation-tabletop-gaming

View File

@ -1,104 +0,0 @@
[#]: subject: "Documentation Isnt Just Another Aspect of Open Source Development"
[#]: via: "https://www.opensourceforu.com/2022/04/documentation-isnt-just-another-aspect-of-open-source-development/"
[#]: author: "Harsh Bardhan Mishra https://www.opensourceforu.com/author/harsh-bardhan-mishra/"
[#]: collector: "lkxed"
[#]: translator: "lkxed"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
文档并不是开源项目开发的附属品
======
有些项目长期保持活跃,有些项目却过早消亡 —— 这两者的区别往往在于它们的文档。严谨、聪明的文档可以给你的项目带来它所需要的动力。你应该把文档工作视为一项主要工作,把它与开发相提并论,下面我将说明这么做的理由和正确的做法。
![文档的重要性][1]
经常会有开发者简单地认为他们的代码已经足够“<ruby>自我记录<rt>self-documented</rt></ruby>”了,继而认为额外的文档是没有必要的。这种过度的自信会让项目付出很大的代价。不足或不好的文档会扼杀你的项目。没有适当的文档,用户将无法理解项目的目标以及正确的工作流程。这可能会导致人们对采用你的开源产品产生一些疑虑。
### 撰写文档,从项目第一天就开始
文档不应该是次要的工作,它应该是与代码开发和管理同等的主要任务。在 Community Threads、stack overflow 和 Quora 问答等社区中,文档内容广泛传播,其本身承担了“<ruby>信息源<rt>source of truth</rt></ruby>”的角色。 它应该满足那些想参考一手资料的贡献者的需要,并给工程师提供必要的参考支持。它还应该与股东沟通基本计划。一个好的文档可以确保产品的持续改进和发展。
当发布一个软件产品时,我们不仅要发布代码,还要发布好的文档。这给我们带来了一个最重要的概念,大多数维护着良好文档的开源项目都遵循这个概念 —— “文档即代码”。
### 文档及代码
今天,文档不再被存储为 Microsoft Word 或 PDF 文件。新的需求是版本控制文档,其中所有的文档都是通过版本控制系统添加的,并持续发布。这个概念因 Read the DocsLCTT 译注:一个文档创建、托管和浏览的平台)而流行,现在已经成为大多数文档团队的内容策略的重要组成部分。
像 Bugzilla 和 GitHub Issues 这样的工具可以用来跟踪待处理的文档工作,并从维护者和用户那里获得反馈以验证文档的发布。外部审查可以用来验证文档作品,并持续发布文档。这就保证了除代码外,文档也能不断改进并快速发布。
请记住,如果不遵循任何规范化的实践,每个文档都会不同。这可能会导致一些混乱,使人们难以获取正确的信息。
哪些东西会被归类为混乱呢?当大多数文件都不遵循规范实践时,不一致就会产生,从而导致一个大混乱!那么,如何整理混乱的开源文档呢?
### 整理混乱的开源文档
遵循一个“文档风格指南”是很重要的。风格指南是创建和展示内容的指导方针的集合。无论你是一个独立的作家还是一个大型文档团队的成员,它都有助于在你的文档中保持一致的风格、声音和语气。
有几个流行的风格指南,如红帽风格指南,谷歌文档风格指南,和苹果风格指南。如何选用?首先要从定义你的需求开始。如果你的要求与其他开源项目没有太大区别,你可以遵循一个现成的风格指南,或者你也可以先选一个,然后在它的基础上根据自身需要做一些修改。大多数与语法有关的准则和内容规则可能是通用的,但整体术语可能会有所不同。
你还需要在你的项目中自动采用这些风格指南。为此,你可以使用 Vale它集成了本地的持续集成CI服务该服务能帮助你确保文档严格遵循风格指南。
### 文档类型
* 自述文件:包含基本的安装和使用说明,这也是任何开源文档中最重要的部分之一。它是潜在的用户/开发者与项目之间的第一个连接点。
* 参考指南:可能包括一些基本的参考资料,以便帮助你快速上手,或者是与项目贡献相关的文档。
* 用户文档:是最基本的文档,它描述了项目的使用方式。如果没有任何用户文档,大多数人就会对如何使用该项目感到迷茫。
* 开发文档:旨在支持开发团队在项目中不断取得新的进展。它还应该为内部开发工作提供一个良好的途径,并确保功能被很好地传达给股东。
* 社区内容:包括基本的博客、视频和外部内容,旨在为那些想进一步了解项目的社区成员提供支持。
通过使用风格指南,文件的整体前提将以统一的语言风格传达给用户。但是,这些文件是毕竟由一个技术作家团队准备的,它们的写作风格可能会冲突,因为写作风格是因人而异的。那么,如何才能使文档规范化呢?
### 规范化文档
当涉及到规范化文档时,有许多方法可以采取。第一个方法显然是创建适用于各种角色的预定义模板。这些模板可以用来记录新的功能、识别错误和问题,以及更新变更日志以适应正在增加的新内容。
如果你采用的是基于 Git 的工作流,试着开发一个规范的工作流程来发布你的文档。最规范的工作流是:<ruby>复刻<rt>fork</rt></ruby>发布文档的仓库,在本地分支上添加你的修改,推送这些修改,提出请求并要求对其进行审查。规范化文档的一个好处就是带来更好的反馈和审查过程。
### 反馈和自动审查
规范化使得你能够得到用户的反馈并生成自动的审查,这些反馈可以被考虑用来改进项目和文档。通过这些反馈,你也可以评估所分享的信息对用户是否有意义。像 GitBook 这样的文档平台会提供合适的反馈服务,这有助于验证文档是否有用。
始终寻求主题专家SME对文档的反馈他们可以是股东、开发者、工程师甚至是外部贡献者。你也可以使用自动测试和CI来验证你的文档是否遵循风格指南。
### 文档众包
如果你想开源你的文档最好的方法也许是提供一个快速入门指南。它可以像“CONTRIBUTING.md”那样简单基本上只要说明该如何设置项目并为其作出贡献/单纯使用它即可。
始终开发以用户为中心的文档,它介绍了项目的目标。同时,打造学习课程来帮助新的贡献者。
### 带着目的编写文档
始终带着目的编写文档。它是最基本的写作策略之一,它定义了你编写某个特定文档的理由,而非方式。首先回答以下问题:
* 这个文档的目标是什么?
* 需要传递的信息是什么?
* 你希望用户在这之后采取什么行动?
* 我与读者分享的价值观是什么?
* 我的文档风格是否简洁、一致?
### 定义一致的内容策略
一致的内容策略有助于确保文档工作和项目基础设施的长期愿景。它可以围绕以下两个主要方面:
1. 资源:包括项目文档、案例研究和白皮书、项目架构等
2. 品牌内容:博客和特邀帖子、新闻和社区故事、学习课程等
每个开源项目都应该有适当的文档,以说明它能为用户提供的功能,这样用户就可以选择最合适的解决方案。适当的文档可以传达正确的信息,也可以让其他开发者贡献力量来进一步加强和改进项目。虽然听起来很简单,但只有做对了,文档才能成功。而你的项目,反过来,只有在你的文档是正确的情况下才能成功,所以永远不要低估它的目标或过程!
策划Laveesh Kocher
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/04/documentation-isnt-just-another-aspect-of-open-source-development/
作者:[Harsh Bardhan Mishra][a]
选题:[lkxed][b]
译者:[lkxed](https://github.com/lkxed)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/harsh-bardhan-mishra/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/03/Importance-of-documentation-696x477.jpg

View File

@ -0,0 +1,329 @@
[#]: subject: "Learn Rust in 2022"
[#]: via: "https://opensource.com/article/22/1/rust-cheat-sheet"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "hanszhao80"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
在 2022 年学习 Rust
======
如果你打算在今年探索 Rust请下载我们的免费 Rust 速查表,以供快速参考基础知识。
![Cheat Sheet cover image][1]
Rust 是一门相对较新的编程语言,受到各个企业的 [程序员的欢迎][2]。尽管如此它仍是一门建立在之前所有事物之上的语言。毕竟Rust 不是一天做出来的,所以即便 Rust 中的一些概念看起来与你从 Python、Java、C++ 等编程语言学到的东西大不相同,但它们都是在同一个 CPU 和你一直交互使用(无论你是否知道)的 <ruby>非一致性内存访问<rt>NUMA</rt></ruby> 架构上打下的基础,因此 Rust 中的一些新功能让人感觉有些熟悉。
现在我的职业不是程序员。我没耐心但我又有点儿强迫症。当我需要完成某件事时如果一门语言不能帮助相对较快地获得我想要的结果那么我很少会受到鼓舞而使用它。Rust 试图平衡两个矛盾:现代计算机对安全和结构化代码的需求和现代程序员对编码工作事半功倍的渴望。
### 安装 Rust
[rust-lang.org][3] 网站有丰富的的文档指导如何安装 Rust但通常它就像下载 `sh.rustup.rs` 脚本并运行它一样简单。
```
$ curl --proto '=https' --tlsv1.2 -sSf <https://sh.rustup.rs>
$ less sh.rustup.sh
$ sh ./sh.rustup.rs
```
### 没有类
Rust 没有类,也不使用 `class` 关键字。Rust 确实有 `struct` 数据类型,但它的作用是充当数据集合的一种模板。因此,你可以使用<ruby>结构体<rt>struct</rt></ruby>,而不是创建一个类来表示虚拟对象:
```
struct Penguin {
    genus: String,
    species: String,
    extinct: bool,
    classified: u64,
}
```
你可以像使用类一样使用它。例如,当定义完 `Penguin` 结构,你就可以创建它的实例,并与该实例进行交互:
```
struct Penguin {
    genus: String,
    species: String,
    extinct: bool,
    classified: u64,
}
fn main() {
    let p = Penguin { genus: "Pygoscelis".to_owned(),
         species: "R adeliæ".to_owned(), 
         extinct: false, 
         classified: 1841 };
    println!("Species: {}", p.species);    
    println!("Genus: {}", p.genus);
    println!("Classified in {}", p.classified);
    if p.extinct == true {
        println!("Sadly this penguin has been made extinct.");
    }
    
}
```
`impl` 数据类型与 `struct` 数据类型结合使用,你可以实现一个包含函数的结构体,并且可以添加继承和其他与类相似的特性。
### 函数
Rust 中的函数很像其他语言中的函数。每个函数都代表一组严谨的任务,你可以在需要时调用它们。主函数名必须是 `main`
`fn` 关键字声明函数,后跟函数名称和函数接受的所有参数。
```
fn foo() {
  let n = 8;
  println!("Eight is written as {}", n);
}
```
通过参数,将信息从一个函数传递到另一个函数。例如,我已经创建了一个 `Penguin` 类,并且我有一个 `Penguin` 的实例为 `p`,将目标函数的参数指定为 `Penguin`类型,就可把 `p` 的属性从一个函数传递到另一个函数。
```
fn main() {
  let p = Penguin { genus: "Pygoscelis".to_owned(), 
    species: "R adeliæ".to_owned(), 
    extinct: false, classified: 1841 };
  printer(p);
}
fn printer(p: Penguin) {
  println!("Species: {}", p.species);    
  println!("Genus: {}", p.genus);
  println!("Classified in {}", p.classified);
  if p.extinct == true {
      println!("Sadly this penguin has been made extinct.");
  }
}
```
### 变量
Rust 默认创建的为<ruby>不可变<rt>immutable</rt></ruby>变量。这意味着你创建的变量以后无法更改。这段代码虽然看起来没问题,但无法编译:
```
fn main() {
 let n = 6;
 let n = 5;
 }
```
但你可以使用关键字 `mut` 声明一个<ruby>可变<rt>mutable</rt></ruby>变量,因此下面这段代码可以编译成功:
```
fn main() {
 let mut n = 6;
 println!("Value is {}", n);
 n = 5;
 println!("Value is {}", n);
}
```
### 编译
Rust 编译器,至少就其报错信息而言,是可用的最好的编译器之一。当你在 Rust 中出错时,编译器会真诚地告诉你做错了什么。实际上,仅通过从编译器错误消息中学习,我就了解了 Rust 的许多细微差别(就我理解到的 Rust 的任何细微差别而言)。即便有时错误消息太过于模糊,而不知所以然,互联网搜索几乎总能得到解释。
启动 Rust 程序的最简单方法是使用 `cargo`,即 Rust 包管理和构建系统。
```
$ mkdir myproject
$ cd myproject
$ cargo init 
```
以上命令为项目创建了基本的基础架构,最值得注意的是 `src` 子目录中的 `main.rs` 文件。打开此文件,把我为本文生成的示例代码粘贴进去:
```
struct Penguin {
    genus: String,
    species: String,
    extinct: bool,
    classified: u64,
}
fn main() {
    let p = Penguin { genus: "Pygoscelis".to_owned(), species: "R adeliæ".to_owned(), extinct: false, classified: 1841 };
    printer(p);
    foo();
}
fn printer(p: Penguin) {
    println!("Species: {}", p.species);    
    println!("Genus: {}", p.genus);
    println!("Classified in {}", p.classified);
    if p.extinct == true {
        println!("Sadly this penguin has been made extinct.");
    }
}
fn foo() {
     let mut n = 6;
 println!("Value is {}", n);
 n = 8;
  println!("Eight is written as {}", n);
}
```
使用 `cargo build` 命令进行编译:
```
$ cargo build
```
执行 `target` 子目录下的二进制程序,或者直接运行 `cargo run` 命令来运行你的项目:
```
$ cargo run
Species: R adeliæ
Genus: Pygoscelis
Classified in 1841
Value is 6
Eight is written as 8
```
### Crates
任何语言的大部分便利都来自于它的库或模块。在 Rust 中,进行分发和跟踪的库称为 `crate`。 [crates.io][4] 是一个很好的社区 `crate` 注册网站。
把一个 `crate` 添加到你的 Rust 项目,首先要在 `Cargo.toml` 文件中添加这个 `crate`。 例如,要安装随机数函数,我使用名为 `rand``crate`,使用 `*` 作为通配符,以确保在编译时获得最新版本:
```
[package]
name = "myproject"
version = "0.1.0"
authors = ["Seth &lt;[seth@opensource.com][5]&gt;"]
edition = "2022"
[dependencies]
rand = "*"
```
在 Rust 代码中使用它需要在最顶行使用 `use` 语句:
```
use rand::Rng;
```
以下是一些创建随机种子和随机范围的示例代码:
```
fn foo() {
    let mut rng = rand::thread_rng();
    let mut n = rng.gen_range(1..99);
    println!("Value is {}", n);
    n = rng.gen_range(1..99);
    println!("Value is {}", n);
}
```
你可以使用 `cargo run` 来运行它,它会检测代码是否被更改并触发一个新的构建。构建过程中下载名为 `rand``crete` 和它依赖的所有 `crate`,编译代码,然后运行它:
```
$ cargo run
Updating crates.io index
Downloaded ppv-lite86 v0.2.16
Downloaded 1 crate (22.2 KB) in 1.40s
 Compiling libc v0.2.112
 Compiling cfg-if v1.0.0
 Compiling ppv-lite86 v0.2.16
 Compiling getrandom v0.2.3
 Compiling rand_core v0.6.3
 Compiling rand_chacha v0.3.1
 Compiling rand v0.8.4
 Compiling rustpenguin v0.1.0 (/home/sek/Demo/rustpenguin)
 Finished dev [unoptimized + debuginfo] target(s) in 13.97s
 Running `target/debug/rustpenguin`
Species: R adeliæ
Genus: Pygoscelis
Classified in 1841
Value is 70
Value is 35
```
### Rust 速查表
Rust 是一门令人非常愉快的语言。它拥有在线注册网站的集成、有用的编译器和几乎直观的语法,给人的感觉非常现代。
但请不要误会Rust 仍是一门复杂的语言它具有严格的数据类型、强作用域变量和许多内置方法。Rust 值得一看,如果你要探索它,那么你应该下载我们的免费 **[Rust 速查表][6]**,以便快速了解基础知识。越早开始,就越早了解 Rust。当然你应该经常练习以避免生疏。
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/1/rust-cheat-sheet
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[hanszhao80](https://github.com/hanszhao80)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coverimage_cheat_sheet.png?itok=lYkNKieP (Cheat Sheet cover image)
[2]: https://opensource.com/article/20/5/rust-java
[3]: http://rust-lang.org
[4]: https://crates.io/
[5]: mailto:seth@opensource.com
[6]: https://opensource.com/downloads/rust-cheat-sheet

View File

@ -0,0 +1,42 @@
[#]: subject: "Bloomberg Open Sources Memray, A Python Memory Profiler"
[#]: via: "https://www.opensourceforu.com/2022/04/bloomberg-open-sources-memray-a-python-memory-profiler/"
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
彭博社开源 Memray一个 Python 内存分析器
======
![soft][1]
Memray 是一个内存分析器,由彭博社发,现在已经开源。它可以跟踪 Python 代码中的内存分配,包括本地扩展和 Python 解释器本身。内存剖析是了解程序如何利用内存的有力工具,因此可以检测内存泄漏或确定程序中哪些区域消耗的内存最多。
与 py-spy 等抽样内存剖析器相比Memray 可以跟踪每个函数调用,包括对 C/C++ 库的调用,并详细显示调用栈。彭博社称,这并不以牺牲性能为代价,剖析只使解释代码的速度变慢一点。然而,原生代码剖析的速度较慢,因此需要直接启用。
Memray 可以根据获得的内存消耗数据生成各种报告,包括火焰图,这对快速、准确地识别最常见的代码路径很有价值。
据 EgdeDB 的联合创始人兼 CEO Yury Selivanov 称,该工具提供了以前无法获得的对 Python 应用的洞察力。Memray 可以用来从命令行中执行和分析 Python 应用。
```python
$ python3 -m memray run -o output.bin my_script.py
$ python3 -m memray flamegraph output.bin
```
另外,你可以使用 pytest-memray 将 Memray 集成到你的测试套件中。你也可以用 -native 命令行选项对所有的 C/C++ 调用进行剖析,或者用 -live 命令行选项在程序执行过程中实时分析内存分配。Memray 可以在 Linux x86/64 系统上用 python3 -m pip install memray 来安装。
--------------------------------------------------------------------------------
via: https://www.opensourceforu.com/2022/04/bloomberg-open-sources-memray-a-python-memory-profiler/
作者:[Laveesh Kocher][a]
选题:[lkxed][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
[b]: https://github.com/lkxed
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/04/soft-1-696x363.jpg