<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">

    <channel>
        <title>news view</title>
        <link>https://zsqk.github.io/news/</link>
        <description>每日新闻.</description>
        <lastBuildDate>Tue, 10 Nov 2026 01:49:20 +0000</lastBuildDate>
        
        <item>
            <title>Cloudflare Workers 處理函數計算中的 CPU 性能問題</title>
            <link>
                https://zsqk.github.io/2025-10-16-cf-worker-cpu.html
            </link>
            <description>
                &lt;p&gt;原文:
&lt;a href=&quot;https://blog.cloudflare.com/unpacking-cloudflare-workers-cpu-performance-benchmarks/&quot;&gt;https://blog.cloudflare.com/unpacking-cloudflare-workers-cpu-performance-benchmarks/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;原文主要講述了 Cloudflare Workers 和 Vercel 在 CPU 性能方面的一些對比,
在應用上的重點是 React SSR 類應用的 TTFB 測試.&lt;/p&gt;

&lt;p&gt;其中我認為的一些關鍵點是:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;函數計算的調度問題 (非 CPU 計算消耗).&lt;/li&gt;
  &lt;li&gt;Node.js 對 V8 調參導致的性能問題.&lt;/li&gt;
  &lt;li&gt;代碼中處理 buffer 不當導致的內存佔用及後續 GC 的問題.&lt;/li&gt;
  &lt;li&gt;Node.js 的非 Web 標準化問題, 比如 Streams API.&lt;/li&gt;
  &lt;li&gt;Cloudflare Workers 團隊在解決自己問題的過程中如果發現了生態問題, 甚至竟品問題,
也期望一併解決.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;我們的核心業務均由函數計算承擔, 在此處有許多經驗. 函數計算中的幾大時間消耗為:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;調度時間&lt;/li&gt;
  &lt;li&gt;(可能) 冷啟動時間&lt;/li&gt;
  &lt;li&gt;執行時間 (被計算為 CPU 消耗)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;一般來說, “執行時間” 與函數計算無關. 函數計算需要重點考慮的, 是 “調度時間” 和
“冷啟動時間”.&lt;/p&gt;

&lt;p&gt;作為用戶, 一些配置會影響到調度時間, 比如使用什麼操作系統, 是否要接入 VPC 等.&lt;/p&gt;

&lt;p&gt;想要優化冷啟動時間, 則應該將重點放在 “架構” 上. 一般來說, 解釋型語言的冷啟動時間會小很多.
比如函數計算一般使用 Python, JavaScript, 而不使用 Java.&lt;/p&gt;

&lt;p&gt;另外一種優化就是 “預熱”, 可以理解為提前啟動. 但是預熱是有成本開銷的,
並且我認為預熱是有悖於函數計算模式的. 我更傾向於減少冷啟動時間, 而不是預熱.&lt;/p&gt;

&lt;p&gt;Cloudflare Workers 針對調度問題的優化, 是所有用戶樂於看到的. 加量不加價,
並且默認生效, 用戶無需任何額外配置.&lt;/p&gt;

&lt;p&gt;Node.js 的非 Web 標準化問題, 就是我們幾年前選型 Deno, 而非 Node.js 的關鍵原因.
即便我們不是全棧團隊, 也希望在 JS 領域, 技術棧儘量統一, 減少不必要的消耗.&lt;/p&gt;

&lt;p&gt;最後, 看到問題就想要去解決, 無論這個問題是否影響到自身利益,
這不僅是工程師應該有的素質, 也是每一個人應該有的素質.
就像走路時如果看到了腳邊的垃圾, 可以順手撿起來扔到垃圾箱中.&lt;/p&gt;

&lt;p&gt;不是鼓勵大家無償奉獻, 而是舉手之勞, 何樂而不為?
每個人多付出 1%, 就會讓整個世界進步不只 100%.&lt;/p&gt;

            </description>
            <pubDate>Thu, 16 Oct 2025 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2025-10-16-cf-worker-cpu.html
            </guid>
        </item>
        
        <item>
            <title>Deno Fresh 2.x 支持 Vite</title>
            <link>
                https://zsqk.github.io/2025-09-03-deno-fresh-vite.html
            </link>
            <description>
                &lt;p&gt;Update:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;目前 Fresh 文檔默認的版本已經是 2.x.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;在許多前端項目中, 都使用 Vite 處理構建流程.&lt;/p&gt;

&lt;p&gt;對於 Deno 團隊來說, Node.js 生態下的項目, 如 ESLint 等一直是受到排斥的.
基於零配置易用性及性能考慮, Deno 會在相關領域重做一套工具, 比如 deno lint, fmt.&lt;/p&gt;

&lt;p&gt;不過隨著 Deno 對 Node.js 兼容性的增強, Deno 團隊對 Node.js 生態也越來越包容.&lt;/p&gt;

&lt;p&gt;現在, Deno 官方項目 Fresh 會主動集成 Vite (而不是 deno compile 或者剛剛恢復的 deno bundle).&lt;/p&gt;

&lt;p&gt;官方 Blog 文章: &lt;a href=&quot;https://deno.com/blog/fresh-and-vite&quot;&gt;Fresh 2.0 Graduates to Beta, Adds Vite Support&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deno compile&lt;/code&gt; 一直沒有實現一鍵打包 Deno Fresh 項目. 或許跟 Fresh 特殊的路由策略有關.&lt;/p&gt;

&lt;p&gt;但是 Vite 是支持在編譯時處理動態路由並且打包的, 也支持代碼分割.&lt;/p&gt;

&lt;p&gt;在官方文章中, 主要介紹了下面幾個功能:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;藉助 Vite 的 島內熱加載, 而不是全頁熱加載.&lt;/li&gt;
  &lt;li&gt;藉助 Vite 的 服務器代碼打包, 加快啟動時間.&lt;/li&gt;
  &lt;li&gt;藉助 Vite 的 React 別名.&lt;/li&gt;
  &lt;li&gt;迴歸的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Head&lt;/code&gt; 組件&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Fresh 2.0 正式進入 beta, 不再會有重大變動. 現在就可以嘗試了.&lt;/p&gt;

            </description>
            <pubDate>Wed, 03 Sep 2025 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2025-09-03-deno-fresh-vite.html
            </guid>
        </item>
        
        <item>
            <title>TypeScript 使用 Go 進行了重構</title>
            <link>
                https://zsqk.github.io/2025-03-13-typescript-go.html
            </link>
            <description>
                &lt;p&gt;我在 GitHub 上看到了 @ahejlsberg 為 &lt;a href=&quot;https://github.com/microsoft/typescript-go&quot;&gt;https://github.com/microsoft/typescript-go&lt;/a&gt;
project 點了 star.&lt;/p&gt;

&lt;p&gt;在 11 日, TypeScript 官方博客發佈了一篇名為 &lt;a href=&quot;https://devblogs.microsoft.com/typescript/typescript-native-port/&quot;&gt;A 10x Faster TypeScript&lt;/a&gt;
的文章, 介紹了微軟正在使用 Go 語言重寫 TypeScript 編譯器, 並取得了顯著的性能提升.&lt;/p&gt;

&lt;p&gt;Anders Hejlsberg 是 TypeScript 的主要設計者, 也是 C# 和 Delphi 的最初設計者.
為瞭解決性能問題, 他帶領的團隊沒有使用 C# 或者 Rust 等語言, 而是使用了 Go,
在社區中引起了一些質疑的聲音.&lt;/p&gt;

&lt;p&gt;我認為最重要的原因就是新項目是 “port”, 而不是 “rewrite”. 在一眾備選項中,
Go 的語法是最容易從 TypeScript 遷移過去的.&lt;/p&gt;

&lt;p&gt;我理解微軟開發團隊這樣的做法, 比如 VS Code 在宣傳的時候也會使用 create-react-app
這樣的 Facebook 項目來宣傳. 可見, 微軟想要與技術社區進行融合的意願很強.&lt;/p&gt;

&lt;h2 id=&quot;為什麼選擇-go&quot;&gt;為什麼選擇 Go?&lt;/h2&gt;

&lt;p&gt;根據 TypeScript 官方博客 &lt;a href=&quot;https://devblogs.microsoft.com/typescript/typescript-native-port/&quot;&gt;A 10x Faster TypeScript&lt;/a&gt; 的介紹, 微軟選擇
Go 語言進行編譯器移植的原因主要包括:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;可維護性&lt;/strong&gt;: Go 語言擁有高效且易於理解的垃圾收集器, 簡單易學的語法以及良好的
開發者生態系統, 使得維護大型代碼庫更加容易&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;性能優勢&lt;/strong&gt;: Go 編譯器的多方面優化使其非常適合構建編譯器這類程序, 並且與
JavaScript 版本相比, 能夠顯著提高編譯速度&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;跨平臺能力&lt;/strong&gt;: Go 的原生編譯特性讓 TypeScript 編譯器能夠輕鬆構建為適用於
各種操作系統的單一二進制文件&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;開發效率&lt;/strong&gt;: Go 語言的錯誤處理模式, 簡單的語法和快速的編譯時間,
讓開發團隊能夠快速迭代和實現功能&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;C/C++ 的跨平臺能力較差, 比如不支持簡單編譯為各個平臺的單一二進制文件.
而 Rust 的內存安全模型過於複雜, 不適合作為 port 項目.
C# 應該更多是語言特性上與 TypeScript 有區別, 嚴格的 OOP 風格不適合作為 port.&lt;/p&gt;

&lt;h2 id=&quot;當前進展與兼容性&quot;&gt;當前進展與兼容性&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/microsoft/typescript-go&quot;&gt;repo&lt;/a&gt; 的 init commit 是 2024-10-01 &lt;a href=&quot;https://github.com/microsoft/typescript-go/commit/cdcc0cb808d8ad0c91d9520edac3d815bff92514&quot;&gt;https://github.com/microsoft/typescript-go/commit/cdcc0cb808d8ad0c91d9520edac3d815bff92514&lt;/a&gt;,
僅用大概半年的時間, 就取得了顯著的進展, 據說完成了 80% 的代碼遷移.&lt;/p&gt;

&lt;p&gt;根據 GitHub 倉庫的 README 文檔, TypeScript 的 Go 原生移植版(稱為”TypeScript 7”)
目前仍處於積極開發階段. 當前已完成的功能包括:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;程序創建(讀取 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lib&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;target&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reference&lt;/code&gt; 等配置)&lt;/li&gt;
  &lt;li&gt;解析/掃描(讀取源文本並確定語法結構)&lt;/li&gt;
  &lt;li&gt;命令行和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tsconfig.json&lt;/code&gt; 解析&lt;/li&gt;
  &lt;li&gt;類型解析和類型檢查&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;為了實現遷移, 微軟會在 TypeScript 6 (仍然是 TypeScript) 的時候, 做一些功能調整,
以保證將來發布 TypeScript 7 (Go 版本) 時大家可以無縫遷移.&lt;/p&gt;

&lt;p&gt;TypeScript 6 和 TypeScript 7 的 API 是完全兼容的, 所以開發者可以隨時升級或降級.
在 TypeScript 7 被完全接受前, TypeScript 6 會繼續開發, 以作為備選.&lt;/p&gt;

&lt;h2 id=&quot;社區反應&quot;&gt;社區反應&lt;/h2&gt;

&lt;p&gt;這一項目在公佈後引起了開發社區的廣泛關注, 截至目前 GitHub 倉庫已獲得超過 11.9k
的星標. 許多開發者對於提升 TypeScript 性能的前景表示期待, 特別是那些處理大型
代碼庫的團隊.&lt;/p&gt;

&lt;p&gt;社區討論主要集中在性能提升, 工具鏈兼容性以及 &lt;a href=&quot;https://github.com/microsoft/typescript-go/discussions/411&quot;&gt;為什麼選擇 Go&lt;/a&gt;
而非其他語言 (如 Rust) 上.&lt;/p&gt;

&lt;h2 id=&quot;相關鏈接&quot;&gt;相關鏈接&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://devblogs.microsoft.com/typescript/typescript-native-port/&quot;&gt;A 10x Faster TypeScript&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/microsoft/typescript-go&quot;&gt;GitHub 倉庫: typescript-go&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


            </description>
            <pubDate>Thu, 13 Mar 2025 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2025-03-13-typescript-go.html
            </guid>
        </item>
        
        <item>
            <title>JS 中的鏈式調用</title>
            <link>
                https://zsqk.github.io/2025-01-14-method-chaining-in-javascript.html
            </link>
            <description>
                &lt;h2 id=&quot;數組中的鏈式調用&quot;&gt;數組中的鏈式調用&lt;/h2&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 過濾偶數&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 每個數乘以2&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 求和&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;但是僅限於數組, 如果想要在其他對象上實現鏈式調用, 就需要自定義方法.&lt;/p&gt;

&lt;h2 id=&quot;多變量鏈式調用&quot;&gt;多變量鏈式調用&lt;/h2&gt;

&lt;p&gt;為了可以對任何數據使用自定義方法, 我們可以這樣做:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;num&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;num2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;num3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;num2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;num4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;num3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;num4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 13&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;這種做法的缺點是額外增加了許多變量, 為了這些變量要進行許多不必要的命名.&lt;/p&gt;

&lt;h2 id=&quot;多函數嵌套鏈式調用&quot;&gt;多函數嵌套鏈式調用&lt;/h2&gt;

&lt;p&gt;為了避免不必要的命名, 我們可以直接調用:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 13&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;可是這樣做後, 代碼的可讀性很差.&lt;/p&gt;

&lt;h2 id=&quot;對象方法鏈式調用&quot;&gt;對象方法鏈式調用&lt;/h2&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Calculator&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;calc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Calculator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;calc&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 13&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;但是需要額外新增對象, 並且許多時候函數作為方法並不合適.&lt;/p&gt;

&lt;h2 id=&quot;promise-中的鏈式調用&quot;&gt;Promise 中的鏈式調用&lt;/h2&gt;

&lt;p&gt;為瞭解決上述問題, 我們可以使用 Promise 的鏈式調用:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Promise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 13&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;並且這種做法可以僅僅使用匿名函數, 不使用函數, 在一些小變動的時候很方便:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Promise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 13&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;目前這是我最常用的方法. 但是缺點是強制將代碼轉為了異步.&lt;/p&gt;

&lt;h2 id=&quot;js-pipe-operator-管道操作符-提案&quot;&gt;JS Pipe Operator (管道操作符) 提案&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/tc39/proposal-pipeline-operator&quot;&gt;https://github.com/tc39/proposal-pipeline-operator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;參考了幾種語言的語法:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Hack&lt;/li&gt;
  &lt;li&gt;F#&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;另外, 許多其他語言也有類似語法, 比如 Elixir.&lt;/p&gt;

            </description>
            <pubDate>Tue, 14 Jan 2025 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2025-01-14-method-chaining-in-javascript.html
            </guid>
        </item>
        
        <item>
            <title>Flutter Web 開發注意事項</title>
            <link>
                https://zsqk.github.io/2024-12-31-flutter-web.html
            </link>
            <description>
                &lt;h2 id=&quot;注意事項&quot;&gt;注意事項&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;為了更好支持 web WebAssembly, 建議 Flutter 版本 &amp;gt;= 3.24.&lt;/li&gt;
  &lt;li&gt;可以使用 &lt;a href=&quot;https://flutterweb-wasm.web.app/&quot;&gt;https://flutterweb-wasm.web.app/&lt;/a&gt; 測試 Flutter Web 的性能.&lt;/li&gt;
  &lt;li&gt;目前默認使用 canvaskit 渲染, 性能較差. 如果使用 wasm 構建, 則使用 Skwasm 渲染.&lt;/li&gt;
  &lt;li&gt;Safari 17.5, Firefox 133 目前渲染目前會回退到 canvaskit, 性能較差.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;編譯參數&quot;&gt;編譯參數&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flutter run&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flutter build web&lt;/code&gt; 命令的參數:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--wasm&lt;/code&gt; 使用 wasm 的方式構建
    &lt;ul&gt;
      &lt;li&gt;如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flutter run -d chrome --wasm&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flutter build web --wasm&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;包&quot;&gt;包&lt;/h2&gt;

&lt;p&gt;參考 Flutter 文檔: &lt;a href=&quot;https://docs.flutter.dev/platform-integration/web/renderers&quot;&gt;https://docs.flutter.dev/platform-integration/web/renderers&lt;/a&gt;,
開發時不建議使用的包有:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dart:html&lt;/code&gt;, 建議使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package:web&lt;/code&gt; 替代. 以使用 WebAssembly 方式構建.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dart:js&lt;/code&gt;, 建議使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dart:js_interop&lt;/code&gt; 替代. 以使用 WebAssembly 方式構建.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dart:js_util&lt;/code&gt;, 建議使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dart:js_interop&lt;/code&gt; 替代. 以使用 WebAssembly 方式構建.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package:js&lt;/code&gt;, 建議使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dart:js_interop&lt;/code&gt; 替代. 以使用 WebAssembly 方式構建.&lt;/li&gt;
&lt;/ol&gt;

            </description>
            <pubDate>Tue, 31 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-31-flutter-web.html
            </guid>
        </item>
        
        <item>
            <title>軟件架構與實驗藝術</title>
            <link>
                https://zsqk.github.io/2024-12-25-architecture-experimentation.html
            </link>
            <description>
                &lt;blockquote&gt;
  &lt;p&gt;:bulb: 原文鏈接:
&lt;a href=&quot;https://www.infoq.com/articles/architecture-experimentation/&quot;&gt;https://www.infoq.com/articles/architecture-experimentation/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;在軟件架構領域, 我們經常會做出許多決策. 有些決策會帶來積極的影響,
而有些則會產生消極的後果. 在做出這些決策時, 我們往往會陷入兩難境地:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;我們希望做出正確的決策&lt;/li&gt;
  &lt;li&gt;我們無法預知未來&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;這就像是在玩一個概率遊戲. 我們可以通過研究, 分析和經驗來提高做出好決策的概率,
但我們永遠無法完全確定某個決策就一定是正確的.&lt;/p&gt;

&lt;h2 id=&quot;通過實驗來驗證決策&quot;&gt;通過實驗來驗證決策&lt;/h2&gt;

&lt;p&gt;在這種情況下, 唯一合理的方法就是通過實驗來驗證我們的決策. 這意味著:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;承認我們可能會犯錯&lt;/li&gt;
  &lt;li&gt;設計實驗來測試我們的假設&lt;/li&gt;
  &lt;li&gt;收集數據來驗證決策的效果&lt;/li&gt;
  &lt;li&gt;準備好在需要時調整或改變方向&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;讓我給您舉個例子. 假設您正在開發一個新的在線零售平臺, 需要決定使用哪種數據庫技術.
您可能會考慮:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;關係型數據庫(如 PostgreSQL)&lt;/li&gt;
  &lt;li&gt;NoSQL 解決方案(如 MongoDB)&lt;/li&gt;
  &lt;li&gt;分佈式數據存儲系統&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;與其僅僅基於理論討論做出選擇, 不如設計一些實驗來測試每種選項在您的具體場景中的表現.&lt;/p&gt;

&lt;h2 id=&quot;最小可行架構mva&quot;&gt;最小可行架構(MVA)&lt;/h2&gt;

&lt;p&gt;最小可行架構(MVA)是一個重要概念, 它強調:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;從最簡單的可工作方案開始&lt;/li&gt;
  &lt;li&gt;通過實驗逐步驗證和改進&lt;/li&gt;
  &lt;li&gt;在實際使用中收集反饋&lt;/li&gt;
  &lt;li&gt;根據反饋調整架構決策&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;MVA 與最小可行產品(MVP)的理念相似, 但關注點是技術架構而不是業務功能.&lt;/p&gt;

&lt;h2 id=&quot;實驗的重要性&quot;&gt;實驗的重要性&lt;/h2&gt;

&lt;p&gt;在軟件開發中, 每個產品發佈實際上都是一系列實驗的集合. 這些實驗不僅關於產品功能,
還包括:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;技術可行性&lt;/strong&gt; - 選擇的技術方案是否真的能夠實現預期目標&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;可維護性&lt;/strong&gt; - 系統是否容易維護和更新&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;可擴展性&lt;/strong&gt; - 系統能否應對增長需求&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;運營成本&lt;/strong&gt; - 解決方案在財務上是否可持續&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;實驗設計的關鍵要素&quot;&gt;實驗設計的關鍵要素&lt;/h3&gt;

&lt;p&gt;好的架構實驗應該包含以下要素:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;明確的假設&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;清晰陳述我們認為會發生什麼&lt;/li&gt;
      &lt;li&gt;為什麼我們認為會這樣&lt;/li&gt;
      &lt;li&gt;這些假設基於什麼依據&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;可測量的目標&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;具體的性能指標&lt;/li&gt;
      &lt;li&gt;明確的成功標準&lt;/li&gt;
      &lt;li&gt;可量化的結果&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;實驗方法&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;如何進行測試&lt;/li&gt;
      &lt;li&gt;需要收集什麼數據&lt;/li&gt;
      &lt;li&gt;如何收集這些數據&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;風險控制&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;失敗後的回退方案&lt;/li&gt;
      &lt;li&gt;對系統其他部分的影響評估&lt;/li&gt;
      &lt;li&gt;如何隔離實驗的影響範圍&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;時間框架&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;實驗持續時間&lt;/li&gt;
      &lt;li&gt;關鍵時間節點&lt;/li&gt;
      &lt;li&gt;評估週期&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;實驗的實際案例&quot;&gt;實驗的實際案例&lt;/h3&gt;

&lt;p&gt;讓我們看一個具體的例子：&lt;/p&gt;

&lt;p&gt;假設一個團隊正在考慮將單體應用遷移到微服務架構。他們可以這樣設計實驗：&lt;/p&gt;

&lt;p&gt;實驗名稱：核心功能微服務遷移測試&lt;/p&gt;

&lt;p&gt;假設：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;將訂單處理模塊拆分為獨立微服務將提高系統擴展性&lt;/li&gt;
  &lt;li&gt;服務間通信不會顯著影響性能&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;測試方法：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;選擇一個非關鍵時段&lt;/li&gt;
  &lt;li&gt;將訂單處理模塊拆分為獨立服務&lt;/li&gt;
  &lt;li&gt;部署到生產環境的隔離區域&lt;/li&gt;
  &lt;li&gt;使用影子流量進行測試&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;成功標準：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;響應時間不超過現有系統的 120%&lt;/li&gt;
  &lt;li&gt;系統資源使用率保持在可接受範圍&lt;/li&gt;
  &lt;li&gt;服務間通信延遲低於 50ms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;回退計劃：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;保留原有系統運行&lt;/li&gt;
  &lt;li&gt;準備快速切換回原架構的腳本&lt;/li&gt;
  &lt;li&gt;預設故障轉移機制&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;實驗的陷阱&quot;&gt;實驗的陷阱&lt;/h3&gt;

&lt;p&gt;在進行架構實驗時,需要注意避免以下常見陷阱：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;範圍過大&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;試圖一次性解決太多問題&lt;/li&gt;
      &lt;li&gt;實驗週期過長&lt;/li&gt;
      &lt;li&gt;難以確定具體問題的根源&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;指標模糊&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;成功標準不夠具體&lt;/li&gt;
      &lt;li&gt;缺乏量化指標&lt;/li&gt;
      &lt;li&gt;難以做出客觀評判&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;忽視成本&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;未考慮實驗失敗的代價&lt;/li&gt;
      &lt;li&gt;忽視長期維護成本&lt;/li&gt;
      &lt;li&gt;低估遷移成本&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;實驗驅動的架構演進&quot;&gt;實驗驅動的架構演進&lt;/h2&gt;

&lt;h3 id=&quot;漸進式變更&quot;&gt;漸進式變更&lt;/h3&gt;

&lt;p&gt;在進行架構演進時,採用漸進式的變更策略非常重要：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;小步快跑&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;將大型變更分解成小的、可管理的步驟&lt;/li&gt;
      &lt;li&gt;每個步驟都可以獨立驗證&lt;/li&gt;
      &lt;li&gt;降低每次變更的風險&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;持續驗證&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;在每個階段收集反饋&lt;/li&gt;
      &lt;li&gt;及時發現問題並調整&lt;/li&gt;
      &lt;li&gt;建立度量標準來評估進展&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;保持可逆性&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;確保每個變更都是可回退的&lt;/li&gt;
      &lt;li&gt;維護多個系統版本的能力&lt;/li&gt;
      &lt;li&gt;準備應急方案&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;實驗的生命週期&quot;&gt;實驗的生命週期&lt;/h3&gt;

&lt;p&gt;一個完整的架構實驗生命週期包括：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;規劃階段
    &lt;ul&gt;
      &lt;li&gt;定義實驗目標&lt;/li&gt;
      &lt;li&gt;設計實驗方案&lt;/li&gt;
      &lt;li&gt;確定評估標準&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;準備階段
    &lt;ul&gt;
      &lt;li&gt;搭建測試環境&lt;/li&gt;
      &lt;li&gt;準備監控工具&lt;/li&gt;
      &lt;li&gt;建立基準數據&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;執行階段
    &lt;ul&gt;
      &lt;li&gt;實施變更&lt;/li&gt;
      &lt;li&gt;收集數據&lt;/li&gt;
      &lt;li&gt;監控系統&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;評估階段
    &lt;ul&gt;
      &lt;li&gt;分析結果&lt;/li&gt;
      &lt;li&gt;總結經驗&lt;/li&gt;
      &lt;li&gt;決定下一步&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;調整階段
    &lt;ul&gt;
      &lt;li&gt;根據結果優化&lt;/li&gt;
      &lt;li&gt;擴大或縮小範圍&lt;/li&gt;
      &lt;li&gt;準備下一輪實驗&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;實驗文化的建立&quot;&gt;實驗文化的建立&lt;/h3&gt;

&lt;p&gt;要在團隊中建立良好的實驗文化：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;鼓勵創新&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;接受失敗作為學習的一部分&lt;/li&gt;
      &lt;li&gt;獎勵大膽嘗試&lt;/li&gt;
      &lt;li&gt;分享經驗教訓&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;數據驅動&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;基於事實做決策&lt;/li&gt;
      &lt;li&gt;建立度量體系&lt;/li&gt;
      &lt;li&gt;重視客觀反饋&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;持續學習&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;定期回顧實驗結果&lt;/li&gt;
      &lt;li&gt;記錄和分享知識&lt;/li&gt;
      &lt;li&gt;調整實驗方法&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;實際案例研究&quot;&gt;實際案例研究&lt;/h3&gt;

&lt;p&gt;讓我們看一個更詳細的案例：&lt;/p&gt;

&lt;p&gt;案例：緩存層改造實驗&lt;/p&gt;

&lt;p&gt;背景：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;現有系統使用單機緩存&lt;/li&gt;
  &lt;li&gt;隨著用戶增長，出現性能瓶頸&lt;/li&gt;
  &lt;li&gt;考慮遷移到分佈式緩存&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;實驗設計：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;第一階段：小規模測試
    &lt;ul&gt;
      &lt;li&gt;選擇非核心業務模塊&lt;/li&gt;
      &lt;li&gt;部署分佈式緩存集群&lt;/li&gt;
      &lt;li&gt;監控性能和穩定性&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;第二階段：負載測試
    &lt;ul&gt;
      &lt;li&gt;模擬生產環境負載&lt;/li&gt;
      &lt;li&gt;測試故障轉移&lt;/li&gt;
      &lt;li&gt;評估運維複雜度&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;第三階段：灰度發佈
    &lt;ul&gt;
      &lt;li&gt;逐步遷移業務模塊&lt;/li&gt;
      &lt;li&gt;觀察系統表現&lt;/li&gt;
      &lt;li&gt;收集用戶反饋&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;評估指標：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;緩存命中率&lt;/li&gt;
  &lt;li&gt;響應時間&lt;/li&gt;
  &lt;li&gt;系統資源使用&lt;/li&gt;
  &lt;li&gt;運維成本&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;長期架構演進&quot;&gt;長期架構演進&lt;/h2&gt;

&lt;h3 id=&quot;平衡短期與長期目標&quot;&gt;平衡短期與長期目標&lt;/h3&gt;

&lt;p&gt;在進行架構實驗時,需要考慮：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;短期收益&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;立即可見的性能提升&lt;/li&gt;
      &lt;li&gt;快速解決當前問題&lt;/li&gt;
      &lt;li&gt;用戶直接感受的改進&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;長期影響&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;技術債務的累積&lt;/li&gt;
      &lt;li&gt;維護成本的變化&lt;/li&gt;
      &lt;li&gt;未來的擴展性&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;權衡因素&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;開發速度 vs 代碼質量&lt;/li&gt;
      &lt;li&gt;創新 vs 穩定性&lt;/li&gt;
      &lt;li&gt;靈活性 vs 複雜度&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;持續改進的策略&quot;&gt;持續改進的策略&lt;/h3&gt;

&lt;p&gt;為確保架構能持續演進：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;建立反饋循環
    &lt;ul&gt;
      &lt;li&gt;監控系統性能&lt;/li&gt;
      &lt;li&gt;收集用戶反饋&lt;/li&gt;
      &lt;li&gt;分析運營數據&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;定期評估
    &lt;ul&gt;
      &lt;li&gt;架構審查會議&lt;/li&gt;
      &lt;li&gt;性能基準測試&lt;/li&gt;
      &lt;li&gt;技術棧評估&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;適應性調整
    &lt;ul&gt;
      &lt;li&gt;根據業務需求調整&lt;/li&gt;
      &lt;li&gt;採納新技術&lt;/li&gt;
      &lt;li&gt;淘汰過時組件&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;常見陷阱和解決方案&quot;&gt;常見陷阱和解決方案&lt;/h3&gt;

&lt;p&gt;在長期架構演進中常見的問題：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;過度工程&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;問題：構建超出實際需求的複雜系統&lt;/li&gt;
      &lt;li&gt;解決：堅持”足夠好”原則,循序漸進&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;決策慣性&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;問題：因為歷史原因繼續使用次優方案&lt;/li&gt;
      &lt;li&gt;解決：定期重新評估決策,保持開放心態&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;忽視維護性&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;問題：只關注功能實現,忽視後期維護&lt;/li&gt;
      &lt;li&gt;解決：將可維護性作為架構決策的關鍵指標&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;文檔和知識管理&quot;&gt;文檔和知識管理&lt;/h3&gt;

&lt;p&gt;保持良好的文檔習慣：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;決策記錄
    &lt;ul&gt;
      &lt;li&gt;記錄重要決策的原因&lt;/li&gt;
      &lt;li&gt;記錄被否決的方案&lt;/li&gt;
      &lt;li&gt;保存相關討論內容&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;實驗日誌
    &lt;ul&gt;
      &lt;li&gt;詳細的實驗過程&lt;/li&gt;
      &lt;li&gt;數據收集方法&lt;/li&gt;
      &lt;li&gt;結果分析&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;經驗教訓
    &lt;ul&gt;
      &lt;li&gt;成功和失敗的案例&lt;/li&gt;
      &lt;li&gt;意外情況的處理&lt;/li&gt;
      &lt;li&gt;改進建議&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;團隊協作&quot;&gt;團隊協作&lt;/h3&gt;

&lt;p&gt;有效的團隊協作對實驗成功至關重要：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;溝通機制&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;定期架構討論會&lt;/li&gt;
      &lt;li&gt;技術評審流程&lt;/li&gt;
      &lt;li&gt;知識分享會議&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;角色分工&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;實驗負責人&lt;/li&gt;
      &lt;li&gt;監控人員&lt;/li&gt;
      &lt;li&gt;評估團隊&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;決策流程&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;提案機制&lt;/li&gt;
      &lt;li&gt;評審流程&lt;/li&gt;
      &lt;li&gt;實施審批&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;結論與展望&quot;&gt;結論與展望&lt;/h2&gt;

&lt;h3 id=&quot;實驗驅動的架構方法總結&quot;&gt;實驗驅動的架構方法總結&lt;/h3&gt;

&lt;p&gt;成功的架構實驗方法建立在以下基礎之上：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;實驗思維&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;承認不確定性的存在&lt;/li&gt;
      &lt;li&gt;願意通過實驗來驗證假設&lt;/li&gt;
      &lt;li&gt;對失敗保持開放態度&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;系統方法&lt;/strong&gt;&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;明確的實驗流程&lt;/li&gt;
      &lt;li&gt;可靠的數據收集&lt;/li&gt;
      &lt;li&gt;客觀的評估標準&lt;/li&gt;
      &lt;li&gt;完善的反饋機制&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;持續改進&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;不斷優化實驗方法&lt;/li&gt;
      &lt;li&gt;積累經驗教訓&lt;/li&gt;
      &lt;li&gt;調整決策流程&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;未來趨勢&quot;&gt;未來趨勢&lt;/h3&gt;

&lt;p&gt;架構實驗在未來可能的發展方向：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;自動化實驗&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;自動化測試和部署&lt;/li&gt;
      &lt;li&gt;AI 輔助決策&lt;/li&gt;
      &lt;li&gt;智能監控和分析&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;混沌工程&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;主動故障注入&lt;/li&gt;
      &lt;li&gt;彈性測試&lt;/li&gt;
      &lt;li&gt;系統邊界探索&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;實驗工具鏈&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;集成的實驗平臺&lt;/li&gt;
      &lt;li&gt;可視化分析工具&lt;/li&gt;
      &lt;li&gt;協作決策系統&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;最佳實踐建議&quot;&gt;最佳實踐建議&lt;/h3&gt;

&lt;p&gt;給架構師和開發團隊的建議：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;開始時要小
    &lt;ul&gt;
      &lt;li&gt;從小規模實驗開始&lt;/li&gt;
      &lt;li&gt;逐步增加複雜度&lt;/li&gt;
      &lt;li&gt;積累經驗和信心&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;保持警惕
    &lt;ul&gt;
      &lt;li&gt;持續監控系統&lt;/li&gt;
      &lt;li&gt;注意早期警告信號&lt;/li&gt;
      &lt;li&gt;及時調整方向&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;分享知識
    &lt;ul&gt;
      &lt;li&gt;記錄和分享經驗&lt;/li&gt;
      &lt;li&gt;建立知識庫&lt;/li&gt;
      &lt;li&gt;促進團隊學習&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;結束語&quot;&gt;結束語&lt;/h3&gt;

&lt;p&gt;架構實驗不是一次性的活動,而是持續改進的過程。成功的關鍵在於：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;建立正確的實驗文化&lt;/li&gt;
  &lt;li&gt;採用系統的方法論&lt;/li&gt;
  &lt;li&gt;保持學習和適應的能力&lt;/li&gt;
  &lt;li&gt;重視團隊協作和知識共享&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;通過實驗驅動的方法,我們可以：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;降低架構決策的風險&lt;/li&gt;
  &lt;li&gt;提高系統的可靠性&lt;/li&gt;
  &lt;li&gt;促進團隊的成長&lt;/li&gt;
  &lt;li&gt;推動技術的創新&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;最終,架構實驗的目標是幫助我們構建更好的系統,為用戶創造更大的價值。&lt;/p&gt;

&lt;h3 id=&quot;參考資料&quot;&gt;參考資料&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;相關書籍和文章推薦&lt;/li&gt;
  &lt;li&gt;實用工具和框架&lt;/li&gt;
  &lt;li&gt;案例研究和最佳實踐&lt;/li&gt;
  &lt;li&gt;社區資源和討論組&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;這就是全文的完整翻譯. 這篇文章深入探討了軟件架構中實驗的重要性,
以及如何通過系統化的方法來進行架構實驗和演進. 希望這個翻譯對您有幫助!&lt;/p&gt;

            </description>
            <pubDate>Wed, 25 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-25-architecture-experimentation.html
            </guid>
        </item>
        
        <item>
            <title>OpenAI 12 Days 總結</title>
            <link>
                https://zsqk.github.io/2024-12-22-openai-12-days.html
            </link>
            <description>
                &lt;details lang=&quot;zh&quot; open=&quot;&quot;&gt;
&lt;summary&gt;中文版本&lt;/summary&gt;
&lt;div&gt;

    &lt;h2 id=&quot;section&quot;&gt;發佈會&lt;/h2&gt;

    &lt;p&gt;OpenAI 最新辦了一場 12 天 “發佈會”: &lt;a href=&quot;https://openai.com/12-days/&quot;&gt;https://openai.com/12-days/&lt;/a&gt;&lt;/p&gt;

    &lt;p&gt;國內文章: &lt;a href=&quot;https://www.infoq.cn/article/WXPMviOWQ1LNZhqZC5ZE&quot;&gt;https://www.infoq.cn/article/WXPMviOWQ1LNZhqZC5ZE&lt;/a&gt;&lt;/p&gt;

    &lt;p&gt;總結這幾天的內容, 核心為:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;ChatGPT Pro 服務, 200 美元/月 (Day 1)&lt;/li&gt;
      &lt;li&gt;正式發佈 o1 模型 (Day 1, 9)&lt;/li&gt;
      &lt;li&gt;正式發佈 Sora 模型 (Day 3)&lt;/li&gt;
      &lt;li&gt;技術預覽 (微調與 o3 模型) (Day 2, 12)&lt;/li&gt;
      &lt;li&gt;更多應用層面的更新 (創作者助手, 蘋果集成, 會話整理, 多媒體信息, 搜索,
電話版 ChatGPT 等) (Day 4, 5, 6, 7, 8, 10, 11)&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;應用層面的創建無疑是收入的一個重要增長點. 但是對於 OpenAI 來說, 應用不是撒手鐧,
模型才是.&lt;/p&gt;

    &lt;p&gt;所以這裡面除了影響營收的 Pro 版本的收費, Sam 僅參加了模型相關發佈 o1, Sora, o3.&lt;/p&gt;

    &lt;h2 id=&quot;section-1&quot;&gt;模型&lt;/h2&gt;

    &lt;p&gt;感覺有意義的點還不如 Ilya Sutskever 在 NeurIPS 2024 的演講.&lt;/p&gt;

    &lt;p&gt;不過都在一個發力: &lt;strong&gt;邏輯性&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;AI 的幻覺問題比較嚴重, 這個問題其實也是 AI 缺乏邏輯性的一個表現.&lt;/p&gt;

    &lt;p&gt;可是人類的神經元就可以讓自己有邏輯, 那 AI 為什麼不能?&lt;/p&gt;

    &lt;p&gt;這就是 AI 的下一步方向, 不是找更多數據, 而是利用當前數據如何讓 “邏輯性” 顯現.&lt;/p&gt;

    &lt;p&gt;這種邏輯性, 而非知識性的問題我們也遇到了. 針對一些稍微複雜一點的邏輯問題,
當前主流模型都回答得不好 (應該說不對).&lt;/p&gt;

  &lt;/div&gt;
&lt;/details&gt;

&lt;details lang=&quot;en&quot;&gt;
&lt;summary&gt;English Version&lt;/summary&gt;
&lt;div&gt;

    &lt;h2 id=&quot;launch-event&quot;&gt;Launch Event&lt;/h2&gt;

    &lt;p&gt;OpenAI recently held a 12-day “launch event”: &lt;a href=&quot;https://openai.com/12-days/&quot;&gt;https://openai.com/12-days/&lt;/a&gt;&lt;/p&gt;

    &lt;p&gt;Key announcements during these days include:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;ChatGPT Pro service at $200/month (Day 1)&lt;/li&gt;
      &lt;li&gt;Official release of o1 model (Day 1, 9)&lt;/li&gt;
      &lt;li&gt;Official release of Sora model (Day 3)&lt;/li&gt;
      &lt;li&gt;Technical previews (fine-tuning and o3 model) (Day 2, 12)&lt;/li&gt;
      &lt;li&gt;More application-level updates (Creator Assistant, Apple integration,
conversation organization, multimedia handling, search, phone version of
ChatGPT, etc.) (Day 4, 5, 6, 7, 8, 10, 11)&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;Application-level innovations are undoubtedly an important growth point for
revenue. However, for OpenAI, applications are not their trump card - models are.&lt;/p&gt;

    &lt;p&gt;That’s why among all these announcements, Sam only participated in model-related
releases: o1, Sora, and o3.&lt;/p&gt;

    &lt;h2 id=&quot;models&quot;&gt;Models&lt;/h2&gt;

    &lt;p&gt;The meaningful points here are not as significant as Ilya Sutskever’s speech at
NeurIPS 2024.&lt;/p&gt;

    &lt;p&gt;However, they all focus on one direction: &lt;strong&gt;logical reasoning&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;AI’s hallucination problem is quite serious, which is actually a manifestation
of AI’s lack of logical reasoning ability.&lt;/p&gt;

    &lt;p&gt;Human neurons can enable logical thinking, so why can’t AI?&lt;/p&gt;

    &lt;p&gt;This is the next direction for AI - not finding more data, but utilizing existing
data to manifest “logical reasoning”.&lt;/p&gt;

    &lt;p&gt;We’ve also encountered this issue of logical reasoning versus knowledge. Current
mainstream models don’t perform well (or more accurately, don’t perform correctly)
on slightly more complex logical problems.&lt;/p&gt;

  &lt;/div&gt;
&lt;/details&gt;

            </description>
            <pubDate>Sun, 22 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-22-openai-12-days.html
            </guid>
        </item>
        
        <item>
            <title>Deno 使用實踐與總結</title>
            <link>
                https://zsqk.github.io/2024-12-19-deno-practice-and-summary.html
            </link>
            <description>
                &lt;details lang=&quot;zh&quot; open=&quot;&quot;&gt;
&lt;summary&gt;中文版本&lt;/summary&gt;
&lt;div&gt;

    &lt;h2 id=&quot;deno-&quot;&gt;Deno 中的依賴管理&lt;/h2&gt;

    &lt;ol&gt;
      &lt;li&gt;直接使用 import 進行相對路徑的文件引用.&lt;/li&gt;
      &lt;li&gt;直接使用 import 進行 HTTPS 絕對路徑的文件引用.
2.1. 比如使用 deno.land 的包 (僅限公共包).
2.2. 比如使用 GitHub 的包 (raw.githubusercontent.com).
2.3. 如 &lt;a href=&quot;https://esm.sh/&quot;&gt;https://esm.sh/&lt;/a&gt;
2.4. 如 &lt;a href=&quot;https://jspm.org/&quot;&gt;https://jspm.org/&lt;/a&gt;
2.5. 如 &lt;a href=&quot;https://www.skypack.dev/&quot;&gt;https://www.skypack.dev/&lt;/a&gt;
2.6. 如 &lt;a href=&quot;https://www.jsdelivr.com/esm&quot;&gt;https://www.jsdelivr.com/esm&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;引用 npm 包.&lt;/li&gt;
      &lt;li&gt;引用 jsr 包. (僅限公共包).&lt;/li&gt;
    &lt;/ol&gt;

    &lt;h3 id=&quot;jsrio-&quot;&gt;jsr.io 包倉庫&lt;/h3&gt;

    &lt;p&gt;jsr.io 是 Deno 官方團隊開發維護的一個包倉庫, 可以同時發佈為 Deno 和 Node.js 的包.&lt;/p&gt;

    &lt;p&gt;如果沒有 jsr.io, 如果一個包想要同時支持 Deno 和 Node.js, 那麼需要維護兩套代碼.&lt;/p&gt;

    &lt;p&gt;如果不想維護兩套代碼, 則可以構建時魔改代碼, 但會受到許多約束:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;轉為 Node.js 包的時候移除 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ts&lt;/code&gt; 後綴名.&lt;/li&gt;
      &lt;li&gt;無法添加 deno 依賴.&lt;/li&gt;
      &lt;li&gt;無法添加 Node.js 依賴.&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;jsr.io 的包可以同時支持 Deno 和 Node.js, 解決了上述痛點.
但是 jsr.io 有兩大問題:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;jsr.io 不支持 HTTP 絕對路徑的文件引用.&lt;/li&gt;
      &lt;li&gt;jsr.io (暫時) 不支持私有包. &lt;a href=&quot;https://github.com/jsr-io/jsr/issues/203&quot;&gt;https://github.com/jsr-io/jsr/issues/203&lt;/a&gt;&lt;/li&gt;
    &lt;/ol&gt;

    &lt;h2 id=&quot;deno--1&quot;&gt;Deno 運行時特點&lt;/h2&gt;

    &lt;h3 id=&quot;deno--2&quot;&gt;Deno 中的浮點誤差&lt;/h3&gt;

    &lt;p&gt;雖然 Deno 的一大核心是 V8 引擎, 但 Deno 的運行時針對浮點計算進行了特殊處理.&lt;/p&gt;

    &lt;p&gt;比如我們要做下面的浮點運算: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.1 * 100&lt;/code&gt;&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Deno 2.1.4 (since 1.9.2) -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;110&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Chrome 131 (since 90) -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;110.00000000000001&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Node.js v20.11.0 -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;110.00000000000001&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;

    &lt;p&gt;Deno 的運行時似乎在刻意避免浮點誤差.&lt;/p&gt;

    &lt;h2 id=&quot;nodejs-&quot;&gt;Node.js 兼容性&lt;/h2&gt;

    &lt;p&gt;Node.js 的生態非常龐大, Deno 想要擴大運行時市場份額,
需要為在 Node.js 環境下開發的軟件提供兼容性.&lt;/p&gt;

    &lt;p&gt;在 Deno 2.x 版本中, Deno 已經儘量支持了許多 Node.js 的包.&lt;/p&gt;

    &lt;p&gt;但是這種支持仍然有限:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;localAddress 參數沒有效果. &lt;a href=&quot;https://github.com/denoland/deno/issues/24153&quot;&gt;https://github.com/denoland/deno/issues/24153&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/denoland/deno/labels/node%20compat&quot;&gt;更多兼容問題見 issue 列表&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://docs.deno.com/runtime/reference/node_apis/#partially-supported-modules&quot;&gt;Deno 支持不完善的 Node.js 功能&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://docs.deno.com/runtime/reference/node_apis/#unsupported-modules&quot;&gt;Deno 暫不支持的 Node.js 功能&lt;/a&gt;&lt;/li&gt;
    &lt;/ol&gt;

    &lt;h2 id=&quot;deno-api&quot;&gt;原生 Deno API&lt;/h2&gt;

    &lt;p&gt;目前 Deno 提供的 API 仍有限, 比如有下面的問題:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;網絡請求時不支持選擇網卡. &lt;a href=&quot;https://github.com/denoland/deno/issues/27376&quot;&gt;https://github.com/denoland/deno/issues/27376&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;不支持 brotli 壓縮. (但通過 Node.js 兼容包可實現)&lt;/li&gt;
    &lt;/ol&gt;

  &lt;/div&gt;
&lt;/details&gt;

&lt;details lang=&quot;en&quot;&gt;
&lt;summary&gt;English Version&lt;/summary&gt;
&lt;div&gt;

    &lt;h2 id=&quot;dependency-management-in-deno&quot;&gt;Dependency Management in Deno&lt;/h2&gt;

    &lt;ol&gt;
      &lt;li&gt;Direct file imports using relative paths.&lt;/li&gt;
      &lt;li&gt;Direct file imports using HTTPS absolute paths.
2.1. Using packages from deno.land (public packages only).
2.2. Using packages from GitHub (raw.githubusercontent.com).
2.3. From &lt;a href=&quot;https://esm.sh/&quot;&gt;https://esm.sh/&lt;/a&gt;
2.4. From &lt;a href=&quot;https://jspm.org/&quot;&gt;https://jspm.org/&lt;/a&gt;
2.5. From &lt;a href=&quot;https://www.skypack.dev/&quot;&gt;https://www.skypack.dev/&lt;/a&gt;
2.6. From &lt;a href=&quot;https://www.jsdelivr.com/esm&quot;&gt;https://www.jsdelivr.com/esm&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;Importing npm packages.&lt;/li&gt;
      &lt;li&gt;Importing jsr packages (public packages only).&lt;/li&gt;
    &lt;/ol&gt;

    &lt;h3 id=&quot;jsrio&quot;&gt;jsr.io&lt;/h3&gt;

    &lt;p&gt;jsr.io is a package registry developed and maintained by the Deno official team,
allowing packages to be published for both Deno and Node.js.&lt;/p&gt;

    &lt;p&gt;Without jsr.io, supporting both Deno and Node.js would require maintaining two
separate codebases.&lt;/p&gt;

    &lt;p&gt;To avoid maintaining dual codebases, code could be transformed during build time,
but with several constraints:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;Removing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ts&lt;/code&gt; extensions when converting to Node.js packages.&lt;/li&gt;
      &lt;li&gt;Cannot add Deno dependencies.&lt;/li&gt;
      &lt;li&gt;Cannot add Node.js dependencies.&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;jsr.io packages can support both Deno and Node.js, solving these pain points.
However, jsr.io has two major issues:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;jsr.io doesn’t support HTTP absolute path imports.&lt;/li&gt;
      &lt;li&gt;jsr.io (temporarily) doesn’t support private packages. &lt;a href=&quot;https://github.com/jsr-io/jsr/issues/203&quot;&gt;https://github.com/jsr-io/jsr/issues/203&lt;/a&gt;&lt;/li&gt;
    &lt;/ol&gt;

    &lt;h2 id=&quot;deno-runtime-characteristics&quot;&gt;Deno Runtime Characteristics&lt;/h2&gt;

    &lt;h3 id=&quot;floating-point-precision-in-deno&quot;&gt;Floating Point Precision in Deno&lt;/h3&gt;

    &lt;p&gt;Although V8 engine is a core component of Deno, the runtime handles floating-point
calculations differently.&lt;/p&gt;

    &lt;p&gt;For example, let’s consider this floating-point calculation: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.1 * 100&lt;/code&gt;&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Deno 2.1.4 (since 1.9.2) -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;110&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Chrome 131 (since 90) -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;110.00000000000001&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Node.js v20.11.0 -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;110.00000000000001&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;

    &lt;p&gt;Deno’s runtime appears to deliberately avoid floating-point errors.&lt;/p&gt;

    &lt;h2 id=&quot;nodejs-compatibility&quot;&gt;Node.js Compatibility&lt;/h2&gt;

    &lt;p&gt;With Node.js’s vast ecosystem, Deno needs to provide compatibility for software
developed in Node.js environment to expand its runtime market share.&lt;/p&gt;

    &lt;p&gt;In Deno 2.x, many Node.js packages are supported.&lt;/p&gt;

    &lt;p&gt;However, this support is still limited:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;localAddress parameter has no effect. &lt;a href=&quot;https://github.com/denoland/deno/issues/24153&quot;&gt;https://github.com/denoland/deno/issues/24153&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/denoland/deno/labels/node%20compat&quot;&gt;More compatibility issues in the issue list&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://docs.deno.com/runtime/reference/node_apis/#partially-supported-modules&quot;&gt;Partially supported Node.js features in Deno&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://docs.deno.com/runtime/reference/node_apis/#unsupported-modules&quot;&gt;Currently unsupported Node.js features in Deno&lt;/a&gt;&lt;/li&gt;
    &lt;/ol&gt;

    &lt;h2 id=&quot;deno-api-1&quot;&gt;Deno API&lt;/h2&gt;

    &lt;p&gt;Currently, Deno’s API offerings are still limited, with issues such as:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;No support for network interface selection in network requests. &lt;a href=&quot;https://github.com/denoland/deno/issues/27376&quot;&gt;https://github.com/denoland/deno/issues/27376&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;No support for brotli compression. (though achievable through Node.js
compatibility packages)&lt;/li&gt;
    &lt;/ol&gt;

  &lt;/div&gt;
&lt;/details&gt;

            </description>
            <pubDate>Thu, 19 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-19-deno-practice-and-summary.html
            </guid>
        </item>
        
        <item>
            <title>Cursor 使用問題</title>
            <link>
                https://zsqk.github.io/2024-12-12-cursor-issues.html
            </link>
            <description>
                &lt;details lang=&quot;zh&quot; open=&quot;&quot;&gt;
&lt;summary&gt;中文版本&lt;/summary&gt;
&lt;div&gt;

    &lt;p&gt;對於中國國內開發者來說, Cursor 尤其好用. 因為通過 Cursor 可以使用多種大語言模型,
並且可以避免自己直接訂閱導致封號等風險.&lt;/p&gt;

    &lt;p&gt;但是作為一個文本編輯器, 雖然集成自 VS Code, 但 Cursor 仍有許多基礎功能沒做好:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;同一用戶多設備的配置數據同步.&lt;/li&gt;
      &lt;li&gt;第三方軟件集成 (如 Fork).&lt;/li&gt;
      &lt;li&gt;macOS 下將 Find 文件或文件夾拖拽到 icon 打開 (系統集成).&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;許多開發者都有多臺開發設備, 大多數開發者希望在多臺設備上擁有較為一致的開發體驗.
VS Code 在這方面做的就很好. 但是 Cursor 無法在統一用戶的多臺設備上進行配置數據的同步,
擴展也需要分別安裝.&lt;/p&gt;

    &lt;p&gt;在第三方軟件集成度上, Cursor 也有問題. 以 Fork 為例, 雖然不知道問題是在 Fork 還是在 Cursor 上,
但用戶體驗上的確不夠, 還不如 Zed. 以前 Open in 都不支持 Cursor, 現在 Reveal Line 還是不支持.&lt;/p&gt;

    &lt;p&gt;在 Mac 上不支持將文件夾拖轉到 icon 上打開. (以前連文件拖拽打開都不支持)&lt;/p&gt;

    &lt;p&gt;Cursor 還需要把編輯器本身的工作做好啊.&lt;/p&gt;

  &lt;/div&gt;
&lt;/details&gt;

&lt;details lang=&quot;en&quot;&gt;
&lt;summary&gt;English Version&lt;/summary&gt;
&lt;div&gt;

    &lt;p&gt;For developers in China, Cursor is particularly useful because it provides access
to various large language models while avoiding the risks of direct subscription
that might lead to account suspension.&lt;/p&gt;

    &lt;p&gt;However, as a text editor, despite being based on VS Code, Cursor still lacks
several basic features:&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;Configuration data synchronization across multiple devices for the same user.&lt;/li&gt;
      &lt;li&gt;Third-party software integration (such as Fork).&lt;/li&gt;
      &lt;li&gt;Opening files/folders by dragging them onto the icon on macOS (system integration).&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;Many developers work with multiple devices, and most prefer to have a consistent
development experience across all their devices. VS Code handles this well.
However, Cursor cannot synchronize configuration data across multiple devices
for the same user, and extensions need to be installed separately on each device.&lt;/p&gt;

    &lt;p&gt;Regarding third-party software integration, Cursor has issues. Taking Fork as an
example, regardless of whether the problem lies with Fork or Cursor, the user
experience is inadequate and inferior to Zed. Previously, “Open in” didn’t support
Cursor, and “Reveal Line” still doesn’t work.&lt;/p&gt;

    &lt;p&gt;On Mac, it doesn’t support opening folders by dragging them onto the icon.
(Previously, it didn’t even support opening files by dragging)&lt;/p&gt;

    &lt;p&gt;Cursor needs to improve its core editor functionality.&lt;/p&gt;

  &lt;/div&gt;
&lt;/details&gt;

            </description>
            <pubDate>Thu, 12 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-12-cursor-issues.html
            </guid>
        </item>
        
        <item>
            <title>談 Alex Russell 談 React</title>
            <link>
                https://zsqk.github.io/2024-12-11-why-react.html
            </link>
            <description>
                &lt;p&gt;我看了部分 &lt;a href=&quot;https://infrequently.org/2024/11/if-not-react-then-what/&quot;&gt;Alex Russell 的原文&lt;/a&gt;,
完整看了這篇&lt;a href=&quot;https://www.infoq.cn/news/Ssc0h0HBY7xkN1uk4P4t&quot;&gt;翻譯文章&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;下面是我的一些看法:&lt;/p&gt;

&lt;h2 id=&quot;frameworkism&quot;&gt;Frameworkism&lt;/h2&gt;

&lt;p&gt;Web 開發者並不是主動要被框架束縛, 在前端 (客戶端) 開發中, Android, iOS,
微信小程序, 鴻蒙應用等, 都在實現更多前端功能的前提下限制了前端的開發流.
而 Web 自身的設計在相同場景下相比其他前端開發技術棧來說交互嚴重不足.&lt;/p&gt;

&lt;p&gt;那我們有交互需求的時候應該怎麼辦? 直接操作 DOM 太繁瑣, 並不是一種現代化的方案,
所以我們在 Web 的基礎上需要框架, 而不是直接寫 HTML + JS + CSS.&lt;/p&gt;

&lt;h2 id=&quot;why-spa&quot;&gt;Why SPA&lt;/h2&gt;

&lt;p&gt;SPA 不是必要的, 但是 Web 應用而不是 Web 網頁是必要的,
因為將 Web 作為應用會讓整體前端技術棧層次更清晰.
而 SPA 是實現 Web 應用的一種直觀的方式, 與其他端開發的架構變得類似.&lt;/p&gt;

&lt;p&gt;隔行如隔山, 我相信 Russell 並沒有站在一個項目整體的立場,
並且沒有考慮許多工程化的概念, 比如 Hydration. Russell 低估了許多應用交互的複雜性.&lt;/p&gt;

&lt;p&gt;我更傾向於讓 Web 承載更多應用的場景, 而不是讓 Web 承載更多網頁的場景.
許多軟件功能都是不必要使用 “系統級別應用” 的, 藉由 PWA 等概念,
Web 可以承載更多這樣的功能.&lt;/p&gt;

&lt;h2 id=&quot;why-react&quot;&gt;Why React&lt;/h2&gt;

&lt;p&gt;不可否認社會上存在許多 “隨大流” 的想法. 但 Russell 這篇文章的受眾不會是隨大流想法.
如果真的沒有思考, 是不會去看 Russell 的文章的.&lt;/p&gt;

&lt;p&gt;那我們為什麼使用 React? 簡單來說有三點:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;React 可以實現我們的需求. React 提供了一套簡單的原則, 狀態數據 + JSX.&lt;/li&gt;
  &lt;li&gt;React 簡單易懂. 在工程上有足夠的優勢.&lt;/li&gt;
  &lt;li&gt;生態好. 因為 React 有先發優勢, 可能也因為 React 在其他方面有優勢.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;並不是因為:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;“Facebook 用了 React, 所以我們用肯定沒問題.” React 是 Facebook 的產物,
但是 React 之所以成為一個開源項目, 是因為 React 解決的是一個通用且樸素的問題.&lt;/li&gt;
  &lt;li&gt;“React 是行業標準.” 我們也不認為 React 是標準, 但不可否認 React
對其他許多流行庫造成了深遠的影響.&lt;/li&gt;
  &lt;li&gt;“React 更容易被招聘.” 一方面, React 並不複雜, 另一方面, React
在我們的環境下並沒有明顯的招聘優勢.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;在 Russell 介紹其他框架的時候, 我一開始難以理解 “React, Angular, etc.” 中的
“etc.” 不包含 Vue 等.&lt;/p&gt;

&lt;p&gt;後來我明白了, Russell 的角度從來都不是 Web 開發者, 而是瀏覽器. Russell
是為了瀏覽器在發聲, 而不是代表 Web 開發者.&lt;/p&gt;

&lt;p&gt;Russell 對現代化框架的定義主要圍繞在: 技術實現上不要針對老舊的 IE,
不要使用虛擬 DOM, 性能要夠好.&lt;/p&gt;

&lt;p&gt;Russell 沒有從 React 的 API 角度說明 React 的 API
設計如何對其他所謂現代化造成的影響, 比如 state 概念, hooks 概念
(當然, hooks 屬於一種打補丁的概念, 但是它確實讓 React 的 API 變得更好用).&lt;/p&gt;

&lt;p&gt;作為 Web 開發者, 其實就是希望 React API 可以有一層進行隔離,
讓開發者可以盡情做交互, 而不是像使用 C 一樣精細化操作 DOM.
這一點上, 其實 Svelte 做的更好, 但是 Svelte 作為框架, 侵入性更強.&lt;/p&gt;

&lt;p&gt;而 React 作為一個庫, 而不是框架, 可以與現有任何 HTML 基礎技術棧兼容,
並且漸進式替換.&lt;/p&gt;

&lt;p&gt;並且, React 與 “core-js, lodash, underscore, polyfills for browsers that no
longer exist, userland ECC libraries, moment.js, and a hundred other horrors”
並沒有密切的關係, 使用所謂現在框架也會遇到這樣的問題. 說白了,
這是開放式的瀏覽器生態與開發者想要避免 JS 語言歷史的坑造成的矛盾,
你不能指望所有用戶都用你開發的最新版渲染引擎.&lt;/p&gt;

&lt;p&gt;React 並不可怕, 對於開發者, 其他渲染庫也的確值得看:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Svelte, 強制需要構建.&lt;/li&gt;
  &lt;li&gt;Lit, 以前是 Polymer, Google 的維護不足讓開發者跟進困難. (我們曾使用 Polymer)&lt;/li&gt;
  &lt;li&gt;Vue 經過多次大版本變化, 語法經常有破壞性變化, 與 Svelte 類似但獨有的語法更多.
(我們曾使用 Vue 1.x, 2.x)&lt;/li&gt;
  &lt;li&gt;Solid, 和 React 的語法及特點最像. (我們在部分項目中在嘗試 Solid)&lt;/li&gt;
  &lt;li&gt;…&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;但是如果要用到生產環境, 我還是建議 React.&lt;/p&gt;

            </description>
            <pubDate>Wed, 11 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-11-why-react.html
            </guid>
        </item>
        
        <item>
            <title>Ionic 顏色</title>
            <link>
                https://zsqk.github.io/2024-12-10-ionic-color.html
            </link>
            <description>
                &lt;p&gt;Ionic 顏色的文檔為: &lt;a href=&quot;https://ionicframework.com/docs/theming/colors&quot;&gt;Ionic Colors&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;本文大部分內容都來自文檔.&lt;/p&gt;

&lt;h2 id=&quot;顏色概述&quot;&gt;顏色概述&lt;/h2&gt;

&lt;p&gt;Ionic 共有 9 種顏色:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;primary (主色, 默認為藍色)&lt;/li&gt;
  &lt;li&gt;secondary (次色, 默認為一種比較近似藍色的顏色)&lt;/li&gt;
  &lt;li&gt;tertiary (三色, 默認為另一種有點近似藍色的顏色)&lt;/li&gt;
  &lt;li&gt;success (成功色, 默認為綠色)&lt;/li&gt;
  &lt;li&gt;warning (警告色, 默認為黃色)&lt;/li&gt;
  &lt;li&gt;danger (危險色, 默認為紅色)&lt;/li&gt;
  &lt;li&gt;light (淺色, 默認為白色)&lt;/li&gt;
  &lt;li&gt;medium (中色, 默認為灰色)&lt;/li&gt;
  &lt;li&gt;dark (深色, 默認為黑色)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;每一種顏色都包含四個屬性:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;base (基礎色)&lt;/li&gt;
  &lt;li&gt;contrast (對比色, 與基礎色形成鮮明對比的顏色, 一般為黑或者白)&lt;/li&gt;
  &lt;li&gt;shade (陰影色, 比基礎色更深一些的顏色)&lt;/li&gt;
  &lt;li&gt;tint (高亮色, 比基礎色更淺一些的顏色)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;修改自帶的顏色&quot;&gt;修改自帶的顏色&lt;/h2&gt;

&lt;p&gt;Ionic 自帶的顏色可以通過修改 CSS 變量來修改.&lt;/p&gt;

&lt;p&gt;比如修改 primary 的顏色, 可以修改 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ion-color-primary&lt;/code&gt; 的 CSS 變量.&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;:root&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-primary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#ff0000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;創建新的自定義顏色&quot;&gt;創建新的自定義顏色&lt;/h2&gt;

&lt;p&gt;首先名曲新的自定顏色的基礎色, 然後使用&lt;a href=&quot;https://ionicframework.com/docs/theming/colors#new-color-creator&quot;&gt;自定義工具&lt;/a&gt;來創建顏色組.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;:bulb: 如果不想要使用自定義工具, 也可以直接自己自定義顏色.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;然後以 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ion-color-{COLOR}&lt;/code&gt; 為類名, 來使用新的顏色組. 如:&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;:root&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-brand-main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#69987b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-brand-main-rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;105&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;152&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;123&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-brand-main-contrast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#000000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-brand-main-contrast-rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-brand-main-shade&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#5c866c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-brand-main-tint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#78a288&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nc&quot;&gt;.ion-color-brand-main&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;--ion-color-brand-main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-base-rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;--ion-color-brand-main-rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-contrast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;--ion-color-brand-main-contrast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-contrast-rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;--ion-color-brand-main-contrast-rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-shade&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;--ion-color-brand-main-shade&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;py&quot;&gt;--ion-color-tint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;--ion-color-brand-main-tint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

            </description>
            <pubDate>Tue, 10 Dec 2024 04:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-10-ionic-color.html
            </guid>
        </item>
        
        <item>
            <title>幫助色盲和色弱使用軟件</title>
            <link>
                https://zsqk.github.io/2024-12-09-web-design-for-color-blind.html
            </link>
            <description>
                &lt;p&gt;在做 Web 設計的時候, 應該考慮色盲和色弱的人更方便使用軟件. 這部分內容常被稱作
accessibility, 縮寫為 a11y, 中文常被稱作無障礙.&lt;/p&gt;

&lt;h2 id=&quot;色盲和色弱的基本認知&quot;&gt;色盲和色弱的基本認知&lt;/h2&gt;

&lt;p&gt;色盲和色弱是常見的視覺障礙，大約影響全球 8% 的男性和 0.5% 的女性人口。主要分為以下幾類：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;紅色盲（紅色視覺缺陷）&lt;/li&gt;
  &lt;li&gt;綠色盲（綠色視覺缺陷）&lt;/li&gt;
  &lt;li&gt;藍色盲（藍色視覺缺陷）&lt;/li&gt;
  &lt;li&gt;全色盲（完全無法識別顏色）&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;設計原則&quot;&gt;設計原則&lt;/h2&gt;

&lt;p&gt;從設計角度, 應該區分兩種設計模式, 普通模式和色彩增強模式.
或者合併為一種設計模式, 支持色盲和色弱和普通用戶一樣正常與軟件進行交互.&lt;/p&gt;

&lt;p&gt;一般的做法是除了顏色, 要給出額外的圖形信息. 比如做國內股市大盤設計時:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;漲, 不僅用紅色字體, 還要用向上的箭頭.&lt;/li&gt;
  &lt;li&gt;跌, 不僅用綠色字體, 還要用向下的箭頭.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;同時, 我們也可以注意使用高對比度顏色. 比如不同顏色時, 如紅色和綠色,
使用高對比度顏色, 那麼色盲和色弱的人也能很容易區分.&lt;/p&gt;

&lt;p&gt;還有增加額外的線條來增加區分度.&lt;/p&gt;

&lt;h2 id=&quot;技術實現&quot;&gt;技術實現&lt;/h2&gt;

&lt;p&gt;從前端角度, 如果設計單獨為色盲和色弱的人設計了一套 UI,
那麼儘量通過額外加載 CSS 的方式進行處理.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;基礎&lt;/li&gt;
  &lt;li&gt;非色盲, 色弱&lt;/li&gt;
  &lt;li&gt;色盲, 色弱&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;普通模式加載 1 + 2, 色彩增強模式加載 1 + 3.&lt;/p&gt;

&lt;p&gt;也可以使用普通 + 擴展的方式:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;普通&lt;/li&gt;
  &lt;li&gt;色盲, 色弱&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;色彩增強模式加載 1, 色彩增強模式加載 1 + 2. 要確保 2 覆蓋 1.&lt;/p&gt;

&lt;h2 id=&quot;模擬與測試&quot;&gt;模擬與測試&lt;/h2&gt;

&lt;p&gt;對於 Web 開發來說, 可以通過 Chrome 的開發者工具, 來模擬色盲和色弱.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;打開 Chrome 開發者工具.&lt;/li&gt;
  &lt;li&gt;選擇更多工具.&lt;/li&gt;
  &lt;li&gt;Rendering 中, 選擇 Emulate vision deficiencies.&lt;/li&gt;
  &lt;li&gt;可以選擇一些情況進行模擬.&lt;/li&gt;
&lt;/ol&gt;

            </description>
            <pubDate>Mon, 09 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-09-web-design-for-color-blind.html
            </guid>
        </item>
        
        <item>
            <title>React 19</title>
            <link>
                https://zsqk.github.io/2024-12-06-react-19.html
            </link>
            <description>
                &lt;p&gt;React 19 終於正式發佈了: &lt;a href=&quot;https://react.dev/blog/2024/12/05/react-19&quot;&gt;https://react.dev/blog/2024/12/05/react-19&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;新版本中新增了許多功能, 其中, 一些功能是我們重點關注的:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;useActionState&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;use&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;useOptimistic&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ref&lt;/code&gt; 作為 props 傳遞&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;useactionstate&quot;&gt;useActionState&lt;/h2&gt;

&lt;p&gt;在使用 useActionState 的時候, 我們需要注意的是, 在函數內部能否調用 setState
函數對數據進行部分修改.&lt;/p&gt;

&lt;p&gt;官方演示非常清晰, 這裡稍作修改:&lt;/p&gt;

&lt;div class=&quot;language-tsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DataTable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;updateData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;isPending&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;useActionState&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;previousState&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getDataPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Table&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;isPending&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isPending&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;button&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;submit&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;disabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isPending&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;nx&quot;&gt;updateData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        Update
      &lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;use&quot;&gt;use&lt;/h2&gt;

&lt;p&gt;use 仍然不是一定足夠可靠的功能. 之前 React 團隊就說了 use 的侷限性, 現在
React 19 仍然沒有解決這個問題.&lt;/p&gt;

&lt;p&gt;我們預期僅在初始化數據的時候使用 use, 在更新數據的時候仍使用 useState.
在組件中, 同時保有這兩種狀態管理的方式, 比如:&lt;/p&gt;

&lt;div class=&quot;language-tsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;MyComponent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;initData&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getDataPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// 👆 因為現在不能在渲染組件中創建 Promise, 所以現在會報錯&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;setData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;currentData&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;useMemo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;initData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;initData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;currentData&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;button&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getDataPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
          &lt;span class=&quot;nx&quot;&gt;setData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        Set Data
      &lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;不過, 如何我們區分初始化數據和更新數據, 僅在系統初始化數據的時候使用 use,
那麼 use 仍然是一個非常有用的功能. 比如:&lt;/p&gt;

&lt;div class=&quot;language-tsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;configPromise&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getConfigPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;MyComponent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;configPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;setData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;button&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getDataPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
          &lt;span class=&quot;nx&quot;&gt;setData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        Set Data
      &lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;useoptimistic&quot;&gt;useOptimistic&lt;/h2&gt;

&lt;p&gt;在上面的例子中, 我們區分了 initData, data 和 currentData. 在 React 19 中,
我們使用 useOptimistic 可以對前端預計修改成功的數據進行優化. 比如:&lt;/p&gt;

&lt;div class=&quot;language-tsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;MyComponent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;setData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;currentData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;setOptimisticData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;useOptimistic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;currentData&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;button&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;nx&quot;&gt;setOptimisticData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;tempData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
          &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;getDataPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;tempData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
          &lt;span class=&quot;nx&quot;&gt;setData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        Set Data
      &lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在大多數情況下, 這是一個純優化, 並不會功能有影響.&lt;/p&gt;

&lt;p&gt;這種優化甚至還有負面效果, 比如:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;如果用戶在點擊按鈕之後, 已經渲染了新的數據, 這時用戶認為已經完成.&lt;/li&gt;
  &lt;li&gt;然後, 如果後端數據更新失敗, 那麼數據會重置回錯誤之前的數據, 但用戶不一定會注意到.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;ref-作為-props-傳遞&quot;&gt;ref 作為 props 傳遞&lt;/h2&gt;

&lt;p&gt;之前, ref 作為 props 傳遞的時候時會報錯. 需要使用 forwardRef 來傳遞.
但是, 現在 React 19 中, 不再需要使用 forwardRef 來傳遞, 可以直接傳遞 ref.&lt;/p&gt;

&lt;p&gt;官方演示為:&lt;/p&gt;

&lt;div class=&quot;language-tsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;MyInput&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ref&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ref&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ref&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyInput&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ref&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ref&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

            </description>
            <pubDate>Fri, 06 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-06-react-19.html
            </guid>
        </item>
        
        <item>
            <title>Deno lint 的侷限</title>
            <link>
                https://zsqk.github.io/2024-12-06-deno-lint-limitations.html
            </link>
            <description>
                &lt;p&gt;ESLint 是行業標準. 但是考慮到簡潔及效率, Deno lint 沒有與 ESLint 做兼容.&lt;/p&gt;

&lt;p&gt;Deno lint 本身也沒有插件機制, 雖然可以向 &lt;a href=&quot;https://github.com/denoland/deno_lint&quot;&gt;https://github.com/denoland/deno_lint&lt;/a&gt;
貢獻規則, 但是生態遠遠不夠好.&lt;/p&gt;

&lt;p&gt;目前比較嚴重的使用上的不足:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/denoland/deno_lint/issues/623&quot;&gt;缺乏對 JSDoc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@deprecated&lt;/code&gt; 的支持&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;只能做單文件檢查, 不能建立多文件關聯.&lt;/li&gt;
  &lt;li&gt;不能將註釋與代碼進行關聯, 只能單獨對註釋或者代碼進行檢查.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;要解決 Deno lint 的這些問題, 可以選擇配合 ESLint 同時使用, 但正如
&lt;a href=&quot;https://github.com/denoland/deno_lint/issues/25#issuecomment-1307626597&quot;&gt;https://github.com/denoland/deno_lint/issues/25#issuecomment-1307626597&lt;/a&gt;
所說, 對於 Deno 項目來說, 使用 ESLint 還是會受到一些限制.&lt;/p&gt;

&lt;p&gt;即便現在 Deno 實驗性支持不寫文件後綴名, 但還是有依賴等問題.&lt;/p&gt;

            </description>
            <pubDate>Fri, 06 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-06-deno-lint-limitations.html
            </guid>
        </item>
        
        <item>
            <title>規則的執行比規則設計是否精妙更重要</title>
            <link>
                https://zsqk.github.io/2024-12-05-rule-execution-over-design.html
            </link>
            <description>
                &lt;p&gt;在管理實踐中, 我們經常會遇到這樣的困惑: 為什麼精心設計的規則在實際執行中收效不佳?
本文將探討規則設計與執行的關係.&lt;/p&gt;

&lt;p&gt;無論是國家治理還是公司管理, 都可以總結為下面的幾點:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;設計規則. (立法, 司法)&lt;/li&gt;
  &lt;li&gt;確保規則被執行. (執法)&lt;/li&gt;
  &lt;li&gt;按照規則進行. (守法)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;針對日常工作存在的問題, 我總想通過制定規則, 然後通過執行這些規則來解決問題.&lt;/p&gt;

&lt;p&gt;但我太執著於規則的設計, 而忽略了規則的執行.&lt;/p&gt;

&lt;p&gt;有的時候規則沒有產生預期的效果, 並不是規則設計的不夠精妙, 而是規則執行的不夠徹底.&lt;/p&gt;

&lt;p&gt;在確保規則被執行的前提下, 再去完善規則才能讓規則發揮最大的作用.&lt;/p&gt;

&lt;p&gt;如果有令不行, 有禁不止, 那麼規則設計的再精妙也是無用.&lt;/p&gt;

            </description>
            <pubDate>Thu, 05 Dec 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-12-05-rule-execution-over-design.html
            </guid>
        </item>
        
        <item>
            <title>隱藏 SSID (Wi-Fi 安全性分析:隱藏 SSID 的作用與侷限)</title>
            <link>
                https://zsqk.github.io/2024-11-29-wifi-security-hidden-ssid.html
            </link>
            <description>
                &lt;p&gt;辦公室 Wi-Fi 出現問題, 多臺終端自動斷開連接, 嘗試再次連接時提示輸入密碼.
但是路由器上的有線連接是正常的.&lt;/p&gt;

&lt;p&gt;我懷疑是有其他設備使用了相同的 SSID, 並且短時間內信號更強,
讓終端設備切換到了這臺其他設備. 但我們的 SSID 並不常見, 故意使用我們的 SSID
有什麼目的呢? 有可能是為了獲得密碼.&lt;/p&gt;

&lt;p&gt;如果密碼是明文傳輸的, 那麼很容易被獲取. 但現代的設備不應該這麼不安全,
客戶端和服務端都應該將其他設備默認為不可信.&lt;/p&gt;

&lt;p&gt;比如我們理想中的一種做法是:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;客戶端構造一個連接請求, 其中包含一個明文隨機數,
還有針對這個隨機數的根據密碼生成的散列值.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;服務端收到一個連接請求, 根據明文的隨機數計算散列值, 看和數據包中的散列值是否相同,
如果不相同, 則判定為無效連接請求, 如果相同, 則創建一個新的隨機數用來將來通信,
並加密後發出.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;客戶端收到加密的數據後用自身密碼解密, 然後使用這個新的隨機數作為密碼用作本次連接的通信密鑰.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;上面這套方案就避免了密碼在網絡間進行明文傳輸, 同時一定程度上避免重放攻擊.
如果想要加強安全性, 還可以在數據包中增加時間戳, 並且定期更換臨時通信密鑰.&lt;/p&gt;

&lt;p&gt;不過回到最初的假設, 如果密碼沒有明文傳輸, 偽造的服務端是不是就沒有意義呢?&lt;/p&gt;

&lt;p&gt;也不全是, 雖然增加了攻擊難度, 但是因為有隨機數和針對隨機數的散列值,
攻擊方可以在自己的密碼字典中全部計算一遍, 嘗試匹配到弱密碼,
甚至在散列方法不夠安全時進行暴力破解.&lt;/p&gt;

&lt;p&gt;對於上述這種方式的攻擊, Wi-Fi 有一個方案可以緩解, 就是隱藏 SSID.&lt;/p&gt;

&lt;p&gt;但是這種隱藏的作用是有限的, 因為客戶端可能會廣播 SSID (Probe Request),
攻擊方還是可以掃描到. 但是大多數攻擊方不會這麼做, 因為攻擊方可能需要破解多個
AP 的密碼, 這麼做會大大增加破解難度.&lt;/p&gt;

&lt;p&gt;另外, WPA3 增加了一些前向安全的特性, 可以緩解一些基於重放攻擊的破解.
建議使用 WPA3 協議.&lt;/p&gt;

            </description>
            <pubDate>Fri, 29 Nov 2024 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2024-11-29-wifi-security-hidden-ssid.html
            </guid>
        </item>
        
        <item>
            <title>GitHub 投票設計</title>
            <link>
                https://zsqk.github.io/2023-05-01-github-polls.html
            </link>
            <description>
                &lt;h2 id=&quot;github-投票&quot;&gt;GitHub 投票&lt;/h2&gt;

&lt;p&gt;GitHub 的投票功能位於 Discussions 中, 有一個分類叫作 Polls.&lt;/p&gt;

&lt;p&gt;Polls 有基礎的投票功能, 但不是表單那種複雜設計.&lt;/p&gt;

&lt;p&gt;如果想要自定義分類也可以, 只需要將分類的 Discussion Format 設置為 Poll 即可.
但有兩個限制:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;已經設置為 Poll 的分類不能修改.&lt;/li&gt;
  &lt;li&gt;其他分類不能改為 Poll 分類.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;所以基本只能在創建分類的時候就選好 Poll 格式.&lt;/p&gt;

&lt;h2 id=&quot;github-的投票相比釘釘飛書群投票功能區別&quot;&gt;GitHub 的投票相比釘釘/飛書群投票功能區別&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;GitHub 僅支持不投票即可查看結果功能.&lt;/li&gt;
  &lt;li&gt;GitHub 不支持不投票則不可查看結果功能.&lt;/li&gt;
  &lt;li&gt;GitHub 僅支持匿名投票.&lt;/li&gt;
  &lt;li&gt;GitHub 不支持查看投票者名單功能.&lt;/li&gt;
  &lt;li&gt;GitHub 不支持設置可投票者名單功能.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;擴展&quot;&gt;擴展&lt;/h2&gt;

&lt;p&gt;2022 年 4 月發佈投票功能.
&lt;a href=&quot;https://github.blog/changelog/2022-04-12-discussions-polls/&quot;&gt;https://github.blog/changelog/2022-04-12-discussions-polls/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;也有其他人有上文說到的 “支持查看投票者名單功能” 的需求.
&lt;a href=&quot;https://github.com/orgs/community/discussions/5650&quot;&gt;https://github.com/orgs/community/discussions/5650&lt;/a&gt;&lt;/p&gt;

            </description>
            <pubDate>Mon, 01 May 2023 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2023-05-01-github-polls.html
            </guid>
        </item>
        
        <item>
            <title>在 Deno 中實現 HTTP 返回 body 的 Brotli 壓縮</title>
            <link>
                https://zsqk.github.io/2022-02-23-deno-web-compress-br.html
            </link>
            <description>
                &lt;blockquote&gt;
  &lt;p&gt;:warning: 本文是 2022 年 2 月 23 日寫的, 現在 Deno 已經有了變動,
所以本文在部分地方可能已經過時.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;在 9 個月之前, 我們在項目中創建了這則 issue, 今天, 伴隨著 Deno 最近標準庫的變動,
我們對此進行更加系統地說明.&lt;/p&gt;

&lt;h2 id=&quot;why--what&quot;&gt;Why &amp;amp; What&lt;/h2&gt;

&lt;p&gt;之前, 我們的 Web 項目對 HTTP 返回 body 實現了 deflate 的壓縮算法, 但使用的是 JS,
還是不夠快. 我們考慮支持對此進行優化.&lt;/p&gt;

&lt;p&gt;我們知道對於大多數瀏覽器來說, 都會發送這樣的請求頭 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Accept-Encoding: gzip, deflate, br&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;其中 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;br&lt;/code&gt; 就是我們暫時不支持的 br 壓縮, 即 Brotli 壓縮算法.&lt;/p&gt;

&lt;p&gt;從發展來看, br 是更適合 HTTP 的壓縮算法, 現代瀏覽器也都支持了.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://hacks.mozilla.org/2015/11/better-than-gzip-compression-with-brotli/&quot;&gt;https://hacks.mozilla.org/2015/11/better-than-gzip-compression-with-brotli/&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;在-deno-項目中實現-br&quot;&gt;在 Deno 項目中實現 br&lt;/h2&gt;

&lt;p&gt;但目前 Deno 仍未有對此的支持計劃. (有 issue, 但還沒計劃去做)&lt;/p&gt;

&lt;p&gt;在 Node.js 中, 有標準庫 zlab 去實現該壓縮算法.
&lt;a href=&quot;https://nodejs.org/api/zlib.html#zlib_class_zlib_brotlicompress&quot;&gt;https://nodejs.org/api/zlib.html#zlib_class_zlib_brotlicompress&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;但在 Deno 中, 官方不支持.&lt;/p&gt;

&lt;p&gt;在 npm 中有這樣的包 &lt;a href=&quot;https://www.npmjs.com/package/brotli&quot;&gt;https://www.npmjs.com/package/brotli&lt;/a&gt; 來實現 br 算法壓縮.
利用了 Emscripten(C++) 去實現.&lt;/p&gt;

&lt;p&gt;npm 的包是不能在 Deno 上使用的. 在調用其他方式上, 是通過 WASM.&lt;/p&gt;

&lt;p&gt;雖然能看到 WASM 本體 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.jsdelivr.net/npm/brotli@1.3.2/build/mem.js&lt;/code&gt;
但是現在還不能直接在 Deno 項目中用, 需要對包引用進行變動.&lt;/p&gt;

&lt;p&gt;然後嘗試在 Deno 社區中找相關解決方案, 就是 &lt;a href=&quot;https://github.com/denosaurs/deno_brotli&quot;&gt;https://github.com/denosaurs/deno_brotli&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;正如所有 Deno 項目一樣, deno_brotli 的使用非常簡單,
只需要 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import { compress } from &#39;https://deno.land/x/brotli@v0.1.4/mod.ts&#39;;&lt;/code&gt; 即可.&lt;/p&gt;

&lt;h2 id=&quot;在-deno-web-項目中實施返回-body-的壓縮&quot;&gt;在 Deno Web 項目中實施返回 body 的壓縮&lt;/h2&gt;

&lt;p&gt;假設我們已經有了要返回的 body 和 headers, 並且知道了請求方支持的壓縮方式 acceptEncoding,
那麼我們可以簡單進行如下操作:&lt;/p&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;acceptEncoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;br&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;compress&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;TextEncoder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;content-encoding&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;br&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;content-length&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;deno_brotli-是什麼&quot;&gt;deno_brotli 是什麼&lt;/h2&gt;

&lt;p&gt;其實 deno_brotli 就做了一件事情: &lt;a href=&quot;https://github.com/denosaurs/deno_brotli/blob/master/src/lib.rs&quot;&gt;src/lib.rs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;然後就是通過命令編譯為 &lt;a href=&quot;https://github.com/denosaurs/deno_brotli/blob/master/wasm.js&quot;&gt;wasm.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;其中, 使用的 &lt;a href=&quot;https://github.com/rustwasm/wasm-bindgen&quot;&gt;https://github.com/rustwasm/wasm-bindgen&lt;/a&gt; 項目還是挺值得我們學習一下的, 可以大幅擴展 JS 的能力,
就像本次利用了 &lt;a href=&quot;https://github.com/dropbox/rust-brotli&quot;&gt;https://github.com/dropbox/rust-brotli&lt;/a&gt; 這個庫一樣.&lt;/p&gt;

            </description>
            <pubDate>Wed, 23 Feb 2022 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2022-02-23-deno-web-compress-br.html
            </guid>
        </item>
        
        <item>
            <title>Arctic Code Vault Contributor</title>
            <link>
                https://zsqk.github.io/2020-07-17-github-arctic-code.html
            </link>
            <description>
                &lt;p&gt;看 GitHub 很少會看個人頁.&lt;/p&gt;

&lt;p&gt;知道 Arctic Code Vault Contributor 這件事還是在&lt;a href=&quot;https://v2ex.com/t/690791&quot;&gt;社區&lt;/a&gt;中.&lt;/p&gt;

&lt;p&gt;社區中大多數人都有, 我也不例外.&lt;/p&gt;

&lt;p&gt;&lt;img width=&quot;634&quot; alt=&quot;Screen Shot 2020-07-17 at 17 59 36&quot; src=&quot;https://user-images.githubusercontent.com/499364/87774569-48f5ce00-c857-11ea-93e3-60de10e17291.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;然後看了 &lt;a href=&quot;https://github.blog/2020-07-16-github-archive-program-the-journey-of-the-worlds-open-source-code-to-the-arctic/&quot;&gt;GitHub blog&lt;/a&gt; 瞭解了更多.&lt;/p&gt;

&lt;p&gt;在2020年2月2日這一天, GitHub 將所有活躍的開源倉庫數據進行了快照, 共 21TB.
然後使用 Piql 的技術將數據寫入到 186 個光敏膠片中. 最終儲存在了挪威 Svalbard
群島 Longyearbyen 小鎮一座廢棄礦井的數百米深坑中. 這將保存至少千年.&lt;/p&gt;

&lt;p&gt;因為疫情, 時間有一些推遲, 但現在終於還是完成了.&lt;/p&gt;

&lt;p&gt;所有相關的代碼貢獻者都獲得了 Arctic Code Vault Contributor 徽章.&lt;/p&gt;

&lt;p&gt;我們向自然索取礦石, 現在向自然反饋代碼.&lt;/p&gt;

&lt;p&gt;想想還是極浪(漫)的.&lt;/p&gt;

&lt;p&gt;我身已死, 漏洞長存.&lt;/p&gt;


            </description>
            <pubDate>Fri, 17 Jul 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-07-17-github-arctic-code.html
            </guid>
        </item>
        
        <item>
            <title>使用多設備開發時的技巧</title>
            <link>
                https://zsqk.github.io/2020-06-09-develop-multi-computers.html
            </link>
            <description>
                &lt;p&gt;多設備開發時, 代碼如何同步, 常用偏好如何同步, 怎麼方便地進行切換. 這是個課題.&lt;/p&gt;

&lt;p&gt;我大概有兩種思路:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;遠程開發機.&lt;/li&gt;
  &lt;li&gt;編輯器同步設置.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;使用遠程開發機的做法是最徹底的, 但同時也是存在弊端的. 比如前端開發時使用 8080
端口, 但如果多人使用開發機或者多臺開發機所在同一網絡, 則會出現衝突.&lt;/p&gt;

&lt;p&gt;編輯器同步設置則需要再對多個開發目錄進行額外同步, 比如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ssh/&lt;/code&gt; 和項目 Git 目錄.&lt;/p&gt;

&lt;p&gt;以下均以 VS Code 為例.&lt;/p&gt;

&lt;h2 id=&quot;遠程開發機&quot;&gt;遠程開發機&lt;/h2&gt;

&lt;p&gt;使用 VS Code 擴展 &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh&quot;&gt;Remote - SSH&lt;/a&gt; 可以更加方便地在遠程開發機上進行開發.&lt;/p&gt;

&lt;h2 id=&quot;編輯器同步設置&quot;&gt;編輯器同步設置&lt;/h2&gt;

&lt;p&gt;看到&lt;a href=&quot;https://www.reddit.com/r/vscode/comments/gyt6ul/is_there_a_way_to_sync_settingsjson_between_two/&quot;&gt;一篇帖子&lt;/a&gt;在問如何在多臺設備上同步 VS Code 的設置. 我正有此痛點.&lt;/p&gt;

&lt;p&gt;在帖子中看到兩種做法:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://code.visualstudio.com/docs/editor/settings-sync&quot;&gt;官方自帶&lt;/a&gt;, 但目前僅限 VS Code Insiders 測試版.&lt;/li&gt;
  &lt;li&gt;使用擴展.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;基於對微軟的信任, 有官方的自然用官方的.&lt;/p&gt;

&lt;p&gt;VS Code Insiders 的圖標是青色的, 可以與 VS Code 同時存在.&lt;/p&gt;

&lt;p&gt;Settings Sync 功能使用起來非常簡單, 登錄然後選擇同步就好了.&lt;/p&gt;

&lt;p&gt;這裡說一下登錄, 和 Live 功能類似, 但以前只有微軟賬號, 現在 (可能和收購有關係?)
還可以選 GitHub 賬號. 如果同時有兩個平臺的賬號, 建議還是選擇 GitHub,
因為在使用中發現如果登錄失敗, 當使用 GitHub 時, 可以通過 code 再次進行登錄嘗試,
程序員更友好一些吧.&lt;/p&gt;


            </description>
            <pubDate>Tue, 09 Jun 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-06-09-develop-multi-computers.html
            </guid>
        </item>
        
        <item>
            <title>Node</title>
            <link>
                https://zsqk.github.io/2020-05-22-node.html
            </link>
            <description>
                &lt;h2 id=&quot;nodejs事件&quot;&gt;Node.js事件&lt;/h2&gt;

&lt;h2 id=&quot;什麼是事件輪詢&quot;&gt;什麼是事件輪詢&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;事件循環是 Node.js 處理非阻塞 I/O 操作的機制——儘管 JavaScript 是單線程處理的——當有可能的時候，它們會把操作轉移到系統內核中去。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;事件輪詢機制解析&quot;&gt;事件輪詢機制解析&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;當 Node.js 啟動後，它會初始化事件輪詢；處理已提供的輸入腳本（或丟入 REPL，本文不涉及到），它可能會調用一些異步的 API、調度定時器，或者調用 process.nextTick()，然後開始處理事件循環。&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;┌───────────────────────────┐
┌─&amp;gt;│           timers          │
│  └─────────────┬─────────────┘
│  ┌─────────────┴─────────────┐
│  │     pending callbacks     │
│  └─────────────┬─────────────┘
│  ┌─────────────┴─────────────┐
│  │       idle, prepare       │
│  └─────────────┬─────────────┘      ┌───────────────┐
│  ┌─────────────┴─────────────┐      │   incoming:   │
│  │           poll            │&amp;lt;─────┤  connections, │
│  └─────────────┬─────────────┘      │   data, etc.  │
│  ┌─────────────┴─────────────┐      └───────────────┘
│  │           check           │
│  └─────────────┬─────────────┘
│  ┌─────────────┴─────────────┐
└──┤      close callbacks      │
   └───────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;階段概述&quot;&gt;階段概述&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;定時器：本階段執行已經被 setTimeout() 和 setInterval() 的調度回調函數。&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;待定回調：執行延遲到下一個循環迭代的 I/O 回調。&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;idle, prepare：僅系統內部使用。&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;輪詢：檢索新的 I/O 事件;執行與 I/O 相關的回調（幾乎所有情況下，除了關閉的回調函數，那些由計時器和 setImmediate() 調度的之外），其餘情況 node 將在適當的時候在此阻塞。&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;檢測：setImmediate() 回調函數在這裡執行。&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;關閉的回調函數：一些關閉的回調函數，如：socket.on(‘close’, …)。&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;在每次運行的事件循環之間，Node.js 檢查它是否在等待任何異步 I/O 或計時器，如果沒有的話，則完全關閉。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;引用鏈接: https://nodejs.org/zh-cn/docs/guides/event-loop-timers-and-nexttick/&lt;/p&gt;

            </description>
            <pubDate>Fri, 22 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-22-node.html
            </guid>
        </item>
        
        <item>
            <title>Next 50 Years</title>
            <link>
                https://zsqk.github.io/2020-05-21-next-50-years.html
            </link>
            <description>
                &lt;h1 id=&quot;未來-50-年讀書總結&quot;&gt;《未來 50 年》讀書總結&lt;/h1&gt;

&lt;h2 id=&quot;前言&quot;&gt;前言&lt;/h2&gt;
&lt;p&gt;《未來 50 年》是一部文集，許多前沿領域的科學家們展望未來 50 年的科學成就和可能有所突破的技術領域。本書正是他們的思考匯聚而成。&lt;/p&gt;

&lt;p&gt;本書英文第一版出版於 21 世紀初， 2002 年，距今已經過去 18 年。透過書中的內容我們可以簡略的瞭解到最前沿的科學和其發展方向。學者們對於未來的預測也得以讓我們一窺科學發展的趨勢。例如，我們對於未來的把握是否過於樂觀或悲觀。有多少知識是按照我們預想的節奏被發現和總結，又有多少爆炸性的新發現的對我們現有知識系統產生了巨大且深遠的影響。&lt;/p&gt;

&lt;p&gt;本書的作者大多是最前沿科學研究的學者和專家，涉及到的話題也必然有所侷限。在我們大膽的展望未來時，也不應忽略其他基礎學科的貢獻。&lt;/p&gt;

&lt;p&gt;下面是以學科領域的維度列出了本書中作者們提出的問題和見解。&lt;/p&gt;

&lt;h2 id=&quot;宇宙和太空探索&quot;&gt;宇宙和太空探索&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;宇宙大爆炸更詳細的解釋&lt;/li&gt;
  &lt;li&gt;佔宇宙密度80%到95%的暗物質和暗能量由什麼組成&lt;/li&gt;
  &lt;li&gt;星系如何形成&lt;/li&gt;
  &lt;li&gt;地球生命是如何開始的&lt;/li&gt;
  &lt;li&gt;我們有望在月球，火星和環繞木星的軌道上建立基地，源源不斷的激發我們的想像力和好奇心。幫助我們探索宇宙的奧秘。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;物理學&quot;&gt;物理學&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;量子物理的合理解釋&lt;/li&gt;
  &lt;li&gt;引力的量子理論是什麼&lt;/li&gt;
  &lt;li&gt;基本粒子的性質和解釋&lt;/li&gt;
  &lt;li&gt;建立物理學的統一理論&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;化學&quot;&gt;化學&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;我們將深入認識更小微粒之間的化學反應和相互作用。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;醫學&quot;&gt;醫學&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;越來越多人會變得抑鬱。
    &lt;ul&gt;
      &lt;li&gt;生活會越來越緊張&lt;/li&gt;
      &lt;li&gt;通過藥物治療並不是很有效&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;生物學&quot;&gt;生物學&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;生命的定義。我們可能會發現更多能夠協同演化的生命系統。更精確的定義生命的本質含義。&lt;/li&gt;
  &lt;li&gt;對基因的認識和改變。現在實驗室能夠誘發從小雞嘴裡生出嫩芽，誘發蛇長出腿。到 2050 年，我們有望重構一般恐龍的基因組。&lt;/li&gt;
  &lt;li&gt;我們將通過機器改善自身。恢復殘障人的能力甚至賦予人類更強大的超能力。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;神經科學&quot;&gt;神經科學&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;替換大腦和認知轉移&lt;/li&gt;
  &lt;li&gt;人類如何認識事物&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;數學&quot;&gt;數學&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;數學證明的觀念會發生改變
    &lt;ul&gt;
      &lt;li&gt;數學證明最重要的是檢驗，任何形式的數學證明將被接受。計算機輔助證明也可以被接受。&lt;/li&gt;
      &lt;li&gt;數學的根本不在於密密麻麻的數字，而在於證明的過程和模式。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;複雜性科學&quot;&gt;複雜性科學&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;複雜性科學在計算機的幫助下將會有更加顯著和切實的發展。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;文化教育&quot;&gt;文化教育&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;我們對於新的觀念和認識會變得更加寬容&lt;/li&gt;
  &lt;li&gt;教育將更加註重個人經驗。同時，虛擬技術的發展將使得我們更容易的獲取人生經歷和體驗。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;人文道德&quot;&gt;人文道德&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;一個更新的更現代的基於新的科學研究的道德理論將會產生。以此來規範人們的行為和人類發展的方向。&lt;/li&gt;
  &lt;li&gt;新的科學將有望完善更精確的人性模型。解答包括行為的主觀和客觀，感覺的真實和虛擬等問題。&lt;/li&gt;
  &lt;li&gt;遺傳學和認知科學的發展將使得人們更加幸福。本文作者是心理學家，在文中表示將發展一門新的系統的現象學，觀察不同人的意識波動規律，使人更加幸福。&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Thu, 21 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-21-next-50-years.html
            </guid>
        </item>
        
        <item>
            <title>Node Npm Cnpm Yarn Pnpm</title>
            <link>
                https://zsqk.github.io/2020-05-18-node-npm-cnpm-yarn-pnpm.html
            </link>
            <description>
                &lt;h2 id=&quot;node依賴管理&quot;&gt;node依賴管理&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Node的依賴管理工具&lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;npm&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;cnpm&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;yarn&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;pnpm&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;npm&quot;&gt;npm&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;使用一個名為package.json的文件，用戶可以通過npm install –save命令把項目裡所有的依賴項保存在這個文件裡&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;npm安裝插件是從國外服務器下載，受網絡影響大，可能出現異常&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;cnpm&quot;&gt;cnpm&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;cnpm跟npm用法完全一致, 服務器在國內, 訪問速度很快&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;yarn&quot;&gt;yarn&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;yarn是經過重新設計的嶄新的npm客戶端，它能讓開發人員並行處理所有必須的操作，並添加了一些其他改進&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;運行速度得到了顯著的提升，整個安裝時間也變得更少&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;像npm一樣，yarn使用本地緩存。與npm不同的是，yarn無需互聯網連接就能安裝本地緩存的依賴項，它提供了離線模式。&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;允許合併項目中使用到的所有的包的許可證&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pnpm&quot;&gt;pnpm&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;pnpm運行起來非常的快，超過了npm和yarn&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;pnpm採用了一種巧妙的方法，利用硬鏈接和符號鏈接來避免複製所有本地緩存源文件，這是yarn的最大的性能弱點之一&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;pnpm繼承了yarn的所有優點，包括離線模式和確定性安裝&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;引用地址:  https://blog.csdn.net/qq_32614411/article/details/80894605&lt;/p&gt;

            </description>
            <pubDate>Mon, 18 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-18-node-npm-cnpm-yarn-pnpm.html
            </guid>
        </item>
        
        <item>
            <title>Js Function</title>
            <link>
                https://zsqk.github.io/2020-05-15-js-function.html
            </link>
            <description>
                &lt;h1 id=&quot;js的幾個常用方法&quot;&gt;JS的幾個常用方法&lt;/h1&gt;

&lt;h3 id=&quot;all&quot;&gt;all&lt;/h3&gt;
&lt;p&gt;如果數組所有元素滿足函數條件，則返回true。調用時，如果省略第二個參數，則默認傳遞布爾值。&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const all = (arr, fn = Boolean) =&amp;gt; arr.every(fn);

all([4, 2, 3], x =&amp;gt; x &amp;gt; 1); // true
all([1, 2, 3]); // true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;allequal&quot;&gt;allEqual&lt;/h3&gt;
&lt;p&gt;判斷數組中的元素是否都相等&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const allEqual = arr =&amp;gt; arr.every(val =&amp;gt; val === arr[0]);

allEqual([1, 2, 3, 4, 5, 6]); // false
allEqual([1, 1, 1, 1]); // true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;currenturl&quot;&gt;currentURL&lt;/h3&gt;
&lt;p&gt;返回當前訪問的 URL 地址。&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const currentURL = () =&amp;gt; window.location.href;

currentURL(); 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;decapitalize&quot;&gt;decapitalize&lt;/h3&gt;
&lt;p&gt;將字符串的首字母轉換成小寫字母&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const decapitalize = ([first, ...rest]) =&amp;gt;
  first.toLowerCase() + rest.join(&#39;&#39;)

decapitalize(&#39;Zsqk&#39;); // &#39;zsqk&#39;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

            </description>
            <pubDate>Fri, 15 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-15-js-function.html
            </guid>
        </item>
        
        <item>
            <title>Deno</title>
            <link>
                https://zsqk.github.io/2020-05-14-deno.html
            </link>
            <description>
                &lt;h1 id=&quot;deno-一個-javascripttypescript-的運行時&quot;&gt;DENO 一個 JavaScript/TypeScript 的運行時&lt;/h1&gt;
&lt;p&gt;deno在5月13日發佈1.0版本，經過簡單的瞭解做一個簡單的介紹。&lt;/p&gt;

&lt;h2 id=&quot;deno簡介&quot;&gt;Deno簡介&lt;/h2&gt;
&lt;p&gt;deno官網對deno的定義如題，是一個 JavaScript/TypeScript 的運行時，基於Rust(Tokio)和V8引擎。具有默認為安全，開箱即用地支持TypeScript，傳送單個可執行文件，具有諸如依賴項檢查器（deno info）和代碼格式化程序（deno fmt）之類的內置實用程序等等。Deno的哲學旨在為現代程序員提供高效且安全的腳本環境。&lt;/p&gt;

&lt;h2 id=&quot;deno與node比較&quot;&gt;Deno與Node比較&lt;/h2&gt;
&lt;p&gt;在查找deno相關資料時，發現許多諸如deno是node的下一代。那在這裡從幾個方面介紹，如下：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;1、deno和node，從字面意思看就是de和no的位置對換，開發deno的人也正是開發node人。&lt;/li&gt;
  &lt;li&gt;2、deno不使用npm而是會像瀏覽器一樣使用稱為URL或文件路徑的模塊。&lt;/li&gt;
  &lt;li&gt;3、Deno不在package.json其模塊解析算法中使用。&lt;/li&gt;
  &lt;li&gt;4、Deno中的所有異步操作均返回承諾。因此，Deno提供的API與Node的不同。&lt;/li&gt;
  &lt;li&gt;5、Deno需要文件，網絡和環境訪問的顯式權限。這也是默認安全的體現。&lt;/li&gt;
  &lt;li&gt;6、deno對ts的支持以及打包，測試，測試話等都是原生支持，node需要第三方包來支持。&lt;/li&gt;
  &lt;li&gt;7、包分發，node中心化npmjs.com，deno去中心化使用import url&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;總結&quot;&gt;總結&lt;/h2&gt;
&lt;p&gt;個人看法，deno的設計是針對node現存的一些痛點，但是目前node的生態發展已經很完善了，deno短時間替代node不太可能，不過前景還是看好。&lt;/p&gt;

&lt;h4 id=&quot;官網httpsdenoland&quot;&gt;官網:https://deno.land&lt;/h4&gt;
&lt;h4 id=&quot;githuabhttpsgithubcomdenoland&quot;&gt;githuab:https://github.com/denoland&lt;/h4&gt;

            </description>
            <pubDate>Thu, 14 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-14-deno.html
            </guid>
        </item>
        
        <item>
            <title>HTTP/3</title>
            <link>
                https://zsqk.github.io/2020-05-13-http.html
            </link>
            <description>
                &lt;p&gt;HTTP3 是 HTTP 協議的最新版本。從誕生之初，HTTP 就是交換超文本文檔的首選應用層協議。
多年來，為了跟上互聯網的發展，以及 WWW 上交換的內容種類增加，HTTP 進行了幾次重大升級。&lt;/p&gt;

&lt;p&gt;本文將深入探討 HTTP/3，介紹 HTTP 協議的演變歷程，重點介紹 HTTP/3 的特點，並對
HTTP/3 將會帶來的互聯網變化提供新的視角。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;背景
在萬維網誕生之時，萬維網僅僅是一群交換超文本文件的計算機。在計算機之間交換文件
是一個簡單的程序，包括請求和響應。在此基礎上設計了一個簡單的基於文本的協議。
HTTP（超文本傳輸協議）應運而生。後來，它被起草成了一個標準化的 IETF 協議，
定義在 RFC 1945 中，也被稱為 HTTP/1.0。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;多年來，HTTP 從 HTTP/1.0 發展到 HTTP/1.1，再到 HTTP/2。在每一次迭代中，
協議都增加了新的功能，以處理大量的需求，如應用層需求、安全考慮、會話處理和媒體類型等。
要深入瞭解 HTTP/2 及其從 HTTP/1.0 演變而來的 HTTP/2，請看我們的 HTTP/2 概念文章。&lt;/p&gt;

&lt;p&gt;儘管經歷了幾次修訂，但 HTTP 的底層傳輸機制基本沒有變化。但是，隨著互聯網流量的激增，
在移動電話的推動下，HTTP 的傳輸機制在保證網頁瀏覽體驗的流暢性方面變得問題重重。&lt;/p&gt;

&lt;p&gt;HTTP/3 是為了處理 HTTP/2.0 的傳輸相關問題而生的，可以在各種設備上更快地訪問 Web。
它基於一個新的傳輸層協議，稱為 QUIC（Quick UDP Internet Protocol），在 UDP 之上工作。
這一選擇與之前版本的 HTTP 截然不同，之前版本都是基於 TCP。TCP 是一個比 UDP 更可靠的協議，
那麼為什麼要在 UDP 之上重新設計 HTTP 的傳輸層呢？&lt;/p&gt;

&lt;p&gt;讓我們來看看在 TCP 上運行 HTTP 的侷限性，並深入瞭解一下基於 QUIC 協議的 HTTP/3 的設計思想。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;什麼是 HTTP/3
當 IETF 正式標準化 HTTP/2 時，Google 正在獨立構建一個新的傳輸協議，名為 gQUIC。
它後來成為新互聯網草案，並被命名為 QUIC。gQUIC 最初的實驗證明，在網絡條件較差的情況下，
gQUIC 在增強網頁瀏覽體驗方面的效果非常好。因此，gQUIC 的發展勢頭越來越好，IETF
的大多數成員贊成建立一個在 QUIC 上運行的 HTTP 新規範。這個新的倡議被稱為 HTTP/3，
以區別於當前的 HTTP/2 標準。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;從語法和語義上看，HTTP/3 與 HTTP/2 相似。HTTP/3 遵循相同的請求和響應消息交換順序，
其數據格式包含方法、標題、狀態碼和 body。然而，HTTP/3 的顯著的偏差在於協議層在 UDP 之上的堆疊順序。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/63285847/81919179-14248b00-960a-11ea-9370-389aab201140.png&quot; alt=&quot;微信圖片_20200514173935&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;HTTP/3 是如何工作的？
HTTP/3 功能的核心是圍繞著底層的 QUIC 協議來實現的。在討論 QUIC 和 UDP 之前，
我們有必要先列出 TCP 的某些限制，這也是導致 QUIC 發展的原因。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;TCP 可能會間歇性地掛起數據傳輸
如果一個序列號較低的數據段還沒有接收到，即使其他序列號較高的段已經接收到，TCP
的接收機滑動窗口也不會繼續處理。這將導致 TCP 流瞬間掛起，在更糟糕的情況下，
即使所有的段中有一個沒有收到，也會導致關閉連接。這個問題被稱為 TCP 流的行頭阻塞（HoL）。
&lt;img src=&quot;https://user-images.githubusercontent.com/63285847/81919326-49c97400-960a-11ea-94da-1c439b1da41e.png&quot; alt=&quot;微信圖片_20200514174222&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;TCP 不支持流級複用
雖然 TCP 確實允許在應用層之間建立多個邏輯連接，但它不允許在一個 TCP 流中複用數據包。
使用 HTTP/2 時，瀏覽器只能與服務器打開一個 TCP 連接，並使用同一個連接來請求多個對象，
如 CSS、JavaScript 等文件。在接收這些對象的同時，TCP 會將所有對象序列化在同一個流中。
因此，它不知道 TCP 段的對象級分區。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;TCP 會產生冗餘通信
TCP 連接握手會有冗餘的消息交換序列，即使是與已知主機建立的連接也是如此。
&lt;img src=&quot;https://user-images.githubusercontent.com/63285847/81919440-71204100-960a-11ea-8c3e-95f446acc0a0.png&quot; alt=&quot;微信圖片_20200514174330&quot; /&gt;
QUIC 協議在以下設計選擇的基礎上，通過引入一些底層傳輸機制的改變，解決了這些問題。&lt;/p&gt;

    &lt;p&gt;1.選擇 UDP 作為底層傳輸層協議。在 TCP 之上建立新的傳輸機制，將繼承 TCP 的上述所有缺點。
因此，UDP 是一個明智的選擇。此外，QUIC 是在用戶層構建的，所以不需要每次協議升級時進行內核修改。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;流複用和流控。QUIC 引入了連接上的多路流複用的概念。QUIC 通過設計實現了單獨的、
針對每個流的流控，解決了整個連接的行頭阻塞問題。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/63285847/81920050-379c0580-960b-11ea-93d0-8ff4e6534703.jpg&quot; alt=&quot;微信圖片_20200514174900&quot; /&gt;&lt;/p&gt;

&lt;p&gt;靈活的擁塞控制機制。TCP 的擁塞控制機制是剛性的。該協議每次檢測到擁塞時，
都會將擁塞窗口大小減少一半。相比之下，QUIC 的擁塞控制設計得更加靈活，
可以更有效地利用可用的網絡帶寬，從而獲得更好的吞吐量。&lt;/p&gt;

&lt;p&gt;更好的錯誤處理能力。QUIC 使用增強的丟失恢復機制和轉發糾錯功能，以更好地處理錯誤數據包。
該功能對於那些只能通過緩慢的無線網絡訪問互聯網的用戶來說是一個福音，
因為這些網絡用戶在傳輸過程中經常出現高錯誤率。&lt;/p&gt;

&lt;p&gt;更快的握手。QUIC 使用相同的 TLS 模塊進行安全連接。然而，與 TCP 不同的是，QUIC
的握手機制經過優化，避免了每次兩個已知的對等者之間建立通信時的冗餘協議交換。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/63285847/81920090-484c7b80-960b-11ea-9016-ae34256368fd.gif&quot; alt=&quot;微信圖片_20200514174927&quot; /&gt;&lt;/p&gt;

&lt;p&gt;靈活的擁塞控制機制。TCP 的擁塞控制機制是剛性的。該協議每次檢測到擁塞時，
都會將擁塞窗口大小減少一半。相比之下，QUIC 的擁塞控制設計得更加靈活，
可以更有效地利用可用的網絡帶寬，從而獲得更好的吞吐量。&lt;/p&gt;

&lt;p&gt;更好的錯誤處理能力。QUIC 使用增強的丟失恢復機制和轉發糾錯功能，以更好地處理錯誤數據包。
該功能對於那些只能通過緩慢的無線網絡訪問互聯網的用戶來說是一個福音，因為這些
網絡用戶在傳輸過程中經常出現高錯誤率。&lt;/p&gt;

&lt;p&gt;更快的握手。QUIC 使用相同的 TLS 模塊進行安全連接。然而，與 TCP 不同的是，QUIC
的握手機制經過優化，避免了每次兩個已知的對等者之間建立通信時的冗餘協議交換。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;為什麼 HTTP/3 很重要？
TCP 已經有 40 多年的歷史了。它在 1981 年通過 RFC 793 從而標準化。多年來，
它經歷了多次更新，是一個非常強大的傳輸協議，可以支持互聯網流量的增長。然而，
由於設計上的原因，TCP 從來就不適合處理有損無線環境中的數據傳輸。在互聯網的早期，
有線網絡將網絡中的每一臺計算機連接起來。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;現在，隨著智能手機和便攜式設備的數量超過臺式機和筆記本電腦的數量，超過 50%
的互聯網流量已經通過無線傳輸。這種趨勢給整體的網絡瀏覽體驗帶來了問題，
其中最重要的是在無線覆蓋率不足的情況下，TCP 中的行頭阻塞。&lt;/p&gt;

&lt;p&gt;Google 的一些初步實驗證明，QUIC 作為 Google 部分熱門服務的底層傳輸協議，
極大地提高了速度和用戶體驗。部署 QUIC 作為 YouTube 視頻的底層傳輸協議，導致
YouTube 視頻流的緩衝率下降了 30%，這直接影響了用戶的視頻觀看體驗。在顯示谷歌搜索結果時，
也有類似的改善。&lt;/p&gt;

&lt;p&gt;網絡條件較差的情況下提升非常明顯，這促使谷歌更加積極地完善該協議，並最終向 IETF
提出標準化。&lt;/p&gt;

&lt;p&gt;由於這些早期的試驗所帶來的所有改進，QUIC 已經成為帶領萬維網走向未來的重要因素。
在 QUIC 的支持下，HTTP 從 HTTP/2 到 HTTP/3 的改頭換面，朝著這個方向合理地邁出了一步。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;HTTP/3 的最佳用例
HTTP/3 將改善我們上網的體驗，特別是在仍無法使用高速無線網絡的地區。儘管 HTTP/2
已經解決了一部分問題，然而 HTTP/3 更進一步。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;物聯網(IoT)
HTTP 可能不是物聯網的首選協議，但在某些情況下，基於 HTTP 的通信非常適合特定的應用。
HTTP/3 可以解決從傳感器收集數據的移動電話的無線連接損耗問題。這個問題同樣適用於
安裝在車輛或可移動資產上的獨立 IoT 設備。通過 HTTP 來訪問這些設備，可以更加可靠。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;大數據
全球各地的企業都在覺醒，意識到從多個部門收集數據的潛力，並將其整合成更大的信息共享 API，
供內部和外部受眾共享。這些 API 也為數據的貨幣化鋪平了道路，通過託管這些數據作為流
API 服務可以實現數據的貨幣化。隨著時間的推移，這些服務會吐出海量的數據。通過
HTTP/3 託管的流 API 將使它們比 HTTP/2 更健壯、更有彈性。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Web VR
隨著瀏覽器能力的提升，內容格局正在快速變化。其中一個領域就是基於網絡的 VR。
雖然還處於起步階段，但有很多的用例可以讓 VR 在加強協作方面發揮關鍵作用。
網絡在促進 VR 互動方面佔據了核心位置。VR 應用需要更多的帶寬來渲染虛擬場景中的複雜細節，
因此遷移到 HTTP/3 會大有收穫。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;採用 HTTP/3：考慮和限制
過渡到 HTTP/3 不僅涉及到應用層的變化，還涉及到底層傳輸層的變化。因此，與它的前身
HTTP/2 相比，HTTP/3 的採用更具挑戰性，因為後者只需要改變應用層。傳輸層承受著
網絡中的大量中間層審查。這些中間層，如防火牆、代理、NAT 設備等會進行大量的
深度數據包檢查，以滿足其功能需求。因此，新的傳輸機制的引入對 IT 基礎設施和
運維團隊來說有一些影響。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;然而，HTTP/3 被廣泛採用的另一個問題是，它是基於 QUIC 的，在 UDP 上運行。大多數的
Web 流量，以及 IETF 定義的知名服務都是在 TCP 之上運行的。這也是為什麼長時間運行
HTTP/3 的 UDP 會話會被防火牆的默認數據包過濾策略所影響的原因。&lt;/p&gt;

&lt;p&gt;隨著 IETF 正在進行的標準化工作，這些問題最終都會得到解決。此外，考慮到 Google
在早期 QUIC 實驗所顯示的積極結果，人們對 HTTP/3 的支持是壓倒性的，
這將最終迫使中間層廠商標準化。&lt;/p&gt;

&lt;p&gt;針對受限的 IoT 設備，HTTP/3 由於過於繁瑣從而無法採用。許多 IoT 應用部署的設備的
外形尺寸非常小。因此，它們的 RAM 和 CPU 功率都是有限的。為了使設備在電池功率、
低比特率和有損連接等限制條件下高效運行，必須執行此要求。HTTP/3 在現有的 UDP 之上，
以 QUIC 的形式在傳輸層處理，增加了 HTTP/3 在整個協議棧中的佔用空間。這使得 HTTP/3
較為笨重，不適合那些 IoT 設備。但這種情況很少出現，而且存在專門的協議，這就避免了
直接在此類設備上支持 HTTP 的需要。此外，還有以物聯網為核心的協議，如 MQTT。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;開始使用 HTTP/3
IETF 的 HTTP 工作組正致力於在 2020 年後期發佈 HTTP/3。因此它還沒有被 NGINX 和
Apache 等主流 web 服務器正式支持。不過，有幾個 lib 可以用來實驗這個新協議，
也提供了非官方的補丁。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;以下是支持 HTTP/3 和 QUIC 傳輸 lib 的列表。請注意，這些實現都是基於互聯網標準草案
某一個版本，而這個版本很可能會被更高的版本所取代，最終的標準會在 RFC 中發佈。&lt;/p&gt;

&lt;p&gt;Quiche (&lt;a href=&quot;https://github.com/cloudflare/quiche&quot;&gt;https://github.com/cloudflare/quiche&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Quiche 提供了通過 QUIC 協議發送和接收數據包的底層編程接口。它還支持 HTTP/3 模塊，
通過其 QUIC 協議實現發送 HTTP 數據包。除此之外，它還為 NGINX 服務器提供了一個
非官方的補丁，可以安裝和託管一個能夠運行 HTTP/3 的 Web 服務器。除此以外，
還提供了額外的程序來支持 Android 和 iOS 移動應用上使用 HTTP/3。&lt;/p&gt;

&lt;p&gt;Aioquic (&lt;a href=&quot;https://github.com/aiortc/aioquic&quot;&gt;https://github.com/aiortc/aioquic&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Aioquic 是 QUIC 的 python 實現。它還內置 HTTP/3 的測試服務器和客戶端庫。Aioquic
建立在 asyncio 模塊之上，asyncio 模塊是 Python 的標準異步 I/O 框架。&lt;/p&gt;

&lt;p&gt;Neqo (https:/github.com/mozilla/neqo)&lt;/p&gt;

&lt;p&gt;Neqo 是 Mozilla 使用 Rust 實現 QUIC 和 HTTP/3。&lt;/p&gt;

&lt;p&gt;原文地址：&lt;a href=&quot;https://www.ably.io/concepts/http3?utm_medium=referral&amp;amp;utm_source=reddit&amp;amp;utm_campaign=evergreen#limitations&quot;&gt;https://www.ably.io/concepts/http3?utm_medium=referral&amp;amp;utm_source=reddit&amp;amp;utm_campaign=evergreen#limitations&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;引用地址：&lt;a href=&quot;https://mp.weixin.qq.com/s/i-QUbVRVicqzMSZ9FUVCfQ&quot;&gt;https://mp.weixin.qq.com/s/i-QUbVRVicqzMSZ9FUVCfQ&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;評論:&lt;/p&gt;

&lt;p&gt;有人說, 當他們身在中國大陸使用 UDP 服務時會被 QoS 限流.&lt;/p&gt;

&lt;p&gt;雖說是將來的標準, 但整體來說, 這還是未來式.&lt;/p&gt;

&lt;p&gt;我們可以通過 &lt;a href=&quot;https://caniuse.com/#feat=http3&quot;&gt;https://caniuse.com/#feat=http3&lt;/a&gt; 來瞭解瀏覽器對其的支持情況.&lt;/p&gt;

            </description>
            <pubDate>Wed, 13 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-13-http.html
            </guid>
        </item>
        
        <item>
            <title>closure</title>
            <link>
                https://zsqk.github.io/2020-05-12-higher-order-function.html
            </link>
            <description>
                &lt;h2 id=&quot;閉包&quot;&gt;閉包&lt;/h2&gt;
&lt;p&gt;函數和對其周圍狀態（lexical environment，詞法環境）的引用捆綁在一起構成閉包（closure）。也就是說，閉包可以讓你從內部函數訪問外部函數作用域。在 JavaScript 中，每當函數被創建，就會在函數生成時生成閉包。&lt;/p&gt;

&lt;p&gt;參考：&lt;a href=&quot;https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Closures&quot;&gt;MDN&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;閉包的特性&quot;&gt;閉包的特性&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;函數嵌套函數&lt;/li&gt;
  &lt;li&gt;函數內部可以引用函數外部的參數和變量&lt;/li&gt;
  &lt;li&gt;參數和變量不會被垃圾回收機制回收&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;閉包的作用&quot;&gt;閉包的作用&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;可以在函數的外部訪問到函數內部的局部變量。&lt;/li&gt;
  &lt;li&gt;讓這些變量始終保存在內存中，不會隨著函數的結束而自動銷燬。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;例子&quot;&gt;例子&lt;/h3&gt;
&lt;p&gt;比如我們定義一個計數器，正常的寫法&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var count = 0;
function add() {
  return count += 1;
}
add(); // 1
add(); // 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;這樣沒問題，可以正常實現功能，也很簡單方便。但是如果我們要同時實現多個計數器呢，總不能&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var count = 0;
function add() {
  return count += 1;
}
var count1 = 0;
function add1() {
  return count += 1;
}
var count2 = 0;
function add2() {
  return count += 1;
}
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;這樣一直寫吧， 所以這時候就可以使用閉包來實現&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function add() {
  var count = 0;
  return function() {
    return count += 1;
  }
}
var fn1 = add(); // 計數器1
var fn2 = add(); // 計數器2
fn1(); // 1
fn1(); // 2
fn1(); // 3
fn2(); // 1
fn2(); // 2
fn2(); // 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;最後總結一下閉包的好處與壞處&quot;&gt;最後總結一下閉包的好處與壞處&lt;/h3&gt;

&lt;h4 id=&quot;好處&quot;&gt;好處&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;保護函數內的變量安全 ，實現封裝，防止變量流入其他環境發生命名衝突&lt;/li&gt;
  &lt;li&gt;在內存中維持一個變量，可以做緩存（但使用多了同時也是一項缺點，消耗內存）&lt;/li&gt;
  &lt;li&gt;匿名自執行函數可以減少內存消耗&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;壞處&quot;&gt;壞處&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;其中一點上面已經有體現了，就是被引用的私有變量不能被銷燬，增大了內存消耗，造成內存洩漏，解決方法是可以在使用完變量後手動為它賦值為null；&lt;/li&gt;
  &lt;li&gt;其次由於閉包涉及跨域訪問，所以會導致性能損失，我們可以通過把跨作用域變量存儲在局部變量中，然後直接訪問局部變量，來減輕對執行速度的影響&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Tue, 12 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-12-higher-order-function.html
            </guid>
        </item>
        
        <item>
            <title>Headless Brower</title>
            <link>
                https://zsqk.github.io/2020-05-11-headless-brower.html
            </link>
            <description>
                &lt;h2 id=&quot;headless-brower&quot;&gt;Headless Brower&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Headless Brower&lt;/code&gt; 直譯為中文是無頭瀏覽器。其中的無頭是指沒有圖形界面的意思。也就是通過代碼來控制與瀏覽器的交互。比如捕獲頁面內容加載完成事件，執行按鈕的點擊事件，執行鍵盤輸入，表單提交等。&lt;/p&gt;

&lt;h2 id=&quot;headless-chrome&quot;&gt;Headless Chrome&lt;/h2&gt;
&lt;p&gt;從 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Chrome 59&lt;/code&gt; 版本開始，Chrome 瀏覽器加入了 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Headless&lt;/code&gt; 運行模式。除了沒有圖形界面以外，在 Headless 模式下可以實現 Chrome 瀏覽器的所有功能。&lt;/p&gt;

&lt;p&gt;此外，Chrome 團隊開發了 Chrome 開發工具協議，簡稱 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CDP(Chrome DevTools Protocol)&lt;/code&gt;。該協議提供了很多有用的功能 API，比如在 DOM，調試器和網絡方面等。Chrome 瀏覽器中的開發者工具正是使用了該協議實現其功能。&lt;/p&gt;

&lt;p&gt;Chrome 開發工具協議使得 Headless Chrome 的功能更加強大。&lt;/p&gt;

&lt;h2 id=&quot;headless-chrome-庫&quot;&gt;Headless Chrome 庫&lt;/h2&gt;
&lt;p&gt;一些第三方代碼庫提供了更加方便的使用 Headless Chrome 功能的方法。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Chromedp&lt;/code&gt; 是使用 Golang 語言實現的一種更加簡單快速的方式驅動支持 Chrome DevTools 協議瀏覽器的方式，無需外部依賴。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Selenium&lt;/code&gt; 是用於測試 Web 應用程序用戶界面的常用框架。同時也支持所有基於 Web 的管理任務自動化。支持的語言有 Java，Python，C#，Ruby，Javascript 和 Kotlin。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;puppeteer&lt;/code&gt; 是使用 Node 語言實現的 Web 應用自動化測試工具。是 Google Chrome 團隊官方的 Headless Chrome 工具。&lt;/p&gt;

&lt;h2 id=&quot;headless-chrome-庫應用場景&quot;&gt;Headless Chrome 庫應用場景&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;頁面自動化測試  &lt;br /&gt;
  可以通過 Headless Chrome 直接測試頁面中的內容和交互。而不僅限於代碼測試。&lt;/li&gt;
  &lt;li&gt;爬蟲  &lt;br /&gt;
  對於某些不會直接顯示在 HTML 節點中的內容，例如頁面成功加載後再通過 AJAX 與後端服務器請求的內容或單頁應用，可以使用 Headless Chrome 來獲取。&lt;/li&gt;
  &lt;li&gt;保存頁面副本  &lt;br /&gt;
  可以通過代碼自動將需要的頁面保存為圖片或 PDF 文件&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;總之，Chrome 瀏覽器能夠實現的功能在 Headless 模式中都可以實現。加入程序使得我們可以實現更多更強大的功能。&lt;/p&gt;

&lt;h2 id=&quot;參考&quot;&gt;參考&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developers.google.com/web/updates/2017/04/headless-chrome&quot;&gt;Getting Started with Headless Chrome&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://chromedevtools.github.io/devtools-protocol/&quot;&gt;Chrome DevTools Protocol&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/chromedp/chromedp&quot;&gt;chromedp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/SeleniumHQ/selenium&quot;&gt;selenium&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/puppeteer/puppeteer&quot;&gt;puppeteer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Mon, 11 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-11-headless-brower.html
            </guid>
        </item>
        
        <item>
            <title>如何用 CSS 自定義使用 Font Awesome 圖標</title>
            <link>
                https://zsqk.github.io/2020-05-09-font-awesome-in-css.html
            </link>
            <description>
                &lt;p&gt;最近想在 CSS &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::after&lt;/code&gt; 中直接使用 Font Awesome 圖標.&lt;/p&gt;

&lt;p&gt;我們可以直接看代碼瞭解如何去使用, 也可以通過 &lt;a href=&quot;https://fontawesome.com/how-to-use/on-the-web/advanced/css-pseudo-elements&quot;&gt;Font Awesome 官方的文章&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;具體實現就是:&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nc&quot;&gt;.need-after&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;::after&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&quot;Font Awesome 5 Free&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&quot;\f007&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;其中 content 的值可以直接在 &lt;a href=&quot;https://fontawesome.com/icons?d=gallery&amp;amp;m=free&quot;&gt;gallery&lt;/a&gt; 中找到.&lt;/p&gt;

&lt;h2 id=&quot;附-css-的編碼&quot;&gt;附: CSS 的編碼&lt;/h2&gt;

&lt;p&gt;這裡順便說一下 CSS 的編碼.&lt;/p&gt;

&lt;p&gt;對於一些編程語言來說, 比如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; 會使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\u0061&lt;/code&gt; 這樣編碼, 其中 u 代表 Unicode.&lt;/p&gt;

&lt;p&gt;但 CSS 沒有, 雖然編碼方式也是 UTF, 但儲存方式是固定的 6 個 hex, 比 UTF-32
少了兩個儲存位置. 比如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; 在 CSS 中可以寫為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\000061&lt;/code&gt;.&lt;/p&gt;


            </description>
            <pubDate>Sat, 09 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-09-font-awesome-in-css.html
            </guid>
        </item>
        
        <item>
            <title>Cloudwatch</title>
            <link>
                https://zsqk.github.io/2020-05-08-cloudwatch.html
            </link>
            <description>
                &lt;h2 id=&quot;什麼是cloudwatch&quot;&gt;什麼是CloudWatch&lt;/h2&gt;
&lt;p&gt;Amazon CloudWatch 實時監控您的 Amazon Web Services (AWS) 資源以及您在 AWS 中運行的應用程序。
可以使用 CloudWatch 收集和跟蹤指標，這些指標是可衡量的相關資源和應用程序的變量。&lt;/p&gt;

&lt;h2 id=&quot;cloudwatch的四大功能&quot;&gt;CloudWatch的四大功能&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;指標：從AWS的服務中收集數據放到metrics,然後通過available statistics顯示到控制台上&lt;/li&gt;
  &lt;li&gt;警報：通過對指標的判斷，可以發出郵件，或執行auto scaling&lt;/li&gt;
  &lt;li&gt;日誌：會將lambda/RDS等執行的日誌放到log中，方便處理&lt;/li&gt;
  &lt;li&gt;對事件處理的功能：通過EC2實例或其他服務觸發，調用到其他的服務，比如調用lambda&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ec2的監控指標&quot;&gt;EC2的監控指標&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;可以查看CPU，磁盤，網絡等指標，但是沒有內存的指標，AWS承諾不會動客戶的任何數據，
  也不會在EC2實例上安裝任何的插件, 客戶可以在市場上找一些流行的性能監控軟件取到EC2的內存，
  然後調用cloudwatch的API然後展示到如下監控的指標列表中。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ec2創建警報&quot;&gt;EC2創建警報&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;可根據各類指標創建警報&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;創建事件&quot;&gt;創建事件&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;可以設置特定的時間或者時間區間，調用一次lamda函數&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Fri, 08 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-08-cloudwatch.html
            </guid>
        </item>
        
        <item>
            <title>Awesome</title>
            <link>
                https://zsqk.github.io/2020-05-06-awesome.html
            </link>
            <description>
                &lt;h1 id=&quot;awesome系列github上超有名的topic&quot;&gt;awesome系列github上超有名的Topic&lt;/h1&gt;
&lt;p&gt;大部分有一定知名度的領域，都有著自己的awesome-xxx項目&lt;/p&gt;

&lt;h2 id=&quot;awesome-topic簡要的事實描述&quot;&gt;awesome Topic簡要的事實描述&lt;/h2&gt;
&lt;p&gt;1、目前awesome系列包含了3325個各類倉庫&lt;br /&gt;
2、Star數最多的awesome的主倉庫，stars&amp;gt;132k&lt;br /&gt;
3、Topic中stars超過10k的有超過60個&lt;/p&gt;

&lt;p&gt;要了解這個系列，可以直接從awesome項目開始(indresorhus/awesome)項目包含平臺類、編程語言、前端開發、後端開發、計算機科學、大數據、理論、書籍、編輯器、遊戲開發、開發環境、娛樂、數據庫、媒體、學習資料與方法、安全、內容管理系統、硬件、創業與商務、工作方法、網絡、分散系統、高等教育、事件、測試等相關集合。&lt;/p&gt;

&lt;p&gt;這些集合包括了相關領域的書籍、課程、論文、軟件、數據集、教程、博客等。以python為例，awesome-python（star：82.1k），倉庫收納了Web框架、網絡爬蟲、內容管理系統、計算機視覺、密碼學、數據分析、數據可視化、深度學習、遊戲開發、機器學習、自然語言處理、內容推薦系統、機器人技術、代碼日誌分析等內容。&lt;/p&gt;

&lt;p&gt;目錄對收錄的資源做了簡要的介紹，點擊鏈接就可以直達資料頁。&lt;/p&gt;

&lt;p&gt;以下是挑選的一些目前10k+的獲取對我們的工作學習有用的熱門awesome倉庫：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;sindresorhus/awesome: Github stars 132k (各種有趣話題的精彩列表)&lt;/li&gt;
  &lt;li&gt;vinta/awesome-python: Github stars 82.1k (一份精選的優秀Python框架列表)&lt;/li&gt;
  &lt;li&gt;avelino/awesome-go: Github stars 54.1k (一份精選的優秀Go框架列表)&lt;/li&gt;
  &lt;li&gt;sindresorhus/awesome-nodejs: Github stars 35.6k (有趣的Node.js包和資源)&lt;/li&gt;
  &lt;li&gt;dypsilon/frontend-dev-bookmarks: Github stars 27.1k (前端web開發人員的資源集合。)&lt;/li&gt;
  &lt;li&gt;ziadoz/awesome-php: Github stars 23.5k (一份精選的PHP庫列表)&lt;/li&gt;
  &lt;li&gt;brillout/awesome-react-components: Github stars 22.4k (React組件和庫的管理列表。)&lt;/li&gt;
  &lt;li&gt;veggiemonk/awesome-docker: Github stars 17.7k (精選的docker資源和項目清單)&lt;/li&gt;
  &lt;li&gt;viatsko/awesome-vscode: Github stars 17.1k (一個令人愉快的VS代碼包和資源的列表)&lt;/li&gt;
  &lt;li&gt;AllThingsSmitty/css-protips: Github stars 14.4k (一個幫助你掌握CSS技巧的技巧集)&lt;/li&gt;
  &lt;li&gt;tmrts/go-patterns: Github stars 12.6k (Go語言慣用設計和應用程序模式的集合)&lt;/li&gt;
  &lt;li&gt;gztchan/awesome-design: Github stars 12k (設計資源)&lt;/li&gt;
  &lt;li&gt;xgrommx/awesome-redux: Github stars 11.7k (很讚的Redux示例和中間產品列表)&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Wed, 06 May 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-05-06-awesome.html
            </guid>
        </item>
        
        <item>
            <title>關於使用 PostgreSQL 的 ENUM 類型</title>
            <link>
                https://zsqk.github.io/2020-04-30-postgresql-enum.html
            </link>
            <description>
                &lt;p&gt;數據庫版本 v9.6&lt;/p&gt;

&lt;h2 id=&quot;數據庫中枚舉值的作用&quot;&gt;數據庫中枚舉值的作用&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;約束數據.&lt;/li&gt;
  &lt;li&gt;更加語義化.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;在數據庫中使用枚舉值只是在數據層面確保數據正確的做法, 不能替代程序中的邏輯.&lt;/p&gt;

&lt;p&gt;程序中應該做足夠的判斷, 儘量確保數據庫中不會出現因枚舉值不匹配導致的問題.&lt;/p&gt;

&lt;h2 id=&quot;關於枚舉值的使用&quot;&gt;關於枚舉值的使用&lt;/h2&gt;

&lt;p&gt;例如:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CREATE TYPE abc AS ENUM (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;雖然在向數據庫中寫數據時, 我們是將 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&#39;a&#39;&lt;/code&gt; 寫入到數據庫中, 但實際數據庫儲存的是
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;abc[1]&lt;/code&gt; 這樣的數據.&lt;/p&gt;

&lt;h2 id=&quot;關於枚舉值的查詢&quot;&gt;關於枚舉值的查詢&lt;/h2&gt;

&lt;p&gt;如何查詢目前數據庫中已經有的枚舉值是哪些.&lt;/p&gt;

&lt;p&gt;可以參考 &lt;a href=&quot;https://stackoverflow.com/questions/9540681/list-postgres-enum-type&quot;&gt;Stack Overflow 上的回答&lt;/a&gt;, 效率還是比較高的, 基本 10ms 以內.&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nspname&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;enum_schema&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;typname&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;enum_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;enum_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumlabel&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;enum_value&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;pg_type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;JOIN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pg_enum&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;ON&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumtypid&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;JOIN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pg_catalog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pg_namespace&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;ON&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;typnamespace&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;ORDER&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;BY&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;enum_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumsortorder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;關於枚舉值的修改&quot;&gt;關於枚舉值的修改&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;支持添加新值.&lt;/li&gt;
  &lt;li&gt;支持修改原值.&lt;/li&gt;
  &lt;li&gt;不支持刪除原值.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;雖然文檔說支持向後添加新值, 但實際可以加在任何地方.&lt;/p&gt;

&lt;p&gt;雖然文檔寫不支持修改排序, 但可以通過修改 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enumsortorder&lt;/code&gt; 來完成重排序. 並且排序
支持浮點數, 比如當執行 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ALTER TYPE abc ADD VALUE a- BEFORE b&lt;/code&gt; 時,
會將新插入值的排序改為浮點數, 如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;關於如何修改枚舉值, 直接 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UPDATE pg_enum&lt;/code&gt; 就可以了.&lt;/p&gt;

&lt;p&gt;能否直接修改原值的排序呢? 實測是沒問題的, 不會影響表中使用到該類型的數據.&lt;/p&gt;

            </description>
            <pubDate>Thu, 30 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-30-postgresql-enum.html
            </guid>
        </item>
        
        <item>
            <title>404 Page</title>
            <link>
                https://zsqk.github.io/2020-04-30-404-page.html
            </link>
            <description>
                &lt;h2 id=&quot;一行暖心的代碼讓世界充滿愛&quot;&gt;一行暖心的代碼，讓世界充滿愛~&lt;/h2&gt;

&lt;p&gt;有時用戶在訪問頁面找不到網站的資源時，就會提示404錯誤。作為網站的開發者，最好應該自己定製404頁面，引導用戶返回到網站，防止用戶流失。&lt;/p&gt;

&lt;h4 id=&quot;你知道嗎&quot;&gt;你知道嗎？&lt;/h4&gt;
&lt;p&gt;在自己定製404頁面時，只需要在網站中加入一行代碼，就能為公益盡一份力。這個頁面叫做&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;公益404頁面&lt;/code&gt;&lt;/p&gt;

&lt;h4 id=&quot;介紹&quot;&gt;介紹&lt;/h4&gt;
&lt;p&gt;公益404頁面是由騰訊公司員工志願者自主發起的互聯網公益活動。&lt;/p&gt;

&lt;p&gt;網站只需要在自己的404頁面中嵌入一段簡單的代碼，就能通過互聯網來迅速傳播失蹤兒童信息，從而提高找回失蹤兒童的概率。失蹤兒童信息來自寶貝回家尋子網。&lt;/p&gt;

&lt;h4 id=&quot;代碼&quot;&gt;代碼&lt;/h4&gt;
&lt;p&gt;複製以下 js 代碼，嵌入到您的 404 頁面，可以自適應移動設備&lt;/p&gt;

&lt;h5 id=&quot;注意事項&quot;&gt;注意事項&lt;/h5&gt;
&lt;p&gt;如果一個 404 頁面的內容小於 512B，IE 會認為該 404 頁面不夠友好，在 IE 下將不會成功返回該 404 錯誤頁面&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;//qzonestyle.gtimg.cn/qzone/hybrid/app/404/search_children.js&quot; charset=&quot;utf-8&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;同時&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;homePageUrl&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;homePageName&lt;/code&gt;兩個參數,提高頁面定製性&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;//qzonestyle.gtimg.cn/qzone/hybrid/app/404/search_children.js&quot; charset=&quot;utf-8&quot; homePageUrl=&quot;返回頁面路徑&quot; homePageName=&quot;返回頁面名稱&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;文章內容參考：&lt;/strong&gt;：https://www.qq.com/404/&lt;/p&gt;

            </description>
            <pubDate>Thu, 30 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-30-404-page.html
            </guid>
        </item>
        
        <item>
            <title>Pm Em Rem</title>
            <link>
                https://zsqk.github.io/2020-04-29-pm-em-rem.html
            </link>
            <description>
                &lt;p&gt;在css中單位長度用的最多的是px、em、rem，這三個的區別是：&lt;/p&gt;

&lt;p&gt;　　px是固定的像素，一旦設置了就無法因為適應頁面大小而改變。&lt;/p&gt;

&lt;p&gt;　　em和rem相對於px更具有靈活性，他們是相對長度單位，意思是長度不是定死了的，更適用於響應式佈局。
        對於em和rem的區別一句話概括：em相對於父元素，rem相對於根元素
        rem中的r意思是root（根），這也就不難理解了&lt;/p&gt;
&lt;h3 id=&quot;em&quot;&gt;em&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;子元素字體大小的em是相對於父元素字體大小&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;元素的width/height/padding/margin用em的話是相對於該元素的font-size
```&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
    我是父元素div
    &lt;p&gt;
        我是子元素p
        &lt;span&gt;我是孫元素span&lt;/span&gt;
    &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;div {
  font-size: 40px;
  width: 10em; /* 400px &lt;em&gt;/
  height: 10em; /&lt;/em&gt; 400px &lt;em&gt;/
  border: solid 1px black;
}
p {
  font-size: 0.5em; /&lt;/em&gt; 20px &lt;em&gt;/ 
  width: 10em; /&lt;/em&gt; 200px &lt;em&gt;/
  height: 10em; /&lt;/em&gt; 200px &lt;em&gt;/
  border: solid 1px red;
}
span {
    font-size: 0.5em; /&lt;/em&gt; chrome有最小字體12px的限制所以這裡為 12px &lt;em&gt;/
    width: 10em; /&lt;/em&gt; 120px &lt;em&gt;/
    height: 10em; /&lt;/em&gt; 120px */
}&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
### rem
rem是全部的長度都相對於根元素，根元素是誰？&amp;lt;html&amp;gt;元素。通常做法是給html元素設置一個字體大小，然後其他元素的長度單位就為rem。

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;html {
    font-size: 10px;
}
div {
    font-size: 4rem; /* 40px &lt;em&gt;/
    width: 30rem;  /&lt;/em&gt; 300px &lt;em&gt;/
    height: 30rem;  /&lt;/em&gt; 300px &lt;em&gt;/
    border: solid 1px black;
}
p {
    font-size: 2rem; /&lt;/em&gt; 20px &lt;em&gt;/
    width: 15rem; /&lt;/em&gt; 150px &lt;em&gt;/
    height: 15rem; /&lt;/em&gt; 150px &lt;em&gt;/
}
span {
    font-size: 1.5rem; /&lt;/em&gt; 15px &lt;em&gt;/
    width: 10rem; /&lt;/em&gt; 100px &lt;em&gt;/
    height: 10rem; /&lt;/em&gt; 100px */
}
```&lt;/p&gt;

            </description>
            <pubDate>Wed, 29 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-29-pm-em-rem.html
            </guid>
        </item>
        
        <item>
            <title>ECMAScript 中的相等</title>
            <link>
                https://zsqk.github.io/2020-04-28-sameness-deep-equal-immutable.html
            </link>
            <description>
                &lt;h2 id=&quot;相等&quot;&gt;相等&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Strict Equality Comparison &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;===&lt;/code&gt; 嚴格相等&lt;/li&gt;
  &lt;li&gt;Abstract Equality Comparison &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; 大概相等&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://ecma-international.org/ecma-262/#sec-samevaluezero&quot;&gt;SameValueZero&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SameValue&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;-與--的區別&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;===&lt;/code&gt; 與 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; 的區別&lt;/h3&gt;

&lt;p&gt;如果兩值類型相等, 則兩種對比沒有區別. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; 的主要功能是隱性地類型轉換.&lt;/p&gt;

&lt;p&gt;如果一個為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Number&lt;/code&gt; 另一個為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;, 則將 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; 轉為 Number 類型進行對比.&lt;/p&gt;

&lt;p&gt;如果任意一個為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Boolean&lt;/code&gt;, 則將 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Boolean&lt;/code&gt; 轉為 Number 類型進行對比.&lt;/p&gt;

&lt;p&gt;如果任意一個為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object&lt;/code&gt;, 則調用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.toString()&lt;/code&gt; 轉類型.&lt;/p&gt;

&lt;p&gt;轉為 Number 類型時, 需要注意: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true =&amp;gt; 1, false =&amp;gt; +0, null =&amp;gt; +0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;總結如下:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;類型&lt;/th&gt;
      &lt;th&gt;轉換&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;null&lt;/td&gt;
      &lt;td&gt;不轉換&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;undefined&lt;/td&gt;
      &lt;td&gt;不轉換&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Number&lt;/td&gt;
      &lt;td&gt;不轉換&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;String&lt;/td&gt;
      &lt;td&gt;轉為 Number&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Object&lt;/td&gt;
      &lt;td&gt;轉為 String&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+0&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;依據上面的規則, 我們可以得到以下結果.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[object Object]&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kc&quot;&gt;NaN&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;NaN&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;有些是我們想要的, 但有些不是. 因為這種類型轉換的複雜性, 不建議使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;samevaluezero-與-samevalue-的區別&quot;&gt;SameValueZero 與 SameValue 的區別&lt;/h3&gt;

&lt;p&gt;主要區別在於是否區分 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-0&lt;/code&gt; 與 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+0&lt;/code&gt;. SameValue 區分, SameValueZero 則不區分.&lt;/p&gt;

&lt;p&gt;這是歷史遺留問題, 我們一般不會直接遇到該問題.&lt;/p&gt;

&lt;h3 id=&quot;-與-samevaluezero-的區別&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;===&lt;/code&gt; 與 SameValueZero 的區別&lt;/h3&gt;

&lt;p&gt;主要區別在於是否區分兩個 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NaN&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;===&lt;/code&gt; 區分, SameValueZero 則不區分.&lt;/p&gt;

&lt;h2 id=&quot;賦值&quot;&gt;賦值&lt;/h2&gt;

&lt;p&gt;整個 &lt;a href=&quot;https://tc39.es/ecma262/#sec-assignment-operators&quot;&gt;Assignment Operators&lt;/a&gt; 比較複雜, 簡單說運算符右側使用的 &lt;a href=&quot;https://tc39.es/ecma262/#sec-getvalue&quot;&gt;GetValue&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;如果不是引用類型, 則只是返回該值就好.&lt;/p&gt;

&lt;p&gt;如果是引用類型, 則將該值複製. 如果右側為對象, 則創建該值的引用.&lt;/p&gt;

&lt;h2 id=&quot;深度對比與不可變值&quot;&gt;深度對比與不可變值&lt;/h2&gt;

&lt;p&gt;概念:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;deep copy&lt;/li&gt;
  &lt;li&gt;deep equal&lt;/li&gt;
  &lt;li&gt;memoization&lt;/li&gt;
  &lt;li&gt;immutable object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;應用:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSON.stringify&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;lodash/isEqual&lt;/li&gt;
  &lt;li&gt;memoize-one&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://runkit.com/iugo/immutability-helper-test&quot;&gt;immutability-helper&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;結論&quot;&gt;結論&lt;/h2&gt;

&lt;p&gt;一般來說, 我們避免使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;, 要使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;===&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;在處理複雜對象同時為了優化性能時, 我們會使用 memo 的方法, 但如何更好判斷依賴項
是否發生了變化, 我們只要在每次變化時, 把這個複雜對象當作 immutable object 就好.&lt;/p&gt;

&lt;p&gt;當我們使用了 immutable object, 就不再那麼需要 deep copy 和 deep equal 了.&lt;/p&gt;


            </description>
            <pubDate>Tue, 28 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-28-sameness-deep-equal-immutable.html
            </guid>
        </item>
        
        <item>
            <title>Jamstack</title>
            <link>
                https://zsqk.github.io/2020-04-27-jamstack.html
            </link>
            <description>
                &lt;h2 id=&quot;什麼是-jamstack&quot;&gt;什麼是 Jamstack&lt;/h2&gt;

&lt;p&gt;只是一個概念, 可以描述一類架構.&lt;/p&gt;

&lt;p&gt;JAM = JavaScript + APIs + Markup&lt;/p&gt;

&lt;p&gt;在網頁應用中, HTML 是通用的 Markup language.&lt;/p&gt;

&lt;p&gt;首先前後端分離, 不是 PHP 擅長的那種服務器端渲染.&lt;/p&gt;

&lt;p&gt;然後需要將前端代碼自動構建為 HTML 及相關部署在 CDN 上.&lt;/p&gt;

&lt;h3 id=&quot;標準寫法&quot;&gt;標準寫法&lt;/h3&gt;

&lt;p&gt;按說, 完整的寫法應該是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;J.A.M. Stack&lt;/code&gt;, 簡單的寫法是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JAMStack&lt;/code&gt; 或 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JAMstack&lt;/code&gt;.
但是 jamstack.org 和 Netlify 給出的寫法是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Jamstack&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;我們的經驗&quot;&gt;我們的經驗&lt;/h2&gt;

&lt;p&gt;我們曾用過 Next.js 的 Static Exporting 功能做過類似的網站. 但還是有一些的限制的,
後來就再沒用過.&lt;/p&gt;

&lt;p&gt;現在我們更傾向於 code splitting + lazy loading 這種方案. 與 JAM 最大的不同就是
沒有 M. 不是在構建的時候生成了多個 HTML, 還是用 JavaScript 生成 DOM, 也就是
Markup.&lt;/p&gt;

&lt;p&gt;我們選擇不使用靜態 HTML 的問題主要是路由, 普通內容站可以說在構建的時候就規劃好了
所有頁面, 但功能性站點可不是.&lt;/p&gt;

&lt;p&gt;比如一個用戶的信息頁面我們希望是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://site/people/jim&lt;/code&gt;, 但我們在構建的時候
並不真的清楚有多少個用戶, 用戶都在 API 中獲取. 如果要用 HTML 頁面和普通 CDN,
我們只能選擇 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://site/people?user=jim&lt;/code&gt; 這樣的方式.&lt;/p&gt;

&lt;h3 id=&quot;結論&quot;&gt;結論&lt;/h3&gt;

&lt;p&gt;Jamstack 僅適用於內容型站點. 類似的概念不是什麼新東西了, 大多數 CMS 都是這樣的.&lt;/p&gt;

&lt;h2 id=&quot;jamstack-淵源&quot;&gt;Jamstack 淵源&lt;/h2&gt;

&lt;p&gt;Jamstack 是由 Netlify 提出的概念.&lt;/p&gt;

&lt;p&gt;在 Netlify 的網站上, 有專門介紹 Jamstack 的頁面:
&lt;a href=&quot;https://www.netlify.com/jamstack/&quot;&gt;https://www.netlify.com/jamstack/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;對於內容展示型網站來說, 如果能遵循原子部署, 那麼即便數據量巨大, 理論上也是可以
使用 Jamstack 的.&lt;/p&gt;

            </description>
            <pubDate>Mon, 27 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-27-jamstack.html
            </guid>
        </item>
        
        <item>
            <title>Photoshop Sharpens Image</title>
            <link>
                https://zsqk.github.io/2020-04-23-photoshop-sharpens-image.html
            </link>
            <description>
                &lt;h3 id=&quot;photoshop使用智能銳化將圖片變清晰&quot;&gt;&lt;strong&gt;Photoshop使用智能銳化將圖片變清晰&lt;/strong&gt;&lt;/h3&gt;
&lt;h5 id=&quot;1首先打開ps並打開一張圖片複製一個圖層&quot;&gt;1.首先打開PS並打開一張圖片，複製一個圖層&lt;/h5&gt;
&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/19698815/80054376-a5e03180-8551-11ea-995a-de4cbaa15837.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;
&lt;h5 id=&quot;2然後點擊菜單欄上的濾鏡下面的銳化選擇銳化下面的智能銳化&quot;&gt;2.然後點擊菜單欄上的濾鏡，下面的銳化，選擇銳化下面的智能銳化&lt;/h5&gt;
&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/19698815/80054475-f3f53500-8551-11ea-9403-4548bf6a8eac.png&quot; alt=&quot;圖片1&quot; /&gt;&lt;/p&gt;
&lt;h5 id=&quot;3點擊智能銳化後先將移去設置成高斯模糊然後根據自己的需求調整數量半徑雜色最後按確定然後可以放大細節對比一下&quot;&gt;3.點擊智能銳化後，先將移去設置成高斯模糊，然後根據自己的需求調整數量，半徑，雜色，最後按確定，然後可以放大細節對比一下。&lt;/h5&gt;
&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/19698815/80054515-08393200-8552-11ea-90ee-d67fb6c5cb50.png&quot; alt=&quot;圖片2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/19698815/80054540-1b4c0200-8552-11ea-95b1-a48f88219622.png&quot; alt=&quot;圖片3&quot; /&gt;&lt;/p&gt;


            </description>
            <pubDate>Thu, 23 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-23-photoshop-sharpens-image.html
            </guid>
        </item>
        
        <item>
            <title>Site By Station Gadgets</title>
            <link>
                https://zsqk.github.io/2020-04-22-site-by-station-gadgets.html
            </link>
            <description>
                &lt;p&gt;前一段時間同事找我扒網站 然後K同學推薦了這個&lt;strong&gt;仿站小工具8.1&lt;/strong&gt; 現在分享給大家&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;介紹&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;仿站小工具8.1是一款用來下載網頁模板的軟件，可以將指定目標網站的資源內容快速索引讀取並複製到本地使用的軟件工具！可以通過該軟件檢測網編碼，下載網頁，它會從html的代碼中將JS、Css、Image、Picture、Flash等靜態文件網址提取過來，再從下載完好的Css代碼中提取出Image靜態文件網址，通過網址下載靜態文件，根據軟件設置好的保存規則，自動修正html和css代碼鏈接路徑，最終這些靜態文件被按分類保存到電腦文件夾。並且會自動分類歸檔。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;軟件特色&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. 從輸入的網址下載html代碼。
2. 支持提取JS、Css、Image、Picture、Flash等靜態文件網址。
3. 可根據軟件設置好的保存規則，自動修正html和css代碼鏈接路徑。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;使用教程&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;輸入需要下載的網頁的網址，點擊添加。
&lt;img src=&quot;https://user-images.githubusercontent.com/19698815/79931742-47964e80-847e-11ea-88d3-8f520284dbe8.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;選擇保存地址，點擊開始下載。
&lt;img src=&quot;http://www.xue51.com/uppic/180404/201804041643079989.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;等待下載完成，打開保存地址裡面的文件就可以了。
&lt;img src=&quot;http://www.xue51.com/uppic/180404/201804041643144531.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

            </description>
            <pubDate>Wed, 22 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-22-site-by-station-gadgets.html
            </guid>
        </item>
        
        <item>
            <title>編程題 聒噪的青蛙</title>
            <link>
                https://zsqk.github.io/2020-04-22-leetcode-minimum-number-of-frogs-croaking.html
            </link>
            <description>
                &lt;p&gt;寫業務代碼, 可能會碰到一些架構上的問題, 但性能不是重點, 很少接觸真正的算法.&lt;/p&gt;

&lt;p&gt;最近&lt;a href=&quot;2020-04-08-working-experience-in-silicon-valley&quot;&gt;聽播客&lt;/a&gt;, 道長介紹在硅谷面試時, 一般初級軟件工程師就是算法題, 資深之後
才會有架構題, 越資深算法就越不重要.&lt;/p&gt;

&lt;p&gt;但代碼與性能是一方面, 另一方面, 能否理解問題, 解決問題, 這是任何人都需要的.&lt;/p&gt;

&lt;p&gt;我們的前端筆試題已經很久沒更新了, 後端則沒有正式的筆試題. 春季招聘正需要,
就打算去 LeetCode 上抄那麼幾道題應對招聘.&lt;/p&gt;

&lt;p&gt;最近的一道中等難度的題是: &lt;a href=&quot;https://leetcode.com/problems/minimum-number-of-frogs-croaking/&quot;&gt;Minimum Number of Frogs Croaking&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;根據 Hints, 用 JavaScript 寫了答案, 思路應該是清晰的, 效率也可以接受.
參考 Hints 寫的答案都是基礎方法, 但軟件工程應該就是使用最簡單的思路去解決問題.&lt;/p&gt;

&lt;p&gt;以下是具體答案:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Runtime: 76 ms, faster than 85.98% of JavaScript online submissions.
Memory Usage: 37.1 MB, less than 100.00% of JavaScript online submissions.
(2020-04-22 17:22:18 +8)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/**
 * @param {string} croakOfFrogs
 * @return {number}
 */&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;minNumberOfFrogs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;croakOfFrogs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;of&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;croakOfFrogs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;croak&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;附&quot;&gt;附&lt;/h2&gt;

&lt;p&gt;這裡給出一些我用過的測試:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;cccroacrkroakroakcroakoak&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;cccroacrkroakroakcroakaok&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;croakcrook&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;croakcroak&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;croakcroa&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;croakcroac&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;of&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;minNumberOfFrogs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; 的結果應該為 &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, 卻是 &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;我最初的答案是這樣的:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/**
 * @param {string} croakOfFrogs
 * @return {number}
 */&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;minNumberOfFrogs0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;croakOfFrogs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;croakOfFrogs&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cDisplayTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cDisplayTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;of&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;這個答案性能不是重點, 看起來也更簡單. 但不能找出錯誤參數. 然後我才意識到,
這道題麻煩的是校驗錯誤.&lt;/p&gt;

&lt;p&gt;然後老老實實依照 Hints 寫了最終的答案.&lt;/p&gt;

&lt;p&gt;Hints:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ol&gt;
    &lt;li&gt;keep the frequency of all characters from “croak” using a hashmap.&lt;/li&gt;
    &lt;li&gt;For each character in the given string, greedily match it to a possible “croak”.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;更新&quot;&gt;更新&lt;/h2&gt;

&lt;p&gt;第二天早上又花了一點時間寫了兩個版本:&lt;/p&gt;

&lt;p&gt;通用版: &lt;a href=&quot;https://leetcode.com/submissions/detail/328828305/&quot;&gt;https://leetcode.com/submissions/detail/328828305/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;性能版: &lt;a href=&quot;https://leetcode.com/submissions/detail/328832285/&quot;&gt;https://leetcode.com/submissions/detail/328832285/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;再翻看大家的討論, 看到其他語言基本與我的性能版思路一致, 但通用版大家都沒怎麼寫.&lt;/p&gt;

&lt;p&gt;在我目前的實際工作中, 性能要求並不高, 我們更期望可讀性強的代碼.&lt;/p&gt;

&lt;p&gt;這道題前前後後, 寫代碼, 整理思路, 發帖, 花了兩三個小時, 我想
改動一下是可以作為筆試題了.&lt;/p&gt;

&lt;p&gt;通用版代碼就不寫了, 以下是性能版源代碼:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/**
 * @param {string} croakOfFrogs
 * @return {number}
 */&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;minNumberOfFrogs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;croakOfFrogs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// 多出的數量&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// 儲存鳴叫數量&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;croakOfFrogs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;croakOfFrogs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nl&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;


            </description>
            <pubDate>Wed, 22 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-22-leetcode-minimum-number-of-frogs-croaking.html
            </guid>
        </item>
        
        <item>
            <title>Rabbitmq</title>
            <link>
                https://zsqk.github.io/2020-04-21-rabbitmq.html
            </link>
            <description>
                &lt;h1 id=&quot;rabbitmq-簡介以及使用場景&quot;&gt;RabbitMQ 簡介以及使用場景&lt;/h1&gt;

&lt;h2 id=&quot;rabbitmq-簡介&quot;&gt;RabbitMQ 簡介&lt;/h2&gt;
&lt;p&gt;MQ全稱為Message Queue, 消息隊列（MQ）是一種應用程序對應用程序的通信方法。應用程序通過讀寫出入隊列的消息（針對應用程序的數據）來通信，而無需專用連接來鏈接它們。&lt;/p&gt;

&lt;p&gt;消息傳遞指的是程序之間通過在消息中發送數據進行通信，而不是通過直接調用彼此來通信，直接調用通常是用於諸如遠程過程調用的技術。排隊指的是應用程序通過 隊列來通信。隊列的使用除去了接收和發送應用程序同時執行的要求。&lt;/p&gt;

&lt;p&gt;RabbitMQ是使用Erlang語言開發的開源消息隊列系統，基於AMQP協議來實現。AMQP的主要特徵是面向消息、隊列、路由(包括點對點和發佈/訂閱)、可靠性、 安全。AMQP協議更多用在企業系統內，對數據一致性、穩定性和可靠性要求很高的場景，對性能和吞吐量的要求還在其次。&lt;/p&gt;

&lt;h2 id=&quot;rabbitmq-使用場景&quot;&gt;RabbitMQ 使用場景&lt;/h2&gt;
&lt;h3 id=&quot;解耦為面向服務的架構soa提供基本的最終一致性實現&quot;&gt;解耦（為面向服務的架構（SOA）提供基本的最終一致性實現）&lt;/h3&gt;
&lt;p&gt;場景說明：用戶下單後，訂單系統需要通知庫存系統。傳統的做法是，訂單系統調用庫存系統的接口。
傳統模式的缺點：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;假如庫存系統無法訪問，則訂單減庫存將失敗，從而導致訂單失敗&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;假如庫存系統無法訪問，則訂單減庫存將失敗，從而導致訂單失敗&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;引入消息隊列：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;訂單系統：用戶下單後，訂單系統完成持久化處理，將消息寫入消息隊列，返回用戶訂單下單成功&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;庫存系統：訂閱下單的消息，採用拉/推的方式，獲取下單信息，庫存系統根據下單信息，進行庫存操作&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;假如：在下單時庫存系統不能正常使用。也不影響正常下單，因為下單後，訂單系統寫入消息隊列就不再關心其他的後續操作了。實現訂單系統與庫存系統的應用解耦&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;為了保證庫存肯定有，可以將隊列大小設置成庫存數量，或者採用其他方式解決。
基於消息的模型，關心的是“通知”，而非“處理”。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;短信、郵件通知、緩存刷新等操作使用消息隊列進行通知。&lt;/p&gt;

&lt;p&gt;消息隊列和RPC的區別與比較：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;RPC(遠程過程調用:Remote Procedure Call）: 異步調用，及時獲得調用結果，具有強一致性結果，關心業務調用處理結果。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;消息隊列：兩次異步RPC調用，將調用內容在隊列中進行轉儲，並選擇合適的時機進行投遞（錯峰流控）&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;異步提升效率&quot;&gt;異步提升效率&lt;/h3&gt;
&lt;p&gt;場景說明：用戶註冊後，需要發註冊郵件和註冊短信。傳統的做法有兩種 1.串行的方式；2.並行方式&lt;/p&gt;

&lt;p&gt;（1）串行方式：將註冊信息寫入數據庫成功後，發送註冊郵件，再發送註冊短信。以上三個任務全部完成後，返回給客戶端
（2）並行方式：將註冊信息寫入數據庫成功後，發送註冊郵件的同時，發送註冊短信。以上三個任務完成後，返回給客戶端。與串行的差別是，並行的方式可以提高處理的時間，引入消息隊列，將不是必須的業務邏輯。&lt;/p&gt;

&lt;h3 id=&quot;流量削峰&quot;&gt;流量削峰&lt;/h3&gt;
&lt;p&gt;流量削峰也是消息隊列中的常用場景，一般在秒殺或團搶活動中使用廣泛&lt;/p&gt;

&lt;p&gt;應用場景：系統其他時間A系統每秒請求量就100個，系統可以穩定運行。系統每天晚間八點有秒殺活動，每秒併發請求量增至1萬條，但是系統最大的處理能力只能每秒處理1000個請求，於是系統崩潰，服務器宕機。&lt;/p&gt;

&lt;p&gt;之前架構：大量用戶（100萬用戶）通過瀏覽器在晚上八點高峰期同時參與秒殺活動。大量的請求湧入我們的系統中，高峰期達到每秒鐘5000個請求，大量的請求打到MySQL上，每秒鐘預計執行3000條SQL。&lt;/p&gt;

&lt;p&gt;但是一般的MySQL每秒鐘扛住2000個請求就不錯了，如果達到3000個請求的話可能MySQL直接就癱瘓了，從而系統無法被使用。但是高峰期過了之後，就成了低峰期，可能也就1萬用戶訪問系統，每秒的請求數量也就50個左右，整個系統幾乎沒有任何壓力。&lt;/p&gt;

&lt;p&gt;引入MQ：100萬用戶在高峰期的時候，每秒請求有5000個請求左右，將這5000請求寫入MQ裡面，系統A每秒最多隻能處理2000請求，因為MySQL每秒只能處理2000個請求。&lt;/p&gt;

&lt;p&gt;系統A從MQ中慢慢拉取請求，每秒就拉取2000個請求，不要超過自己每秒能處理的請求數量即可。MQ，每秒5000個請求進來，結果只有2000個請求出去，所以在秒殺期間（將近一小時）可能會有幾十萬或者幾百萬的請求積壓在MQ中。&lt;/p&gt;

&lt;p&gt;關於流量削峰：秒殺系統流量削峰這事兒應該怎麼做？&lt;/p&gt;

&lt;p&gt;這個短暫的高峰期積壓是沒問題的，因為高峰期過了之後，每秒就只有50個請求進入MQ了，但是系統還是按照每秒2000個請求的速度在處理，所以說，只要高峰期一過，系統就會快速將積壓的消息消費掉。我們在此計算一下，每秒在MQ積壓3000條消息，1分鐘會積壓18萬，1小時積壓1000萬條消息，高峰期過後，1個多小時就可以將積壓的1000萬消息消費掉。&lt;/p&gt;

&lt;h2 id=&quot;引入消息隊列的優缺點&quot;&gt;引入消息隊列的優缺點&lt;/h2&gt;
&lt;p&gt;優點&lt;/p&gt;

&lt;p&gt;優點就是以上的那些場景應用，就是在特殊場景下有其對應的好處，解耦、異步、削峰。&lt;/p&gt;

&lt;p&gt;缺點&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;系統的可用性降低&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;系統引入的外部依賴越多，系統越容易掛掉，本來只是A系統調用BCD三個系統接口就好，ABCD四個系統不報錯整個系統會正常運行。引入了MQ之後，雖然ABCD系統沒出錯，但MQ掛了以後，整個系統也會崩潰。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;系統的複雜性提高&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;引入了MQ之後，需要考慮的問題也變得多了，如何保證消息沒有重複消費？如何保證消息不丟失？怎麼保證消息傳遞的順序？&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;一致性問題&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A系統發送完消息直接返回成功，但是BCD系統之中若有系統寫庫失敗，則會產生數據不一致的問題。&lt;/p&gt;

&lt;p&gt;總結&lt;/p&gt;

&lt;p&gt;所以總結來說，消息隊列是一種十分複雜的架構，引入它有很多好處，但是也得針對它帶來的壞處做各種額外的技術方案和架構來規避。引入MQ系統複雜度提升了一個數量級，但是在有些場景下，就是複雜十倍百倍，還是需要使用MQ。&lt;/p&gt;

            </description>
            <pubDate>Tue, 21 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-21-rabbitmq.html
            </guid>
        </item>
        
        <item>
            <title>2019 年中 社交媒體中最流行的語言是?</title>
            <link>
                https://zsqk.github.io/2020-04-20-programming-language-social-media-popularity-2019.html
            </link>
            <description>
                &lt;p&gt;最近看到 PHP 核心開發成員 &lt;a href=&quot;https://weibo.com/1170999921/IDrEfgE2Z&quot;&gt;Laruence 在微博聊語言噴子&lt;/a&gt;.
我是非常贊同他的基本觀點的, 語言只是解決問題的具體實施細則,
更重要的不是語言本身, 而是解決問題的抽象方法.&lt;/p&gt;

&lt;p&gt;下面這則 2019 年的排行還是可以看出 PHP 仍在一陣.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://redmonk.com/sogrady/2019/07/18/language-rankings-6-19/&quot;&gt;https://redmonk.com/sogrady/2019/07/18/language-rankings-6-19/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://redmonk.com/sogrady/files/2019/07/lang.rank_.619.png&quot; alt=&quot;原圖&quot; /&gt;&lt;/p&gt;

&lt;p&gt;參考兩個社交媒體:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;GitHub&lt;/li&gt;
  &lt;li&gt;Stack Overflow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;X 軸的 GitHub 可以代表開源流行度.
Y 軸的 Stack Overflow 可以代表新人活躍度.&lt;/p&gt;

&lt;p&gt;x + y 為總流行度, x &amp;gt; y 是更硬核的語言, x &amp;lt; y 是更大眾的語言.&lt;/p&gt;

&lt;p&gt;可以看出 Rust 開源流行但新人問題少. (相對)
Visual Basic 新人問題多但開源不夠流行. (相對)&lt;/p&gt;

            </description>
            <pubDate>Mon, 20 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-20-programming-language-social-media-popularity-2019.html
            </guid>
        </item>
        
        <item>
            <title>Data Encapsulation And Unencapsulation</title>
            <link>
                https://zsqk.github.io/2020-04-17-data-encapsulation-and-unencapsulation.html
            </link>
            <description>
                &lt;h1 id=&quot;osi七層模型下四層的數據封裝和解封裝&quot;&gt;OSI七層模型下四層的數據封裝和解封裝&lt;/h1&gt;
&lt;p&gt;osi七層模型的下四層數據封裝是瞭解各個傳輸協議以及數據傳輸方式的基礎&lt;/p&gt;

&lt;h2 id=&quot;osi七層模型下四層模型&quot;&gt;OSI七層模型下四層模型&lt;/h2&gt;
&lt;h3 id=&quot;傳輸層&quot;&gt;傳輸層&lt;/h3&gt;
&lt;p&gt;傳輸層的數據格式為數據報文，主要做的處理是將數據進行分段，然後每個報文的頭部會添加報文頭信息，包含數據完整性的信息。報文大小由主機的吞吐量，帶寬以及一次處理的字節數等限制的。傳輸層的主要協議有TCP,UDP等。其中TCP的三次握手建立起邏輯通路以後就開始將分好的數據報文，在收到報文以後根據報文頭來檢查數據的完整性。&lt;/p&gt;
&lt;h3 id=&quot;網絡層&quot;&gt;網絡層&lt;/h3&gt;
&lt;p&gt;網絡層的數據格式為數據包，對傳輸層分裝好的數據報文再進行封裝。這一步是在報文的頭部添加包頭，包含一些ip的尋址的信息。在網絡層專屬的過程中，路由器只對數據包頭進行檢查，然後進行分組轉發。&lt;/p&gt;
&lt;h3 id=&quot;數據鏈路層&quot;&gt;數據鏈路層&lt;/h3&gt;
&lt;p&gt;數據鏈路層的數據格式為數據幀，對路由層的封裝好的數據包進行再封裝。這一步是在數據包頭部添加數據幀的頭部信息，主要包含硬件地址尋址等信息。&lt;/p&gt;
&lt;h3 id=&quot;物理層&quot;&gt;物理層&lt;/h3&gt;
&lt;p&gt;物理層主要是根據各種協議將數據轉換成物理信號進行傳輸。802協議族，其中802.3是以太網，802.11n是無線局域網（WIFI）。&lt;/p&gt;

&lt;h2 id=&quot;osi數據封裝和解封裝&quot;&gt;OSI數據封裝和解封裝&lt;/h2&gt;
&lt;h3 id=&quot;封裝&quot;&gt;封裝&lt;/h3&gt;
&lt;p&gt;發送數據, 按照 傳輸層-&amp;gt;網絡層-&amp;gt;數據鏈路層 的順序為數據封裝。一般發生在發送發&lt;/p&gt;
&lt;h3 id=&quot;解封裝&quot;&gt;解封裝&lt;/h3&gt;
&lt;p&gt;接受數據, 按照 數據鏈路層-&amp;gt;網絡層-&amp;gt;傳輸層 的數據為解封裝。一般發生在接收方。中間經過的路由器和交換機一般只會對數據進行檢查不會改變數據。&lt;/p&gt;

            </description>
            <pubDate>Fri, 17 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-17-data-encapsulation-and-unencapsulation.html
            </guid>
        </item>
        
        <item>
            <title>Zeit Now</title>
            <link>
                https://zsqk.github.io/2020-04-16-zeit-now.html
            </link>
            <description>
                &lt;h1 id=&quot;zeit-now部署靜態項目&quot;&gt;Zeit-now部署靜態項目&lt;/h1&gt;
&lt;p&gt;現在ZEIT 是一個雲平臺靜態站點和無服務器功能完美地與您的工作流程適合。它使開發人員可以託管Jamstack網站和Web服務，這些網站和Web服務可以立即部署，自動擴展並且不需要任何監督，而且都無需配置。&lt;/p&gt;

&lt;h4 id=&quot;註冊&quot;&gt;註冊&lt;/h4&gt;
&lt;p&gt;註冊鏈接：&lt;a href=&quot;https://zeit.co/&quot;&gt;https://zeit.co/&lt;/a&gt;，首先需要前往zeit官網進行用戶註冊，當然我們也可以用gitlab，github等等方式來進行登錄，這也是使用該工具的一個前提條件&lt;/p&gt;

&lt;h4 id=&quot;安裝&quot;&gt;安裝&lt;/h4&gt;
&lt;p&gt;在命令行工具執行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install now -g&lt;/code&gt;，進行now的全局安裝。&lt;/p&gt;

&lt;h4 id=&quot;使用方法&quot;&gt;使用方法&lt;/h4&gt;
&lt;h5 id=&quot;本地命令行&quot;&gt;本地命令行&lt;/h5&gt;
&lt;ul&gt;
  &lt;li&gt;1.命令行工具進入項目，運行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;now&lt;/code&gt;命令&lt;/li&gt;
  &lt;li&gt;2.根據提示進行配置&lt;/li&gt;
  &lt;li&gt;3.配置完成後會看到一行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;products&lt;/code&gt;提示網站鏈接地址，複製該地址，即可直接訪問部署的項目
    &lt;h5 id=&quot;zeit官網項目部署&quot;&gt;zeit官網項目部署&lt;/h5&gt;
  &lt;/li&gt;
  &lt;li&gt;1.進入&lt;a href=&quot;https://zeit.co/&quot;&gt;https://zeit.co/&lt;/a&gt;並登錄。&lt;/li&gt;
  &lt;li&gt;2.進入個人&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Owerview&lt;/code&gt;頁面，選擇Import Project&lt;/li&gt;
  &lt;li&gt;3.可從gitlab,github等導入已有項目，或者可以選擇模板導入項目&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;zeit支持框架及語言&quot;&gt;zeit支持框架及語言&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Node.js&lt;/li&gt;
  &lt;li&gt;Go&lt;/li&gt;
  &lt;li&gt;Python&lt;/li&gt;
  &lt;li&gt;Ruby&lt;/li&gt;
  &lt;li&gt;Next.js&lt;/li&gt;
  &lt;li&gt;Vue.js&lt;/li&gt;
  &lt;li&gt;Ionic Angular&lt;/li&gt;
  &lt;li&gt;Angular&lt;/li&gt;
  &lt;li&gt;Ionic React&lt;/li&gt;
  &lt;li&gt;Nuxt.js&lt;/li&gt;
  &lt;li&gt;…&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;更多參考httpszeitcodocs&quot;&gt;更多參考：&lt;a href=&quot;https://zeit.co/docs&quot;&gt;https://zeit.co/docs&lt;/a&gt;&lt;/h4&gt;

            </description>
            <pubDate>Thu, 16 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-16-zeit-now.html
            </guid>
        </item>
        
        <item>
            <title>GitHub 免費版不限私有倉庫及協作者數量</title>
            <link>
                https://zsqk.github.io/2020-04-16-github-free.html
            </link>
            <description>
                &lt;p&gt;當地時間2020年04月14日, GitHub 發文 &lt;a href=&quot;https://github.blog/2020-04-14-github-is-now-free-for-teams/&quot;&gt;GitHub is now free for teams&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Free 不再限制私有倉庫及協作者數量.&lt;/li&gt;
  &lt;li&gt;Team 降價為每人每月 4 美元.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;目前 Free 與 Team 的限制主要是私有倉庫的工作流了. 具體差別可以看 &lt;a href=&quot;https://github.com/pricing&quot;&gt;1&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;這裡列舉一些我認為重要的:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;合併代碼前強制要求 review.&lt;/li&gt;
  &lt;li&gt;可為 issue 或 PR 指定多位 assignees.&lt;/li&gt;
  &lt;li&gt;自動指定 code owners 進行 review.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;GitHub 的這次變動主要瞄準的應該是 GitLab 的用戶. 從價格上做到了不輸於 GitLab.&lt;/p&gt;

&lt;p&gt;但究竟有多少企業用戶會轉而選擇 GitHub 呢? 我不知道.&lt;/p&gt;

&lt;p&gt;我們現在在用 GitLab, 暫時不會轉.&lt;/p&gt;

&lt;p&gt;Update 2020-04-23:&lt;/p&gt;

&lt;p&gt;順便提一下 GitLab 官方對 GitHub 此次行為的回應:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://about.gitlab.com/blog/2020/04/14/github-free-for-teams/&quot;&gt;https://about.gitlab.com/blog/2020/04/14/github-free-for-teams/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;然後我最近發現之前已經給過體驗機會的 Gold 計劃再次免費 30 天.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Free Trial of GitLab.com Gold&lt;br /&gt;
Try all GitLab has to offer for 30 days. No credit card required.&lt;/p&gt;
&lt;/blockquote&gt;

            </description>
            <pubDate>Thu, 16 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-16-github-free.html
            </guid>
        </item>
        
        <item>
            <title>倪光南</title>
            <link>
                https://zsqk.github.io/2020-04-15-niguangnan.html
            </link>
            <description>
                &lt;h2 id=&quot;不老人生第五集-倪光南--cctv紀錄&quot;&gt;《不老人生》第五集 倪光南 | CCTV紀錄&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=VP6evXzB_dE&quot;&gt;https://www.youtube.com/watch?v=VP6evXzB_dE&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;倪光南在參與過計算機設計之後就轉到了漢字信息處理方向.&lt;/li&gt;
  &lt;li&gt;倪光南 1999 年回到計算機所. (離開聯想)&lt;/li&gt;
  &lt;li&gt;倪光南說現在開始追趕芯片設計還有機會. (我 99% 不信)&lt;/li&gt;
  &lt;li&gt;倪光南說, 行業中有挺多穿馬甲的國產技術, 也就是國外的技術加個了殼. (太對了)&lt;/li&gt;
  &lt;li&gt;倪光南說, 做國產技術評測得罪過一些人.&lt;/li&gt;
  &lt;li&gt;倪光南說自己現在更重視軟件.&lt;/li&gt;
  &lt;li&gt;倪光南現在是用 iPhone 的. (具體版本不知道, 但帶劉海)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;柳倪之爭&quot;&gt;柳倪之爭&lt;/h2&gt;

&lt;p&gt;在紀錄片中, 更像是宣傳片, 沒有講到倪光南在聯想的時光.&lt;/p&gt;

&lt;p&gt;且不說當初到底誰對誰錯, 歷史也不能假設.&lt;/p&gt;

&lt;p&gt;但有兩點可以確認:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;倪光南選擇舉報柳傳志個人, 最後被裁定 “沒有材料證明柳傳志同志存在個人經濟問題”.&lt;/li&gt;
  &lt;li&gt;倪光南被趕出了聯想, 沒股票.&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Wed, 15 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-15-niguangnan.html
            </guid>
        </item>
        
        <item>
            <title>Css Filter</title>
            <link>
                https://zsqk.github.io/2020-04-15-css-filter.html
            </link>
            <description>
                &lt;h2 id=&quot;css3-fitler屬性&quot;&gt;CSS3： fitler屬性&lt;/h2&gt;
&lt;p&gt;filter 屬性定義了元素(通常是&lt;img /&gt;)的可視效果(例如：模糊與飽和度)。&lt;/p&gt;
&lt;h3 id=&quot;filter-函數&quot;&gt;Filter 函數&lt;/h3&gt;
&lt;p&gt;注意: 濾鏡通常使用百分比 (如：75%), 當然也可以使用小數來表示 (如：0.75)。
|Filter | 描述
|—|—|
|none|默認值，沒有效果|
|blur(px)|給圖像設置高斯模糊。”radius”一值設定高斯函數的標準差，或者是屏幕上以多少像素融在一起， 所以值越大越模糊；如果沒有設定值，則默認是0；這個參數可設置css長度值，但不接受百分比值。|
|brightness(%)|給圖片應用一種線性乘法，使其看起來更亮或更暗。如果值是0%，圖像會全黑。值是100%，則圖像無變化。其他的值對應線性乘數效果。值超過100%也是可以的，圖像會比原來更亮。如果沒有設定值，默認是1|
|contrast(%)|調整圖像的對比度。值是0%的話，圖像會全黑。值是100%，圖像不變。值可以超過100%，意味著會運用更低的對比。若沒有設置值，默認是1。|
|grayscale(%)|將圖像轉換為灰度圖像。值定義轉換的比例。值為100%則完全轉為灰度圖像，值為0%圖像無變化。值在0%到100%之間，則是效果的線性乘子。若未設置，值默認是0；|&lt;/p&gt;

&lt;h3 id=&quot;那麼這些網站到底是如何實現網頁變灰呢&quot;&gt;那麼這些網站到底是如何實現網頁變灰呢？&lt;/h3&gt;
&lt;p&gt;很簡單，只需要在頁面中插入一行CSS代碼&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;style&amp;gt;
  html {
    filter: grayscale(1);
 }
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

            </description>
            <pubDate>Wed, 15 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-15-css-filter.html
            </guid>
        </item>
        
        <item>
            <title>Chrome Plug</title>
            <link>
                https://zsqk.github.io/2020-04-14-chrome-plug.html
            </link>
            <description>
                &lt;h1 id=&quot;chrome便捷插件&quot;&gt;Chrome便捷插件&lt;/h1&gt;
&lt;p&gt;我們都知道Chrome 瀏覽器有一個好處，就是插件極其豐富。&lt;/p&gt;

&lt;h3 id=&quot;octotree-樹形展示-github-項目代碼&quot;&gt;Octotree 樹形展示 Github 項目代碼&lt;/h3&gt;
&lt;p&gt;GitHub網頁連個側欄的文件樹沒有，查看很累，現在有很多開發者還是需要git clone下載到本地在把代碼裝到開發工具裡才能愉快的閱讀代碼。
這款Octotree讓你能像在GitHub上像在你的開發工具裡一樣瀏覽和搜索代碼。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;下載地址：&lt;a href=&quot;https://chromecj.com/web-development/2017-10/840.html&quot;&gt;https://chromecj.com/web-development/2017-10/840.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;fehelperweb前端助手&quot;&gt;「FeHelper」WEB前端助手&lt;/h3&gt;
&lt;p&gt;目前包括 JSON自動/手動格式化、JSON內容比對、代碼美化與壓縮、信息編解碼轉換、二維碼生成與解碼、圖片Base64編解碼轉換、Markdown、 網頁油猴、網頁取色器、腦圖等貼心工具.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;下載地址：&lt;a href=&quot;https://chromecj.com/web-development/2018-01/879.html&quot;&gt;https://chromecj.com/web-development/2018-01/879.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;fatkun圖片批量下載&quot;&gt;Fatkun圖片批量下載&lt;/h3&gt;
&lt;p&gt;找出當前頁面的所有圖片，提供按分辨率、鏈接等篩選圖片，只需點擊一下，即可下載頁面上選擇的所有圖像。可以使用你自己的規則下載圖像列表，可以批量重命名下載的圖像&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;下載地址：&lt;a href=&quot;https://chrome.google.com/webstore/detail/fatkun-batch-download-ima/nnjjahlikiabnchcpehcpkdeckfgnohf?hl=zh-CN&quot;&gt;https://chrome.google.com/webstore/detail/fatkun-batch-download-ima/nnjjahlikiabnchcpehcpkdeckfgnohf?hl=zh-CN&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;baidu-capsule百度網站淨化&quot;&gt;Baidu Capsule（百度網站淨化）&lt;/h3&gt;
&lt;p&gt;使用更純淨的百度，包括這幾個功能：
1.屏蔽百度推廣（就是為了它）
2.阻止百度追蹤 
3.美化首頁（個人感覺沒有用，很醜）&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;下載地址：&lt;a href=&quot;https://chrome.google.com/webstore/detail/%E7%99%BE%E5%BA%A6%E8%8D%AF%E4%B8%B8-baidu-capsule/ngiclcoldiplnjcafhjkacjcmdidcmjp?hl=zh-CN&quot;&gt;https://chrome.google.com/webstore/detail/%E7%99%BE%E5%BA%A6%E8%8D%AF%E4%B8%B8-baidu-capsule/ngiclcoldiplnjcafhjkacjcmdidcmjp?hl=zh-CN&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;
&lt;p&gt;PS：還有一款自己在用的鼠標快捷指令工具（windows）：Quicker。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;下載地址：&lt;a href=&quot;https://getquicker.net/&quot;&gt;https://getquicker.net/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;腳本地址：&lt;a href=&quot;https://getquicker.net/Share/Actions?exe=COMMON&amp;amp;order=voteCountDesc&amp;amp;p=1&quot;&gt;https://getquicker.net/Share/Actions?exe=COMMON&amp;amp;order=voteCountDesc&amp;amp;p=1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Tue, 14 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-14-chrome-plug.html
            </guid>
        </item>
        
        <item>
            <title>好代碼</title>
            <link>
                https://zsqk.github.io/2020-04-14-best-software-engineering-practices.html
            </link>
            <description>
                &lt;p&gt;什麼才是好的代碼?&lt;/p&gt;

&lt;p&gt;每個寫程序的人都會有這樣的思考.&lt;/p&gt;

&lt;p&gt;而其中很多人, 可能都會對 “優雅” 有執念.&lt;/p&gt;

&lt;p&gt;Dan Abramov 今年分享了一篇文章, &lt;a href=&quot;https://overreacted.io/goodbye-clean-code/&quot;&gt;Goodbye, Clean Code&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;裡面提到了幾點:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;重構並不總是好的.&lt;/li&gt;
  &lt;li&gt;在重構或重寫代碼時一定要與團隊充分溝通.&lt;/li&gt;
  &lt;li&gt;在需求不穩定時, 重構會造成額外的負擔. (尤為贊同)&lt;/li&gt;
  &lt;li&gt;不要對代碼層面的抽象化與複用太過執著.&lt;/li&gt;
  &lt;li&gt;每位寫程序的人可能都會經歷這個階段, 別怕.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;這裡一方面提到了團隊的重要性, 加強溝通, 提升信任, 另一方面主要說的就是,
什麼是乾淨的代碼? 我們再延伸一下, 什麼是好代碼?&lt;/p&gt;

&lt;p&gt;在我初學編程的時候, 我在思考如何寫出優良的代碼.&lt;/p&gt;

&lt;p&gt;在我初學軟件工程的時候, 我總會聽到大家的提醒: 不要提前優化.&lt;/p&gt;

&lt;p&gt;好像有一些矛盾, 工程在阻止我寫出好代碼嗎? 讓我們把 “團隊” 也加入其中, 一起想想.&lt;/p&gt;

&lt;p&gt;關於如何定義好代碼, 如何讓團隊寫出好代碼, 是有許多點需要去平衡的:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;功能完整性&lt;/li&gt;
  &lt;li&gt;團隊能力&lt;/li&gt;
  &lt;li&gt;風格一致性&lt;/li&gt;
  &lt;li&gt;開發速度&lt;/li&gt;
  &lt;li&gt;代碼執行效率&lt;/li&gt;
  &lt;li&gt;代碼細節&lt;/li&gt;
  &lt;li&gt;代碼複用&lt;/li&gt;
  &lt;li&gt;程序架構&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;這些點並不能單獨拿來說, 其中一些點是相互制約的, 另一些點是相互促進的.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;功能完整性是一切的前提.&lt;/li&gt;
  &lt;li&gt;但功能也分基礎功能與擴展功能, 基礎功能必做, 擴展功能則需要考慮開發成本可延後.&lt;/li&gt;
  &lt;li&gt;團隊能力影響剩下的許多點. 如果團隊能力弱, 則可以適當放寬風格一致性, 並且不要
使用過於複雜的程序架構.&lt;/li&gt;
  &lt;li&gt;風格一致性看上去沒什麼必要, 但對代碼的觀感與可讀性, 是有很大提升的. 可能會
間接影響開發速度. 一般我們都會使用自動化的 format 工具去做.&lt;/li&gt;
  &lt;li&gt;開發速度與代碼執行效率可以說在一定程度上是互斥的, 比如 Ruby 開發速度快, C
代碼執行效率高. 一般來說都傾向於開發速度, 但沒有絕對的, 如果花 10 分的時間可以
提升 30 分的執行效率, 這時間還是值得的.&lt;/li&gt;
  &lt;li&gt;代碼執行效率可以很高, 但是有一個接受度閾值的, 一旦過了這個閾值, 大家都能接受,
那麼再向上的提升就不那麼必要的. 但隨著程序負載增大等原因, 這個閾值可能會變.&lt;/li&gt;
  &lt;li&gt;關於代碼細節, 可以說的方面很多. 一般, 只要不出錯, 都可以接受, 但如果一個地方
使用生成可迭代對象的方法去做遍歷, 那一定是可以繼續優化的.&lt;/li&gt;
  &lt;li&gt;代碼複用. 一般來說, 能複用的地方就複用. 但如何確定能複用? 我們不該在寫第一個
例子的時候就開始對這個例子進行抽象以方便下一次複用, 而是要在下一次真正到來的
時候再開始抽象並複用. 甚至有時候當第二次, 第三次出現的時候我們都還不做複用,
比如 Dan Abramov 提到的, 需求還在變化中, 提前抽象會導致將來的功能變動難以實現,
從而導致更大的工作量.&lt;/li&gt;
  &lt;li&gt;程序架構. 架構似乎是最不重要的, 但也卻是一開始就要確定的. 當然, 隨著業務發展,
什麼都可能會變, 架構也會隨著變化. 架構是綜合了上面所有的點, 總結出來的. 架構
要能保證功能的完全性, 符合團隊能力, 可以實現自動化的風格一致性, 不會拖慢
開發速度, 在基礎環節上能達到代碼執行效率閾值, 同時儘可能約束代碼細節, 避免
低級錯誤, 提供代碼複用優化的可能.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;關於如何平衡功能的實現與代碼的優雅, 我的觀點一直是:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;代碼的好是沒有止境的, 只能無限接近於滿分.&lt;/li&gt;
  &lt;li&gt;代碼需要適應環境的變化, 尤其是高級語言.&lt;/li&gt;
  &lt;li&gt;基於以上兩點, 好代碼是慢慢進化的, 不斷進化的, 不能一蹴而就.&lt;/li&gt;
  &lt;li&gt;先以最快速度完成基礎功能, 然後不斷優化.&lt;/li&gt;
  &lt;li&gt;開始時, 不使用框架或類庫, 如果要用, 則使用基礎的, 可插拔的.&lt;/li&gt;
  &lt;li&gt;隨著項目的推進, 功能逐漸複雜, 產品目標逐漸清晰, 這時再考慮利用框架重構或重寫.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;在 &lt;a href=&quot;https://go-proverbs.github.io/&quot;&gt;Go Proverbs&lt;/a&gt; 中有這樣一句話與 Dan Abramov 的文章異曲同工:
A little copying is better than a little dependency.&lt;/p&gt;

&lt;p&gt;現在, 就讓我們停下來, 更多的思考, 然後進入對好代碼執著的下一個階段吧.&lt;/p&gt;


            </description>
            <pubDate>Tue, 14 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-14-best-software-engineering-practices.html
            </guid>
        </item>
        
        <item>
            <title>URL and cross-origin</title>
            <link>
                https://zsqk.github.io/2020-04-13-url-and-http203.html
            </link>
            <description>
                &lt;blockquote&gt;
  &lt;p&gt;:bulb: 下面的兩個章節可能無關.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;url-和-uri-有什麼區別&quot;&gt;URL 和 URI 有什麼區別&lt;/h2&gt;

&lt;p&gt;根據 &lt;a href=&quot;https://en.wikipedia.org/wiki/URL&quot;&gt;URL 的 wiki&lt;/a&gt;, URL 是一種特殊的 URI, 用來表示互聯網資源.&lt;/p&gt;

&lt;h2 id=&quot;url-的標準是什麼&quot;&gt;URL 的標準是什麼&lt;/h2&gt;

&lt;p&gt;標準由 WHATWG 制定: &lt;a href=&quot;https://url.spec.whatwg.org/&quot;&gt;https://url.spec.whatwg.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;標準是抽象的, 並且引用套引用, 就像一個包含無數小函數的程序, 需要梳理.&lt;/p&gt;

&lt;p&gt;我們來看看 MDN 的文檔吧, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL&quot;&gt;What is a URL?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;在 UTF-8 的現在, 多語言不是問題, 而是大家的守則.
理論上任何語言都可以成為構成 URL 的 &lt;a href=&quot;https://url.spec.whatwg.org/#valid-domain&quot;&gt;valid domain&lt;/a&gt; 和 &lt;a href=&quot;https://url.spec.whatwg.org/#percent-encoded-byte&quot;&gt;percent-encoded byte&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;但是我們傾向於使用這樣的規則: 小寫字母, 數字, 連字符.&lt;/p&gt;

&lt;h2 id=&quot;談談跨域---http-203&quot;&gt;談談跨域 - HTTP 203&lt;/h2&gt;

&lt;p&gt;這裡 HTTP 203 指的是 Chrome 團隊出品的一檔談話節目.&lt;/p&gt;

&lt;p&gt;HTTP 203 挺好的, 就是說話太快了, 來不及聽.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=vfAHa5GBLio&quot;&gt;https://www.youtube.com/watch?v=vfAHa5GBLio&lt;/a&gt; 提到:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;跨域請求問題來源於歷史上 Cookies 會被一同發送.&lt;/li&gt;
  &lt;li&gt;Access-Control-Allow-Origin 比 Origin 還有歷史.&lt;/li&gt;
  &lt;li&gt;之所有會有 Origin 是因為歷史上避免包含 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt; 的頭被過濾.&lt;/li&gt;
  &lt;li&gt;但現在 Origin 會有更廣泛的作用.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如果網頁不使用 Cookies, 似乎就不是什麼問題了.&lt;/p&gt;

&lt;p&gt;在現在前端當中, Cookies 的功能已經可以完全被替代了.&lt;/p&gt;

&lt;p&gt;但可以被取代, 不是會被取代.&lt;/p&gt;

            </description>
            <pubDate>Mon, 13 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-13-url-and-http203.html
            </guid>
        </item>
        
        <item>
            <title>Npm Fetchpackagemetadata Error</title>
            <link>
                https://zsqk.github.io/2020-04-10-npm-fetchpackagemetadata-error.html
            </link>
            <description>
                &lt;h1 id=&quot;常見問題處理-npm-fetchpackagemetadata-error--unexpected-end-of-json-input-&quot;&gt;常見問題處理 npm fetchPackageMetaData error … Unexpected end of JSON input …&lt;/h1&gt;
&lt;p&gt;之前大多數項目都是使用 yarn, 但現在 yarn 正在切換到 berry, 有一些問題. 所以最近的新項目使用了 npm. 沒想到, 這麼多年過去, 依舊是坑.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;npm 的確是有效率問題的. 並且有一些低級問題沒有進行處理.&lt;/p&gt;

&lt;p&gt;效率問題比如依賴之間關係梳理的複雜, 效率低. 具體不展開了, 但實際使用感受已經足夠說明問題.
是 Yarn 存在的意義. 同時也是 deno 想要避免的.&lt;/p&gt;

&lt;p&gt;這裡說一下在國內都可能遇到的問題:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;網絡原因導致包下載失敗.&lt;/li&gt;
  &lt;li&gt;再次嘗試仍然從緩存中拿失敗的數據.&lt;/li&gt;
  &lt;li&gt;如果不清除緩存, 一直無法跳過失敗數據.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;http fetch GET 304 https://registry.npmjs.org/cssnano-preset-default 982ms (from cache)
silly fetchPackageMetaData error for cssnano-preset-default@^4.0.7 Unexpected end of JSON input while parsing near &#39;...E1piZamJTcxPxUDG/h3FS&#39;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;其實這裡可以增加一個簡單的判斷, 如果 JSON 化失敗, 則判斷為網絡問題, 不再從緩存中拿數據.&lt;/p&gt;

&lt;p&gt;無法單獨清除某緩存, 比如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm cache clean https://registry.npmjs.org/cssnano-preset-default&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;緩存一致性檢查 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm cache verify&lt;/code&gt; 奇慢.&lt;/p&gt;

&lt;p&gt;無奈只好使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm cache clean --force&lt;/code&gt; 清除所有緩存.&lt;/p&gt;

&lt;p&gt;想到清除所有緩存後, 隨之而來的所有依賴被重新下載, 想想都頭疼.&lt;/p&gt;

&lt;p&gt;這真是一個太明顯並且太嚴重的問題了. 網上許多 npm 包的 issues 都是因為 npm 的這一問題.&lt;/p&gt;

&lt;p&gt;重新安裝依賴中, 太慢了… 不過起碼能用, 比代理會快點.&lt;/p&gt;

&lt;p&gt;可是 Yarn berry 還是許多問題, 比如 https://github.com/yarnpkg/berry/issues/1149.&lt;/p&gt;

&lt;p&gt;使用淘寶鏡像吧: https://developer.aliyun.com/mirror/NPM&lt;/p&gt;

&lt;p&gt;即便使用鏡像, 還是挺慢的.&lt;/p&gt;

            </description>
            <pubDate>Fri, 10 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-10-npm-fetchpackagemetadata-error.html
            </guid>
        </item>
        
        <item>
            <title>How To Reduce Cpu Consumption</title>
            <link>
                https://zsqk.github.io/2020-04-10-how-to-reduce-cpu-consumption.html
            </link>
            <description>
                &lt;h1 id=&quot;如何減少cpu消耗&quot;&gt;如何減少CPU消耗&lt;/h1&gt;

&lt;h2 id=&quot;減少等待&quot;&gt;減少等待&lt;/h2&gt;

&lt;p&gt;減少IO量&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;SQL/index，使用合適的索引減少掃描的行數（需平衡索引的正收益和維護開銷，空間換時間）&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;提升IO處理能力&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;加cache/加磁盤/SSD&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;減少計算&quot;&gt;減少計算&lt;/h2&gt;

&lt;p&gt;減少邏輯運算量&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;避免使用函數，將運算轉移至易擴展的應用服務器中 如substr等字符運算，dateadd/datesub等日期運算，abs等數學函數&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;減少排序，利用索引取得有序數據或避免不必要排序 如union all代替 union，order by 索引字段等&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;禁止類型轉換，使用合適類型並保證傳入參數類型與數據庫字段類型絕對一致 如數字用tiny/int/bigint等，必需轉換的在傳入數據庫之前在應用中轉好&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;簡單類型，儘量避免複雜類型，降低由於複雜類型帶來的附加運算。更小的數據類型佔用更少的磁盤、內存、cpu緩存和cpu週期&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;減少邏輯io量&quot;&gt;減少邏輯IO量&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;index，優化索引，減少不必要的表掃描 如增加索引，調整組合索引字段順序，去除選擇性很差的索引字段等等&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;table，合理拆分，適度冗餘 如將很少使用的大字段拆分到獨立表，非常頻繁的小字段冗餘到“引用表”&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;SQL，調整SQL寫法，充分利用現有索引，避免不必要的掃描，排序及其他操作 如減少複雜join，減少order by，儘量union all，避免子查詢等&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;數據類型，夠用就好，減少不必要使用大字段 如tinyint夠用就別總是int，int夠用也別老bigint，date夠用也別總是timestamp&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;減少query請求量非數據庫本身&quot;&gt;減少query請求量（非數據庫本身）&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;適當緩存，降低緩存數據粒度，對靜態並被頻繁請求的數據進行適當的緩存 如用戶信息，商品信息等&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;優化實現，儘量去除不必要的重複請求 如禁止同一頁面多次重複請求相同數據的問題，通過跨頁面參數傳遞減少訪問等&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;合理需求，評估需求產出比，對產出比極端底下的需求合理去除&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;升級cpu&quot;&gt;升級cpu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;低延遲（快速響應），需要更快的cpu（每個查詢只能使用一個cpu）&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;高吞吐，同時運行很多查詢語句，能從多個cpu處理查詢中收益&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Fri, 10 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-10-how-to-reduce-cpu-consumption.html
            </guid>
        </item>
        
        <item>
            <title>Questions Philosophers Ponder</title>
            <link>
                https://zsqk.github.io/2020-04-09-questions-philosophers-ponder.html
            </link>
            <description>
                &lt;h1 id=&quot;前言&quot;&gt;前言&lt;/h1&gt;
&lt;p&gt;通過瞭解哲學家們思考的問題能夠幫助我們更加簡單和通俗的認識到哲學是一門什麼樣的學科以及哲學家都在做些什麼事情。從而對哲學產生一個相對準確和客觀印象。&lt;/p&gt;

&lt;h1 id=&quot;前蘇格拉底時代公元前700公元前370&quot;&gt;前蘇格拉底時代（公元前700~公元前370）&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;前蘇格拉底時代對應中國的春秋戰國時期，老子，孔子的時代&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;泰勒斯&lt;/code&gt;通過觀察水的形態變化提出&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;水是構成世界的基本材料&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;畢達哥拉斯&lt;/code&gt;通過思考數學公式的確定性提出&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;數字是宇宙的統治者&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;普羅塔哥拉&lt;/code&gt;提出&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;人是萬物的尺度&lt;/code&gt;，因為一個人看起來是正確的事情，另一個人可能會認為是錯誤的。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;德謨克利特&lt;/code&gt;提出原子論&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;世間是由原子和虛空組成的&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;前蘇格拉底時代的哲學問題大部門集中在對自然哲學的思考，比如客觀世界的原貌，萬物的構成。&lt;/strong&gt;&lt;/p&gt;

&lt;h1 id=&quot;經典希臘時代公元前470公元前250&quot;&gt;經典希臘時代（公元前470~公元前250）&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;經典希臘時代對應中國的戰國時期&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;蘇格拉底&lt;/code&gt;思考的問題是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;什麼才是好的生活，生命的意義是什麼。提出善是事物的本性，是萬物追求的目標&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;柏拉圖&lt;/code&gt;思考的問題是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;人類如何分辨出萬物的正確的，完美的最本質的基本形態&lt;/code&gt;。比如我們看到不同品種不同形態不同顏色的貓都能分辨出來，那麼必然所有的貓都有某種共同特徵。這種由共同特徵所組成的完美形態的貓才是我們應該去認識的。而現實世界只不過是這種完美形態的複製模型。  &lt;br /&gt;
為此&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;柏拉圖&lt;/code&gt;提出一個“洞穴比喻”來說明。他讓人們想像出一個洞穴，囚犯面向牆壁被綁在洞穴中，身後是一個火堆。囚犯和火堆之間不時有人走動或拿起不同物體，這些物體的影子反映在洞穴牆壁上。那麼這些囚犯實際上並不能真正瞭解事物本身。柏拉圖覺得&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;人類感官所感知到的物質世界正如洞穴牆壁上的影子一樣，是現實的縮影&lt;/code&gt;。  &lt;br /&gt;
這種對人類認識的質疑和問題通常被歸為&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;形而上學&lt;/code&gt;。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;形而上學&lt;/code&gt;是哲學的一個門類，研究世界的本質。比如超自然世界的本原，靈魂是否存在，自由意志是否存在等。通常對於&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;形而上學&lt;/code&gt;的理解誤區在於這一概念本身的形式，它不常與其他學科放在一起，我們會認為形而上學是一個概念而非學科。實際上它和數學，化學，物理學這些文字形式類似，當我們說某一問題是物理問題時，意味著這一問題屬於物理學範疇。而當我們說某一問題是形而上的，也就意味著這一問題屬於形而上學這門學科。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;亞裡士多德&lt;/code&gt;與柏拉圖相反，柏拉圖質疑自己的感官，而&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;亞裡士多德&lt;/code&gt;認為&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;我們是通過感知來認識世界的&lt;/code&gt;。他認為現實世界中的物體並非物體完美形態的複製模型。我們應當通過研究個體來認識某一種類共有的本質。比如研究不同的貓得出貓共有的本質屬性。對於公正，美德這些概念，我們只能通過觀察他們在現實世界的各種不同呈現方式來逐漸修正對他們的瞭解和認識。  &lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;亞裡士多德&lt;/code&gt;按照生物的特徵對生物進行了歸類。在這過程中制定了一套成系統的邏輯形式。期望運用邏輯推理出事實。例如，我們通過兩個命題“所有人都會死”和“蘇格拉底是人”可以推理出“蘇格拉底會死”的結論。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;伊壁鳩魯&lt;/code&gt;認為&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;人應當在短暫的人生中享樂。這種快樂並不是純粹的身體感受到的世俗快樂，而是身體的沒有痛苦和靈魂的不受幹擾，是一種平靜狀態。&lt;/code&gt;。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;芝諾&lt;/code&gt;認為&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;宇宙有自己的規律，自然法則是宇宙的主宰。人應該遵循自然法則，追求各自與自然達成的和諧狀態&lt;/code&gt;。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;從蘇格拉底開始，哲學家們開始關注對人本身的思考和探究。&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;受限於當時的知識水平，其中某些理論可能被現代人認為是簡單的，不值一提的，甚至是錯誤的，但我們也不能否認他們在自己所處的年代開創出這些理論的革命性，和對人類文明後續發展的重要性。現代的很多領域中我們仍然能夠清晰的看到這些理論所留下的印記。&lt;/strong&gt;&lt;/p&gt;

&lt;h1 id=&quot;參考&quot;&gt;參考&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://book.douban.com/subject/25810167/&quot;&gt;哲學百科&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://yangjh.gitee.io/philosophymindmap/&quot;&gt;西方哲學史思維導圖 1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://mm.edrawsoft.cn/template/1478&quot;&gt;西方哲學史思維導圖 2&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://wemp.app/posts/cc88c2c3-1491-4486-9b43-fb6be5778cbc&quot;&gt;西方哲學史思維導圖 3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Thu, 09 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-09-questions-philosophers-ponder.html
            </guid>
        </item>
        
        <item>
            <title>道長在硅谷工作是怎樣一種體驗</title>
            <link>
                https://zsqk.github.io/2020-04-08-working-experience-in-silicon-valley.html
            </link>
            <description>
                &lt;h2 id=&quot;概要&quot;&gt;概要&lt;/h2&gt;

&lt;p&gt;描述了&lt;em&gt;故胤道長&lt;/em&gt;在 Uber, Amazon, Quora 的工作體驗分享.&lt;/p&gt;

&lt;p&gt;主人公是 CMU 畢業, 然後一路都是大廠經驗, 主要從事 iOS 開發.&lt;/p&gt;

&lt;h2 id=&quot;節目&quot;&gt;節目&lt;/h2&gt;

&lt;p&gt;來自播客 ggtalk 的一個系列節目.&lt;/p&gt;

&lt;p&gt;講工作經驗的是其中一期. 也順便講了講對行業, 職業規劃, 生活的看法.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://poddtoppen.se/podcast/1440443653/ggtalk/%E9%81%93%E9%95%BF%E4%B8%89%E5%8D%81%E5%9C%A8%E7%A1%85%E8%B0%B7%E5%B7%A5%E4%BD%9C%E6%98%AF%E6%80%8E%E6%A0%B7%E4%B8%80%E7%A7%8D%E4%BD%93%E9%AA%8C&quot;&gt;https://poddtoppen.se/podcast/1440443653/ggtalk/%E9%81%93%E9%95%BF%E4%B8%89%E5%8D%81%E5%9C%A8%E7%A1%85%E8%B0%B7%E5%B7%A5%E4%BD%9C%E6%98%AF%E6%80%8E%E6%A0%B7%E4%B8%80%E7%A7%8D%E4%BD%93%E9%AA%8C&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;主人公&quot;&gt;主人公&lt;/h2&gt;

&lt;p&gt;故胤道長 soapyigu&lt;/p&gt;

&lt;p&gt;GitHub soapyigu: &lt;a href=&quot;https://github.com/soapyigu&quot;&gt;https://github.com/soapyigu&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;微博: &lt;a href=&quot;https://www.weibo.com/soapyigu&quot;&gt;https://www.weibo.com/soapyigu&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;聽的感受&quot;&gt;聽的感受&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Uber (當時)是一家技術很激進的公司.&lt;/li&gt;
  &lt;li&gt;Amazon (當時)的離職率很高, 許多新人.&lt;/li&gt;
  &lt;li&gt;Quora (當時)是一家常青藤公司(戲謔).&lt;/li&gt;
  &lt;li&gt;NETFLIX 一般不招實習生, 只招資深開發者.&lt;/li&gt;
  &lt;li&gt;選擇工作時, 公司是一項重要參考, 同時具體的技術組和直接領導也很重要.&lt;/li&gt;
  &lt;li&gt;在美國不是隻有灣區, Amazon, 微軟總部都是在西雅圖的.&lt;/li&gt;
  &lt;li&gt;在西雅圖工作生活都挺舒適的.&lt;/li&gt;
  &lt;li&gt;美國大廠多數是現金 + 股票, NETFLIX 則全部是現金.&lt;/li&gt;
  &lt;li&gt;在美國如果想要更長遠的職業發展, 要認真做事, 但同時也要會宣傳自己.&lt;/li&gt;
  &lt;li&gt;作為軟件工程師, 30 歲成為美國大廠 Senior 已經是很出色的了.&lt;/li&gt;
  &lt;li&gt;語言需要多聽多講, 但想要更進一步的溝通, 還需要了解當地的文化.&lt;/li&gt;
  &lt;li&gt;每一家公司都有自己的特點和生存之道, 無須苛責.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;擴展閱讀&quot;&gt;擴展閱讀&lt;/h2&gt;

&lt;p&gt;訪問 Quora 楊蕾: &lt;a href=&quot;https://www.infoq.cn/article/9LhRWeXdYGh6mQQSiVZA&quot;&gt;https://www.infoq.cn/article/9LhRWeXdYGh6mQQSiVZA&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;從 Google 離職加入 Quora.&lt;/li&gt;
  &lt;li&gt;帶領 Quora 工程團隊從 60 人增長為 120 人.&lt;/li&gt;
  &lt;li&gt;建立信任有助於團隊接受批評和建議, 並進步.&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Wed, 08 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-08-working-experience-in-silicon-valley.html
            </guid>
        </item>
        
        <item>
            <title>空值合併運算符 nullish coalescing operator</title>
            <link>
                https://zsqk.github.io/2020-04-08-nullish-coalescing-operator.html
            </link>
            <description>
                &lt;blockquote&gt;
  &lt;p&gt;:bulb: 目前 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??=&lt;/code&gt; 已經是 ECMAScript 正式標準了.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??&lt;/code&gt; 是空值合併運算符 &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator&quot;&gt;nullish coalescing operator&lt;/a&gt;, 現在已經是正式標準了.&lt;/p&gt;

&lt;p&gt;聽名字就挺好理解的, 主要為了替代 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;||&lt;/code&gt; 的部分功能.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??&lt;/code&gt; 與 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;||&lt;/code&gt; 的區別在於, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;||&lt;/code&gt; 判斷真值, 而 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??&lt;/code&gt; 只會判斷非空值, 比如:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null || 1&lt;/code&gt; 結果為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0 || 1&lt;/code&gt; 結果也為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null ?? 1&lt;/code&gt; 結果為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0 ?? 1&lt;/code&gt; 結果為 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;del&gt;空值合併運算符是 Finished Proposals(Stage 4). 將來大家都可以用到.&lt;/del&gt;
&lt;del&gt;在瀏覽器中的支持情況已經很好了, 主流瀏覽器的最新版本都支持. 最新的 V8 已經支持,&lt;/del&gt;
&lt;del&gt;但目前 Node.js 還不支持.&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??&lt;/code&gt; 是一個有用的語法糖, 推薦大家使用.&lt;/p&gt;

&lt;h2 id=&quot;-1&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??=&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??=&lt;/code&gt; 是邏輯空值賦值運算符, 也是 Finished Proposals(Stage 4).&lt;/p&gt;

&lt;p&gt;&lt;del&gt;最近 &lt;a href=&quot;https://github.com/tc39/proposals/commit/943bf8956b7d25032075e4789c1e351fdf2ae9ec&quot;&gt;Logical Assignment Operators 提案到了 Stage 3&lt;/a&gt;.&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;以前沒有關注過&lt;a href=&quot;https://github.com/tc39/proposal-logical-assignment&quot;&gt;這一提案&lt;/a&gt;, 今天特意看了一下.&lt;/p&gt;

&lt;p&gt;提案中說道, 在 ECMAScript 規範中, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators&quot;&gt;有許多數學的賦值運算符&lt;/a&gt;,
但卻沒有邏輯的賦值運算符.&lt;/p&gt;

&lt;p&gt;普通的賦值運算符就是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt;. 數學的賦值運算符比如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+=&lt;/code&gt; 是加法的賦值運算符,
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-=&lt;/code&gt; 是減法的賦值運算符.&lt;/p&gt;

&lt;p&gt;所有的特殊賦值運算符目的都是為了簡潔, 只是一種語法糖.&lt;/p&gt;

&lt;p&gt;不過既然我們都有了數學的賦值運算符, 那就是認可了這種語法糖, 提案者據此提出了
邏輯的賦值運算符.&lt;/p&gt;

&lt;p&gt;當然也是借鑑了其他語言, 如 Ruby.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 傳統寫法&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 使用空值合併運算符的簡寫方式&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 注意：這種寫法會總是觸發賦值操作&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 使用括號來避免不必要的賦值&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 只有在 opts.foo 為 null 或 undefined 時才會執行賦值&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 使用邏輯空值賦值運算符的最簡寫法&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 效果同上，更加簡潔直觀&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;??=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;


            </description>
            <pubDate>Wed, 08 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-08-nullish-coalescing-operator.html
            </guid>
        </item>
        
        <item>
            <title>那些年在網吧被盜的號</title>
            <link>
                https://zsqk.github.io/2020-04-08-internet-cafes-hack.html
            </link>
            <description>
                &lt;p&gt;這裡講一個局域網網絡攻擊的方法，可能已經有點過時&lt;/p&gt;

&lt;h3 id=&quot;知識點&quot;&gt;知識點&lt;/h3&gt;

&lt;h4 id=&quot;arp地址解析協議&quot;&gt;ARP（地址解析協議）&lt;/h4&gt;

&lt;p&gt;定義：根據IP地址獲取物理地址的一個TCP/IP協議。
實現過程：主機發送信息時將包含目標IP地址的ARP請求廣播到局域網絡上的所有主機，並接收返回消息，以此確定目標的物理地址；收到返回消息後將該IP地址和物理地址存入本機ARP緩存中並保留一定時間，下次請求時直接查詢ARP緩存以節約資源。&lt;/p&gt;

&lt;h4 id=&quot;arp欺騙&quot;&gt;ARP欺騙&lt;/h4&gt;

&lt;p&gt;通過欺騙局域網內訪問者PC的網關MAC地址，使訪問者PC錯以為攻擊者更改後的MAC地址是網關的MAC，導致網絡不通。此種攻擊可讓攻擊者獲取局域網上的數據包甚至可篡改數據包，且可讓網上特定計算機或所有計算機無法正常連線。地址解析協議是建立在網絡中各個主機互相信任的基礎上的，局域網絡上的主機可以自主發送ARP應答消息，其他主機收到應答報文時不會檢測該報文的真實性就會將其記入本機ARP緩存；由此攻擊者就可以向某一主機發送偽ARP應答報文，使其發送的信息無法到達預期的主機或到達錯誤的主機，這就構成了一個ARP欺騙。&lt;/p&gt;

&lt;h4 id=&quot;場景模擬&quot;&gt;場景模擬&lt;/h4&gt;

&lt;p&gt;網吧通常採用的是星型拓撲，所有主機連接到一臺或者多臺交換機，再由交換機連接到路由器。這樣就有數量可觀的主機都處在同一個局域網中，也是使用ARP欺騙攻擊的理想場所。當這些主機中的某一臺主機發起了ARP攻擊，將自己偽裝成網關，這時這臺主機成了這個局域網內所有主機的“代理”。所有主機的網絡請求都會通過這臺主機轉發，而這臺偽裝成網關的主機可以通過抓包工具輕鬆的獲取他們請求，這其中就包括了一些賬號的登錄信息。&lt;/p&gt;

            </description>
            <pubDate>Wed, 08 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-08-internet-cafes-hack.html
            </guid>
        </item>
        
        <item>
            <title>Insert Into Select</title>
            <link>
                https://zsqk.github.io/2020-04-07-insert-into-select.html
            </link>
            <description>
                &lt;h1 id=&quot;insert-into-select語句用法提示&quot;&gt;Insert into select語句用法提示&lt;/h1&gt;
&lt;h2 id=&quot;業務場景&quot;&gt;業務場景&lt;/h2&gt;
&lt;p&gt;將表A的數據遷移到表B中去做一個備份。本想通過程序先查詢查出來然後批量插入，但覺得這樣有點慢，需要耗費大量的網絡I/O，查資料後決定採取sql insert into select語句實現，這樣就可以避免使用網絡I/O，直接使用SQL依靠數據庫I/O完成。&lt;/p&gt;
&lt;h2 id=&quot;執行解析&quot;&gt;執行解析&lt;/h2&gt;
&lt;p&gt;在默認的事務隔離級別下：insert into B select * from A 加鎖規則是：B表鎖，A逐步鎖（掃描一個鎖一個）。
通過觀察遷移sql的執行情況你會發現A是全表掃描，也就意味著在執行insert into select from 語句時，mysql會從上到下掃描A內的記錄並且加鎖，這樣一來就和直接鎖表是一樣了。
由於查詢條件會導致A全表掃描，那麼什麼能避免全表掃描呢，給查詢條件字段添加一個索引就可以了，由於走索引查詢，就不會出現掃描全表的情況而鎖表了，只會鎖定符合條件的記錄。&lt;/p&gt;
&lt;h2 id=&quot;總結&quot;&gt;總結&lt;/h2&gt;
&lt;p&gt;使用insert into tableB select * from tableA語句時，一定要確保tableA後面的where，order或者其他條件，都需要有對應的索引，來避免出現tableA全部記錄被鎖定的情況。&lt;/p&gt;

            </description>
            <pubDate>Tue, 07 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-07-insert-into-select.html
            </guid>
        </item>
        
        <item>
            <title>司徒正美, 健康</title>
            <link>
                https://zsqk.github.io/2020-04-04-rip.html
            </link>
            <description>
                &lt;h2 id=&quot;概要&quot;&gt;概要&lt;/h2&gt;

&lt;p&gt;網傳, 司徒正美離世, 可能因為頸椎病, 但具體情況不明.&lt;/p&gt;

&lt;p&gt;因為想以 React 語法開發微信小程序, 瞭解過 &lt;a href=&quot;https://github.com/RubyLouvre/anu&quot;&gt;anu&lt;/a&gt; 和 nanachi.&lt;/p&gt;

&lt;p&gt;紀念一下他, 也提醒大家關注常見疾病頸椎病, 關注自身健康.&lt;/p&gt;

&lt;h2 id=&quot;司徒正美其人&quot;&gt;司徒正美其人&lt;/h2&gt;

&lt;p&gt;網名: 司徒正美 / RubyLouvre&lt;/p&gt;

&lt;p&gt;鍾欽成&lt;/p&gt;

&lt;p&gt;從業多年, &lt;a href=&quot;https://book.douban.com/subject/27133542/&quot;&gt;出過書&lt;/a&gt;, 以前在去哪兒, 現在應該&lt;a href=&quot;https://github.com/RubyLouvre/anu/commit/86911d21feada7ddacb603654853fc0d3aa522a3#diff-0730bb7c2e8f9ea2438b52e419dd86c9&quot;&gt;已經從 qunar.com 離職&lt;/a&gt;,
應該是業內一位人物.&lt;/p&gt;

&lt;p&gt;主要在國內的社群活動, 比如&lt;a href=&quot;https://www.cnblogs.com/rubylouvre/&quot;&gt;博客在 cnblogs&lt;/a&gt;. 在知乎也&lt;a href=&quot;https://www.zhihu.com/people/si-tu-zheng-mei&quot;&gt;有一些回答&lt;/a&gt;.
也&lt;a href=&quot;https://github.com/RubyLouvre&quot;&gt;活躍在 GitHub&lt;/a&gt;. &lt;a href=&quot;https://twitter.com/jslouvre&quot;&gt;有 Twitter&lt;/a&gt;, 但不怎麼用.&lt;/p&gt;

&lt;p&gt;一位堅持寫博客 10 年的人, 值得敬佩.&lt;/p&gt;

&lt;p&gt;工作經歷&lt;a href=&quot;https://www.linkedin.com/in/%E9%92%A6%E6%88%90-%E9%92%9F-735228130/&quot;&gt;可以在 LinkedIn 看到&lt;/a&gt;. 2013 年來北京, 在去哪兒工作多年.&lt;/p&gt;

&lt;p&gt;最近在&lt;a href=&quot;https://leetcode.com/rubylouvre/&quot;&gt;刷題&lt;/a&gt;, 可能是疫情原因, 也可能是離職後有時間了.&lt;/p&gt;

&lt;h2 id=&quot;頸椎病&quot;&gt;頸椎病&lt;/h2&gt;

&lt;p&gt;首先, 推薦大家看&lt;a href=&quot;https://www.msdmanuals.com/zh/%E9%A6%96%E9%A1%B5/brain,-spinal-cord,-and-nerve-disorders/spinal-cord-disorders/cervical-spondylosis&quot;&gt;默沙東關於頸椎病的介紹&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;其次, 默沙東有&lt;a href=&quot;https://www.msdmanuals.com/zh/home/fundamentals/prevention/tools-of-prevention&quot;&gt;一篇文章談到了對任何疾病的預防手段&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;簡單列舉一下就是:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;繫好安全帶&lt;/li&gt;
  &lt;li&gt;飲食健康 (低熱量, 低飽和脂肪, 低反式脂肪酸)&lt;/li&gt;
  &lt;li&gt;身體鍛鍊 (規律, 足量)&lt;/li&gt;
  &lt;li&gt;塗防曬霜&lt;/li&gt;
  &lt;li&gt;不抽菸&lt;/li&gt;
  &lt;li&gt;免疫接種&lt;/li&gt;
  &lt;li&gt;定期體檢&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;希望大家健康.&lt;/p&gt;


            </description>
            <pubDate>Sat, 04 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-04-rip.html
            </guid>
        </item>
        
        <item>
            <title>DynamoDB 心得分享</title>
            <link>
                https://zsqk.github.io/2020-04-01-dynamodb.html
            </link>
            <description>
                &lt;blockquote&gt;
  &lt;p&gt;:warning: 本文可能已過時&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;簡介&quot;&gt;簡介&lt;/h2&gt;

&lt;p&gt;DynamoDB 是一種完全託管的 NoSQL 數據庫服務。&lt;/p&gt;

&lt;h2 id=&quot;dynamodb-的核心&quot;&gt;DynamoDB 的核心&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;在 DynamoDB 中核心組件是表、項目和屬性。&lt;/li&gt;
  &lt;li&gt;表是項目的集合。&lt;/li&gt;
  &lt;li&gt;項目是屬性的集合。&lt;/li&gt;
  &lt;li&gt;DynamoDB 使用主鍵來標識表中的每個項目，還提供了二級索引來提供更大的查詢靈活性，
還可以使用 DynamoDB 流來捕獲 DynamoDB 表中的數據修改事件。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;dynamodb的優點&quot;&gt;DynamoDB的優點&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;性能穩定。為了保證高性能，DynamoDB 採用固態硬盤(SSD)進行存儲，對於一般的請求，
DynamoDB 可以在 10 毫秒內完成，而且請求速度不會因為數據量增加而減慢。&lt;/li&gt;
  &lt;li&gt;讀/寫流量限制預設。用戶可以隨時通過控制台或者API更改數據庫的讀/寫流量的限制。&lt;/li&gt;
  &lt;li&gt;自動擴容。DynamoDB 不會對用戶的數據規模大小做任何限制，後臺會默默地把用戶的
數據分不到各個機器上去。&lt;/li&gt;
  &lt;li&gt;強一致性。用戶可以通過參數指定要讀的數據是否需要一致性。&lt;/li&gt;
  &lt;li&gt;完全分佈式，無中心化結構。一個表上的數據可以分佈在幾百臺機器上。&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;dynamodb-和-simpledb-的區別&quot;&gt;DynamoDB 和 SimpleDB 的區別&lt;/h2&gt;

&lt;p&gt;DynamoDB 與 SimpleDB 都是 AWS 上的 NoSQL 數據庫，DynamoDB 優於 SimpleDB。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;SimpleDB 有單表限制。SimpleDB也有類似於Table的東西叫做Domain，每個 Domain
最多隻能保存10GB的數據，而 DynamoDB 並沒有單表存儲的任何限制。&lt;/li&gt;
  &lt;li&gt;SimpleDB 默認為表內所有屬性創建索引，這就導致 SimpleDB 性能不穩定。&lt;/li&gt;
  &lt;li&gt;SimpleDB 為最終一致性模型，DynamoDB 可以選擇弱一致性或者強一致性。&lt;/li&gt;
&lt;/ul&gt;

            </description>
            <pubDate>Wed, 01 Apr 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-04-01-dynamodb.html
            </guid>
        </item>
        
        <item>
            <title>從物理層面瞭解數據傳輸</title>
            <link>
                https://zsqk.github.io/2020-03-31-use-ip-to-communicate.html
            </link>
            <description>
                &lt;h2 id=&quot;知識點&quot;&gt;知識點&lt;/h2&gt;

&lt;h3 id=&quot;osi七層模型&quot;&gt;OSI七層模型&lt;/h3&gt;

&lt;p&gt;OSI七層模型（從上至下）分為：應用層，表示層，會話層，傳輸層，網絡層，數據鏈路層，
物理層.&lt;/p&gt;

&lt;p&gt;其中上三層（應用層，表示層，會話層）統稱為應用層，在這裡不做考慮。&lt;/p&gt;

&lt;h3 id=&quot;網絡層&quot;&gt;網絡層&lt;/h3&gt;

&lt;p&gt;網絡層通過ip進行尋址，在這一層的網絡設備主要以路由器為主。
路由器的特點是用來連接不同的網絡。&lt;/p&gt;

&lt;h3 id=&quot;數據鏈路層&quot;&gt;數據鏈路層&lt;/h3&gt;

&lt;p&gt;數據鏈路層主要通過mac進行尋址，這一層的網絡設備主要以交換機（二層交換機）為主。
交換機的特點是所有連接交換機的主機都必須處在同一個網段中。&lt;/p&gt;

&lt;h3 id=&quot;交換機與路由器的區別&quot;&gt;交換機與路由器的區別&lt;/h3&gt;

&lt;p&gt;交換機的接口較多，路由器的接口較少。（一般情況下）路由器的每個接口都代表一個不同的網段，
交換機的每接口必須處在同一個網段中。&lt;/p&gt;

&lt;h3 id=&quot;arp協議&quot;&gt;ARP協議&lt;/h3&gt;

&lt;p&gt;ARP協議屬於網絡層協議，將網絡地址（ip地址)解析為硬件地址（mac地址）。
當局域網（192.168.1.0網段）內的兩臺主機A、B進行通信時且A只知道B的網絡地址不知道B
的硬件地址的情況下A如何將數據發送給B。
A先查找自身的ARP緩存列表，查找B無果。會向192.168.1.255（網絡地址）發送一條
攜帶目標ip地址的ARP廣播請求並設定一個過期時間，
該網段內的所有主機會收到該條廣播，並且跟自身ip地址進行對比，如果該條廣播的目標ip
地址與自身的ip地址不相符則將這條請求拋棄，
如果相符則響應這條廣播。主機A在超時時間之內收到響應，則將主機B的硬件地址和緩存
地址保存在自己的ARP緩存列表中以備下次進行數據傳輸。
如果超過過期時間任然沒有接收到響應，則判定主機B不在當前局域網內。&lt;/p&gt;

&lt;h2 id=&quot;數據封裝&quot;&gt;數據封裝&lt;/h2&gt;

&lt;p&gt;這裡主要介紹網絡層和數據鏈路層的封裝。
網絡層對傳輸層的數據報進行封裝，封裝成為數據包，包的頭部保存ip地址等信息。&lt;br /&gt;
數據鏈路層對網絡層的數據包進行封裝，封裝成為數據幀，幀的頭部保存mac地址等信息。&lt;br /&gt;
路由器屬於三層設備，只檢查數據包的頭部信息。&lt;br /&gt;
（二層）交換機數據二層設備，只檢查幀的頭部信息。&lt;/p&gt;

&lt;h2 id=&quot;ip地址為19216812的主機a要給ip地址為1000212的主機b發送一條消息數據怎樣傳輸的&quot;&gt;ip地址為192.168.1.2的主機A要給ip地址為10.0.0.212的主機B發送一條消息數據怎樣傳輸的&lt;/h2&gt;

&lt;p&gt;主機A將數據層層封裝為數據幀發送出去，由於目標ip不在當前網段，主機A會將數據幀直接發送給網關。
路由器在接收到數據以後就將數據幀解封到三層的數據包，
並查詢自身的路由表將數據分組轉發到對應的接口，目標數據發送到目標局域網，
進行查找目標主機（通過arp協議進行輔助查找），目標數據在封裝成幀發送給主機B。&lt;/p&gt;

            </description>
            <pubDate>Tue, 31 Mar 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-03-31-use-ip-to-communicate.html
            </guid>
        </item>
        
        <item>
            <title>JavaScript ES6 簡單數組去重</title>
            <link>
                https://zsqk.github.io/2020-03-30-javascript-array-duplicate.html
            </link>
            <description>
                &lt;p&gt;Set對象是值的集合，你可以按照插入的順序迭代它的元素。 Set中的元素只會出現一次，即 Set 中的元素是唯一的。
Set 本身是一個構造函數，用來生成 Set 數據結構。&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;另外，NaN和undefined都可以被存儲在Set 中， NaN之間被視為相同的值（NaN被認為是相同的，儘管 NaN !== NaN）。&lt;/p&gt;

&lt;h2 id=&quot;set-簡單擴展應用&quot;&gt;Set 簡單擴展應用&lt;/h2&gt;

&lt;p&gt;用Set實現並集，交集， 差集&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 並集&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;union&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])];&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// ==&amp;gt; [1, 2, 3, 4];&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 交集&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;intersect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;has&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))];&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// ==&amp;gt; [2, 3];&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 差集&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;difference&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;has&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))];&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// ==&amp;gt; [1];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;擴展閱讀: &lt;a href=&quot;https://stackoverflow.com/a/9229821/4124389&quot;&gt;https://stackoverflow.com/a/9229821/4124389&lt;/a&gt;&lt;/p&gt;

            </description>
            <pubDate>Mon, 30 Mar 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-03-30-javascript-array-duplicate.html
            </guid>
        </item>
        
        <item>
            <title>Node.js 生態中的流行包 request 正式被棄用</title>
            <link>
                https://zsqk.github.io/2020-03-29-request-has-been-deprecated.html
            </link>
            <description>
                &lt;p&gt;在 2019 年 3 月份, 作者就創建了&lt;a href=&quot;https://github.com/request/request/issues/3142&quot;&gt;相關 issue&lt;/a&gt; 討論逐步讓 request 進入歷史.&lt;/p&gt;

&lt;p&gt;最近, &lt;a href=&quot;https://github.com/request/request/commit/aded7e4f8e57f6f33cf39d65634bfb822bfcb2c8&quot;&gt;作者正式宣佈棄用該包&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;關於棄用的原因, 主要是歷史比較久遠, 核心代碼已經跟不上 Node.js 的發展.&lt;/p&gt;

&lt;p&gt;我傾向標準庫強大的語言. Go 從設計之初就擁有強大的標準庫, Node.js 則是隨著
ECMAScript 的進步, 逐漸通過語法來完善與豐富自己.&lt;/p&gt;

&lt;h2 id=&quot;替代&quot;&gt;替代&lt;/h2&gt;

&lt;p&gt;關於 request 的替代品可以參考&lt;a href=&quot;https://github.com/request/request/issues/3143&quot;&gt;這個 issue&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;經驗&quot;&gt;經驗&lt;/h2&gt;

&lt;p&gt;其實我們並沒有使用過 request, 在 Node.js 中只是用 node-fetch 和 axios.&lt;/p&gt;

&lt;p&gt;在最初進入 Node.js 的時候, 我們關注到了 request, 但語法並沒有打動我們,
所以我們轉向了 node-fetch.&lt;/p&gt;

&lt;p&gt;因為我們同時會寫前後端, 在前端標準化的 fetch 讓我們能儘快入手.
但正是由於我們前後端同時在寫, 我們發現 node-fetch 的語法並不完全等同 fetch.
這讓我們更容易因為忽略了差異項而出錯.&lt;/p&gt;

&lt;p&gt;之後我們再次尋找替代品, 發現了 r2. r2 代碼的體積很小, 我們就看看源代碼,
發現只是簡單調用了 node-fetch.&lt;/p&gt;

&lt;p&gt;在最近的項目中, 我們才開始用當時還流行的 axios.&lt;/p&gt;

&lt;p&gt;我不太喜歡 axios 的語法, 有些過度了. 但基於流行原則我們還是在繼續使用.&lt;/p&gt;

&lt;p&gt;現在來看, request 作者的新包 &lt;a href=&quot;https://github.com/mikeal/bent&quot;&gt;bent&lt;/a&gt; 才是我們在 Node.js 中更應該做的選擇.&lt;/p&gt;

&lt;h2 id=&quot;bent&quot;&gt;bent&lt;/h2&gt;

&lt;p&gt;bent 是一個同時支持瀏覽器與 Node.js 的 HTTP client.&lt;/p&gt;

&lt;p&gt;在 Node.js 環境中, 進行了 Promise 化和流的支持.&lt;/p&gt;

&lt;p&gt;在瀏覽器端, 對 fetch 進行了簡單封裝以符合 bent 的 API.&lt;/p&gt;

&lt;p&gt;源代碼很小, 依賴也不多. API 簡潔實用. 是我們理想的選擇.&lt;/p&gt;

&lt;p&gt;但在瀏覽器端, bent 的封裝對我們幫助不大, 我們還是會選擇 fetch 然後自己封裝.&lt;/p&gt;


            </description>
            <pubDate>Sun, 29 Mar 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-03-29-request-has-been-deprecated.html
            </guid>
        </item>
        
        <item>
            <title>PHP, Go, Node.js 框架性能綜合對比</title>
            <link>
                https://zsqk.github.io/2020-03-28-php-go-nodejs-web-framework-benchmarks.html
            </link>
            <description>
                &lt;h2 id=&quot;數據來源&quot;&gt;數據來源&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.techempower.com/benchmarks/#section=data-r18&amp;amp;hw=cl&amp;amp;test=query&quot;&gt;https://www.techempower.com/benchmarks/#section=data-r18&amp;amp;hw=cl&amp;amp;test=query&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;分析的指標&quot;&gt;分析的指標&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;JSON serialization 序列化響應&lt;/li&gt;
  &lt;li&gt;Plaintext 簡單響應&lt;/li&gt;
  &lt;li&gt;Single query 單行查詢&lt;/li&gt;
  &lt;li&gt;Multiple queries 多行查詢&lt;/li&gt;
  &lt;li&gt;Data updates 數據更新&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;分析的對象&quot;&gt;分析的對象&lt;/h2&gt;

&lt;p&gt;考慮的幾種方案:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Node.js (函數計算)&lt;/li&gt;
  &lt;li&gt;Go (單機部署)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;這裡的單機部署並非只有一臺機器, 只是區別於 網關 + 函數計算 的方式.&lt;/p&gt;

&lt;p&gt;具體應用:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;echo (Go)&lt;/li&gt;
  &lt;li&gt;go-pgx-easyjson&lt;/li&gt;
  &lt;li&gt;nodejs-postgres (ORM)&lt;/li&gt;
  &lt;li&gt;php (nginx)&lt;/li&gt;
  &lt;li&gt;php-pgsql-raw (nginx)&lt;/li&gt;
  &lt;li&gt;lumen (nginx, ORM, MySQL)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;沒有看到 PHP + PostgreSQL 的組合.&lt;/p&gt;

&lt;p&gt;與 Golang 組合的基本都是 PostgreSQL.&lt;/p&gt;

&lt;h2 id=&quot;分析概覽&quot;&gt;分析概覽&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Rust 非常快, 甚至超過 C 與 C++.&lt;/li&gt;
  &lt;li&gt;Java 也很快, 但我不知道這些框架流行程度.&lt;/li&gt;
  &lt;li&gt;原生 PHP 整體並不慢, 但結合框架就慢了.&lt;/li&gt;
  &lt;li&gt;Go 數據請求的處理性能比 Node.js 更快.&lt;/li&gt;
  &lt;li&gt;雖然顯示 Go 的性能是 Node.js 的 3 倍以上, 但慢一部分出在 ORM 上.&lt;/li&gt;
  &lt;li&gt;原生寫 Go 與使用 echo 性能基本一致.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;分析細節&quot;&gt;分析細節&lt;/h2&gt;

&lt;h3 id=&quot;json-serialization-序列化響應&quot;&gt;JSON serialization 序列化響應&lt;/h3&gt;

&lt;p&gt;不涉及具體數據庫.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Framework&lt;/th&gt;
      &lt;th&gt;Performance&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;echo&lt;/td&gt;
      &lt;td&gt;32.8%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;go&lt;/td&gt;
      &lt;td&gt;31.9%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;go-pgx-easyjson&lt;/td&gt;
      &lt;td&gt;31.4%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;nodejs&lt;/td&gt;
      &lt;td&gt;23.6%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;php&lt;/td&gt;
      &lt;td&gt;12.5%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;lumen&lt;/td&gt;
      &lt;td&gt;1.1%&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;plaintext-簡單響應&quot;&gt;Plaintext 簡單響應&lt;/h3&gt;

&lt;p&gt;不涉及具體數據庫.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Framework&lt;/th&gt;
      &lt;th&gt;Performance&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;fasthttp&lt;/td&gt;
      &lt;td&gt;65.3%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;nodejs&lt;/td&gt;
      &lt;td&gt;7.9%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;go&lt;/td&gt;
      &lt;td&gt;6.4%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;echo&lt;/td&gt;
      &lt;td&gt;5.2%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;lumen&lt;/td&gt;
      &lt;td&gt;0.1%&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Go 在這個環節比 Node.js 慢有點出乎意料,
但換用 fasthttp 第三方庫還是一騎絕塵的.&lt;/p&gt;

&lt;p&gt;一般來說, 這種簡單響應的應用場景主要是 HTTP OPTIONS method.
但在函數計算中, 可以由網關響應該請求以節省運行開支.&lt;/p&gt;

&lt;h3 id=&quot;single-query-單行查詢&quot;&gt;Single query 單行查詢&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Framework&lt;/th&gt;
      &lt;th&gt;Performance&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;echo&lt;/td&gt;
      &lt;td&gt;46.2%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;go-pgx-easyjson&lt;/td&gt;
      &lt;td&gt;43.1%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;nodejs-postgres&lt;/td&gt;
      &lt;td&gt;13.8%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;php-pgsql-raw&lt;/td&gt;
      &lt;td&gt;13.8%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;lumen&lt;/td&gt;
      &lt;td&gt;1.5%&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;multiple-queries-多行查詢&quot;&gt;Multiple queries 多行查詢&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Framework&lt;/th&gt;
      &lt;th&gt;Performance&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;go-pgx-easyjson&lt;/td&gt;
      &lt;td&gt;47.8%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;echo&lt;/td&gt;
      &lt;td&gt;44.3%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;php-pgsql-raw&lt;/td&gt;
      &lt;td&gt;30.0%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;nodejs-postgres&lt;/td&gt;
      &lt;td&gt;14.4%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;lumen&lt;/td&gt;
      &lt;td&gt;8.1%&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;data-updates-數據更新&quot;&gt;Data updates 數據更新&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Framework&lt;/th&gt;
      &lt;th&gt;Performance&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;go-pgx-easyjson&lt;/td&gt;
      &lt;td&gt;35.4%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;echo&lt;/td&gt;
      &lt;td&gt;31.8%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;php-pgsql-raw&lt;/td&gt;
      &lt;td&gt;20.4%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;nodejs-postgres&lt;/td&gt;
      &lt;td&gt;8.2%&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;lumen&lt;/td&gt;
      &lt;td&gt;6.9%&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;總結&quot;&gt;總結&lt;/h2&gt;

&lt;p&gt;如果單機部署, 使用 echo 作為基礎是一個好的方案, 良好的社區支持, 簡單易用.&lt;/p&gt;

&lt;p&gt;如果使用了 echo, 就不考慮 fasthttp 了. 雖然在 v2 中支持過 fasthttp,
但在 &lt;a href=&quot;https://github.com/labstack/echo/issues/665&quot;&gt;https://github.com/labstack/echo/issues/665&lt;/a&gt; 中,
echo 作者解釋了為什麼放棄, 保持簡單及社區兼容, 也就是儘量使用標準庫.&lt;/p&gt;

&lt;p&gt;如果函數計算, 那麼 Node.js 也是不錯的選擇, 可以接受的性能, 與前端通用的語法.&lt;/p&gt;

&lt;p&gt;從以上的性能測試來看, PHP 本身的性能問題不大, 但標準庫太過老舊,
必須使用框架才能提高開發效率. 但普通框架導致性能極具下降. 並且因為歷史原因,
PHP 配合 Nginx 才能高效完成網絡任務, 單機部署步驟更多.&lt;/p&gt;

            </description>
            <pubDate>Sat, 28 Mar 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-03-28-php-go-nodejs-web-framework-benchmarks.html
            </guid>
        </item>
        
        <item>
            <title>國內部分地區用戶遭到中間人攻擊</title>
            <link>
                https://zsqk.github.io/2020-03-27-man-in-the-middle-attack.html
            </link>
            <description>
                &lt;p&gt;根據 V2EX 社區帖子, GitHub 在國內遭受大規模中間人攻擊.&lt;/p&gt;

&lt;p&gt;什麼是中間人攻擊? 如何防範?&lt;/p&gt;

&lt;h2 id=&quot;什麼是中間人&quot;&gt;什麼是中間人&lt;/h2&gt;

&lt;p&gt;在用戶與服務器之間的任何層, 都可以稱為中間人. 包括但不僅限於:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;本機設備的惡意軟件&lt;/li&gt;
  &lt;li&gt;本地路由器&lt;/li&gt;
  &lt;li&gt;各級電信運營商&lt;/li&gt;
  &lt;li&gt;國際出口&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;攻擊目的&quot;&gt;攻擊目的&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;阻斷溝通.&lt;/li&gt;
  &lt;li&gt;偽造身份.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;大多數中間人攻擊都是為了偽造身份, 比如攻擊者不是銀行, 偽裝成銀行與客戶進行溝通
以套取密碼.&lt;/p&gt;

&lt;h2 id=&quot;如何進行&quot;&gt;如何進行&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;直接劫持並替換數據包.&lt;/li&gt;
  &lt;li&gt;通過 DNS spoofing.&lt;/li&gt;
  &lt;li&gt;阻斷數據包.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;什麼是 DNS spoofing?&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/DNS_spoofing&quot;&gt;https://en.wikipedia.org/wiki/DNS_spoofing&lt;/a&gt;
&lt;a href=&quot;https://www.cloudflare.com/learning/dns/dns-cache-poisoning/&quot;&gt;https://www.cloudflare.com/learning/dns/dns-cache-poisoning/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;我們經常遇到這種 DNS 攻擊, 如何識別與防範以後單獨寫一下.&lt;/p&gt;

&lt;h2 id=&quot;如何防範&quot;&gt;如何防範&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;本地客戶端對等加密.&lt;/li&gt;
  &lt;li&gt;傳輸層加密.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;本地客戶端對等加密 比較簡單, 應用範圍有限, 目的是為了防止中間人直接獲取有效信息,
提高難度.&lt;/p&gt;

&lt;p&gt;什麼是本地客戶端對等加密? 比如本地向服務器傳輸 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;123&lt;/code&gt; 這個字符串, 但不直接傳輸,
而是與服務器端溝通好, 以 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; 代表 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt; 代表 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; 代表 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;,
實際傳輸 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!@#&lt;/code&gt;. 這樣, 如果中間人不知道二者的加解密方法, 則無法獲取有效信息.&lt;/p&gt;

&lt;p&gt;但這種方法有很大侷限性, 比如如何保證中間人不知情? 加解密方法不能通過中間人網絡.
前期溝通成本高.&lt;/p&gt;

&lt;p&gt;為瞭解決上述問題, 更常用的是傳輸層加密, 比如 HTTP over TLS, 也就是我們說的 HTTPS.&lt;/p&gt;

&lt;p&gt;有人會問, TLS 與 SSL 是什麼關係? 調侃地說: 就像 ECMAScript 與 JavaScript 的關係.
中文維基百科上有一句話: “IETF將SSL進行標準化，1999年公佈第一版TLS標準文件”.&lt;/p&gt;

&lt;p&gt;TLS 是如何防範偽造身份為目的的中間人攻擊呢?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;客戶端發給服務器端本地可用的加密方法.&lt;/li&gt;
  &lt;li&gt;服務器端看一下自己能使用哪一種, 然後告訴客戶端用什麼方法加密和公鑰證書.&lt;/li&gt;
  &lt;li&gt;客戶端此時判斷服務器的公鑰證書是否可信. 證書是由第三方發放的, 如果客戶端認為
該第三方可信, 即證書頒發者在自己的可信根內, 則認為服務器可信.&lt;/li&gt;
  &lt;li&gt;客戶端與服務器端建立有效連接.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;如果想進一步知道, 客戶端與服務器端如何建立有效連接, 服務器如何信任客戶端, 請看:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;客戶端根據公鑰加密一個隨機數據, 發給服務器端.&lt;/li&gt;
  &lt;li&gt;服務器端解密後得到這個隨機數據.&lt;/li&gt;
  &lt;li&gt;此時雙方都獲得了這個隨機數據, 然後雙方利用這個隨機數據再次對等加密收發數據.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;詳細的 TLS 細節請看:
&lt;a href=&quot;https://en.wikipedia.org/wiki/Transport_Layer_Security#Protocol_details&quot;&gt;https://en.wikipedia.org/wiki/Transport_Layer_Security#Protocol_details&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;相關新聞&quot;&gt;相關新聞&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://v2ex.com/t/656394&quot;&gt;https://v2ex.com/t/656394&lt;/a&gt;
&lt;a href=&quot;https://www.cnbeta.com/articles/tech/960295.htm&quot;&gt;https://www.cnbeta.com/articles/tech/960295.htm&lt;/a&gt;&lt;/p&gt;

            </description>
            <pubDate>Fri, 27 Mar 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-03-27-man-in-the-middle-attack.html
            </guid>
        </item>
        
        <item>
            <title>雲計算實例可以有多個 IP 嗎</title>
            <link>
                https://zsqk.github.io/2020-03-26-one-instance-have-multiple-ips.html
            </link>
            <description>
                &lt;p&gt;對於運維, 什麼是雲服務? 雲服務有什麼好處? 雲服務提供商有區別嗎?&lt;/p&gt;

&lt;p&gt;雲服務是為了節省運維開支的, 中小公司儘可能用雲.&lt;/p&gt;

&lt;p&gt;今天有人問我, &lt;strong&gt;一臺服務器可以有多個 IP 嗎?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;我回復說:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;雲服務器計算，儲存，網絡都是分開的。一個計算可以有多個 IP。
就像我們電腦可以有多個網卡，可以連接不同貓獲得多個 IP。只不過雲上是虛擬的。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img width=&quot;380&quot; alt=&quot;Screen Shot 2020-03-27 at 13 01 58&quot; src=&quot;https://user-images.githubusercontent.com/499364/77723538-b58c5900-702b-11ea-8b69-c0c4cd060a71.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;但以上為理論, 我們沒有類似需求, 沒有實踐過. 出於謹慎, 我實操了一下:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;AWS 中國&lt;strong&gt;支持&lt;/strong&gt;一個 EC2 實例多私網 IP 及多公網 IP. (僅限操作檯)&lt;/li&gt;
  &lt;li&gt;阿里雲 VPC &lt;strong&gt;不支持&lt;/strong&gt;為一個 ECS 實例提供多個公網 IP. (僅限操作檯)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;但需要注意, 我僅在 Web 操作檯上進行了操作, 沒有使用 CLI 工具. 不排除阿里雲在 API
層面提供更多功能的可能性. 因為以我們的經驗, 在安全組設置的時候, 有些不太安全的
設置在操作檯上被禁止, 但是在 API 層面是允許的.&lt;/p&gt;

            </description>
            <pubDate>Thu, 26 Mar 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-03-26-one-instance-have-multiple-ips.html
            </guid>
        </item>
        
        <item>
            <title>VS Code, Eclipse Theia, Remote Development</title>
            <link>
                https://zsqk.github.io/2020-03-25-vs-code-eclipse-theia.html
            </link>
            <description>
                &lt;h2 id=&quot;eclipse-theia&quot;&gt;Eclipse Theia&lt;/h2&gt;

&lt;p&gt;項目: &lt;a href=&quot;https://github.com/eclipse-theia/theia&quot;&gt;https://github.com/eclipse-theia/theia&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;說到前後分離可以運行在遠端的編輯器甚至工作臺, 我第一個想到的就是 VS Code.&lt;/p&gt;

&lt;p&gt;如果你在用遠程工作臺, 不要認為這一定是 VS Code, 即便 UI 看上去很像. 因為這也有可能是: Theia.&lt;/p&gt;

&lt;p&gt;Theia 是一個開源項目, 而不是開箱即用的編輯器. 想要試試看可以通過 Gitpod.&lt;/p&gt;

&lt;h2 id=&quot;eclipse-theia-與-vs-code-的區別&quot;&gt;Eclipse Theia 與 VS Code 的區別&lt;/h2&gt;

&lt;p&gt;Theia 官網說, 自己與 VS Code 最大的不同有三點:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;更加模塊化與可定製.&lt;/li&gt;
  &lt;li&gt;專為桌面和遠程設計.&lt;/li&gt;
  &lt;li&gt;獨立基金會.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img width=&quot;504&quot; alt=&quot;截屏2020-03-29下午9 30 25&quot; src=&quot;https://user-images.githubusercontent.com/499364/77850351-82e98880-7204-11ea-9b71-324b7af0e374.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;不過, 從使用者角度看就一點:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;VS Code 是開箱即用的工具.&lt;/li&gt;
  &lt;li&gt;Theia 是搭建自有編輯器的基礎.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;做普通用戶, 我們在做遠程開發的時候, 還是會選擇 VS Code. 但很感謝 Theia 對開源社區的貢獻, 我覺得正是有了 Theia 這樣的項目, 才鞭策 VS Code 做得更好.&lt;/p&gt;

&lt;h2 id=&quot;remote-development&quot;&gt;Remote Development&lt;/h2&gt;

&lt;p&gt;為什麼要用 Remote Development?&lt;/p&gt;

&lt;p&gt;經常有遠程辦公不來辦公室的需求(大多數情況不是加班), 如果不是一臺筆記本帶來帶去的,
就會遇到需要在不同機器上安裝開發依賴, 拉取項目, 系統配置等一系列問題, 都要做一遍, 很耗時.&lt;/p&gt;

&lt;p&gt;如何結合遠程服務器來使用 VS Code?&lt;/p&gt;

&lt;p&gt;一般來說, 一定會有服務器端與客戶端. VS Code 就是我們的客戶端了. 那服務器端呢? 怎麼安裝?&lt;/p&gt;

&lt;p&gt;我們無需特別地在服務器端安裝什麼, 這一些都會在 VS Code 這個客戶端中幫我們自動設置好. 當然, SSH 還是需要的.&lt;/p&gt;

&lt;p&gt;我們只需要在 VS Code 上安裝 &lt;a href=&quot;https://aka.ms/VSCodeRemoteExtensionPack&quot;&gt;https://aka.ms/VSCodeRemoteExtensionPack&lt;/a&gt; 插件.&lt;/p&gt;

&lt;p&gt;VS Code 這個插件通過 SSH 在服務器上自動安裝了服務器端依賴.&lt;/p&gt;

&lt;p&gt;前置步驟:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;本地安裝 VS Code.&lt;/li&gt;
  &lt;li&gt;VS Code 安裝 Remote Development 擴展.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;步驟如下:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;打開 VS Code.&lt;/li&gt;
  &lt;li&gt;左側功能導航欄選擇 Remote Explorer 圖標.&lt;br /&gt;
&lt;img width=&quot;43&quot; alt=&quot;截屏2020-03-29下午10 04 26&quot; src=&quot;https://user-images.githubusercontent.com/499364/77851062-43716b00-7209-11ea-9253-191b856ac2dd.png&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;選擇 SSH Targets.&lt;br /&gt;
&lt;img width=&quot;301&quot; alt=&quot;截屏2020-03-29下午10 05 28&quot; src=&quot;https://user-images.githubusercontent.com/499364/77851097-94815f00-7209-11ea-98ec-f6e32dc7463e.png&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;點加號創建一個 SSH.&lt;br /&gt;
&lt;img width=&quot;257&quot; alt=&quot;截屏2020-03-29下午10 07 45&quot; src=&quot;https://user-images.githubusercontent.com/499364/77851126-d8746400-7209-11ea-9652-78dade3001a7.png&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;使用 SSH 登錄到服務器, VS Code 會自動安裝服務器需要的東西.&lt;/li&gt;
  &lt;li&gt;結束, 就像本地一樣使用遠程機器進行開發吧.&lt;/li&gt;
&lt;/ol&gt;

            </description>
            <pubDate>Wed, 25 Mar 2020 00:00:00 +0000</pubDate>
            <guid>
                https://zsqk.github.io/2020-03-25-vs-code-eclipse-theia.html
            </guid>
        </item>
        
    </channel>
</rss>
