1
0
DavidZhang73.github.io/search.xml

139 lines
67 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>Windows 包管理器 - Scoop</title>
<link href="/windows-package-manager-scoop/"/>
<url>/windows-package-manager-scoop/</url>
<content type="html"><![CDATA[<p>一直以来作为开发者Windows 相较于 Linux 都缺少两样重要的工具,</p><ol><li><strong>好用</strong>的 Shell - 现在可以用 PowerShell Core 或者 WSL 暂时代替。</li><li><strong>好用</strong>的包管理器 - 在开发时 C/Cpp 的库可以用<a href="https://github.com/microsoft/vcpkg" target="_blank" rel="noopener">VCPKG</a>,而日常使用的软件就可以使用本文的主角<a href="https://github.com/lukesampson/scoop" target="_blank" rel="noopener">Scoop</a> 了。</li></ol><h2 id="安装"><a class="header-anchor" href="#安装">¶</a>安装</h2><blockquote><p>按照官网的<a href="https://github.com/lukesampson/scoop/wiki/Quick-Start" target="_blank" rel="noopener">教程</a>,只能使用 PowerShell 而不是 CMD 进行安装。</p></blockquote><pre><code class="language-powershell"># 指定 Scoop 的安装路径,之后安装的 APP 会安装在 path/to/scoop/apps/$env:SCOOP='path/to/scoop'[environment]::setEnvironmentVariable('SCOOP',$env:SCOOP,'User')# 安装 ScoopInvoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')</code></pre><h3 id="Buckets"><a class="header-anchor" href="#Buckets">¶</a><a href="https://github.com/lukesampson/scoop/wiki/Buckets" target="_blank" rel="noopener">Buckets</a></h3><p>Scoop 只是一个包安装器,我们还需要软件源。</p><p>使用,</p><pre><code class="language-powershell">scoop bucket known</code></pre><p>可以列出所有官方已知并推荐的源,使用,</p><pre><code class="language-powershell">scoop bucket add &lt;bucket-name&gt;</code></pre><p>即可安装源。</p><ol><li><code>main</code> - Scoop 官方默认主源,里面所有的软件符合<a href="https://github.com/lukesampson/scoop/wiki/Criteria-for-including-apps-in-the-main-bucket" target="_blank" rel="noopener">标准</a>。</li><li><code>extras</code> - Scoop 官方扩展你源,里面的软件不完全符合标准。</li><li><code>versions</code> - 可选版本的源。</li><li><code>nightlies</code> - nightly 软件源,不推荐。</li><li><code>nirsoft</code> - <a href="https://nirsoft.net/" target="_blank" rel="noopener">Nir Sofer</a>开发的软件。</li><li><code>php</code> - 不同版本的 php。</li><li><code>nerd-fonts</code> - <a href="https://github.com/ryanoasis/nerd-fonts" target="_blank" rel="noopener">Nerd Fonts</a> 和一些其他字体。</li><li><code>nonportable</code> - 非便携软件(可能需要 UAC。</li><li><code>java</code> - 不同版本的 JDKJRE。</li><li><code>games</code> - 开源或免费的游戏以及游戏工具。</li><li><code>jetbrains</code> - JetBrains 全家桶。</li></ol><h2 id="使用"><a class="header-anchor" href="#使用">¶</a>使用</h2><p>和 Ubuntu 的 aptCentOS 的 yum 基本相同。</p><pre><code class="language-powershell"># 搜索scoop search &lt;package-name&gt;# 查看主页scoop home &lt;package-name&gt;# 安装scoop install &lt;package-name&gt;# 更新scoop update &lt;package-name&gt;# 卸载scoop uninstall &lt;package-name&gt;# 更新 Scoop所有源所有软件包scoop update *# 列出所有软件包scoop list</code></pre><h2 id="推荐的软件包"><a class="header-anchor" href="#推荐的软件包">¶</a>推荐的软件包</h2><h3 id="aria2"><a class="header-anchor" href="#aria2">¶</a><a href="https://aria2.github.io/" target="_blank" rel="noopener">aria2</a></h3><p>基本上常见的所有开源下载软件都是基于这个,不但可以跑在 x86 的电脑上, mips 的路由器arm 的手机都不是问题。</p><p>需要注意的是,安装 aria2 后Scoop 的默认下载器会自动改成 aria2并开启多线程下载。</p><h3 id="7zip"><a class="header-anchor" href="#7zip">¶</a><a href="https://www.7-zip.org/" target="_blank" rel="noopener">7zip</a></h3><p>界面超原始,但是替代个收费的 WinRAR以及一众国内带广告的解压软件不是问题。同时 Scoop 有时候也依赖于 7zip 来解压。</p><h3 id="adb"><a class="header-anchor" href="#adb">¶</a><a href="https://developer.android.com/studio/releases/platform-tools.html" target="_blank" rel="noopener">adb</a></h3><p>有的时候连个安卓手机就需要这个东西,虽然我不做安卓开发,但是我玩过<a href="https://github.com/chiqj/WechatJump" target="_blank" rel="noopener">微信跳一跳</a>呀。</p><h3 id="bat"><a class="header-anchor" href="#bat">¶</a><a href="https://github.com/sharkdp/bat" target="_blank" rel="noopener">bat</a></h3><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/bat.png" alt="bat"></p><p>用于代替 cat带行号带高亮可<code>tail -f</code>。</p><h3 id="cpu-z"><a class="header-anchor" href="#cpu-z">¶</a><a href="https://www.cpuid.com/softwares/cpu-z.html" target="_blank" rel="noopener">cpu-z</a></h3><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/cpuz.png" alt="cpuz"></p><p>著名的 CPU 信息查看软件。</p><h3 id="fiddler"><a class="header-anchor" href="#fiddler">¶</a><a href="https://www.telerik.com/fiddler" target="_blank" rel="noopener">fiddler</a></h3><p>著名的抓包软件大学机考神器CCTR-E 的题目和答案一起传输,哈哈哈)。</p><h3 id="figlet"><a class="header-anchor" href="#figlet">¶</a><a href="https://github.com/lukesampson/figlet" target="_blank" rel="noopener">figlet</a></h3><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/figlet.png" alt="figlet"></p><p>把字符串改成字符串图像,还有好几个主题,现在知道那些文档的开头是怎么生成了吧😄。</p><h3 id="git"><a class="header-anchor" href="#git">¶</a><a href="https://gitforwindows.org/" target="_blank" rel="noopener">git</a></h3><p>什么,你没听说过 git !!!,右上角,再见😢。</p><h3 id="motrix"><a class="header-anchor" href="#motrix">¶</a><a href="https://motrix.app/" target="_blank" rel="noopener">motrix</a></h3><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/motrix.png" alt="motrix"></p><p>使用 Electron 开发的 aria2 GUI 客户端,可惜不能指定 aria2只能使用自带的。</p><h3 id="neofetch"><a class="header-anchor" href="#neofetch">¶</a><a href="https://github.com/dylanaraps/neofetch" target="_blank" rel="noopener">neofetch</a></h3><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/neofetch.png" alt="neofetch"></p><p>当你想截个屏,展示一下你的 Terminal 又不知道放什么内容时,就它了。</p><h3 id="psutils"><a class="header-anchor" href="#psutils">¶</a><a href="https://github.com/lukesampson/psutils" target="_blank" rel="noopener">psutils</a></h3><p>Scoop 同开发者开发的一系列 PowerShell 工具,我就说 PS 在国外还是很火的吧。</p><ul><li>gitignore - 从 <a href="http://gitignore.io" target="_blank" rel="noopener">gitignore.io</a> 获取 .gitignore 文件模板并打印出来。</li><li>ln - 类似于 Linux 的 ln实现&quot;软连接&quot;。</li><li>runat - at 命令(微软从 Windows Server 2012 开始废弃)。</li><li>say - 类似于 MacOS 的 say让电脑说话。</li><li>shasum - 类似于 Linux 下的 shasum校验文件。</li><li>sudo - 类似于 Linux 的 sudo但是会显示 UAC 弹出窗口。</li><li>time - 类似 Linux 的 time显示程序运行时间。</li><li>touch - 类似 Linux 的 touch创建文件。</li><li>vimtutor - 因为 Scoop 中的 vim 自带的 vimtutor 无法使用,所以有了这个。</li></ul><h3 id="snipaste"><a class="header-anchor" href="#snipaste">¶</a><a href="https://www.snipaste.com/" target="_blank" rel="noopener">snipaste</a></h3><p><img src="https://i.v2ex.co/71Ftp04b.png" alt="snipaste"></p><p>带边缘检测的强大截图软件。</p><h3 id="spacesniffer"><a class="header-anchor" href="#spacesniffer">¶</a><a href="http://www.uderzo.it/main_products/space_sniffer/index.html" target="_blank" rel="noopener">spacesniffer</a></h3><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/spacesniffer.png" alt="spacesniffer"></p><p>想知道那个文件夹占用了你的 C 盘最多?</p><h3 id="teamviewer"><a class="header-anchor" href="#teamviewer">¶</a><a href="https://www.teamviewer.com/" target="_blank" rel="noopener">teamviewer</a></h3><p>在山威如何快速获得妹子的 QQ微信和手机号加入<a href="https://www.baidu.com/link?url=FSXLyJOtkvCZMj4zl2J-mFLG0Q1GrF6rysPOH8fHKwIAF44VnyyhI7fUML9i99xH&amp;wd=&amp;eqid=cbce32e700025b47000000065e37cf45" target="_blank" rel="noopener">极客鸟</a>,用 Teamviewer 帮妹子修电脑吧。</p><h3 id="wget"><a class="header-anchor" href="#wget">¶</a><a href="https://eternallybored.org/misc/wget/" target="_blank" rel="noopener">wget</a></h3><p>下载个 1kb 的文本文件还需要动用迅雷aria2<code>wget</code>一行命令搞定。</p><h3 id="win32-openssh"><a class="header-anchor" href="#win32-openssh">¶</a><a href="https://github.com/PowerShell/Win32-OpenSSH" target="_blank" rel="noopener">win32-openssh</a></h3><p>微软已经把 ssh 迁移到 Windows 平台上啦。</p><h3 id="winscp"><a class="header-anchor" href="#winscp">¶</a><a href="https://winscp.net/eng/docs/lang:chs" target="_blank" rel="noopener">winscp</a></h3><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/winscp.png" alt="winscp"></p><p>图形化管理服务器的文件。</p><h2 id="软件结构"><a class="header-anchor" href="#软件结构">¶</a>软件结构</h2><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/tree.png" alt="目录结构"></p><p>虽然结构还是很清晰的,但不得不说,这几个名字起的太谜了。</p><h3 id="apps"><a class="header-anchor" href="#apps">¶</a>apps</h3><p>这个目录下面时所有安装的软件包。每个软件包都是这样的,</p><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/apps.png" alt="apps"></p><p>每个 app 的 current 都指向最新的那个文件夹。</p><h3 id="buckets"><a class="header-anchor" href="#buckets">¶</a>buckets</h3><p><img src="//davidz.cn/static/blog/2020-02-03-windows-package-manager-scoop/buckets.png" alt="buckets"></p><p>这个目录下是所有安装的源。</p><p>实际上每个源只是一个单独的 git 仓库仓库里面有该源的所有软件包的信息文件。Scoop 依照这个信息文件安装配置软件包。</p><p>比如 7zip 的,</p><pre><code class="language-json">{ &quot;homepage&quot;: &quot;https://www.7-zip.org/&quot;, &quot;description&quot;: &quot;A multi-format file archiver with high compression ratios&quot;, &quot;license&quot;: { &quot;identifier&quot;: &quot;Freeware,LGPL-2.0-only,BSD-3-Clause&quot;, &quot;url&quot;: &quot;https://www.7-zip.org/license.txt&quot; }, &quot;version&quot;: &quot;19.00&quot;, &quot;architecture&quot;: { &quot;64bit&quot;: { &quot;url&quot;: &quot;https://7-zip.org/a/7z1900-x64.msi&quot;, &quot;hash&quot;: &quot;a7803233eedb6a4b59b3024ccf9292a6fffb94507dc998aa67c5b745d197a5dc&quot; }, &quot;32bit&quot;: { &quot;url&quot;: &quot;https://7-zip.org/a/7z1900.msi&quot;, &quot;hash&quot;: &quot;b49d55a52bc0eab14947c8982c413d9be141c337da1368a24aa0484cbb5e89cd&quot; } }, &quot;extract_dir&quot;: &quot;Files/7-Zip&quot;, &quot;bin&quot;: &quot;7z.exe&quot;, &quot;checkver&quot;: { &quot;url&quot;: &quot;https://www.7-zip.org/download.html&quot;, &quot;regex&quot;: &quot;Download 7-Zip ([\\d.]+)&quot; }, &quot;autoupdate&quot;: { &quot;architecture&quot;: { &quot;64bit&quot;: { &quot;url&quot;: &quot;https://7-zip.org/a/7z$cleanVersion-x64.msi&quot; }, &quot;32bit&quot;: { &quot;url&quot;: &quot;https://7-zip.org/a/7z$cleanVersion.msi&quot; } } }, &quot;shortcuts&quot;: [[&quot;7zFM.exe&quot;, &quot;7-Zip&quot;]]}</code></pre><h3 id="cache"><a class="header-anchor" href="#cache">¶</a>cache</h3><p>这个目录里面是下载的软件包安装程序等等缓存。</p><h3 id="persist"><a class="header-anchor" href="#persist">¶</a>persist</h3><p>这个目录存放的是这些软件的配置之类的文件,这些文件的特点是在软件更新时不变。</p><h3 id="shims"><a class="header-anchor" href="#shims">¶</a>shims</h3><p>这个目录是所有软件包的快捷方式。</p><p>每一个软件包都对应三个,</p><ol><li>package-name.exe</li><li>package-name.ps1</li><li>package-name.shim</li></ol><p>我其实有个疑问,我在命令行里输<code>package-name</code>,执行的是<code>package-name.exe</code>还是<code>package-name.ps1</code>呢?</p><p>简单的测试后发现,是根据使用的 shell 确定的CMD 里面是<code>package-name.exe</code>,而 PowerShell 里面是 <code>package-name.ps1</code>。</p><h2 id="软件包管理哲学"><a class="header-anchor" href="#软件包管理哲学">¶</a>软件包管理哲学</h2><blockquote><h3 id="引用自-SpencerWoo"><a class="header-anchor" href="#引用自-SpencerWoo">¶</a>引用自 <a href="https://sspai.com/u/spencerwoo/posts" target="_blank" rel="noopener">SpencerWoo</a></h3><p>最后我还是想说一说:为什么我们推荐使用「包管理」?<br>在写这篇文章之前我也看了我派上面对包管理工具介绍的文章,我觉得这些文章其实都没太讲清为什么我们需要用「包管理」这个看上去复杂难用的命令行工具去下载、管理我们的软件。毕竟现在的软件管理哲学是「我去 App Store 下一个不就行了嘛?」<br>需要明确的是:包管理的设计初衷是为了方便开发者管理和搭建开发环境。用包管理工具能够快速的安装开发工具、开发依赖,从而免去复杂的路径、环境变量等信息的配置。而我们作为普通用户,实际上用「包管理」工具的过程,就是在借鉴这种「软件管理哲学」。<br>但更重要的,也是更对我们用户安装基本软件的过程来说的,是我前文提到的:<br>一行代码省去了搜索、筛选、下载等繁琐步骤<br>安装方便、更新方便、卸载也方便<br>同时也最大程度杜绝了流氓捆绑软件的安装(因为 Scoop 本身和 Scoop 安装过程参考的配置文件都是开源的,要安装什么一目了然)<br>这些都是传统的「搜索 - 筛选 - 下载」的软件管理过程带来的复杂过程和安全隐患的极佳解决方法。<br>尝试一下 Scoop 吧!如果你对这个简洁、克制却依旧强大的工具产生兴趣,你一定离高阶 Windows 用户不远了。</p></blockquote><h2 id="推荐阅读"><a class="header-anchor" href="#推荐阅读">¶</a>推荐阅读</h2><p><a href="https://sspai.com/post/52496" target="_blank" rel="noopener">「一行代码」搞定软件安装卸载,用 Scoop 管理你的 Windows 软件</a></p>]]></content>
<categories>
<category> Productivity </category>
</categories>
<tags>
<tag> Open-Source </tag>
</tags>
</entry>
<entry>
<title>颜值是第一生产力 - Windows Terminal</title>
<link href="/beauty-is-productivity-windows-terminal/"/>
<url>/beauty-is-productivity-windows-terminal/</url>
<content type="html"><![CDATA[<p><img src="//davidz.cn/static/blog/2020-01-31-beauty-is-productivity-windows-terminal/cmd.png" alt="CMD"></p><p>记得我最早的时候用 Visual Studio 写了第一个 Hello World 程序,激动的点运行,出来个黑框一闪就过去了,啥也没看到。</p><p><img src="//davidz.cn/static/blog/2020-01-31-beauty-is-productivity-windows-terminal/powershell.png" alt="PowerShell"></p><p>后来偶然了解 PowerShell又变成了一个蓝色的框还会有进度提示红的黑的突兀得很😢。</p><p><img src="//davidz.cn/static/blog/2020-01-31-beauty-is-productivity-windows-terminal/bash.png" alt="bash"></p><p>后来上了大学终于在 Ubuntu 上见到了 bash完全改变了我对 Shell 的认知。</p><p>傻傻分不清 Shell 和 Terminal 的我,激动的打开 Git 自带的 bash它却长成了这样。</p><p><img src="//davidz.cn/static/blog/2020-01-31-beauty-is-productivity-windows-terminal/git-bash.png" alt="Git-Bash"></p><p>一番优化之后也不是不能用,后来还入坑了 <a href="https://github.com/cmderdev/cmder" target="_blank" rel="noopener">Cmder</a>,用于替代 <a href="https://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank" rel="noopener">Putty</a> 那个更加原始的 terminal。</p><p>终于2019 年微软开始进入开源世界,为我们带来了颜狗的胜利: <a href="https://github.com/microsoft/terminal" target="_blank" rel="noopener">Windows Terminal</a>。</p><iframe src="//player.bilibili.com/player.html?aid=51700920&cid=90502402&page=1&high_quality=1&danmaku=0" allowfullscreen="true" width="100%" height="600" scrolling="no" frameborder="0" sandbox="allow-top-navigation allow-same-origin allow-forms allow-scripts" ></iframe><h2 id="下载-安装"><a class="header-anchor" href="#下载-安装">¶</a>下载&amp;安装</h2><blockquote><p>截止 2020 年 2 月 1 号Windows Terminal 还处在测试阶段,但是已经相对比较完善了,正常使用没有什么大问题了。</p></blockquote><h3 id="方法-1-通过-Windows-Store"><a class="header-anchor" href="#方法-1-通过-Windows-Store">¶</a>方法 1: 通过 Windows Store</h3><p><a href="https://www.microsoft.com/en-us/p/windows-terminal-preview/9n0dx20hk701" target="_blank" rel="noopener">点击这里安装</a></p><h3 id="方法-2-通过-Github"><a class="header-anchor" href="#方法-2-通过-Github">¶</a>方法 2: 通过 Github</h3><p>在 Github 的 <a href="https://github.com/microsoft/terminal/releases" target="_blank" rel="noopener">Release</a> 中下载最新的那个双击安装就好啦,和方法 1 是一样的。</p><h3 id="方法-3-通过-Scoop"><a class="header-anchor" href="#方法-3-通过-Scoop">¶</a>方法 3: 通过 Scoop</h3><blockquote><p><strong>不推荐</strong><br>用 wt 命令启动时会有一个 CMD 窗口,逼死强迫症。</p></blockquote><p>Windows Terminal 在 Scoop 的 extras bucket 里面。</p><pre><code class="language-powershell">scoop install windows-terminal</code></pre><h2 id="配置"><a class="header-anchor" href="#配置">¶</a>配置</h2><p>通过配置,最终 terminal 可以长成这个样子。</p><p><img src="//davidz.cn/static/blog/2020-01-31-beauty-is-productivity-windows-terminal/windows-terminal.png" alt="windows terminal"></p><p>现阶段只有 json 格式的配置文件,还没有图形化配置界面,项目组说正式版会有,最终应该会与 Vscode 的配置一样。</p><p>根据官网给出的 <a href="https://raw.githubusercontent.com/microsoft/terminal/master/doc/cascadia/profiles.schema.json" target="_blank" rel="noopener">Profiles Schema</a>,我们可以很快的配置我们自己定制化的 Terminal。</p><p>下面是我自己用的配置文件,</p><pre><code class="language-json">{ &quot;$schema&quot;: &quot;https://aka.ms/terminal-profiles-schema&quot;, &quot;defaultProfile&quot;: &quot;{807502AB-0C92-4DF7-9C7C-1E9F7A2A47DE}&quot;, // 默认配置的 GUID 和下面的 profiles.list 中的一个相同 &quot;alwaysShowTabs&quot;: true, // 无论有几个 tab 是否都显示标签栏 &quot;requestedTheme&quot;: &quot;dark&quot;, // &quot;light&quot;,&quot;dark&quot;,&quot;system&quot; &quot;copyOnSelect&quot;: true, // 选择时复制 &quot;launchMode&quot;: &quot;maximized&quot;, // &quot;maximized&quot;,&quot;default&quot; &quot;profiles&quot;: { // shell 或程序的配置 &quot;defaults&quot;: { // 所有 shell 或程序配置的默认值 &quot;acrylicOpacity&quot;: 0.7, // 背景透明度 &quot;useAcrylic&quot;: true, // 是否启用透明背景 &quot;colorScheme&quot;: &quot;One Half Dark&quot;, // 色彩配置,和下面 schemes 中的一个相同 &quot;fontFace&quot;: &quot;JetBrains Mono&quot;, // 字体 &quot;fontSize&quot;: 12, // 字号 &quot;startingDirectory&quot;: &quot;.&quot;, // 工作路径,设置成 “.” 可以实现在资源管理器的地址栏输入 wt 直接打开时工作目录是当前目录 &quot;closeOnExit&quot;: &quot;always&quot; // &quot;never&quot;,&quot;graceful&quot;,&quot;always&quot; }, &quot;list&quot;: [ { &quot;guid&quot;: &quot;{807502AB-0C92-4DF7-9C7C-1E9F7A2A47DE}&quot;, // 唯一 GUID &quot;name&quot;: &quot;powershell core&quot;, // 在下拉框中显示的名称 &quot;commandline&quot;: &quot;pwsh.exe -nol&quot;, // 执行的命令,-nol 的作用是不显示 Microsoft 那些提示 &quot;icon&quot;: &quot;path/to/icon&quot; // 标签栏和下拉菜单中显示的图标 }, { &quot;guid&quot;: &quot;{85933BC0-E5D2-4299-9FBC-AC6C9F6DFD46}&quot;, &quot;name&quot;: &quot;davidz.cn&quot;, &quot;commandline&quot;: &quot;ssh.exe root@davidz.cn&quot;, // ssh 也可以,用于代替 Putty &quot;icon&quot;: &quot;path/to/icon&quot; } ] }, &quot;schemes&quot;: [ // 配色 { &quot;name&quot;: &quot;One Half Dark&quot;, // 我最喜欢的主题VscodeVSJetBrains 全家桶都有类似主题,关键词 atom one dark &quot;background&quot;: &quot;#282C34&quot;, &quot;black&quot;: &quot;#282C34&quot;, &quot;blue&quot;: &quot;#61AFEF&quot;, &quot;brightBlack&quot;: &quot;#5A6374&quot;, &quot;brightBlue&quot;: &quot;#61AFEF&quot;, &quot;brightCyan&quot;: &quot;#56B6C2&quot;, &quot;brightGreen&quot;: &quot;#98C379&quot;, &quot;brightPurple&quot;: &quot;#C678DD&quot;, &quot;brightRed&quot;: &quot;#E06C75&quot;, &quot;brightWhite&quot;: &quot;#DCDFE4&quot;, &quot;brightYellow&quot;: &quot;#E5C07B&quot;, &quot;cyan&quot;: &quot;#56B6C2&quot;, &quot;foreground&quot;: &quot;#DCDFE4&quot;, &quot;green&quot;: &quot;#98C379&quot;, &quot;purple&quot;: &quot;#C678DD&quot;, &quot;red&quot;: &quot;#E06C75&quot;, &quot;white&quot;: &quot;#DCDFE4&quot;, &quot;yellow&quot;: &quot;#E5C07B&quot; } ]}</code></pre><blockquote><p>GUID 可以使用这个<a href="https://www.guidgen.com" target="_blank" rel="noopener">在线网站</a> 或者 Visual Studio 自带的工具 guidgen 生成。</p></blockquote><h3 id="主题"><a class="header-anchor" href="#主题">¶</a>主题</h3><p>除了我最喜欢的这个 One Half Dark你还可以在<a href="https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/windowsterminal" target="_blank" rel="noopener">这里</a>选择自己喜欢的主题,复制到配置文件即可。</p><h3 id="字体"><a class="header-anchor" href="#字体">¶</a>字体</h3><p>我推荐使用 JetBrains 推出的字体 <a href="https://www.jetbrains.com/lp/mono/" target="_blank" rel="noopener">JetBrains Mono</a>,这是一款适合写代码的带连字的字体。类似的字体还有微软特意为 Windows Terminal 开发的 <a href="https://github.com/microsoft/cascadia-code" target="_blank" rel="noopener">Cascadia Code</a>,或者是 Mozilla 主推由 Nikita Prokopov 开发的 <a href="https://github.com/tonsky/FiraCode" target="_blank" rel="noopener">Fira Code</a>。</p><p>这些字体都在积极的维护和更新中,除了双击安装之外,还可以使用 Scoop 安装方便更新。在 Scoop 的 nerd-fonts bucket 中。</p><pre><code class="language-powershell">scoop install JetBrains-Mono</code></pre><h2 id="PowerShell-Core"><a class="header-anchor" href="#PowerShell-Core">¶</a><a href="https://github.com/PowerShell/PowerShell" target="_blank" rel="noopener">PowerShell Core</a></h2><p>PowerShell Core 是微软推出的基于 .Net Core 跨平台开源脚本语言,用于代替 PowerShell 和更加原始的 CMD。目前来看在国内基本上没什么影响力国外相对好一些。除非大家都用 Windows Server 作为服务器,否则我感觉前景也不是很乐观。但是作为个人使用起来还是很好用的。</p><p>PowerShell Core 也有自己的模块管理平台 <a href="https://www.powershellgallery.com" target="_blank" rel="noopener">PowerShell Gallery</a>。</p><p>搜索</p><pre><code class="language-powershell">Find-Module xxx</code></pre><p>安装</p><pre><code class="language-powershell">Install-Module xxx</code></pre><p>卸载</p><pre><code class="language-powershell">Uninstall-Module xxx</code></pre><p>更新</p><pre><code class="language-powershell">Update-Module xxx</code></pre><p>类似于 <code>.bashrc</code> 之与 bash <code>.zshrc</code> 之与 zshPowerShell 也有自己的配置文件<code>Microsoft.PowerShell_profile.ps1</code>,可以通过<code>$PROFILE</code>访问。</p><p>使用模块<code>Module</code>时,</p><pre><code class="language-powershell">Import-Module xxx</code></pre><p>如果每次启动 PowerShell 都想引用该插件,则在<code>Microsoft.PowerShell_profile.ps1</code>中添加<code>Import-Module xxx</code>即可。</p><h3 id="oh-my-posh"><a class="header-anchor" href="#oh-my-posh">¶</a><a href="https://github.com/JanDeDobbeleer/oh-my-posh" target="_blank" rel="noopener">oh-my-posh</a></h3><p>这个是 oh-my-zsh 的 PowerShell 版本,但是只能管理主题。</p><p><img src="//davidz.cn/static/blog/2020-01-31-beauty-is-productivity-windows-terminal/robbyrussel.png" alt="robbyrussel"></p><p>我比较喜欢的是这个 robbyrussel 主题,因为比较简洁。</p><p><img src="//davidz.cn/static/blog/2020-01-31-beauty-is-productivity-windows-terminal/my-theme.png" alt="my-theme"></p><p>后来参考了<a href="https://github.com/spencerwooo/dotfiles#powershell" target="_blank" rel="noopener">dotfiles</a>,自己按照 oh-my-zsh 的 ys 主题魔改了一个,为了区分不同环境,我把最前面的符号改成了<code>PS</code>。</p><p><a href="https://github.com/DavidZhang73/Config/blob/master/themes/MyTheme.psm1" target="_blank" rel="noopener">我的主题</a></p><h3 id="z"><a class="header-anchor" href="#z">¶</a><a href="https://github.com/vincpa/z" target="_blank" rel="noopener">z</a></h3><p>类似于 autojump实现原理就是每次 cd 都记录下来,然后 z name 会去匹配访问最多的那个路径,直接跳转到。非常实用。</p><h2 id="Linux-or-Windows-Subsystem-for-Linux"><a class="header-anchor" href="#Linux-or-Windows-Subsystem-for-Linux">¶</a>Linux or <a href="https://docs.microsoft.com/zh-cn/windows/wsl/about" target="_blank" rel="noopener">Windows Subsystem for Linux</a></h2><p>我用了好久好久的 bash 才终于知道了还有像 zshfish 这样更加人性化的 shell。从前者切换到后者就像从 dos 切换到 windows 一样惊艳。</p><h3 id="ohmyzsh"><a class="header-anchor" href="#ohmyzsh">¶</a><a href="https://github.com/ohmyzsh/ohmyzsh" target="_blank" rel="noopener">ohmyzsh</a></h3><p>这个是 zsh 的插件平台,支持添加主题,工具等等插件。</p><h4 id="z内置"><a class="header-anchor" href="#z内置">¶</a>z内置</h4><p>和上面 PowerShell 中的 z 是一样的。</p><h4 id="git内置"><a class="header-anchor" href="#git内置">¶</a>git内置</h4><p>这个主要是 git 命令的提示与自动补全(我没怎么用过)。</p><h4 id="sudo内置"><a class="header-anchor" href="#sudo内置">¶</a>sudo内置</h4><p>当你输入<code>apt update</code>提示无法获得锁的时候,按上键加两下<code>esc</code>就可以自动加上<code>sudo</code>啦。</p><h4 id="extract内置"><a class="header-anchor" href="#extract内置">¶</a>extract内置</h4><p>你背的过不同压缩文件的解压命令吗???背不过的话还是用用<code>extract</code>吧。</p><h4 id="zsh-autosuggestions"><a class="header-anchor" href="#zsh-autosuggestions">¶</a><a href="https://github.com/zsh-users/zsh-autosuggestions/" target="_blank" rel="noopener">zsh-autosuggestions</a></h4><p>根据命令历史记录自动建议,按右键自动补全。</p><h4 id="zsh-syntax-highlighting"><a class="header-anchor" href="#zsh-syntax-highlighting">¶</a><a href="https://github.com/zsh-users/zsh-syntax-highlighting" target="_blank" rel="noopener">zsh-syntax-highlighting</a></h4><p>命令高亮。</p><p>具体的配置文件可以参考<a href="https://github.com/DavidZhang73/Config/blob/master/dotfiles/.zshrc" target="_blank" rel="noopener">这里</a>。同时,如果你和我一样闲的话,也可以写一个简单的<a href="https://github.com/DavidZhang73/Config" target="_blank" rel="noopener">一键配置脚本</a>,这样只需要有网络链接的环境下,就可以一键还原 zsh 环境了。</p><h3 id="dircolors"><a class="header-anchor" href="#dircolors">¶</a>dircolors</h3><p>在 WSL 里面使用默认的<code>.dircolors</code>可能会亮瞎眼,所以可以使用 <a href="https://github.com/seebi/dircolors-solarized" target="_blank" rel="noopener">dircolors-solarize</a>作为代替。</p><p>下载后放到用户目录里面,在<code>.zshrc</code>里面添加</p><pre><code class="language-shell">eval $(dircolors -b $HOME/.dircolors)</code></pre><p>即可。</p><h2 id="推荐阅读"><a class="header-anchor" href="#推荐阅读">¶</a>推荐阅读</h2><p><a href="https://dowww.spencerwoo.com/" target="_blank" rel="noopener">Dev on Windows with WSL</a> - 强烈推荐</p><p><a href="https://sspai.com/post/52907" target="_blank" rel="noopener">5 个 PowerShell 主题,让你的 Windows 终端更好看</a></p><p><a href="https://sspai.com/post/52868" target="_blank" rel="noopener">告别 Windows 终端的难看难用,从改造 PowerShell 的外观开始</a></p>]]></content>
<categories>
<category> Productivity </category>
</categories>
<tags>
<tag> Open-Source </tag>
<tag> Microsoft </tag>
<tag> Terminal </tag>
</tags>
</entry>
<entry>
<title>浪潮实习</title>
<link href="/inspur-internship/"/>
<url>/inspur-internship/</url>
<content type="html"><![CDATA[<p>到了期末都说要找个实习的工作,我也跟个风😂。</p><p>我是主要是在<a href="https://www.shixiseng.com/" target="_blank" rel="noopener">实习僧</a>上找的(就当免费做个广告吧),我住在美丽的泉城济南,<s>这个地方好就好在</s>,咳咳咳,我大概填了填简历,可能是没啥亮点,投了三四家都不要我😢。</p><p>我分析原因大概有以下几条:</p><ol><li>我最喜欢最熟练的语言是 Python但是现在国内的环境Python 很少作为 Web 的后端,主要是用在机器学习(大数据分析,量化交易之类的)方面。济南大多数都是 Java 和 Cpp 岗。</li><li>我个人没有参加过 acm 之类的比赛,除了几个项目没法有效证明我的能力。</li><li>我这个寒假只能干 2 个月,<s>其实最终只干了一个半月</s>。</li><li>我是个大三的学生。可能培养了对于公司来说也没啥意义吧。</li></ol><p>最后还是十分感谢秦老师❤️,不但收了我到浪潮实习,还在实习过程中给了我很多帮助和指导。</p><p>下面列一列我学习了解的项目工具之类的。</p><h2 id="CppMicroServices"><a class="header-anchor" href="#CppMicroServices">¶</a><a href="https://github.com/CppMicroServices/CppMicroServices" target="_blank" rel="noopener">CppMicroServices</a></h2><p>我们主要做了一个插件管理器,是基于 CppMicroServices 的二次开发。这是一个 Cpp 的微服务框架,主要实现了 Bundle 的全生命周期管理,注册,启动,停止,状态管理等。</p><h2 id="CLion"><a class="header-anchor" href="#CLion">¶</a><a href="https://www.jetbrains.com/clion" target="_blank" rel="noopener">CLion</a></h2><p>大爱 Jetbrains 全家桶,我实习的第一件事大概就是给组里所有人安利了 CLion 吧。与宇宙第一 IDE Visual Studio 相比最突出的优点有</p><ol><li>精美的全功能编辑器。不是我吐槽VS 的编辑器为了向下兼容现在甚至已经落后 VSCode 了,这还是曾经的宇宙第一 IDE 嘛。举一个简单的例子,连字功能连个开关都找不到,重启 VS 没成功,重启电脑就成功了?再加上没有拼写检查?没有自动注释补全?没有缺陷提示?你可能觉得没什么,但是这些都是 CLion 的自带功能啊。</li><li>丰富完善的插件生态。虽然感觉比不上 VSCode但是相对于 VS😄。</li><li>CMake 项目的原生支持。VS 虽然也有,但是感觉应该还处在开发状态。</li><li>SVN &amp; Git 的原生支持。</li><li>远程开发功能。因为我们要求项目有跨平台能力所以需要在多个平台切换。VS 虽然也有这个功能,但是也是感觉在开发状态,相比 CLion 少了很多配置的灵活性。</li><li>丰富的主题。VS 硬伤。</li></ol><p>综上所述,对于 Cpp 的 CMake 跨平台项目,还是推荐使用 CLion 作为 IDE。</p><p>我猜测 Visual Studio 是宇宙第一 IDE 应该说的是对于 C# 项目吧。</p><h2 id="CMake"><a class="header-anchor" href="#CMake">¶</a><a href="www.cmake.org">CMake</a></h2><p>以前的 C/Cpp 项目对我来说就是个谜解决方案、项目傻傻分不清楚Visual Studio 写单文件程序,解算法题还是很溜的,但是两个文件以上就很晕。</p><p>傻瓜式的配置的优点和确定都是非常显著的,好用是好用,用好是真的难。</p><p>CMake 作为这几年流行的跨平台构建工具,实现了配置式构建,终于让我理解了大学里 Linux 老师讲的程序编译链接都是些啥。</p><p>下面我简单写一写 CMake 的入门知识。</p><h3 id="常见编译器"><a class="header-anchor" href="#常见编译器">¶</a>常见编译器</h3><table><thead><tr><th style="text-align:center">Platform</th><th style="text-align:center">Windows</th><th style="text-align:center">Linux</th></tr></thead><tbody><tr><td style="text-align:center">GNU(open source)</td><td style="text-align:center">MinGW, MinGW-w64</td><td style="text-align:center">GCC(GNU Compiler Collection)</td></tr><tr><td style="text-align:center">Other</td><td style="text-align:center">Clang(Apple), MSVC(Microsoft), ICC(Intel) etc.</td><td style="text-align:center">Clang(Apple), ICC(Intel) etc.</td></tr></tbody></table><p>上面这些编译器都可以作为 CMake 的编译器。</p><p>这里主要还是推荐 GCC毕竟老牌经过这么多年的洗礼了。</p><p>其次的话推荐 CLang这些年对于新特性特别是 C++20支持的不错。</p><p>再次就是如果真的需要 Windows 原生底层支持,那就只能使用 MSVC 啦。</p><h3 id="常见构建工具"><a class="header-anchor" href="#常见构建工具">¶</a>常见构建工具</h3><table><thead><tr><th style="text-align:center">Platform</th><th style="text-align:center">Windows</th><th style="text-align:center">Linux</th></tr></thead><tbody><tr><td style="text-align:center">GNU(open source)</td><td style="text-align:center">MinGW-make(Makefile)</td><td style="text-align:center">make(Makefile)</td></tr><tr><td style="text-align:center">Other</td><td style="text-align:center">nmake(Makefile), MSBuild(.vcxproj), ninja(.ninja), qmake etc.</td><td style="text-align:center">ninja(.ninja), qmake etc.</td></tr><tr><td style="text-align:center">Solution</td><td style="text-align:center">Visual Studio(.sln), QT(.project)</td><td style="text-align:center">XCode, QT(.project)</td></tr></tbody></table><p>以上所有都可以作为 CMake 的 Generator。</p><p>IDE 可以识别 CMake 根据 CMakeLists.txt 生成的 CMakeCache.txt从中获得项目构成编译连接选项等从而替代解决方案。</p><p>我们在项目中使用的情况是,在 Linux 下使用 make在 Windows 下使用 nmake。</p><h3 id="CMake-常用指令"><a class="header-anchor" href="#CMake-常用指令">¶</a>CMake 常用指令</h3><pre><code class="language-shell">Generate a Project Buildsystem cmake [&lt;options&gt;] &lt;path-to-source&gt; cmake [&lt;options&gt;] &lt;path-to-existing-build&gt; cmake [&lt;options&gt;] -S &lt;path-to-source&gt; -B &lt;path-to-build&gt;Build a Project cmake --build &lt;dir&gt; [&lt;options&gt;] [-- &lt;build-tool-options&gt;]Install a Project cmake --install &lt;dir&gt; [&lt;options&gt;]Open a Project cmake --open &lt;dir&gt;Run a Script cmake [{-D &lt;var&gt;=&lt;value&gt;}...] -P &lt;cmake-script-file&gt;Run a Command-Line Tool cmake -E &lt;command&gt; [&lt;options&gt;]Run the Find-Package Tool cmake --find-package [&lt;options&gt;]View Help cmake --help[-&lt;topic&gt;]</code></pre><p>这些其实用不太到,构建别人的项目只使用简单的<code>cmake ..</code>就好啦。</p><p>其他常用的 CLion 都有相应的图形化设置。</p><h3 id="Makefile"><a class="header-anchor" href="#Makefile">¶</a>Makefile</h3><pre><code class="language-makefile">&lt;TargetName&gt;: gcc &lt;arg1&gt; &lt;arg2&gt; ... &lt;file&gt; g++ &lt;arg1&gt; &lt;arg2&gt; ... &lt;file&gt; gcc &lt;arg1&gt; &lt;arg2&gt; ... &lt;file&gt;</code></pre><p>这个是传统的 makefile事实上对于大型项目已经很少有人这么写了详细参考<a href="https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html" target="_blank" rel="noopener">Autotools</a>。</p><h3 id="CMakeLists-txt"><a class="header-anchor" href="#CMakeLists-txt">¶</a>CMakeLists.txt</h3><pre><code class="language-cmake">cmake_minimum_required(VERSION 3.16)project(Demo)set(CMAKE_CXX_STANDARD 14)find_package(Poco REQUIRED COMPONENTS Foundation)include_directories(include)add_executable(Demo src/main.cpp)set(BUILD_SHARED_LIBS true)add_library(Cal src/cal.cpp include/cal.h)message(STATUS ${Poco_LIBRARIES})target_link_libraries(Demo ${Poco_LIBRARIES} Cal)set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin/)set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib/)</code></pre><p>这个是一个简单的 Demo链接外部的 Poco 库,还编译生成了一个动态库和一个可执行文件,然后指定了输出目录。</p><p>整体难度中等,主要原因是<a href="https://cmake.org/" target="_blank" rel="noopener">官网文档</a>有一点看不懂😢。</p><h2 id="Vcpkg"><a class="header-anchor" href="#Vcpkg">¶</a><a href="https://github.com/microsoft/vcpkg" target="_blank" rel="noopener">Vcpkg</a></h2><p>这个是微软开发的,类似于 Python 的 pipNodejs 的 npm总而言之就是个依赖包管理器。主要适用于解决开发依赖问题。</p><p>比如安装一个 poco原来你需要下载源码-&gt;编译源码-&gt;把文件放进项目-&gt;修改编译链接选项,然后才能用,现在你只需要</p><pre><code class="language-shell">vcpkg install poco</code></pre><p>然后在 CMakeLists.txt 里面添加</p><pre><code class="language-cmake">find_package(Poco REQUIRED COMPONENTS Foundation)</code></pre><p>然后再连接上 Target 就好啦。</p><p>Vcpkg 甚至还允许你使用</p><pre><code class="language-shell">vcpkg install poco:x64-windows</code></pre><p>直接安装 64 位的 Poco 库。</p><p>至于搜索和卸载都大同小异。</p><p><strong>但是</strong>,它有一个致命问题是,不支持版本管理,每个库都是由一个文件指定的,而不是像 pipnpm 之类的,有个在线仓库,所以,你 vcpkg 的版本直接决定了依赖的版本。</p><p>vcpkg 安装依赖都是下载后现编译安装的,不过这个应该是 C/Cpp 项目不可避免的,我也没找到 Windows 下更好的依赖包管理器。</p><h2 id="Poco"><a class="header-anchor" href="#Poco">¶</a><a href="https://github.com/pocoproject/poco" target="_blank" rel="noopener">Poco</a></h2><p>这个类似于野生 C++标准类库<a href="https://www.boost.org" target="_blank" rel="noopener">Boost</a>,但是官网说很轻量,使用感觉也确实是这样。但是用起来总感觉有一些问题,我也提了 issue作者也没回我可能太忙了吧。</p><p>基本上能够让 Cpp 在使用上达到 Java 的水平吧,但是肯定还是有一定的差距的,跟我熟悉的 Python 更是相差甚远,毕竟不是标准库,也情有可原吧。</p><p>用了一段时间之后,感觉这个库的实现还是很标准的,看了一些源代码,也很规范,以后再有 Cpp 的项目可以着重考虑一下了。</p><h2 id="Linux"><a class="header-anchor" href="#Linux">¶</a>Linux</h2><p>因为跨平台,在项目开发过程中大量使用了 Linux 上 shellsystemctldocker 这些工具以及 CFEngine Zabbix 这些运维的东西,感觉又喜欢上了 Linux 和命令行,熟悉了之后真是很方便。</p><p>同时因为是 C/Cpp 项目,我们编译了很多开源项目,算是终于知道了 Linux 根目录下面每个目录都是干啥的。</p><p>Linux 下的包管理器比如 aptyum 用起来也很爽。所以我也看了看 Windows 下面的包管理器,发现了 Scoop 这个神器,在另外一篇<a href="https://blog.davidz.cn/beauty-is-productivity-windows-terminal">博文</a>里介绍了它。</p><h2 id="MSYS2"><a class="header-anchor" href="#MSYS2">¶</a><a href="https://github.com/msys2/msys2" target="_blank" rel="noopener">MSYS2</a></h2><p>因为快离职的时候,新的需求要交叉编译 CFEngine虽然到离职也没搞成功但是让我发现了 MSYS2 这个交叉编译神器。</p><blockquote><p>MinGW 是在 Windows 平台的<a href="https://www.gnu.org/software/gcc" target="_blank" rel="noopener">GCC</a>,而 CygWin 和 MSYS2 均是在 MinGW 基础上的<a href="https://www.gnu.org/software/libc/manual/html_node/POSIX.html" target="_blank" rel="noopener">POSIX</a>子操作系统(概念类似于微软 WSL。<br><a href="https://www.cnblogs.com/Netsharp/p/11073142.html" target="_blank" rel="noopener">CygWin、Msys、MinGW、Msys2 的区别与联系</a></p></blockquote><p>选择 MSYS2 而不是 MinGW 也不是 CygWin 的主要原因也是因为 MSYS2 的包管理器 pacman。</p><p>交叉编译也是个大坑,巨坑无比,反正我也没研究明白,七八个可执行文件就编译出来一个。</p><h2 id="感谢"><a class="header-anchor" href="#感谢">¶</a>感谢</h2><p>感谢所有在实习中帮助过我的老师,同事们❤️。</p>]]></content>
<categories>
<category> Internship </category>
</categories>
<tags>
<tag> Cpp </tag>
</tags>
</entry>
<entry>
<title>ANU COMP2310(2019) Assignment1</title>
<link href="/anu-comp2310-assignment1/"/>
<url>/anu-comp2310-assignment1/</url>
<content type="html"><![CDATA[<blockquote><p><strong>敬告</strong></p><div style="color: red">本博客请供参考,请不要抄袭。</div></blockquote><p>这是 ANU <a href="http://courses.cecs.anu.edu.au/courses/COMP2310/" target="_blank" rel="noopener">COMP2310</a>的第一次大作业,历时一个月左右,也是这个学期我写的最认真的一次作业,所以在博客搭建伊始,我先把这个记录下来。</p><h2 id="问题"><a class="header-anchor" href="#问题">¶</a>问题</h2><p>根据<a href="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/assignment-1.pdf" target="_blank" rel="noopener">Assignment 1 PDF</a>中的描述,大概的意思就是在三维空间中有许多的<code>车</code>,具有速度和加速度(都是三维向量),而且不管是否加速,都会消耗一定的能量,当然加速也会加快能量的消耗。然后就是有一个或多个<code>能量球</code>,当然也是在运动中的,同样具有速度和加速度。当<code>车</code>和<code>能量球</code>靠近的时候,<code>车</code>能够获取到<code>能量球</code>的信息(加速度,速度,位置),并且加满能量,而当<code>车</code>与<code>车</code>靠近的时候,能够互相交换一次信息,这个信息的内容是自己定义的。<code>车</code>在能量耗尽后就消失了,而我们需要做的就是在一定的时间内,保证尽可能多的<code>车</code>存活。</p><h2 id="分析"><a class="header-anchor" href="#分析">¶</a>分析</h2><p>其实这个问题最关键的地方在于,没有一个中央的控制节点,也就是说对于每一个<code>车</code>来说都是完全平等且独立的。所以我们需要他们能够尽可能的一直处在能够交流的状态,并且都能知道<code>能量球</code>在哪里。</p><blockquote><p><strong>注意</strong><br>这个问题在没有中央控制时<strong>不存在</strong>最优解,我们只能无线接近最优解。<br>我采用的是<strong>球形模型</strong>,这个模型参考于这次作业的 <a href="https://cs.anu.edu.au/courses/comp2310/1-Labs-Assignments.html" target="_blank" rel="noopener">Examples</a>。<br>在和我的同学互相交流时,这个模型是最普遍的,解决方案是最多的,效果也是相对最好的。</p></blockquote><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure1.svg" alt="3D球形模型"></p><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure2.svg" alt="2D球形模型"></p><p>球形模型设计的两大重点是:</p><ol><li>所有的<code>车</code>都均匀平等地分布在球面上(球面是个相对概念,可以是球壳???)。</li><li>所有的<code>车</code>都能随时交流,也就是说大家形成一个通讯网络。</li></ol><h2 id="实现"><a class="header-anchor" href="#实现">¶</a>实现</h2><blockquote><p><strong>注意</strong><br>所有的 Ada 代码都是示意性的,有可能不能直接在项目中使用。</p></blockquote><h3 id="Stage-A-B"><a class="header-anchor" href="#Stage-A-B">¶</a>Stage A&amp;B</h3><p>这个阶段中,能量球只有一个,我们让所有的<code>车</code>都围绕这个能量球运动来实现一个基本的球形模型。</p><h4 id="基本程序结构Basic-Program-Structure"><a class="header-anchor" href="#基本程序结构Basic-Program-Structure">¶</a>基本程序结构Basic Program Structure</h4><p>程序基本的结构是一个死循环,每次循环分为 4 个步骤:</p><ol><li>判断<code>能量球</code>信息</li><li>发送信息</li><li>接受信息</li><li>设置目的地和油门</li></ol><h4 id="消息结构Message-Structure"><a class="header-anchor" href="#消息结构Message-Structure">¶</a>消息结构Message Structure</h4><p>最基础的消息需要包括:</p><ol><li><code>能量球</code>的信息</li><li>获得<code>能量球</code>信息的时间戳</li></ol><h4 id="中央控制Central-Control"><a class="header-anchor" href="#中央控制Central-Control">¶</a>中央控制Central Control</h4><p>允许中央控制是 Stage 1 中的条件,我在作业中跳过了这一部分,因为</p><ol><li>在允许中央控制时,该问题存在最优解,该最优解应该是一个数学问题,对我来说难度过大。</li><li>后面的 Stage 2,3,4 均不允许中央控制。</li></ol><h4 id="能量球位置估计Energy-Globe-Position-Estimation"><a class="header-anchor" href="#能量球位置估计Energy-Globe-Position-Estimation">¶</a>能量球位置估计Energy Globe Position Estimation</h4><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure3.svg" alt="能量球位置估计"></p><p>这个问题类似于一个追击问题(红球是一个匀速导弹,蓝球是拦截导弹),我们需要求的是预计追击时间$T_e$。</p><p><code>能量球</code>到追击点$P_m$,两个坐标相同,所以,</p><p>$$<br>P_m=VeT_{total}+P_e<br>$$</p><p>易得总时间,</p><p>$$<br>T_{total}=T_f-T_n+T_e<br>$$</p><p>通过边相等得,</p><p>$$<br>P_e+(T_f-T_n+T_e)V_e=V_vT_e+\frac{1}{2}A_vT_e^2+P_v<br>$$</p><p>即可解出$T_e$。</p><blockquote><p><strong>注意</strong><br>存在无法追击的情况,即($\Delta&lt;0$),因为我们这里是严格的计算,实际上整个追击过程只有 1-2 秒,并且在不断地更新<code>能量球</code>的信息,所以预计的那一段时间$T_e$通常可以忽略不计。但是在可以计算时,能够提供更加准确的预计到达时间,从而让<code>车</code>能够更加精准的决策何时去充电。</p></blockquote><h4 id="充电决策Charge-Determination"><a class="header-anchor" href="#充电决策Charge-Determination">¶</a>充电决策Charge Determination</h4><p>当同时满足以下两个条件时:</p><ol><li><code>车</code>知道<code>能量球</code>的信息</li><li><code>车</code>的预计剩余能量小于等于警戒能量</li></ol><p>预计剩余能量:</p><pre><code class="language-ada">Left_Charge := Current_Charge - Current_Discharge_Per_Sec * Estimated_Time;</code></pre><h4 id="半径决策Radius-Determination"><a class="header-anchor" href="#半径决策Radius-Determination">¶</a>半径决策Radius Determination</h4><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure4.svg" alt="半径决策"></p><p>半径向量:</p><pre><code class="language-ada">Radius_Vector := Radius_Distance * Norm (Position - Vehicle_Message.EG.Position);</code></pre><p><code>车</code>的位置:</p><pre><code class="language-ada">Destination := Vehicle_Message.EG.Position + Radius_Vector;</code></pre><p>其中有些变量的值或初始值是由经验确定的</p><ol><li><code>Radius_Distance</code>的值是<code>0.3</code>,是因为多次实验发现在 64 个128 个256 个<code>车</code>的情况下<code>0.3</code>表现均衡。</li><li><code>Destination</code>的初始值是<code>(0, 0, 0)</code>,这样能够避免一开始时<code>车</code>四散,导致失去联系,不能构成球形。</li></ol><h4 id="使用当前能量优化半径Radius-Optimization-With-Current-Charge"><a class="header-anchor" href="#使用当前能量优化半径Radius-Optimization-With-Current-Charge">¶</a>使用当前能量优化半径Radius Optimization With Current Charge</h4><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure5.svg" alt="使用当前能量优化半径"></p><pre><code class="language-ada">Radius_Vector = (0.75 + 0.25 * Current_Charge) * Radius_Vector;</code></pre><p><code>0.75</code>和<code>0.25</code>都是人为确定的,没什么依据😄。</p><h4 id="一个解决碰撞的机制A-Solution-To-Collision"><a class="header-anchor" href="#一个解决碰撞的机制A-Solution-To-Collision">¶</a>一个解决碰撞的机制A Solution To Collision</h4><blockquote><p><strong>注意</strong><br>这个机制未经过控制变量实验验证,只是理论上分析得到的。</p></blockquote><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure6.svg" alt="一个解决碰撞的机制"></p><p>因为<code>车</code>和<code>车</code>离的足够近时会发生碰撞,表现为大家都减速不动。所以当一个<code>车</code>从外层到<code>能量球</code>去加油时,周围的<code>车</code>减速会一定程度的减少碰撞的发生。</p><p>实现时,需要在消息结构中添加<code>Vehicle_Charge</code>来判断谁的能量更低。</p><h3 id="Stage-C"><a class="header-anchor" href="#Stage-C">¶</a>Stage C</h3><p>这个阶段中,能量球有两个或更多。我们遇到的新问题有:</p><ol><li>如何决策去围绕哪一个<code>能量球</code>运动</li><li>如何自适应球形模型大小的变化</li></ol><h4 id="多个能量球决策Multiple-Energy-Globes-Decision"><a class="header-anchor" href="#多个能量球决策Multiple-Energy-Globes-Decision">¶</a>多个<code>能量球</code>决策Multiple Energy Globes Decision</h4><p>当有多个<code>能量球</code>时(<code>能量球</code>还有可能凭空消失),每个<code>车</code>都要独立的选择其中一个作为他所在球形模型的球心,而且这个过程时动态的。</p><p>我们分两种情况去讨论这个问题:</p><h5 id="1-车发现了两个以上能量球"><a class="header-anchor" href="#1-车发现了两个以上能量球">¶</a>1. <code>车</code>发现了两个以上<code>能量球</code></h5><p>这种情况比较简单,我们只需要从中选择最近的哪一个即可。距离公式如下:</p><pre><code class="language-ada">distance := EG.Position + (Clock - EG_Find_Time) * EG.Velocity - Vehicle_Position</code></pre><h5 id="2-车从别的车获得的信息中有新的能量球"><a class="header-anchor" href="#2-车从别的车获得的信息中有新的能量球">¶</a>2. <code>车</code>从别的<code>车</code>获得的信息中有新的<code>能量球</code></h5><p>这种情况实际上是非常复杂的,因为存在一种情况:两个<code>车</code>说的时同一个<code>能量球</code>,但是不是同时发现的,很难判断是否是同一个<code>能量球</code>。</p><p>我们可以使用时间戳来判断获得更新的<code>能量球</code>。但是这个更新不能以时间戳作为唯一判据,因为存在一种情况,<code>车A</code>知道一个旧的<code>能量球</code>,但是发现的时间已经过去很久了,<code>车B</code>发现一个新的<code>能量球</code>,从远处靠近<code>车A</code>,时,两车交换信息,该如何选择呢?</p><p>所以,我又加入了一个失效时间,来解决上述问题。</p><pre><code class="language-ada">Clock - Vehicle_Message.EG_Update_Time &gt; Vehicle_Message_Expire_Time</code></pre><p>当上述条件为真时,<code>车</code>才会选择更新的信息。</p><h4 id="使用旋转优化Optimization-With-Rotation"><a class="header-anchor" href="#使用旋转优化Optimization-With-Rotation">¶</a>使用旋转优化Optimization With Rotation</h4><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure7.svg" alt="旋转半径"></p><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure8.svg" alt="旋转轴"></p><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure9.svg" alt="2D旋转半径"></p><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure10.svg" alt="3D旋转"></p><p>相对于静态的在球面等待,动态的在球面旋转在实验中取得了更稳定的表现。</p><blockquote><p><strong>注意</strong><br>这个优化措施可能无效,我的同学们对这个优化反应褒贬不一,但是我觉得确实让这个模型更好看啦😄</p></blockquote><p>旋转半径向量与旋转轴垂直:</p><p>$$<br>X_rX_a+Y_rY_a+Z_rZ_a=0<br>$$</p><p>易得无数个解,但是为了尽量让两个<code>车</code>不会面对面相撞(随机赋值的话),这里手动赋值$X_a$和$Y_a$为$1$,求得唯一解。</p><h4 id="自动半径适应Automatic-Radius-Adaptation"><a class="header-anchor" href="#自动半径适应Automatic-Radius-Adaptation">¶</a>自动半径适应Automatic Radius Adaptation</h4><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure11.svg" alt="通讯环"></p><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure12.svg" alt="通讯环内"></p><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/figure13.svg" alt="通讯环外"></p><p>我们在 Stage A&amp;B 中的半径是手动设置的,但是在 Stage C 中,每个球星模型的<code>车</code>的数量是动态的,如果半径不跟随数量变化,那么就有可能丢失通讯。</p><p>在理想的球星模型中,我们可以发现一个通讯环,在通讯环中的所有<code>车</code>都是互联的,并且中心的<code>能量球</code>很难突破这层环。在<code>车</code>进出通讯环时,我们可以通过当时的位置,动态修正半径大小。</p><p>我们分三种情况讨论该模型:</p><ol><li>半径过大,此时会有更多的<code>车</code>进到通讯环以内,从而使得半径变小。</li><li>半径国小,此时会有更多的<code>车</code>进到通讯环以外,从而使得半径变大。</li><li>半径正好,进到通讯环以内的<code>车</code>和进到通讯环以外的<code>车</code>大致是相同的,所以半径会稳定在某一个数值。</li></ol><p>在自动修正半径时,我们需要一个学习率参数<code>Track_Correction_Rate</code>,来确保不会因为充能量的不确定性而使得半径不稳定。</p><p>要实现该模型,我们还需要存在一个弹出通讯环的效果,即<code>车</code>在<code>能量球</code>加完能量后,弹出到通讯环外。实现如下,</p><pre><code class="language-ada">Actual_Radius_Vector := 1.5 * Rotated_Radius_Vector;</code></pre><h3 id="Stage-D"><a class="header-anchor" href="#Stage-D">¶</a>Stage D</h3><p>最后一个阶段,要求<code>车</code>之间随机协商出一定数量的<code>车</code>存活,剩下的自主“死亡“,比如一开始是 64 个,最终要求剩下 42 个。</p><p>这个问题最简单的解决方案是直接从 1 开始分配编号,按照编号顺序“死亡”就好啦,但是我觉得这个方案无法体现<code>随机</code>。</p><p>通过分析,这个类似于现在大火的<code>区块链</code>中最重要的一个问题,即分布式节点如何达成共识,解决方案也是一样的:共识算法。</p><p>推荐观看<a href="https://www.bilibili.com/video/av78588312?from=search&amp;seid=1453987515383608625" target="_blank" rel="noopener">李永乐老师:拜占庭将军问题是什么?区块链如何防范恶意节点?</a></p><h4 id="共识算法-Consensus-Algorithm"><a class="header-anchor" href="#共识算法-Consensus-Algorithm">¶</a>共识算法(Consensus Algorithm)<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup></h4><p>在这里我们仅利用共识算法的思想(不解决恶意节点问题),利用时间戳达成共识。</p><p>在<code>车</code>与<code>车</code>的通讯过程中,我们约定以下原则:</p><ol><li>在消息中添加三个字段:<code>Vehicle_No</code>数组,<code>Target_No_of_Elements</code>数组长度和<code>Vehicle_List_Update_Time</code>上一次更新时间。</li><li>所有的<code>车</code>一直都能接受和发送信息。</li><li>在最开始,所有的<code>车</code>都把自己的编号放到数组的第一个位置。</li><li>如果<code>车</code>接收到的信息与自身存储的信息不同(数组长度不同,或者上一次更新时间不同),那么按照下面的规则确定保留哪个<br>保留数组更长的那个<br>选择上一次更新时间更早的那个</li><li>检查自己的编号是否在<code>Vehicle_No</code>数组中,若不在并且仍有空间,那么就把自己的编号加进去。</li><li>在上一次更新时间又<code>Confirm_Time_Interval</code>秒后,如果数组已满并且自己的编号不在里面,那么该<code>车</code>就不能再去加能量了。</li></ol><p>经过实验,在 64 个<code>车</code>,缩减到 42 个的情况下,<code>Confirm_Time_Interval</code>设置为 1 秒就可以满足要求。</p><h2 id="结果"><a class="header-anchor" href="#结果">¶</a>结果<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup></h2><h3 id="截图"><a class="header-anchor" href="#截图">¶</a>截图</h3><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/cover.png" alt="截图"></p><h3 id="Stage-A-B-Single-Globe-In-Orbit"><a class="header-anchor" href="#Stage-A-B-Single-Globe-In-Orbit">¶</a>Stage A&amp;B(<code>Single_Globe_In_Orbit</code>)</h3><table><thead><tr><th style="text-align:center">Initial Number</th><th style="text-align:center">Target Number</th><th style="text-align:center">Duration</th><th style="text-align:center">Test times</th><th style="text-align:center">Average Result</th><th style="text-align:center">Survival Rate</th><th style="text-align:center">Average Frame Rate</th></tr></thead><tbody><tr><td style="text-align:center">32</td><td style="text-align:center">32</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">31.8</td><td style="text-align:center">0.99375</td><td style="text-align:center">30 Hz</td></tr><tr><td style="text-align:center">64</td><td style="text-align:center">64</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">63.4</td><td style="text-align:center">0.990625</td><td style="text-align:center">28 Hz</td></tr><tr><td style="text-align:center">128</td><td style="text-align:center">128</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">126.8</td><td style="text-align:center">0.990625</td><td style="text-align:center">20 Hz</td></tr><tr><td style="text-align:center">256</td><td style="text-align:center">256</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">233</td><td style="text-align:center">0.910156</td><td style="text-align:center">9 Hz</td></tr></tbody></table><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/table1.svg" alt="Stage A&amp;B"></p><h3 id="Stage-C-Random-Globes-In-Orbits"><a class="header-anchor" href="#Stage-C-Random-Globes-In-Orbits">¶</a>Stage C(<code>Random_Globes_In_Orbits</code>)</h3><table><thead><tr><th style="text-align:center">Initial Number</th><th style="text-align:center">Target Number</th><th style="text-align:center">Duration</th><th style="text-align:center">Test times</th><th style="text-align:center">Average Result</th><th style="text-align:center">Survival Rate</th><th style="text-align:center">Average Frame Rate</th></tr></thead><tbody><tr><td style="text-align:center">32</td><td style="text-align:center">32</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">26.8</td><td style="text-align:center">0.8375</td><td style="text-align:center">30 Hz</td></tr><tr><td style="text-align:center">64</td><td style="text-align:center">64</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">60.2</td><td style="text-align:center">0.940625</td><td style="text-align:center">28 Hz</td></tr><tr><td style="text-align:center">128</td><td style="text-align:center">128</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">109.2</td><td style="text-align:center">0.853125</td><td style="text-align:center">20 Hz</td></tr><tr><td style="text-align:center">256</td><td style="text-align:center">256</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">208.2</td><td style="text-align:center">0.813281</td><td style="text-align:center">9 Hz</td></tr></tbody></table><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/table2.svg" alt="Stage C"></p><h3 id="Stage-D-Random-Globes-In-Orbits"><a class="header-anchor" href="#Stage-D-Random-Globes-In-Orbits">¶</a>Stage D(<code>Random_Globes_In_Orbits</code>)</h3><table><thead><tr><th style="text-align:center">Initial Number</th><th style="text-align:center">Target Number</th><th style="text-align:center">Duration</th><th style="text-align:center">Test times</th><th style="text-align:center">Average Result</th><th style="text-align:center">Survival Rate</th><th style="text-align:center">Average Frame Rate</th></tr></thead><tbody><tr><td style="text-align:center">32</td><td style="text-align:center">42</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">24</td><td style="text-align:center">0.571429</td><td style="text-align:center">30 Hz</td></tr><tr><td style="text-align:center">64</td><td style="text-align:center">42</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">37.4</td><td style="text-align:center">0.890476</td><td style="text-align:center">28 Hz</td></tr><tr><td style="text-align:center">128</td><td style="text-align:center">100</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">83.4</td><td style="text-align:center">0.834</td><td style="text-align:center">20 Hz</td></tr><tr><td style="text-align:center">256</td><td style="text-align:center">150</td><td style="text-align:center">5 min</td><td style="text-align:center">5</td><td style="text-align:center">133</td><td style="text-align:center">0.886667</td><td style="text-align:center">9 Hz</td></tr></tbody></table><p><img src="//davidz.cn/static/blog/2020-01-11-anu-comp2310-assignment1/table3.svg" alt="Stage D"></p><h2 id="感谢"><a class="header-anchor" href="#感谢">¶</a>感谢</h2><p>感谢所有在作业中帮助过我的同学,辅导员和老师❤️。</p><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p>共识算法:<a href="https://en.wikipedia.org/wiki/Consensus_decision-making" target="_blank" rel="noopener">https://en.wikipedia.org/wiki/Consensus_decision-making</a> <a href="#fnref1" class="footnote-backref">↩︎</a></p></li><li id="fn2" class="footnote-item"><p>测试平台: 笔记本 Intel I7 处理器 @ 3.43GHz16GB 内存。因为我是用 Python 编写测试脚本,通过识别当前程序线程数量来判断<code>车</code>的数量的,所以测试结果可能不准确。 <a href="#fnref2" class="footnote-backref">↩︎</a></p></li></ol></section>]]></content>
<categories>
<category> Study </category>
</categories>
<tags>
<tag> Ada </tag>
<tag> ANU </tag>
</tags>
</entry>
<entry>
<title>Hello World</title>
<link href="/hello-world/"/>
<url>/hello-world/</url>
<content type="html"><![CDATA[<p>哈哈哈,这是一个经典的测试页面。</p><p>一直以来都想拥有一个自己的博客,从<a href="https://wordpress.org/" target="_blank" rel="noopener">WordPress</a>开始,到<a href="http://typecho.org/" target="_blank" rel="noopener">Typecho</a>,再到<a href="https://halo.run/" target="_blank" rel="noopener">Halo</a>,甚至中途尝试用 Django 自己实现了一个(不过样子也太丑了),虽然说一直在捣鼓博客,但是从来都是安装=&gt;部署=&gt;安装插件=&gt;选择主题=&gt;发布第一篇文章,然后就没有然后了。</p><p>今天我突然看到<a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>的<a href="https://github.com/TriDiamond/hexo-theme-obsidian" target="_blank" rel="noopener">Obsidian</a>主题,我觉得时机到了,毕竟颜值是第一生产力。</p><p>给自己列一个简单的 TODO LIST 吧。</p><ul class="contains-task-list"><li class="task-list-item"><input class="task-list-item-checkbox" checked="" disabled="" type="checkbox"> 完善 BLOG</li><li class="task-list-item"><input class="task-list-item-checkbox" checked="" disabled="" type="checkbox"> COMP2310 作业整理</li><li class="task-list-item"><input class="task-list-item-checkbox" checked="" disabled="" type="checkbox"> 浪潮实习</li><li class="task-list-item"><input class="task-list-item-checkbox" checked="" disabled="" type="checkbox"> 终端与 WSL</li></ul><p>希望这个寒假能做完这些吧。</p><p>就这样。</p>]]></content>
<categories>
<category> Personal </category>
</categories>
<tags>
<tag> Others </tag>
</tags>
</entry>
</search>