345 lines
107 KiB
XML
345 lines
107 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<search>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>技巧速记:Windows 10 透明效果无法正常工作</title>
|
||
<link href="/acrylic-not-working/"/>
|
||
<url>/acrylic-not-working/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="Q"><a class="header-anchor" href="#Q">¶</a>Q</h2><p>一开始我发现 <a href="https://github.com/microsoft/terminal" target="_blank" rel="noopener">Windows Terminal</a> 的 <code>useAcrylic</code> 选项无效,github 之后发现 <a href="https://github.com/microsoft/terminal/issues/1414" target="_blank" rel="noopener">Acrylic transparency not working</a>,这个 Issue 里面有好几个描述的和我一样,不仅仅是 Windows Terminal,很多系统的透明特效也都不工作。</p><p>原来,Windows Terminal 是使用 <a href="https://www.microsoft.com/design/fluent/#/" target="_blank" rel="noopener">Fluent Design</a> 里面的 Acrylic 效果实现的透明,所以说,这个问题是个系统层面的,而不是 Windows Terminal 本身的。</p><p>问题的具体表现为,除了任务栏是透明的之外,其余所有的透明特效都不工作。所以我直接到 <a href="https://github.com/microsoft/microsoft-ui-xaml" target="_blank" rel="noopener">microsoft/microsoft-ui-xaml</a> 提了一个 <a href="https://github.com/microsoft/microsoft-ui-xaml/issues/2737" target="_blank" rel="noopener">Issue</a>。</p><h2 id="A"><a class="header-anchor" href="#A">¶</a>A</h2><p><a href="https://github.com/microsoft/microsoft-ui-xaml/issues/2737#issuecomment-650471950" target="_blank" rel="noopener">解决方案</a>,把英特尔显卡控制面板里面的输入范围调整成<code>全</code>,重启电脑即可。</p>]]></content>
|
||
|
||
|
||
<categories>
|
||
|
||
<category> Workaround </category>
|
||
|
||
</categories>
|
||
|
||
|
||
<tags>
|
||
|
||
<tag> Windows </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>技巧速记:如何在Hexo中插入多行公式</title>
|
||
<link href="/multiline-equation-in-hexo/"/>
|
||
<url>/multiline-equation-in-hexo/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="Q"><a class="header-anchor" href="#Q">¶</a>Q</h2><p>我在博客中写公式的时候使用双斜线<code>\\</code>来代表换行,效果是这样的,</p><p>$$<br>\begin{bmatrix}<br>cos\theta & sin\theta \<br>-sin\theta & cos\theta<br>\end{bmatrix}<br>$$</p><pre><code class="language-latex">$$\begin{bmatrix}cos\theta & sin\theta \\-sin\theta & cos\theta\end{bmatrix}$$</code></pre><p>那么如何插入多行公式呢?</p><h2 id="A"><a class="header-anchor" href="#A">¶</a>A</h2><p>根据<a href="https://github.com/gcushen/hugo-academic/issues/291#issuecomment-334746889" target="_blank" rel="noopener">Multiple lines Mathjax formulas flattened to one line</a>,应该插入 <em>六个</em> 斜线来表示换行,应该是由于Markdown的渲染机制导致<code>\\</code>被反义。</p><p>$$<br>\begin{bmatrix}<br>cos\theta & sin\theta \\\<br>-sin\theta & cos\theta<br>\end{bmatrix}<br>$$</p><pre><code class="language-latex">$$\begin{bmatrix}cos\theta & sin\theta \\\\\\-sin\theta & cos\theta\end{bmatrix}$$</code></pre>]]></content>
|
||
|
||
|
||
<categories>
|
||
|
||
<category> Workaround </category>
|
||
|
||
</categories>
|
||
|
||
|
||
<tags>
|
||
|
||
<tag> Markdown </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>想法速记:SVD求齐次线性方程组 Ax=0 的解</title>
|
||
<link href="/SVD-for-homogeneous-linear-equation/"/>
|
||
<url>/SVD-for-homogeneous-linear-equation/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><p>众所周知,SVD(奇异值分解)可以用于最小二乘法求齐次线性方程组$A\vec{x}=\vec{0}$的解。我看了很多资料,大多使用数学公式推导,得出结论。但是,曾经线性代数差点挂科的我,总觉得有些蹊跷。想了两天,终于有了一些感性的认知(不一定是对的😂),赶紧记录下来。</p><h2 id="矩阵有何意义"><a class="header-anchor" href="#矩阵有何意义">¶</a>矩阵有何意义</h2><p>按照我的理解,一个矩阵的实际意义是对应一个线性变换,这个变换可以理解为瞬间运动。例如,一个旋转矩阵,</p><p>$$<br>A=\begin{bmatrix}<br>cos\theta & sin\theta \\\<br>-sin\theta & cos\theta<br>\end{bmatrix}<br>$$</p><p>它的意思是,把一个向量顺时针旋转$\theta$。也就是说,给定一个$\vec{v_1}=[-1, 1]^T$, 那么变换的结果就是$\vec{v_2}=A\vec{v_1}=[1, 1]^T$.</p><p>除了旋转,矩阵还可以表示包括缩放,投影在内的所有<strong>线性变换</strong>。</p><p>十分推荐大家去看 3Blue1Brown 的 <em>线性代数的本质</em>,B 站有<a href="https://www.bilibili.com/video/BV1ys411472E" target="_blank" rel="noopener">官方翻译版</a>,它完全颠覆了我对线性代数的认知。</p><h2 id="SVD到底干了什么"><a class="header-anchor" href="#SVD到底干了什么">¶</a>SVD到底干了什么</h2><p>$$<br>A = U\Sigma V^T<br>$$</p><p>SVD把矩阵$A(m\times n)$分解成了,</p><ul><li>$U(m\times m)$: 左奇异矩阵</li><li>$\Sigma(m\times n)$: 奇异值矩阵</li><li>$V(n\times n)$: 右奇异矩阵</li></ul><p>重点来了,SVD的意思就是,把一个本来由矩阵$A$表示的变换,转化成一个由$U,\Sigma,V$表示的变换。这个变换是,把一个向量,从以$V$为基向量的空间线性变换到成以$U$为基向量的空间中去($\Sigma$的意义可以说是缩放,待证实,暂时忽略)。这样我们就可以更深入的理解这个变换了。</p><p>例如旋转$\vec{v_1}$90度得到$\vec{v_2}$,</p><p><img src="//davidz.cn/static/blog/2020-06-04-SVD-for-homogeneous-linear-equation/rotate90.svg" alt="rotate 90"></p><p>其中,</p><p>$$<br>U=\begin{bmatrix}<br>0 & 1 \\\<br>1 & 0<br>\end{bmatrix}<br>$$</p><p>$$<br>\Sigma=\begin{bmatrix}<br>1 & 1<br>\end{bmatrix}<br>$$</p><p>$$<br>V=\begin{bmatrix}<br>-1 & 0 \\\<br>0 & 1<br>\end{bmatrix}<br>$$</p><p>也就是说,矩阵$A$可以被理解为,我们把一个向量$\vec{v_1}$,从以$\vec{e_1}=[-1, 0]^T,\vec{e_2}=[0, 1]^T$为基向量的空间线性变换到了以$\vec{e_1}=[0, 1]^T,\vec{e_2}=[1, 0]^T$为基向量的空间中。这个变换表现为旋转了90度。</p><h2 id="所以如何理解"><a class="header-anchor" href="#所以如何理解">¶</a>所以如何理解</h2><p>说回求齐次线性方程组$Ax=0$的解来。</p><p>按照矩阵的意义,我们这里要求的是,已知一个线性变换$A$,给定一个$\vec{x}$,使得线性变换后的结果为$\vec{0}$。</p><p>此时非常重要的是,如果$x=\vec{0}$,那一定成立,但是我们想找一个非平凡的解。</p><p>我们暂时不关心这个解是否存在,也就是说如果不存在,我们就找个最接近的(最小二乘法思想),我们直接使用SVD分解矩阵$A$,得到对应的$U,\Sigma,V$。</p><p>按照SVD的作用,我们现在可以说,矩阵$A$这个线性变换,把一个$\vec{x}$,从以$V$为基向量的空间线性变换到了以$U$为基向量的空间中,而我们想找,在以$V$为基向量的空间中,哪个向量会在投影后趋近于或者等于$\vec{0}$。更重要的是,我们只在乎这个向量的方向,而不在乎他的大小,因为它等于$\vec{0}$是个平凡解,这就像最小二乘法中,我们规定$|\vec{x}|=1$。</p><p>这时,答案就开始变得清晰了,因为我们想找的$\vec{x}$,应该就是$V$这组基向量中特异值$\sigma$最小的那一个$\vec{e_{min}}$,也就是说$\vec{x}=\vec{e_{min}}$。此时有两种情况,</p><ol><li>$\sigma=0$, 那么$\vec{x}$投影后的就是$\vec{0}$。</li><li>$\sigma\neq0$,那么$\vec{x}$投影后是使$A\vec{x}$最小的解。因为如果$\vec{x}\neq\vec{e_{min}}$,也就是说它偏离了$\vec{e_{min}}$,那么它一定由$\vec{e_{min}}$和另一个基向量线性组合,而无论怎么组合,$\sigma_{combine}\geq\sigma_{min}$。</li></ol><p>因此,我们求解$A\vec{x}=0$的过程就是,</p><ol><li>$U,\Sigma,V^T=SVD(A)$</li><li>$\vec{x}=V[:, -1]$</li></ol>]]></content>
|
||
|
||
|
||
<categories>
|
||
|
||
<category> Idea </category>
|
||
|
||
</categories>
|
||
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>技巧速记:更改 Rattle 的语言</title>
|
||
<link href="/rattle-change-language/"/>
|
||
<url>/rattle-change-language/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="Q"><a class="header-anchor" href="#Q">¶</a>Q</h2><p>如何把Rattle的语言设置成英文,从而避免显示<code>XXX</code>。</p><h2 id="A"><a class="header-anchor" href="#A">¶</a>A</h2><p>在<code>R_HOME/etc/Rprofile.site</code>的最后添加,</p><pre><code class="language-R">Sys.setenv(LANG="en")</code></pre>]]></content>
|
||
|
||
|
||
<categories>
|
||
|
||
<category> Workaround </category>
|
||
|
||
</categories>
|
||
|
||
|
||
<tags>
|
||
|
||
<tag> R </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>墙内 Jenkins 插件下载的一种解决方案</title>
|
||
<link href="/jenkins-update-solution-inside-gfw/"/>
|
||
<url>/jenkins-update-solution-inside-gfw/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="前言"><a class="header-anchor" href="#前言">¶</a>前言</h2><p>闲来无聊,在家折腾 DevOps,第一步当然是部署一个 Jenkins 啦,然而一顿操作猛如虎,插件一个都下载不下来,总不能给 Jenkins 加个代理吧,所以有了下面这一通折腾。</p><h2 id="原因"><a class="header-anchor" href="#原因">¶</a>原因</h2><p><img src="//davidz.cn/static/blog/2020-02-21-jenkins-update-solution-inside-gfw/intro.png" alt="下载超时"></p><p>根据经验,国外这些软件下载失败基本上都是因为链接不上服务器,换个源就好了。所以简单百度,找到大量相关教程,换了<a href="https://mirrors.tuna.tsinghua.edu.cn/" target="_blank" rel="noopener">清华源</a>在内的四五个镜像源,均无效。</p><p>这就非常奇怪了,所以我打开了清华源的<a href="https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json" target="_blank" rel="noopener">update-center.json</a>,仔细看了看,发现了蹊跷之处。原来,这个文件里面基本上所有插件的链接都指向了官网链接<code>http://updates.jenkins-ci.org/download/plugins/</code>。所以我们使用<code>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</code>只加速了下载这个文件的过程,而并没有加速下载插件的过程。</p><h2 id="解决方案"><a class="header-anchor" href="#解决方案">¶</a>解决方案</h2><p>那么解决方案就很简单了,我们只需要把<code>/var/jenkins_home/updates/default.json</code>这个文件中的所有</p><pre><code class="language-htmlmixed">http://updates.jenkins-ci.org/download/plugins/</code></pre><p>替换成,</p><pre><code class="language-htmlmixed">https://mirrors.tuna.tsinghua.edu.cn/jenkins/plugins/</code></pre><p>这样就好啦,但是总不能每次都自己手动替换吧,所以有下面这两个稍微复杂一点的自动化解决方案。</p><h3 id="方案-1-使用-nginx-重定向"><a class="header-anchor" href="#方案-1-使用-nginx-重定向">¶</a>方案 1 使用 nginx 重定向</h3><p>这个方法是参考的<a href="https://my.oschina.net/VASKS/blog/3106314" target="_blank" rel="noopener">jenkins 插件下载加速最终方案</a></p><p>具体我没有试,但是我之前写过 Nginx 的重定向,简单来讲就是遇到官方的地址,就重定向到清华源,配置起来稍微复杂一点。</p><h3 id="方案-2-自己搭建-Jenkins-Update-Center"><a class="header-anchor" href="#方案-2-自己搭建-Jenkins-Update-Center">¶</a>方案 2 自己搭建 Jenkins Update Center</h3><p>这个是我自己尝试出来的,原理就是我在服务器上定时(每小时)从清华源下载<code>update-center.json</code>,然后再把里面的 URL 替换成正确的地址,然后对外提供服务。</p><p>但是 Jenkins 对于<code>update-center.json</code>的地址有验证,<a href="https://github.com/jenkins-zh/mirror-adapter" target="_blank" rel="noopener">具体验证方法</a>不清楚(<s>我实在是懒的研究了</s>)。</p><blockquote><p>山重水复疑无路,柳暗花明又一村</p></blockquote><p>我在 Jenkins 的 Issue 里面找到一个<a href="https://issues.jenkins-ci.org/browse/JENKINS-11598?focusedCommentId=212431&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-212431" target="_blank" rel="noopener">老哥</a>说验证这个功能可以通过属性参数关闭,于是,这个问题就很简单啦。</p><pre><code class="language-shell">hudson.model.DownloadService.noSignatureCheck=true</code></pre><p>加上这个属性就好啦。</p><p><a href="https://jenkins-update.davidz.cn/" target="_blank" rel="noopener">具体教程</a></p><p>哈,插件全秒!😄</p>]]></content>
|
||
|
||
|
||
<categories>
|
||
|
||
<category> DevOps </category>
|
||
|
||
</categories>
|
||
|
||
|
||
<tags>
|
||
|
||
<tag> Linux </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>使用 Markdown 编写基于 Latex 的报告</title>
|
||
<link href="/write-latex-report-with-markdown/"/>
|
||
<url>/write-latex-report-with-markdown/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="前言"><a class="header-anchor" href="#前言">¶</a>前言</h2><p>计算机这个专业,有很多报告要做。在山威的时候,报告格式没有什么限制 Word,PDF 都可以,那个时候我开始使用 Markdown 作为我的排版工具,因为实在是没有时间经历去研究 Word 的各种高级功能(<s>主要是懒</s>)。Markdown 十分简单,易学,在<a href="https://github.com" target="_blank" rel="noopener">Github</a>等计算机专业相关平台使用也非常广泛,还可以通过各种模板快速生成<strong>好看</strong>,<strong>美观</strong>,<strong>专业</strong>的文档。</p><p>后来到了澳国立,老师教授们开始极力鼓吹 Latex 和 PDF,基本上算是软性要求我们使用 Latex 编写,还规定了衬线字体,非衬线字体,字号,段落等等,图片还需要是 SVG 格式的矢量图片(最奇葩的是竟然一整节课只讲这个😂),最后生成 PDF 提交(据说这样分数高一些)。所以我开始了漫漫 Latex 学习之路。然而整个过程十分痛苦,装个 TeX Live 跑了好几个小时,换个字体换的我一脸懵逼,预览竟然都不是实时的!!!我甚至觉得还不如 Word 好用,又开始找那些 Latex 编辑器(同学的 MacOS 上有很不错的,然而我是 Windows),之后是在线编辑器<a href="https://www.overleaf.com/" target="_blank" rel="noopener">Overleaf</a>,体验还行,但是一边学习 Latex 一边做实验写报告的体验实在是太差劲了,人都要<s>有丝</s>分裂了。我就先用 Markdown 记录下来,想着之后再改成 Latex 吧。然后,我用了 2 天左右的时间,找到了 Markdown 直接转报告的方法,就没再碰 Latex(<s>还是懒</s>)。</p><h2 id="样例"><a class="header-anchor" href="#样例">¶</a>样例</h2><p><a href="https://github.com/Wandmalfarbe/pandoc-latex-template/#example-images" target="_blank" rel="noopener">eisvogel 主题样例</a></p><p>你也可以从<a href="//davidz.cn/static/blog/2020-02-12-write-latex-report-with-markdown/report.pdf" target="_blank" rel="noopener">这里</a>看一下我的成果作为参考,我觉得完全符合我的要求。</p><h2 id="思路"><a class="header-anchor" href="#思路">¶</a>思路</h2><p>其实思路很简单,一切的一切都是因为<a href="https://pandoc.org/" target="_blank" rel="noopener">Pandoc</a>这个文档转换软件软件(类似于影音界的格式工厂?)的存在。它官网有一张巨型图片描述了它可以从那些格式转换成那些格式,基本上可以说覆盖了常见的所有文档格式。所以我们就可以用它把 Markown 语言写的文档转换成 PDF 格式的报告,过程中再用一套模板修饰一下就好啦。</p><blockquote><p>注意<br>Pandoc 通过 Markdown -> Latex -> PDF 的方式得到 PDF,中间文件是 Latex</p></blockquote><h2 id="准备"><a class="header-anchor" href="#准备">¶</a>准备</h2><h3 id="Markdown-语法"><a class="header-anchor" href="#Markdown-语法">¶</a>Markdown 语法</h3><blockquote><p>注意<br>Markdown 实际上和 HTML 是“近亲”,你甚至可以直接使用 HTML 标签。</p></blockquote><p>这个百度或者谷歌一下,很容易找到教程,学起来也很简单,10 分钟上手,1 天熟练。</p><h3 id="Markdown-编辑器"><a class="header-anchor" href="#Markdown-编辑器">¶</a>Markdown 编辑器</h3><p>下面这俩我都有,看心情切换😄。</p><h4 id="选项-1-VSCode"><a class="header-anchor" href="#选项-1-VSCode">¶</a>选项 1: VSCode</h4><p><img src="//davidz.cn/static/blog/2020-02-12-write-latex-report-with-markdown/vscode.png" alt="VSCode with Markdown Preview Enhanced"></p><p>微软出品,宇宙最强 IDE <code>Visual Studio</code> 的“弟弟”,宇宙最强编辑器。</p><p><a href="https://code.visualstudio.com/" target="_blank" rel="noopener">官网</a>|<a href="https://github.com/microsoft/vscode" target="_blank" rel="noopener">Github</a>下载安装包,双击安装即可。</p><p>虽然 <code>VSCode</code> 原生支持 Markdown,但是下面这几个属于增强型插件:</p><ol><li><code>Markdown Preview Enhanced</code>,增强对 Markdown 的预览。</li><li><code>Code Spell Checker</code>,检查你报告里的拼写错误(不过只支持英文)。</li><li><code>Markdownlint</code>,检查 Markdown 的语法规范(强迫症专属)。</li></ol><h4 id="选项-2-Typora"><a class="header-anchor" href="#选项-2-Typora">¶</a>选项 2: Typora</h4><p><img src="//davidz.cn/static/blog/2020-02-12-write-latex-report-with-markdown/typora.png" alt="Typora"></p><p>写作体验一级棒👍。</p><p><a href="https://www.typora.io/" target="_blank" rel="noopener">官网</a>下载安装包,双击安装即可。</p><h3 id="Latex-Engine"><a class="header-anchor" href="#Latex-Engine">¶</a>Latex Engine</h3><blockquote><p>注意<br>Latex 是个语言规范,Latex Engine 是它的实现,下面这俩都是 Latex Engine 的集合</p></blockquote><p>因为 Scoop 里面只有 MiKTeX,所以我选择 MiKTeX。反正我只是写个报告,选哪个应该都无所谓吧。</p><h4 id="选项-1-MiKTeX"><a class="header-anchor" href="#选项-1-MiKTeX">¶</a>选项 1: MiKTeX</h4><p>通过 Scoop 安装:</p><pre><code class="language-powershell">scoop install latex</code></pre><p>或者<a href="https://miktex.org/" target="_blank" rel="noopener">官网</a>下载安装。</p><h4 id="选项-2-TeX-Live"><a class="header-anchor" href="#选项-2-TeX-Live">¶</a>选项 2: TeX Live</h4><p><a href="http://tug.org/texlive/" target="_blank" rel="noopener">官网</a>下载安装。</p><h3 id="Pandoc"><a class="header-anchor" href="#Pandoc">¶</a>Pandoc</h3><p>这个就是前文所说的万能文档格式转换器软件了。</p><p>通过 Scoop 安装:</p><pre><code class="language-powershell">scoop install pandoc</code></pre><p>或者<a href="https://www.pandoc.org/" target="_blank" rel="noopener">官网</a>下载安装。</p><p>用到的过滤器(类似于插件):</p><ol><li><a href="https://github.com/lierdakil/pandoc-crossref" target="_blank" rel="noopener">pandoc-crossref</a>,用于 pandoc 中的交叉引用,图片,公式,章节等,这个我也是用 Scoop 安装的,没有 Scoop 的话看看<a href="https://github.com/lierdakil/pandoc-crossref#installation" target="_blank" rel="noopener">安装教程</a>吧。</li></ol><h3 id="Eisvogel-主题"><a class="header-anchor" href="#Eisvogel-主题">¶</a>Eisvogel 主题</h3><p><img src="//davidz.cn/static/blog/2020-02-12-write-latex-report-with-markdown/eisvogel.png" alt="Eisvogel"></p><p>这个是我找到的计算机专业风格的论文/报告/书籍/幻灯片的开源模板,对于我来说是真的很合适了,美观,简约又专业。</p><p><a href="https://github.com/Wandmalfarbe/pandoc-latex-template" target="_blank" rel="noopener">Github Release</a>下载,放到<a href="https://github.com/Wandmalfarbe/pandoc-latex-template#installation" target="_blank" rel="noopener">指定路径</a>就完了,很简单。</p><h2 id="配置"><a class="header-anchor" href="#配置">¶</a>配置</h2><pre><code class="language-YAML">---title: COMP 2310 Assignment 1 Reportauthor: Jiahao Zhang U6921098date: Sept. 27, 2019documentclass: articlepapersize: a4geometry: margin=2cmmainfont: Calibrifontsize: 10pttitlepage: trueheader-right: Jiahao Zhang U6921098footer-left: Australian National UniversityautoSectionLabels: truelistings: truesubfigGrid: true---</code></pre><p>在每个 Markdown 文件最上面形如上面 YAML 代码的叫做<code>YAML Front Matter</code>,可以理解为对全文的配置。这里主要是一些对<a href="https://www.pandoc.org/MANUAL.html#variables" target="_blank" rel="noopener">Pandoc 的配置</a>以及对<a href="https://github.com/Wandmalfarbe/pandoc-latex-template#custom-template-variables" target="_blank" rel="noopener">Eisvogel 主题的配置</a>。</p><h2 id="生成"><a class="header-anchor" href="#生成">¶</a>生成</h2><p>运行下面的命令就可以生成 PDF 啦😄。</p><pre><code class="language-powershell">pandoc Report.md `-o Report.pdf `--standalone `--listings `--number-sections `--pdf-engine=xelatex `--filter pandoc-crossref `--template eisvogel</code></pre><p>简单解释一下,</p><ul><li><code>-o</code> 指定输出文件</li><li><code>--standalone</code> 独立完整文件</li><li><code>--listings</code> 使用<a href="https://ctan.org/pkg/listings" target="_blank" rel="noopener">listings</a>高亮代码</li><li><code>--number-sections</code> 启用段落编号</li><li><code>--pdf-engine=xelatex</code> 指定 PDF 的 engine 为 <code>xelatex</code></li><li><code>--filter pandoc-crossref</code> 指定过滤器为 <code>pandoc-crossref</code></li><li><code>--template eisvogel</code> 指定模板为 <code>eisvogel</code></li></ul><h2 id="想法"><a class="header-anchor" href="#想法">¶</a>想法</h2><p>完整的捣鼓下来其实也和学习 Latex 难度差不多了,但是配置完了这一套,只要要求不变,我再写报告的速度会加快很多很多,因为我只需要专注的写 Markdown 就好了😄。</p><p>PS: 这个博客所有的文章就是使用 Markdown 编写的。</p>]]></content>
|
||
|
||
|
||
<categories>
|
||
|
||
<category> Productivity </category>
|
||
|
||
</categories>
|
||
|
||
|
||
<tags>
|
||
|
||
<tag> Windows </tag>
|
||
|
||
<tag> Markdown </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>卸载浪潮安装的 IP-GUARD 监控软件</title>
|
||
<link href="/inspur-ip-guard-uninstallation/"/>
|
||
<url>/inspur-ip-guard-uninstallation/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="前言"><a class="header-anchor" href="#前言">¶</a>前言</h2><blockquote><p>屋漏更遭连夜雨,船迟又遇打头风。</p></blockquote><p>刚刚处理完 Docker 里面的“病毒”,又发现自己的笔记本被安装了监控软件,身后一阵凉风。</p><h2 id="发现"><a class="header-anchor" href="#发现">¶</a>发现</h2><blockquote><p>事发突然,因为影响我开发,所以也没有来得及截图。</p></blockquote><p>为了使用 WSL2 里面的 Docker,我加入了 <code>Windows 预览体验计划 - 慢</code>,把系统升级到了 Windows 10 2004。结果怪事就出现了——基本上所有的命令行都会在执行前显示一个错误。</p><pre><code class="language-shell">ANOMALY: use of REX.w is meaningless (default operand size is 64)</code></pre><p>从来没见过这个错误,我进入安全模式发现竟然也会报错,在百度 + 谷歌 + stackoverflow 依然无任何有效答案后,陷入了绝望😢。</p><p>本来呢,这个只是报个错,并不是什么大问题(<s>我本身有一点强迫症,不能忍</s>),但是 JetBrains 全家桶全部报错找不到 Git,CLion 报错找不到 VS。这就严重影响我开发了。Windows 预览体验计划还非常坑,不能回退,于是我又尝试了<code>Windows 预览体验计划 - 快</code>,结果问题依旧。</p><p>终于我突发奇想在 Github 上搜了一下(<s>不是到我当时咋想的,病急乱投医把</s>),发现了一个叫<a href="https://github.com/martona/mhook" target="_blank" rel="noopener">mhook</a>的项目,在其类库代码中发现了<a href="https://github.com/martona/mhook/blob/master/disasm-lib/disasm_x86.c#L1749" target="_blank" rel="noopener">disasm_x86</a>这个文件,在第 1749 行发现了错误提示的源代码。</p><pre><code class="language-c">if (!SuppressErrors) printf("[0x%08I64X] ANOMALY: use of REX.w is meaningless (default operand size is 64)\n", VIRTUAL_ADDRESS);</code></pre><p>现在我大体知道了这个问题产生的原因。</p><ol><li>disasm 是一个 hook(钩子)库,可以注入到别的程序。</li><li>更新系统后,这个钩子库和新的系统发生了冲突,于是报错,理论上所有被注入的程序都会报错。</li><li>这个钩子应该是个<strong>监控软件</strong>或者病毒木马之类的。</li></ol><p>我想起了在浪潮实习的时候,我的老师给我说浪潮作为面向政府国企的公司,对内部信息安全非常重视,所以会在员工的电脑里面安装监控软件,监控员工的一举一动,我当时感觉应该不会对实习生下手吧,想不到。。。回想起来,应该是入职浪潮的时候安装的那个上网小助手吧。</p><p>于是我下载了<a href="https://www.freefixer.com/" target="_blank" rel="noopener">freefixer</a>,查找注入的钩子,果不出其然,发现了在系统中安装的<a href="http://www.ip-guard.net/" target="_blank" rel="noopener">IP-GUARD</a>。按照官网的介绍,监控能力之强,范围之广令人汗颜,从网络到文件,邮件,应用等等,简直神通广大。</p><h2 id="处理"><a class="header-anchor" href="#处理">¶</a>处理</h2><p>我已经离职多日,第一时间肯定是卸载这个监控软件,直接删除文件肯定不行,结果 freefixer 也卸不掉(卸载完重启又出现),没有办法,只能到 WinPE 中手动逐一筛查,删除。</p><p>基本步骤如下</p><h3 id="1-进入-WinPE"><a class="header-anchor" href="#1-进入-WinPE">¶</a>1. 进入 WinPE</h3><blockquote><p>安全模式也会打开例如 explorer.exe 这样的系统进程,而监控软件也注入到了其中,所以安装全模式也不能删除</p></blockquote><p>这里免费帮<a href="https://www.itsk.com/forum.php?mod=viewthread&tid=404842" target="_blank" rel="noopener">优启通</a>做个广告。</p><p>下载上面这个 PE 安装到本地或者 U 盘 都行,然后重启进入 WinPE 就好了。</p><h3 id="2-到系统盘中删除对应的所有文件"><a class="header-anchor" href="#2-到系统盘中删除对应的所有文件">¶</a>2. 到系统盘中删除对应的所有文件</h3><p>想不到这个公司还是很良心的,所有程序文件都签了名,在 freefixer 上查得到,叫<a href="https://www.freefixer.com/library/publisher/t.e.c%20solutions%20(g.z.)limited/" target="_blank" rel="noopener">T.E.C Solutions (G.Z.)Limited</a>。</p><blockquote><p>下面这些文件都是在 freefixer 上有记录的文件,可以作为检测 IP-GUARD 是否安装的标志。</p></blockquote><table><thead><tr><th style="text-align:center">File Name</th></tr></thead><tbody><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/ONacAgent.exe-211770/" target="_blank" rel="noopener">ONacAgent.exe</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/TIjtdrvd64.dll-261434/" target="_blank" rel="noopener">TIjtdrvd64.dll</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/thooksv364.dll-261436/" target="_blank" rel="noopener">thooksv364.dll</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/ONacAgent.exe-206855/" target="_blank" rel="noopener">ONacAgent.exe</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/winhadnt64.dll-95360/" target="_blank" rel="noopener">winhadnt64.dll</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/DtFrame32.dll-206842/" target="_blank" rel="noopener">DtFrame32.dll</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/winrdgv3.exe-122257/" target="_blank" rel="noopener">winrdgv3.exe</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/winrdlv3.exe-177929/" target="_blank" rel="noopener">winrdlv3.exe</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/winhafnt64.dll-211772/" target="_blank" rel="noopener">winhafnt64.dll</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/TIjtdrvd64.dll-211775/" target="_blank" rel="noopener">TIjtdrvd64.dll</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/ipnpf.sys-225950/" target="_blank" rel="noopener">ipnpf.sys</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/thooksv364.dll-211779/" target="_blank" rel="noopener">thooksv364.dll</a></td></tr><tr><td style="text-align:center"><a href="https://www.freefixer.com/library/file/winhadnt.dll-239634/" target="_blank" rel="noopener">winhadnt.dll</a></td></tr></tbody></table><p>我们可以利用 Windows Explorer 的按公司分组,快速找到所有相关文件。</p><ol><li>打开系统盘(这里假设是 C 盘),右键 - 分组依据 - 更多 - 勾选 公司 - 确定。</li><li>右键 - 分组依据 - 公司。</li><li>查看 - 选项 - 查看 - 应用到文件夹。</li><li>在下面的路径中找到所有公司为<code>T.E.C Solutions (G.Z.)Limited</code>的文件,删除。</li></ol><pre><code class="language-cmd">C:\Program Files\Common Files\SystemC:\Program Files (x86)\Common Files\SystemC:\WINDOWSC:\WINDOWS\System32C:\WINDOWS\System32\driversC:\WINDOWS\SysWOW64C:\WINDOWS\SysWOW64\drivers</code></pre><h3 id="3-重启"><a class="header-anchor" href="#3-重启">¶</a>3. 重启</h3><p>再次运行 freefixer 检查是否删干净了。</p><h2 id="想法"><a class="header-anchor" href="#想法">¶</a>想法</h2><p>像浪潮这样主要客户是政府,国企的企业,确实需要证明其安全能力,在他的员工的电脑上安装监控软件确实是有效措施,我能够理解。但是,这么大一企业,安装监控时没有主动告知(至少应该告知监控我的哪些行为),毕竟是我自己私人的笔记本,不是企业配发的,也没让我签字。离职时就算知道了也找不到卸载方法(那个上网小助手也是我进入安全模式手动删除的,因为正常卸载需要密码,我嫌麻烦就自己删了),所有面向实习生的文档教程都只有安装方法,我不知道是不是因为实习生的缘故,全程只有我的那个老师给我口头说了一声,我现在感觉自己受到了欺骗,个人隐私受到了严重侵犯,很难受,同时也非常生气,可是又很无力,因为这件事情可大可小,从网上的评论来看在各大企业中都很正常。</p><p>希望这样的事情以后不会发生了吧。🙏</p>]]></content>
|
||
|
||
|
||
<categories>
|
||
|
||
<category> Internship </category>
|
||
|
||
</categories>
|
||
|
||
|
||
<tags>
|
||
|
||
<tag> Windows </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>"寄生"于 Docker 的病毒 - Kinsing</title>
|
||
<link href="/kinsing-virus/"/>
|
||
<url>/kinsing-virus/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="前言"><a class="header-anchor" href="#前言">¶</a>前言</h2><p>2020 年开年不顺,2019 新型冠状病毒肺炎爆发,从年三十居家隔离到了正月十五,没想到自己的服务器也”感染“上了病毒 - Kinsing(进程的名字,姑且这样称呼)。</p><h2 id="发现"><a class="header-anchor" href="#发现">¶</a>发现</h2><p><img src="//davidz.cn/static/blog/2020-02-10-kinsing-virus/netdata.png" alt="netdata"></p><p>偶然看了看服务器状态,发现 CPU 占用一直保持在 100%上下,有些蹊跷。</p><p>难道是我的博客访问量<s>暴增</s>???那是当然不可能的,然后我去看了看<a href="https://github.com/portainer/portainer" target="_blank" rel="noopener">Portainer</a>看了看,果然,</p><p><img src="//davidz.cn/static/blog/2020-02-10-kinsing-virus/portainer.png" alt="portainer"></p><p>这个随机名称的容器就是 Kinsing 基于 Ubuntu 的容器,CPU 占用 100%。</p><p><img src="//davidz.cn/static/blog/2020-02-10-kinsing-virus/process.png" alt="进程"></p><p>简单看了看容器里面的进程表,第一个运行了一个 shell 脚本,这个病毒就是这个脚本下载启动的关键,我打开看了看,<s>也没看懂</s>,大概是下载了几个可执行文件。第二个是 cron,这个是定时脚本,我猜应该是病毒定时检查一下运行情况?第三个好像是个守护进程,第四个应该是用于容器保持,第五个在网上能搜到,是个<a href="https://www.baidu.com/s?wd=kdevtmpfsi" target="_blank" rel="noopener">挖矿的程序</a>。</p><p>无聊的我还简单看了看这个脚本的服务器 IP,</p><p><img src="//davidz.cn/static/blog/2020-02-10-kinsing-virus/ip.png" alt="ip"></p><p>难道是俄罗斯大佬???</p><p>这个时候我突然想起来,前几天为了调试<a href="https://certbot.eff.org/" target="_blank" rel="noopener">certbot</a>的 Dockerfile, 我直接打开了 Docker 的<a href="https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-socket-option" target="_blank" rel="noopener">远程访问</a>,在默认的情况下是没有任何加密措施的。</p><p>这样,就真相大白了,这个病毒通过未加密的接口,在我的服务器上运行了挖矿的容器来盈利,同时也占用了服务器全部的 CPU😢.</p><h2 id="处理"><a class="header-anchor" href="#处理">¶</a>处理</h2><p>Kinsing 病毒还是很良心的(至少我遇到的这个是),把自己”关“在了容器里面,反正后来我也没有在别的地方发现相关文件。</p><p>所以处理起来也简单,</p><ol><li>删掉容器和镜像</li><li>关闭 Docker 远程访问即可。如果不想关闭的话也可以<a href="https://docs.docker.com/engine/security/https/" target="_blank" rel="noopener">用 https 的方式加密</a>。</li></ol><h2 id="小想法"><a class="header-anchor" href="#小想法">¶</a>小想法</h2><p>其实这个 Kinsing 病毒实现起来还是很简单的,</p><ol><li>扫描全网的 2375 这个默认端口</li><li>用 Docker API 连接并部署容器</li><li>执行脚本运行挖矿程序</li></ol><p><s>突然有一个邪恶的想法,一台机器一天就算 1 毛钱好啦</s>,哈哈哈,但是违法的事情不能做呀😄。</p><p>大家一定要注意呀,时刻谨记服务器安全,不要随意开放服务器端口。</p>]]></content>
|
||
|
||
|
||
<categories>
|
||
|
||
<category> DevOps </category>
|
||
|
||
</categories>
|
||
|
||
|
||
<tags>
|
||
|
||
<tag> Linux </tag>
|
||
|
||
<tag> Shell </tag>
|
||
|
||
<tag> Docker </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>Windows 包管理器 - Scoop</title>
|
||
<link href="/windows-package-manager-scoop/"/>
|
||
<url>/windows-package-manager-scoop/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="前言"><a class="header-anchor" href="#前言">¶</a>前言</h2><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 <bucket-name></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> - 不同版本的 JDK,JRE。</li><li><code>games</code> - 开源或免费的游戏以及游戏工具。</li><li><code>jetbrains</code> - JetBrains 全家桶。</li></ol><h2 id="使用"><a class="header-anchor" href="#使用">¶</a>使用</h2><p>和 Ubuntu 的 apt,CentOS 的 yum 基本相同。</p><pre><code class="language-powershell"># 搜索scoop search <package-name># 查看主页scoop home <package-name># 安装scoop install <package-name># 更新scoop update <package-name># 卸载scoop uninstall <package-name># 更新 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,实现"软连接"。</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&wd=&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">{ "homepage": "https://www.7-zip.org/", "description": "A multi-format file archiver with high compression ratios", "license": { "identifier": "Freeware,LGPL-2.0-only,BSD-3-Clause", "url": "https://www.7-zip.org/license.txt" }, "version": "19.00", "architecture": { "64bit": { "url": "https://7-zip.org/a/7z1900-x64.msi", "hash": "a7803233eedb6a4b59b3024ccf9292a6fffb94507dc998aa67c5b745d197a5dc" }, "32bit": { "url": "https://7-zip.org/a/7z1900.msi", "hash": "b49d55a52bc0eab14947c8982c413d9be141c337da1368a24aa0484cbb5e89cd" } }, "extract_dir": "Files/7-Zip", "bin": "7z.exe", "checkver": { "url": "https://www.7-zip.org/download.html", "regex": "Download 7-Zip ([\\d.]+)" }, "autoupdate": { "architecture": { "64bit": { "url": "https://7-zip.org/a/7z$cleanVersion-x64.msi" }, "32bit": { "url": "https://7-zip.org/a/7z$cleanVersion.msi" } } }, "shortcuts": [["7zFM.exe", "7-Zip"]]}</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>
|
||
|
||
<tag> Windows </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[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="回顾"><a class="header-anchor" href="#回顾">¶</a>回顾</h2><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>下载&安装</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">{ "$schema": "https://aka.ms/terminal-profiles-schema", "defaultProfile": "{807502AB-0C92-4DF7-9C7C-1E9F7A2A47DE}", // 默认配置的 GUID, 和下面的 profiles.list 中的一个相同 "alwaysShowTabs": true, // 无论有几个 tab 是否都显示标签栏 "requestedTheme": "dark", // "light","dark","system" "copyOnSelect": true, // 选择时复制 "launchMode": "maximized", // "maximized","default" "profiles": { // shell 或程序的配置 "defaults": { // 所有 shell 或程序配置的默认值 "acrylicOpacity": 0.7, // 背景透明度 "useAcrylic": true, // 是否启用透明背景 "colorScheme": "One Half Dark", // 色彩配置,和下面 schemes 中的一个相同 "fontFace": "JetBrains Mono", // 字体 "fontSize": 12, // 字号 "startingDirectory": ".", // 工作路径,设置成 “.” 可以实现在资源管理器的地址栏输入 wt 直接打开时工作目录是当前目录 "closeOnExit": "always" // "never","graceful","always" }, "list": [ { "guid": "{807502AB-0C92-4DF7-9C7C-1E9F7A2A47DE}", // 唯一 GUID "name": "powershell core", // 在下拉框中显示的名称 "commandline": "pwsh.exe -nol", // 执行的命令,-nol 的作用是不显示 Microsoft 那些提示 "icon": "path/to/icon" // 标签栏和下拉菜单中显示的图标 }, { "guid": "{85933BC0-E5D2-4299-9FBC-AC6C9F6DFD46}", "name": "davidz.cn", "commandline": "ssh.exe root@davidz.cn", // ssh 也可以,用于代替 Putty "icon": "path/to/icon" } ] }, "schemes": [ // 配色 { "name": "One Half Dark", // 我最喜欢的主题,Vscode,VS,JetBrains 全家桶都有类似主题,关键词 atom one dark "background": "#282C34", "black": "#282C34", "blue": "#61AFEF", "brightBlack": "#5A6374", "brightBlue": "#61AFEF", "brightCyan": "#56B6C2", "brightGreen": "#98C379", "brightPurple": "#C678DD", "brightRed": "#E06C75", "brightWhite": "#DCDFE4", "brightYellow": "#E5C07B", "cyan": "#56B6C2", "foreground": "#DCDFE4", "green": "#98C379", "purple": "#C678DD", "red": "#E06C75", "white": "#DCDFE4", "yellow": "#E5C07B" } ]}</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> 之与 zsh,PowerShell 也有自己的配置文件<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 才终于知道了还有像 zsh,fish 这样更加人性化的 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> Windows </tag>
|
||
|
||
<tag> Terminal </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>浪潮实习</title>
|
||
<link href="/inspur-internship/"/>
|
||
<url>/inspur-internship/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><h2 id="前言"><a class="header-anchor" href="#前言">¶</a>前言</h2><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 & 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 [<options>] <path-to-source> cmake [<options>] <path-to-existing-build> cmake [<options>] -S <path-to-source> -B <path-to-build>Build a Project cmake --build <dir> [<options>] [-- <build-tool-options>]Install a Project cmake --install <dir> [<options>]Open a Project cmake --open <dir>Run a Script cmake [{-D <var>=<value>}...] -P <cmake-script-file>Run a Command-Line Tool cmake -E <command> [<options>]Run the Find-Package Tool cmake --find-package [<options>]View Help cmake --help[-<topic>]</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"><TargetName>: gcc <arg1> <arg2> ... <file> g++ <arg1> <arg2> ... <file> gcc <arg1> <arg2> ... <file></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 的 pip,Nodejs 的 npm,总而言之就是个依赖包管理器。主要适用于解决开发依赖问题。</p><p>比如安装一个 poco,原来你需要下载源码->编译源码->把文件放进项目->修改编译链接选项,然后才能用,现在你只需要</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>,它有一个致命问题是,不支持版本管理,每个库都是由一个文件指定的,而不是像 pip,npm 之类的,有个在线仓库,所以,你 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 上 shell,systemctl,docker 这些工具以及 CFEngine, Zabbix 这些运维的东西,感觉又喜欢上了 Linux 和命令行,熟悉了之后真是很方便。</p><p>同时因为是 C/Cpp 项目,我们编译了很多开源项目,算是终于知道了 Linux 根目录下面每个目录都是干啥的。</p><p>Linux 下的包管理器比如 apt,yum 用起来也很爽。所以我也看了看 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> Windows </tag>
|
||
|
||
<tag> Cpp </tag>
|
||
|
||
<tag> Linux </tag>
|
||
|
||
</tags>
|
||
|
||
</entry>
|
||
|
||
|
||
|
||
<entry>
|
||
<title>ANU COMP2310(2019) Assignment 1</title>
|
||
<link href="/anu-comp2310-assignment1/"/>
|
||
<url>/anu-comp2310-assignment1/</url>
|
||
|
||
<content type="html"><![CDATA[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><blockquote><p><strong>敬告</strong></p><div style="color: red">本博客仅供参考,请不要抄袭。</div></blockquote><h2 id="前言"><a class="header-anchor" href="#前言">¶</a>前言</h2><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&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<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 > 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&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&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&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&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.43GHz,16GB 内存。因为我是用 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[<blockquote><p>原创发表于 <a href="https://blog.davidz.cn">DavidZ Blog</a>,遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode" target="_blank" rel="noopener">CC 4.0 BY-NC-SA</a> 版权协议,转载请附上原文出处链接及本声明。</p></blockquote><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 自己实现了一个(不过样子也太丑了),虽然说一直在捣鼓博客,但是从来都是安装=>部署=>安装插件=>选择主题=>发布第一篇文章,然后就没有然后了。</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>
|