<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nick Huang on Medium]]></title>
        <description><![CDATA[Stories by Nick Huang on Medium]]></description>
        <link>https://medium.com/@nickhuang9527?source=rss-acfb91a7aa1d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FLK73u-YE0zStyUzopfNcw@2x.jpeg</url>
            <title>Stories by Nick Huang on Medium</title>
            <link>https://medium.com/@nickhuang9527?source=rss-acfb91a7aa1d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 09:06:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nickhuang9527/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Design Pattern (1) — Object-Oriented Concepts (物件導向概念)]]></title>
            <link>https://medium.com/@nickhuang9527/design-pattern-1-object-oriented-concepts-%E7%89%A9%E4%BB%B6%E5%B0%8E%E5%90%91%E6%A6%82%E5%BF%B5-09b7be7a0b93?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/09b7be7a0b93</guid>
            <category><![CDATA[object-oriented-concepts]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Tue, 02 Jul 2024 15:00:32 GMT</pubDate>
            <atom:updated>2024-07-19T03:56:37.982Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design Pattern (1) — Object-Oriented Concepts (物件導向概念)</h3><blockquote>探索封裝、繼承、多態和抽象的力量，為理解複雜設計模式奠定基礎。</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*YUQKGaXHeKLsyyx97kBkpg.jpeg" /></figure><blockquote><em>您可於此 </em><a href="https://github.com/nickhuangcyh/design_pattern"><em>design_pattern repo</em></a><em> 下載 Design Pattern 系列程式碼。</em></blockquote><h3>Object-Oriented Concepts 物件導向概念</h3><p>學物件導向設計一定都會知道這四大概念，這邊我就簡單描述帶過</p><h3>Encapsulation 封裝</h3><p>將屬性及方法實作細節隱藏起來在類別當中，只暴露部分方法給使用者，使用者無法任意修改內部屬性及方法實作細節。</p><blockquote><em>像是開車一樣，我們只需知道踩油門會加速，踩煞車會停止，不需要知道馬達、電瓶、發動機等等原理，這些都被專業汽車工程師封裝在引擎蓋中了。</em></blockquote><h3>Inheritance 繼承</h3><p>子類別可以繼承父類別的屬性及方法，達到程式碼重複使用之目的。</p><blockquote><em>自然界中，狗與貓都是動物能呼吸行動，花草及樹木都是植物能行光合作用，這就是繼承。</em></blockquote><h3>Polymorphism 多型</h3><p>為不同的類別提供統一介面或抽象類別，以操作不同的實體物件。</p><blockquote><em>以前 iPhone 6S 年代還不像現在全是台積電代工，有一部分 i6S 是給三星代工，但無論是台積電或三星代工的晶圓，都能被 i6S 使用，使用者拿到的 i6S 無論是台積電或三星代工，手機的功能都一樣都是 i6S，這就是多型。</em></blockquote><h3>Abstraction 抽象</h3><p>透過類型子類及抽象方式，隱藏依賴於類型或接口的實作細節。</p><blockquote><em>我們會在手機上裝很多 App，App 就是對各種不同 Application 的一個抽象名稱，我們會說去市場買水果，可能是蘋果也可能是香蕉，水果也是一種抽象名稱，其他像是肉、蔬菜等等也是，這就是抽象。</em></blockquote><h3>總結</h3><p>在理解了物件導向的核心概念後，我們將看到這些概念如何自然地引導我們進入設計原則的世界。物件導向概念為我們提供了創建模塊化、可重用和易於維護代碼的基礎，而設計原則則教我們如何有效地應用這些概念來解決更複雜的設計問題。接下來，我們將探討這些原則，並了解它們如何幫助我們實現高質量的軟體設計。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LHhXc40yOZAg4R6G.png" /></figure><blockquote><em>Object-Oriented Concepts -&gt; Design Principle -&gt; Design Pattern</em></blockquote><h3>參考</h3><ul><li><a href="https://www.tenlong.com.tw/products/9789867794529">Head First Design Patterns</a></li><li><a href="https://www.tenlong.com.tw/products/9789866761799">大話設計模式</a></li><li><a href="https://www.linkedin.com/learning/advanced-design-patterns-design-principles/what-are-design-principles?autoAdvance=true&amp;autoSkip=false&amp;autoplay=true&amp;resume=true">Advanced Design Patterns: Design Principles</a></li><li><a href="https://www.linkedin.com/learning/programming-foundations-design-patterns-2/trying-interfaces?autoAdvance=true&amp;autoSkip=false&amp;autoplay=true&amp;resume=true">Programming Foundations: Design Patterns</a></li><li><a href="https://www.linkedin.com/learning/design-patterns-creational/think-about-how-you-create-objects?autoAdvance=true&amp;autoSkip=false&amp;autoplay=true&amp;resume=true">Design Patterns: Creational</a></li><li><a href="https://www.youtube.com/watch?v=yOe-uywb2qs&amp;list=PLicQRHHL75d7EXEI9nWfUYJyrPdI79M70&amp;pp=iAQB">水球潘 — Design Pattern 之路</a></li></ul><p><strong>Note:</strong> 如果有任何建議、問題或不同想法，歡迎留言或寄信給我，可以一起討論進步成長🙂</p><p><em>Originally published at </em><a href="https://nickhuangcyh.github.io/blog/design%20pattern/design-pattern-1-object-oriented-concepts/"><em>https://nickhuangcyh.github.io</em></a><em> on July 2, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=09b7be7a0b93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[搞懂 P2P 技術 (3) — WebRTC x AWS x KVS]]></title>
            <link>https://medium.com/@nickhuang9527/%E6%90%9E%E6%87%82-p2p-%E6%8A%80%E8%A1%93-3-webrtc-x-aws-x-kvs-830092639b9a?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/830092639b9a</guid>
            <category><![CDATA[kinesis]]></category>
            <category><![CDATA[webrtc]]></category>
            <category><![CDATA[p2p]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Tue, 04 Jan 2022 15:13:00 GMT</pubDate>
            <atom:updated>2022-02-20T16:05:34.931Z</atom:updated>
            <content:encoded><![CDATA[<h3>搞懂 P2P 技術 (3) — WebRTC x AWS x KVS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eNh8vmxMjKJe5t1w8jm_Rg.jpeg" /><figcaption>Photo by NASA from Unsplash</figcaption></figure><h3>WebRTC</h3><p>全名 Web Real-Time Communication，是一個支援網頁瀏覽器進行即時語音對話或影片對話的 API</p><blockquote><a href="https://zh.wikipedia.org/wiki/WebRTC"><em>WebRTC Wiki</em></a></blockquote><p>WebRTC 的底層就是使用 ICE 來進行 P2P 打洞</p><h3>Signaling Server</h3><p>信令伺服器，用來交換雙方的 SDP 及 Ice candidate 來完成 P2P 打洞</p><h3>實作 Signaling Server</h3><p>WebRTC 沒有明確定義如何實作 Signaling Server，主要原因在於如果雙方一開始就知道對方的資訊，那其實就不需要 Signaling Server 來交換資訊</p><p>實作一個 Signaling Server 方式有很多種，可以用 HTTP 協議也可以用 WebSocket 協議，只要能順利將雙方的資訊做交換即可</p><h3>SDP (Session Description Protocol)</h3><p>會話描述協議（Session Description Protocol 或簡寫 SDP）描述的是流媒體的初始化參數。此協議由 IETF 發表為 <a href="https://datatracker.ietf.org/doc/html/rfc2327">RFC 2327</a> 。</p><h3>SDP 格式</h3><pre>v=0<br>o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4<br>s=SDP Seminar<br>i=A Seminar on the session description protocol<br>u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps<br>e=mjh@isi.edu (Mark Handley)<br>c=IN IP4 224.2.17.12/127<br>t=2873397496 2873404696<br>a=recvonly<br>m=audio 49170 RTP/AVP 0<br>m=video 51372 RTP/AVP 31<br>m=application 32416 udp wb<br>a=orient:portrait</pre><ul><li>v=協議版本</li><li>o=發起者的 Session、Session ID 及 Session 版本</li><li>s=Session 名字</li><li>i=Session 資訊</li><li>u=有關會議資訊的 url</li><li>e=Email</li><li>p=手機號碼</li><li>c=連線資訊</li><li>t = Session 活動時間</li><li>m = 媒體資訊 ((media) (port) (transport) (fmt list))</li><li>a = 媒體屬性</li></ul><h3>Ice Candidate</h3><p>Ice Candidate 描述 WebRTC 能與 遠程設備通訊所需的協議和路由，啟動 WebRTC P2P 後，通常會在連接的每一端提供多個 IceCandidate，直到絕定最佳線路達成為止．</p><h3>WebRTC Flow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*o46pgpjoXqBMNeHR.png" /></figure><ol><li>雙方 Peer 先連上 Signaling Server</li><li>PeerA 取得自身 SDP 並呼叫 setLocalDescription</li><li>PeerA 將 SDP 傳給 Signaling Server</li><li>Signaling Server 將 PeerA 的 SDP 送給 PeerB</li><li>PeerB 呼叫 setRemoteDescription 將 PeerA 的 SDP 寫入</li><li>PeerB 取得自身 SDP 並呼叫 setLocalDescription</li><li>PeerB 將 SDP 傳給 Signaling Server</li><li>Signaling Server 將 PeerB 的 SDP 送給 PeerA</li><li>PeerA 呼叫 setRemoteDescription 將 PeerB 的 SDP 寫入</li><li>PeerA 向 Stun server 詢問 public IP</li><li>Stun server 回應 public IP</li><li>PeerA 向 TURN server 詢問 relay 資訊 (relay ip/port)</li><li>TURN server 回應 relay 資訊</li><li>PeerA 將 Ice candidates 傳給 Signaling Server</li><li>Signaling Server 將 PeerA 的 Ice candidates 送給 PeerB</li><li>PeerB 呼叫 setRemoteIceCandidate 將 PeerA 的 Ice candidates 寫入</li><li>PeerB 向 Stun server 詢問 public IP</li><li>Stun server 回應 public IP</li><li>PeerB 向 TURN server 詢問 relay 資訊 (relay ip/port)</li><li>TURN server 回應 relay 資訊</li><li>PeerB 將 Ice candidates 傳給 Signaling Server</li><li>Signaling Server 將 PeerB 的 Ice candidates 送給 PeerA</li><li>PeerA 呼叫 setRemoteIceCandidate 將 PeerB 的 Ice candidates 寫入</li><li>P2P 通道建立完成</li></ol><h3>AWS KVS (Amazon Kinesis Video Streams)</h3><p>Amazon Kinesis Video Streams 以全受管功能提供符合標準的 WebRTC 實作。您可以使用 Amazon Kinesis Video Streams and WebRTC 安全地即時串流媒體，或在任何攝影機 IoT 裝置與符合 WebRTC 標準的行動或 Web 播放器之間，執行雙向音訊或視訊互動。因為是全受管功能，您不需要建置、執行或擴展任何與 WebRTC 相關的雲端基礎設施，例如訊號或媒體轉送伺服器，即可在應用程式和裝置之間安全地串流媒體。</p><blockquote><em>簡單來說 KVS 就是幫你把 STUN, TURN, Signaling Server 加密權限驗證等等都實作了，WebRTC 的部分跟 KVS 是完全獨立的，你也可以選擇自己架設 STUN, TURN, Signaling Server 搭配 Google WebRTC 也能成功串流．</em></blockquote><p>KVS 的 Signaling server 是用 WebSocket 去實作的</p><blockquote><em>注意: WebSocket 與 Socket.IO 是不是一樣的，Socket.IO 是根據 Websocket 協議去實作，Socket.IO 有自己的通訊格式，請不要拿 Socket.IO 套件去串接 KVS，會失敗，有興趣可以參考這篇 </em><a href="https://leesonhsu.blogspot.com/2018/07/socketwebsocketsocketio.html"><em>【筆記】Socket，Websocket，Socket.io 的差異</em></a></blockquote><h3>成果</h3><p>理解這些 P2P 相關的知識，我們就可以很清楚的實作每一步驟，出錯時也能清楚哪一部分出錯，甚至是替換 Stun / TURN / signaling server 都沒問題，下面貼一下成果圖</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/0*bOw0Tl_r-Vq5ByQ3.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/0*3FCOccpcbmf58LFg.png" /></figure><h3>踩雷補充</h3><ul><li>在串接 AWS KVS 時，AWS Android 的 sample code 是使用 tyrus 套件連 signaling server，但此套件在舊版有一些 SSL 問題有機會失敗，所以我把 tyrus 換成 okhttp 去連 signaling server，但一直連不上 403 Forbidden，iOS 用 starscream 連線正常，後來比對兩平台 URL 發現，Android 的會多做一次 url encode，在 tyrus 沒問題，但在 okhttp 上會有問題 (解法請參考 : <a href="https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-android/issues/74">https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-android/issues/74</a>)</li></ul><h3>總結</h3><p>P2P 的基本觀念大致就到這邊，如果想要更深入的理解 P2P 的朋友，可以看參考資源欄中的文章，或直接看 RFC ，裡面會說到每個協議的格式細節．</p><h3>參考資源</h3><ul><li><a href="https://developer.mozilla.org/zh-TW/docs/Web/API/WebRTC_API">WebRTC API</a></li><li><a href="https://zh.wikipedia.org/wiki/WebRTC">WebRTC Wiki</a></li><li><a href="https://zh.wikipedia.org/wiki/%E4%BC%9A%E8%AF%9D%E6%8F%8F%E8%BF%B0%E5%8D%8F%E8%AE%AE">SDP Wiki</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate">RTCIceCandidate</a></li><li><a href="https://docs.aws.amazon.com/zh_tw/kinesisvideostreams-webrtc-dg/latest/devguide/what-is-kvswebrtc.html">Amazon Kinesis Video Streams for WebRTC</a></li><li><a href="http://www.52im.net/thread-50-1-1.html">《P2P 技术详解》系列文章</a></li><li><a href="https://www.flaticon.com/">flaticon</a></li></ul><p><em>Originally published at </em><a href="https://nickhuang9527.github.io/blog/p2p/aws/p2p-tech-3-webrtc-kvs/"><em>https://nickhuang9527.github.io</em></a><em> on January 4, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=830092639b9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[搞懂 P2P 技術 (2) — STUN x TURN x ICE]]></title>
            <link>https://medium.com/@nickhuang9527/%E6%90%9E%E6%87%82-p2p-%E6%8A%80%E8%A1%93-2-stun-x-turn-x-ice-e55910e52c94?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e55910e52c94</guid>
            <category><![CDATA[turn]]></category>
            <category><![CDATA[p2p]]></category>
            <category><![CDATA[ice]]></category>
            <category><![CDATA[stun]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Tue, 04 Jan 2022 07:09:00 GMT</pubDate>
            <atom:updated>2022-02-20T16:05:56.538Z</atom:updated>
            <content:encoded><![CDATA[<h3>搞懂 P2P 技術 (2) — STUN x TURN x ICE</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eNh8vmxMjKJe5t1w8jm_Rg.jpeg" /><figcaption>Photo by NASA from Unsplash</figcaption></figure><p>上一篇介紹完中心化、去中心化、分佈式網路以及 IPv4、NAT、NAT 類型，但我們依舊還有些問題未解決</p><ul><li>A, B 兩端要如何知道彼此的內部網路 IP 及外部網路 IP (STUN)</li><li>上篇有提到 NAT 類型如果是對稱型時，會無法打通 P2P，當遇到此情形時該 (TURN)</li><li>有沒有一種框架整合這整個 P2P 流程 (ICE)</li></ul><h3>STUN</h3><p>STUN（Session Traversal Utilities for NAT，NAT 對談穿越應用程式）是一種網路協定，它允許位於 NAT（或多重 NAT）後的客戶端找出自己的公網位址，查出自己位於哪種類型的 NAT 之後以及 NAT 為某一個本地埠所繫結的 Internet 端埠。這些資訊被用來在兩個同時處於 NAT 路由器之後的主機之間建立 UDP 通信。該協定由 RFC 5389 定義。</p><blockquote><a href="https://zh.wikipedia.org/wiki/STUN"><em>STUN Wiki</em></a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ILU1Cw71WqL9euic.png" /></figure><h3>TURN</h3><p>TURN（全名 Traversal Using Relay NAT），是一種資料傳輸協定（data-transfer protocol）。允許在 TCP 或 UDP 的連線上跨越 NAT 或防火牆。</p><p>TURN 是一個 client-server 協定。TURN 的 NAT 穿透方法與 STUN 類似，都是通過取得應用層中的公有位址達到 NAT 穿透。但實現 TURN client 的終端必須在通訊開始前與 TURN server 進行互動，並要求 TURN server 產生”relay port”，也就是 relayed-transport-address。這時 TURN server 會建立 peer，即遠端端點（remote endpoints），開始進行中繼（relay）的動作，TURN client 利用 relay port 將資料傳送至 peer，再由 peer 轉傳到另一方的 TURN client。</p><p>當無法打通 NAT 時，就會需要用 TURN 的方式來解決 NAT 穿透</p><blockquote><a href="https://zh.wikipedia.org/wiki/TURN"><em>TURN Wiki</em></a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*vn5yuEqpOEg1znai.png" /></figure><h3>ICE</h3><p>ICE（Interactive Connectivity Establishment），一種綜合性的 NAT 穿越的技術。</p><p>互動式連接建立是由 IETF 的 MMUSIC 工作組開發出來的一種 framework，可整合各種 NAT 穿透技術，如 STUN、TURN（Traversal Using Relay NAT，中繼 NAT 實現的穿透）、RSIP（Realm Specific IP，特定域 IP）等。該 framework 可以讓 SIP 的客戶端利用各種 NAT 穿透方式打穿遠程的防火牆。</p><blockquote><a href="https://zh.wikipedia.org/wiki/%E4%BA%92%E5%8B%95%E5%BC%8F%E9%80%A3%E6%8E%A5%E5%BB%BA%E7%AB%8B"><em>ICE Wiki</em></a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*hVc-DZC_6n7b9-4X.png" /></figure><h3>總結</h3><p>簡單來說</p><ul><li>STUN Server 是讓 client 端詢問自身的 Public IP，雙方交換 Public IP 來做 P2P</li><li>TURN Server 是當 NAT 穿透失敗時(通常是 Symmetric NAT)的替代方案，透過 TURN server 做資料的轉傳，也稱為 Relay，走 TURN 時 TURN Server 傳輸流量等等就會需要額外費用</li><li>ICE 是一種框架，結合了 STUN 及 TURN 等等協議，解決單一協議缺陷的問題，列如遇上 Symmetric NAT 但沒有實作 TURN，雙方就會無法通訊．</li></ul><p>這篇介紹了 STUN、TURN 及 ICE，下一篇將介紹 Signaling Server, WebRTC 以及 AWS KVS for WebRTC．</p><h3>參考資源</h3><ul><li><a href="https://zh.wikipedia.org/wiki/STUN">STUN</a></li><li><a href="https://zh.wikipedia.org/wiki/TURN">TURN</a></li><li><a href="https://zh.wikipedia.org/wiki/%E4%BA%92%E5%8B%95%E5%BC%8F%E9%80%A3%E6%8E%A5%E5%BB%BA%E7%AB%8B">ICE</a></li><li><a href="http://www.52im.net/thread-50-1-1.html">《P2P 技术详解》系列文章</a></li><li><a href="https://www.flaticon.com/">flaticon</a></li></ul><p><em>Originally published at </em><a href="https://nickhuang9527.github.io/blog/p2p/p2p-tech-2-stun-turn-ice/"><em>https://nickhuang9527.github.io</em></a><em> on January 4, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e55910e52c94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[搞懂 P2P 技術 (1) — P2P x IPv4 x NAT]]></title>
            <link>https://medium.com/@nickhuang9527/%E6%90%9E%E6%87%82-p2p-%E6%8A%80%E8%A1%93-1-p2p-x-ipv4-x-nat-13cbed45ec7e?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/13cbed45ec7e</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[nat]]></category>
            <category><![CDATA[ipv4]]></category>
            <category><![CDATA[p2p]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Mon, 03 Jan 2022 15:45:03 GMT</pubDate>
            <atom:updated>2022-02-20T16:06:17.990Z</atom:updated>
            <content:encoded><![CDATA[<h3>搞懂 P2P 技術 (1) — P2P x IPv4 x NAT</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eNh8vmxMjKJe5t1w8jm_Rg.jpeg" /><figcaption>Photo by NASA from Unsplash</figcaption></figure><p>之前工作上遇到需要將自家 IPCam 與 iOS/Android 手機做 P2P 串流影音，研究了許多有關 P2P 的技術，因此想寫一系列有關 P2P 技術的文章．</p><h3>P2P</h3><h3>為什麼會需要 P2P</h3><p>在了解一門技術前，我們先來看看為什麼會需要這門技術，這門技術是為了解決什麼問題</p><h3>Centralized vs Decentralized vs Distributed</h3><h3>中心化網路 (Centralized)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z2ZB3fWP1XwpW_Zb.png" /></figure><p>所有 client 都連接到同一台 Server，Server 擁有所有 client 的數據訊息</p><blockquote><em>可以想成是國家央行發行貨幣，所有人的錢都來自國家央行</em></blockquote><p>優點</p><ul><li>部署簡單好維護</li><li>集中管理數據</li></ul><p>缺點</p><ul><li>安全及隱私風險 (中心 server 遭破解串改，全部都會受影響)</li><li>離 Server 較遠的 client 拿資料的時間會更長</li><li>server 一但故障，其他 client 都不可使用</li></ul><h3>去中心化網路 (Decentralized)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ND_ai7EuAmtjrV0G.png" /></figure><p>顧名思義就是不只有一台 server，會有多台 server ，所以當一台或多台 server 故障時，client 還是可以繼續從其他 server 存取數據</p><blockquote><em>可以想成是很多銀行可以存錢領錢，有美銀、高盛、摩根、富國等等銀行，且每家都能互相轉錢</em></blockquote><p>優點</p><ul><li>比中心化網路有較高的容錯率 (因為有多個 server)</li><li>更好的性能 (在一些用戶多的地區新增節點)</li></ul><p>缺點</p><ul><li>安全及隱私風險 (與中心化一樣)</li><li>較高維護成本 (系統設計較複雜多變)</li><li>較難部署</li></ul><h3>分佈式網路 (Distributed)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*qs-85QwHr1jS6sVk.png" /></figure><p>類似 Decentralized ， 沒有唯一的中心 server，用戶間可以共享資料所有權，消除了中心 server 的概念，如此可以避免中心 server 故障導致所有 user 無法使用的問題，internet 就是一個分佈式網路，p2p 也屬於此類</p><blockquote><em>可以想成是目前的區塊鏈比特幣，並沒有像央銀銀行的角色，貨幣是由鏈上的所有主機幫你做驗證交易紀錄等等，必須要串改超過 51% 以上的主機才能成功串改資訊，較安全</em></blockquote><p>優點</p><ul><li>極高的容錯率</li><li>資料透明安全，不易遭串改</li><li>資源共享</li></ul><p>缺點</p><ul><li>較高維護成本 (系統設計較複雜多變)</li><li>較難部署</li></ul><blockquote><em>三種網路方式皆有各自優點，可以依照遇到的情況去設計．</em></blockquote><p>在 IoT 應用中，假如你要控制家中的 IPCam，就會有以下兩種做法</p><ol><li>中心化方式為透過 Server 轉發 command 給 IPCam</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*dHJosuQ7Vn2Da0_k.png" /></figure><ul><li>這種作法的優點在於好部署修改，有新增功能時只要 Server 改完部署，其他設備就可更新支援此功能，缺點就是 Server 只要故障就完全不能控制 IoT 裝置，且 Server 的硬體效能要很好才足以應對龐大的 client，需要每月一筆租 Server 機器及流量的費用</li></ul><p>2. 分佈式方式為不透過 Server 直接向 IPCam 下達指令</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*K6ZNOis1HawfwjR3.png" /></figure><ul><li>這種作法的優點在於不需要每月一筆租 server 機器及流量的費用，不會有 Server 故障導致無法操作 IoT 裝置的問題，硬體效能也不需要很好，缺點就是部署程式變得複雜，因為不是每個人都會定期更新手機 app 及 IoT Firmware，還有程式碼會變得複雜，需要處理 p2p tunnel 斷線重新 p2p 流程，也叫容易發生斷線重連，e.g. 手機由 4G/5G 環境走到有 Wifi 環境，網卡自動切換成 Wifi 就會導致斷線需重新 p2p．</li></ul><blockquote><em>疑問 : 分佈式方式在複雜的 Internet 下，如何讓手機與 IoT 裝置溝通，就是接下來我們要講解 P2P 技術的部分</em></blockquote><h3>什麼是 P2P (Peer to Peer)</h3><p>P2P 是一種無中心化的技術，每一個 client 既是 client 也是 server，在每台主機皆存在共享的數據，以此降低資料遺失安全性等等的風險．</p><h3>IPv4</h3><p>Internet 能夠如此成功進入人類的生活中，IP 的設計可以說是非常重要的一個基礎，可以把 IP 想成你在 Internet 世界裡的地址，任何人要寄信給你都需要知道你的地址才能與你通信，IPv4 的設計就是希望可以容納大家上網，IPv4 總共有 4 * 8(bits) = 32 bits，大約為 43 億，在當時認為已經非常足夠使用，但如今在 Internet 高速發展下，IPv4 已經不夠用了，所以網路專家一方面尋找 IPv4 替代方案(也就是 IPv6)，一方面研究如何減緩 IPv4 耗盡的問題，於是 NAT 誕生了．</p><h3>NAT (Network Address Translation)</h3><p>就如同字面上的意思，他會在私有網域及公有網域之間做將封包的 IP 做轉換，根據 <a href="https://datatracker.ietf.org/doc/rfc1918/">RFC1918</a> 保留了三段 IP 地址給內部網路做使用，10.0.0.0–10.255.255.255；172.16.0.0–172.31.255.255；192.168.0.0–192.168.255.255，這些地址在公有網路上是沒有意義的，且不需像 IANA 做申請，如此就大大增加了 IPv4 環境可以容納的上網裝置，因為一個組織只需要一個公有 IP 即可讓所有內部裝置連上 Internet．</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*vvIwnEQ13sIswpgY.png" /></figure><p>但是 NAT 這樣的設計是有缺點的，外部網路主機無法直接與在 NAT 路由器內的內網主機進行連線</p><p>一般沒有 NAT 情況下，Internet 上的兩台主機只要知道彼此 IP 就能進行通訊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*id3fgzr4bL_RkN19.png" /></figure><p>在有一方於 NAT 情況下，外部網路主機 B 要與內部網路主機 A 通訊，就會遇到 NAT 不知道要將來自 B 的封包轉給哪一台內部主機</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*uUMkwHYDiCcPdUNc.png" /></figure><p>除非 A 已經先訪問過 B 主機的情況下，NAT 會將 A 的轉址紀錄在 mapping table 中，之後由 B 發給 A 的封包，NAT 就會透過 mapping table 轉址將封包正確轉發給 A</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oYcHCEJqr9oOuf6S.png" /></figure><p>但如果兩台主機皆在 NAT 下，此時不管是由 A 或 B 發起 (A → B 或 B → A)，都無法連接到對方，因為兩邊的 mapping table 都是空的沒有紀錄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*nj8atyVCeOlYWIhc.png" /></figure><p>此時就必須要由任一方先發起封包，假設由 A 發起 (1)，此時 A 的 NAT mapping table 會留下 A 的轉換 IP (2)，但封包到了 B 的 NAT 時，因 B 的 NAT mapping table 為空，所以會先失敗 (3)，再來由 B 發起封包給 A (4)，會在 B NAT mapping table 留下 B 的轉換 IP (5)，封包到了 A NAT 後 (6)，因 A 的 NAT mapping table 存在 A 的 IP，所以封包可以順利到達 A (7)，A 在發送封包到 B (8)，此時雙方的 NAT mapping table 皆有紀錄(9, 10)，在 NAT 裡的 Client 就能順利相互通訊，此時 P2P 就成功了，反之亦然</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*_blq_QdFdko4u2Xo.png" /></figure><h3>NAT 類型</h3><h3>Full-cone NAT (完全錐型 NAT)</h3><ul><li>一旦內部位址（iAddr:iPort）對映到外部位址（eAddr:ePort），所有發自 iAddr:iPort 的封包都經由 eAddr:ePort 向外傳送。</li><li>任意外部主機都能經由發送封包給 eAddr:ePort 到達 iAddr:iPort。</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/0*jB7jxMgY1__2qCUW.png" /></figure><h3>Restricted cone NAT (受限錐型 NAT)</h3><ul><li>一旦內部位址（iAddr:iPort）對映到外部位址（eAddr:ePort），所有發自 iAddr:iPort 的封包都經由 eAddr:ePort 向外傳送。</li><li>唯 iAddr:iPort 曾經發送封包到外部主機（nAddr:any），外部主機才能經由發送封包給 eAddr:ePort 到達 iAddr:iPort。（註：any 指外部主機源埠不受限制。）</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/0*Io_bC2YWT-18iC08.png" /></figure><h3>Port-Restricted cone NAT (端口受限錐型 NAT)</h3><p>類似受限制錐形 NAT（Restricted cone NAT），但是還有埠限制。</p><ul><li>一旦內部位址（iAddr:iPort）對映到外部位址（eAddr:ePort），所有發自 iAddr:iPort 的封包都經由 eAddr:ePort 向外傳送。</li><li>在受限圓錐型 NAT 基礎上增加了外部主機源埠必須是固定的。</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/0*zKp0xYJv9E8lifpu.png" /></figure><h3>Symmetric NAT (對稱型 NAT)</h3><ul><li>每一個來自相同內部 IP 與埠，到一個特定目的地 IP 和埠的請求，都對映到一個獨特的外部 IP 和埠。 同一內部 IP 與埠發到不同的目的地和埠的資訊包，都使用不同的對映</li><li>只有曾經收到過內部主機資料的外部主機，才能夠把封包發回</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/0*MFFLZlwq006kugky.png" /></figure><blockquote><em>Symmetric NAT 無法實現 P2P ，原因就在於對稱型每次的請求都會對應到不同的外部 IP 和 Port</em></blockquote><h3>結論</h3><p>有關 P2P、IPv4、NAT 就先介紹到此，下一篇會介紹實現 P2P 需要哪些協定工具，STUN、TURN、ICE 是什麼</p><h3>參考資源</h3><ul><li><a href="https://medium.com/berty-tech/berty-tech-centralized-vs-decentralized-vs-distributed-systems-2e9efd856c2">Centralized vs Decentralized vs Distributed Systems</a></li><li><a href="http://www.52im.net/thread-50-1-1.html">《P2P 技术详解》系列文章</a></li><li><a href="https://zh.wikipedia.org/wiki/%E5%B0%8D%E7%AD%89%E7%B6%B2%E8%B7%AF">對等網路</a></li><li><a href="https://zh.wikipedia.org/wiki/%E7%BD%91%E7%BB%9C%E5%9C%B0%E5%9D%80%E8%BD%AC%E6%8D%A2">網路位址轉換</a></li><li><a href="https://www.flaticon.com/">flaticon</a></li></ul><p><em>Originally published at </em><a href="https://nickhuang9527.github.io/blog/p2p/p2p-tech-1-ipv4-nat/"><em>https://nickhuang9527.github.io</em></a><em> on January 3, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13cbed45ec7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3D Graphic Engine Tips — 三角形 x UV mapping x Vertices & Indices]]></title>
            <link>https://medium.com/@nickhuang9527/3d-graphic-engine-tips-%E4%B8%89%E8%A7%92%E5%BD%A2-x-uv-mapping-x-vertices-indices-7b8861c7990c?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b8861c7990c</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[3d]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Sun, 02 Jan 2022 02:04:00 GMT</pubDate>
            <atom:updated>2022-02-20T16:06:39.096Z</atom:updated>
            <content:encoded><![CDATA[<h3>3D Graphic Engine Tips — 三角形 x UV mapping x Vertices &amp; Indices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LWBiZUL0nVvDRiXztVqPjg.jpeg" /><figcaption>Photo by Nick Brunner from Unsplash</figcaption></figure><p>前陣子在 iOS, Android 上開發 AR 相關的功能，因為本身沒有 3D 繪圖的相關知識，後來仔細研究，終於有一些成果，這篇用來紀錄有關 3D 繪圖的小小知識，希望可以幫助到其他人．</p><h3>3D 圖形世界所有物件都是由小三角形所構成</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/0*SfueaxrAH1Q6LAcY.png" /></figure><blockquote><a href="https://www.researchgate.net/figure/3D-mesh-triangles-with-different-resolution-3D-Modelling-for-programmers-Available-at_fig2_322096576"><em>https://www.researchgate.net/figure/3D-mesh-triangles-with-different-resolution-3D-Modelling-for-programmers-Available-at_fig2_322096576</em></a></blockquote><h3>UV mapping</h3><blockquote><em>將 2D 圖像投影到 3D 模型表面進行 Texture 映射的 3D 建模過程</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*B0EOak1lTaJJJUT3.png" /></figure><blockquote><a href="https://en.wikipedia.org/wiki/UV_mapping"><em>https://en.wikipedia.org/wiki/UV_mapping</em></a></blockquote><p>以立方體為例，將各面 Texture 壓平為 2D，在映射到 UV 座標中 UV 座標，U 為橫軸，V 為縱軸，左上為(0,0)，右上為(1,1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ukWSNwaKMgxpCQkq.gif" /></figure><blockquote><a href="https://wiki.povray.org/content/Reference:UV_Mapping"><em>https://wiki.povray.org/content/Reference:UV_Mapping</em></a></blockquote><h3>Vertices and Indices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2eki0SjvyIDoKGjY.png" /></figure><blockquote><a href="https://www.oreilly.com/library/view/real-time-3d-graphics/9781788629690/0e5b1b24-f1a7-414d-868b-37df694749ad.xhtml"><em>https://www.oreilly.com/library/view/real-time-3d-graphics/9781788629690/0e5b1b24-f1a7-414d-868b-37df694749ad.xhtml</em></a></blockquote><p>順著頂點標示出頂點的 Index，根據要畫出的三角形，以逆時鐘方向依序填入 Index</p><p>另一種方式可以用 <a href="https://zh.wikipedia.org/wiki/%E5%AE%89%E5%9F%B9%E5%AE%9A%E5%BE%8B">安培右手定則</a> ，旋轉方向為 index 的順序，大拇指指向方向為面朝向的方位</p><p>因此在 3D 世界要畫出雙面三角形，code 裡的 index 必須為 [0, 2, 1, 0, 1, 2]，[0, 2, 1] 為正面，[0, 1, 2] 為背面</p><blockquote><a href="https://www.oreilly.com/library/view/real-time-3d-graphics/9781788629690/0e5b1b24-f1a7-414d-868b-37df694749ad.xhtml"><em>https://www.oreilly.com/library/view/real-time-3d-graphics/9781788629690/0e5b1b24-f1a7-414d-868b-37df694749ad.xhtml</em></a></blockquote><h3>總結</h3><p>不管是在開發 iOS, Android, Web，只要與 3D 相關，3D 遊戲, AR, VR 等等都會用到，是非常實用的觀念!</p><p><em>Originally published at </em><a href="https://nickhuang9527.github.io/blog/mobile/3d_graphic_tips/"><em>https://nickhuang9527.github.io</em></a><em> on January 2, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b8861c7990c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[如何使 Jekyll website 能被 Google 搜索到 — Google x Search x Blog]]></title>
            <link>https://medium.com/@nickhuang9527/%E5%A6%82%E4%BD%95%E4%BD%BF-jekyll-website-%E8%83%BD%E8%A2%AB-google-%E6%90%9C%E7%B4%A2%E5%88%B0-google-x-search-x-blog-c39891f7509a?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c39891f7509a</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[jekyll]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Fri, 31 Dec 2021 03:26:00 GMT</pubDate>
            <atom:updated>2022-02-20T16:09:12.763Z</atom:updated>
            <content:encoded><![CDATA[<h3>如何使 Jekyll website 能被 Google 搜索到 — Google x Search x Blog</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9D-OQIt8dcfkOFs8R-sqhQ.jpeg" /><figcaption>Photo by Alfons Morales from Unsplash</figcaption></figure><h3>在 Google 搜尋不到我的 Blog</h3><p>當我們在建立完 Jekyll Blog 後，會發現竟然 Google 不到我們的 Blog 網站，別擔心這是因為我們尚未將網站提交加入 Google Search Console 中</p><h3>將網站加入 Google Search Console</h3><p>進入 <a href="https://search.google.com/search-console/welcome?hl=zh-CN&amp;utm_source=about-page&amp;pli=1">Google Search Console</a></p><p>這邊使用網址前綴方式添加，加你的 Blog domain 填入並繼續</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*alo0DSUOCWhNB6ks.png" /></figure><p>下載 googlexxxxxxxxxx.html 檔案放到 Jekyll 根目錄，commit 上傳到 GitHub 上，點擊驗證</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*dn5H4Wb55KFNRuZL.png" /></figure><p>驗證成功 👍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*5yZfQOSUFTOenO7P.png" /></figure><h3>提交 Sitemap</h3><p>「Sitemap」是一種用來提供網站資訊的檔案，您可以在其中列出網頁、影片和其他檔案的資訊，並呈現這些內容彼此間的關係。Google 等搜尋引擎都會讀取網站的 Sitemap 檔案，藉此以更有效率的方式檢索網站。</p><blockquote><a href="https://developers.google.com/search/docs/advanced/sitemaps/overview?hl=zh-tw"><em>瞭解 Sitemap</em></a></blockquote><p>打開 Gemfile 在 group :jekyll_plugins 中加入 jekyll-sitemap</p><pre>group :jekyll_plugins do<br>  gem &quot;jekyll-sitemap&quot;<br>end</pre><p>打開 _config.yml 在 plugins 加入 jekyll-sitemap</p><pre>plugins:<br>  - jekyll-sitemap</pre><p>執行 bundle install 安裝 jekyll-sitemap 並在 local 測試一下，在 _site/ 資料夾中會出現 sitemap.xml 文件，代表 jekyll-sitemap 有順利產生 sitemap</p><pre>bundle install<br>bundle exec jekyll serve</pre><p>將 code commit 推上 GitHub，回到 Google Search Console 提交 sitemap</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*QuHnDzXr1tHa3Qpx.png" /></figure><p>完成，等待下次 Google Search Engine 下更新檢索就能搜尋到我們 Blog 的內容囉! 🙌</p><p><em>Originally published at </em><a href="https://nickhuang9527.github.io/blog/blog/how-to-add-your-jekyll-blog-website-to-google-search-console/"><em>https://nickhuang9527.github.io</em></a><em> on December 31, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c39891f7509a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 Jekyll + minimal-mistakes 在 Github pages 上架設自己的部落格 — Jekyll x Minimal-Mistakes x GitHub pages]]></title>
            <link>https://medium.com/@nickhuang9527/%E4%BD%BF%E7%94%A8-jekyll-minimal-mistakes-%E5%9C%A8-github-pages-%E4%B8%8A%E6%9E%B6%E8%A8%AD%E8%87%AA%E5%B7%B1%E7%9A%84%E9%83%A8%E8%90%BD%E6%A0%BC-jekyll-x-minimal-mistakes-x-github-pages-c5699ffabd28?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5699ffabd28</guid>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[jekyll]]></category>
            <category><![CDATA[themes]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 07:45:03 GMT</pubDate>
            <atom:updated>2022-02-20T16:06:56.620Z</atom:updated>
            <content:encoded><![CDATA[<h3>使用 Jekyll + minimal-mistakes 在 Github pages 上架設自己的部落格 — Jekyll x Minimal-Mistakes x GitHub pages</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9D-OQIt8dcfkOFs8R-sqhQ.jpeg" /><figcaption>Photo by Alfons Morales from Unsplash</figcaption></figure><h3>為什麼寫 Blog 文章</h3><p>工作上受到了很多教學網站及 Blog 文章非常多的幫助，因此想架設一個自己的 Blog，將工作及生活學到的技術知識記錄下來，幫助自己複習，也希望能幫助到有需要的人。</p><h3>為什麼選用 Jekyll + minimal-mistakes</h3><p>選用 Jekyll 的原因</p><ol><li>可用 Markdown 語法寫文章，Jekyll 會將 markdown 轉成 html 檔案</li><li>有非常豐富的主題</li><li>可客製化</li></ol><p>選用 Minimal-mistakes 主題的原因</p><ol><li>較多人使用，Github 上 star 有 9k</li><li>支援 Dark skin</li><li>可以放大圖，跟 Medium 類似</li></ol><p>其實原本我是用 Octopress ，後來因為 Octopress 已不再維護，且主題沒有 Jekyll 來得豐富，最後決定使用 Jekyll 重新架一個 Blog</p><blockquote><a href="http://octopress.org/"><em>Octopress</em></a></blockquote><p>廢話不多說，現在讓我們一起用 Jekyll 在 Github pages 上架設一個專屬 Blog 吧!</p><h3>為什麼選 GitHub Pages</h3><p>因為 免費 不用花錢租一台機器，也不需買 domain 跟 SSL，GitHub Pages 通通幫你搞定，當然之後要換自己買的 domain 跟 SSL 也是做得到</p><h3>事前準備</h3><h4>申請 <a href="https://github.com/">Github</a> 帳號<a href="https://nickhuang9527.github.io/blog/blog/creating_a_github_pages_with_jekyll_and_minimal_mistakes/#%E7%94%B3%E8%AB%8B-github-%E5%B8%B3%E8%99%9F">Permalink</a></h4><h4>安裝 <a href="https://git-scm.com/">Git</a></h4><blockquote><em>做版本控管</em></blockquote><pre>brew install git<br>git --version       #檢查版本</pre><h4>安裝 <a href="https://nickhuang9527.github.io/blog/blog/creating_a_github_pages_with_jekyll_and_minimal_mistakes/[https://](https://github.com/rbenv/rbenv)">rbenv</a></h4><blockquote><em>管理 ruby 版本</em></blockquote><pre>brew install rbenv<br>rbenv init<br># 依照你使用的 Shell，如果是 bash 請替換為 ~/.bashrc<br>echo &#39;export PATH=&quot;$HOME/.rbenv/bin:$PATH&quot;&#39; &gt;&gt; ~/.zshrc<br>echo &#39;eval &quot;$(rbenv init -)&quot;&#39; &gt;&gt; ~/.zshrc<br>rbenv -v        #檢查版本</pre><h4>安裝 <a href="https://www.ruby-lang.org/">ruby</a></h4><pre>rbenv install 3.0.0<br>rbenv global 3.0.0<br>rbenv rehash        # Rehash rbenv shims (run this after installing executables)</pre><p>用 rbenv -v 檢查版本</p><h4>檢查 <a href="https://rubygems.org/">RubyGems</a></h4><blockquote><em>Gem 套件管理服務，讓你能立即地發佈及安裝你的 Gem 套件，裝 ruby 時會一起安裝</em></blockquote><pre>gem update --system<br>gem -v</pre><h4>檢查 <a href="https://gcc.gnu.org/install/">GCC</a> / <a href="https://www.gnu.org/software/make/">Make</a></h4><pre>gcc -v<br>g++ -v<br>make -v</pre><h3>建立 Jekyll Blog 網站</h3><blockquote><em>這邊我是參考 GitHub 官網教學，如果英文可以的朋友可以直接參考 GitHub 的教學 </em><a href="https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/creating-a-github-pages-site-with-jekyll"><em>Creating a GitHub Pages site with Jekyll</em></a></blockquote><p>打開終端機，cd 到要建立 Blog 的目錄</p><pre>cd PARENT-FOLDER</pre><p>創建一個 Git repo 目錄，REPOSITORY-NAME 替換為你 GitHub repo 想取的名字 (e.g. blog)</p><pre>git init REPOSITORY-NAME</pre><p>cd 到 repo 目錄</p><pre>cd REPOSITORY-NAME</pre><p>決定你 GitHub Pages 網站發佈抓取 source 的方式 <a href="https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages#publishing-sources-for-github-pages-sites">Publishing sources for GitHub Pages sites</a></p><ol><li>用 gh-pages branch 當發佈 source</li><li>用任何分支上的 /docs folder 作為發佈 source</li></ol><p>這邊我選擇使用 1. 用 gh-pages branch 當發佈 source</p><p>創建 gh-pages branch</p><pre>git checkout --orphan gh-pages<br># Creates a new branch, with no history or contents, called gh-pages and switches to the gh-pages branch</pre><p>創建一個新的 Jekyll site</p><pre>jekyll new --skip-bundle .      # --skip-bundle : jekyll 創建時先不執行 `bundle install` 安裝 gem 套件</pre><p>打開 Gemfile，在 gem &quot;jekyll&quot; 前面加上 &quot;#&quot;，不安裝 jekyll 加入 github-pages gem</p><pre>gem &quot;github-pages&quot;, &quot;~&gt; GITHUB-PAGES-VERSION&quot;, group: :jekyll_plugins</pre><blockquote><em>請將 GITHUB-PAGES-VERSION 替換成 </em><em>github-pages 最後支援版本，請參考 </em><a href="https://pages.github.com/versions/"><em>Dependency versions</em></a></blockquote><p>存檔 Gemfile，執行 bundle install</p><blockquote><em>安裝 Gemfile 中的 gem 套件</em></blockquote><pre>bundle install</pre><p>修改 _config.yml</p><pre>domain: my-site.github.io       # if you want to force HTTPS, specify the domain without the http at the start, e.g. example.com<br>url: https://my-site.github.io  # the base hostname and protocol for your site, e.g. http://example.com<br>baseurl: /REPOSITORY-NAME/      # place folder name if the site is served in a subfolder</pre><p>加入 webrick gem</p><pre>bundle add webrick</pre><p>Fix <a href="https://github.com/jekyll/jekyll/issues/7329">favicon.ico not found issue</a></p><pre>touch favicon.ico</pre><h3>在 local 測試 Jekyll Blog 網站</h3><p>打開終端機執行</p><pre>bundle install<br>bundle exec jekyll serve</pre><p>點擊 Server address: http://localhost:4000 預覽你的網站</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*lkacKo-0Jv5zRCFz.png" /></figure><p>恭喜，你已經完成了你的第一個 Jekyll 網站 🎉🎉🎉🎉🎉 但我們只能在 local 欣賞，不能分享給朋友同事看，接上來我們將他推上去 GitHub，讓 GitHub Pages 幫我們建置 Blog 吧!</p><h3>上傳 GitHub 讓 GitHub Pages 自動建置 Blog</h3><p>首先要到 GitHub 網站創建一個 repository，請使用 Public 專案，名字隨便你取 (e.g. blog)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*g-uWnrIer2s5EuOc.png" /></figure><p>複製 repo 的 URL 等等會用到</p><p>先回到終端機將我們的測試過的 code commit</p><pre>git add .<br>git commit -m &quot;[feature] Initial GitHub pages site with Jekyll&quot;</pre><p>將剛剛複製的 repo URL 加入 git remote URL</p><pre>git remote add origin https://github.com/USER/REPOSITORY.git</pre><p>將 code 推上 GitHub</p><pre>git push -u origin BRANCH   # 因為上面是用 gh-pages 作為 source，這邊就直接將 BRANCH 換為 gh-pages 推上 GitHub 即可</pre><p>回到 GitHub 網頁 -&gt; Settings -&gt; Pages 點擊上面的網址 <a href="https://username.github.io/">https://USERNAME.github.io/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*y-uy_eGhr9K4BglY.png" /></figure><p>恭喜，你已經成功將 Jekyll 網站推上 GitHub Pages，現在全世界都看得到你的 Blog 了 🎉🎉🎉🎉🎉</p><p>但我們的 Blog 目前還非常的陽春，讓我們為 Blog 套上主題美化吧!</p><h3>加入 Minimal-mistakes 主題</h3><blockquote><em>這邊我是參考 minimal-mistakes 官網教學，如果英文可以的朋友可以直接參考 minimal-mistakes 的教學 </em><a href="https://mmistakes.github.io/minimal-mistakes/docs/quick-start-guide/"><em>Quick-Start Guide</em></a></blockquote><p>這邊 minimal-mistakes 作者提供了三種方式來安裝主題</p><ol><li>Gem-based method</li><li>Remote theme method</li><li>Fork</li></ol><p>GitHub Pages 很適合第 2 種方式，所以這邊我們選擇第二種安裝方式 打開 Gemfile 並加入下面的 code</p><pre>source &quot;https://rubygems.org&quot;<br><br>gem &quot;github-pages&quot;, group: :jekyll_plugins<br>gem &quot;jekyll-include-cache&quot;, group: :jekyll_plugins</pre><p>打開 _config.yml 找到 plugins 並加入 jekyll-include-cache plugin</p><p>抓取及更新 bundle 的 gems 套件</p><pre>bundle</pre><p>打開 _config.yml 加入 remote_theme: &quot;mmistakes/minimal-mistakes@4.24.0&quot;，並移除其他 theme: 及 remote_theme</p><p>編輯 _config.yml，這邊我是複製 <a href="https://github.com/mmistakes/minimal-mistakes/blob/master/_config.yml">Minimal Mistakes/index.html</a> ，並保留之前修改過的 domain, url, baseurl</p><ul><li>將 index.md 內容替換成 <a href="https://github.com/mmistakes/minimal-mistakes/blob/master/index.html">Minimal Mistakes/index.md</a></li><li>打開_posts/0000-00-00-welcome-to-jekyll.markdown，將layout: post改成layout: single</li><li>刪除 about.md</li></ul><p>好了，在測試一下結果如何</p><pre>bundle install<br>bundle exec jekyll serve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*NDxmWGO_n4Ebkb-g.png" /></figure><p>恭喜，你已經成功套用 Minimal-mistakes 主題進你的 Jekyll Blog 了 🎉🎉🎉🎉🎉</p><p>最後我們將 code commit 推上 GitHub</p><pre>git add .<br>git commit -m &quot;[feature] Add Minimal-mistakes theme to Jekyll&quot;<br>git push origin gh-pages</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*8FlktcMzcrGTkKXu.png" /></figure><p>Done! 🎉🎉🎉🎉🎉</p><p><em>Originally published at </em><a href="https://nickhuang9527.github.io/blog/blog/creating_a_github_pages_with_jekyll_and_minimal_mistakes/"><em>https://nickhuang9527.github.io</em></a><em> on December 29, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5699ffabd28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[如何使 Octopress website 能被 Google 搜索到 — Google x Search x Blog]]></title>
            <link>https://medium.com/@nickhuang9527/%E5%A6%82%E4%BD%95%E4%BD%BF-octopress-website-%E8%83%BD%E8%A2%AB-google-%E6%90%9C%E7%B4%A2%E5%88%B0-google-x-search-x-blog-6d63502a85eb?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d63502a85eb</guid>
            <category><![CDATA[octopress]]></category>
            <category><![CDATA[blog]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Thu, 10 Sep 2020 15:29:22 GMT</pubDate>
            <atom:updated>2022-02-20T16:07:17.056Z</atom:updated>
            <content:encoded><![CDATA[<h3>如何使 Octopress website 能被 Google 搜索到 — Google x Search x Blog</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9D-OQIt8dcfkOFs8R-sqhQ.jpeg" /><figcaption>Photo by Alfons Morales from Unsplash</figcaption></figure><h3>在 Google 搜尋不到我的 Blog</h3><p>當我們在建立完 Jekyll Blog 後，會發現竟然 Google 不到我們的 Blog 網站，別擔心這是因為我們尚未將網站提交加入 Google Search Console 中</p><h3>將網站加入 Google Search Console</h3><p>進入 <a href="https://search.google.com/search-console/welcome?hl=zh-CN&amp;utm_source=about-page&amp;pli=1">Google Search Console</a></p><p>這邊使用網址前綴方式添加，加你的 Blog domain 填入並繼續</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*IgvtUyov0Tu0RqV6.png" /></figure><p>下載 googlexxxxxxxxxx.html 檔案放到 octopress/source 目錄下，commit 上傳到 GitHub 上，點擊驗證</p><pre>rake gen_deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*3Ic-dMGLqyuu2vj1.png" /></figure><p>驗證成功 👍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*SgqH1ccgB1Dw6xRe.png" /></figure><p><a href="https://nickhuang9527.github.io/blog/blog/octopress-setup/">Previous</a></p><p><a href="https://nickhuang9527.github.io/blog/blog/creating_a_github_pages_with_jekyll_and_minimal_mistakes/">Next</a></p><p><em>Originally published at </em><a href="https://nickhuang9527.github.io/blog/blog/how-to-add-your-octopress-blog-website-to-google-search-console/"><em>https://nickhuang9527.github.io</em></a><em> on September 10, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d63502a85eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 Octopress 架設靜態 Blog — Octopress x GitHub pages x Blog]]></title>
            <link>https://medium.com/@nickhuang9527/%E4%BD%BF%E7%94%A8-octopress-%E6%9E%B6%E8%A8%AD%E9%9D%9C%E6%85%8B-blog-octopress-x-github-pages-x-blog-3a7286f11481?source=rss-acfb91a7aa1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a7286f11481</guid>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[octopress]]></category>
            <dc:creator><![CDATA[Nick Huang]]></dc:creator>
            <pubDate>Thu, 10 Sep 2020 15:18:16 GMT</pubDate>
            <atom:updated>2022-02-20T16:07:38.721Z</atom:updated>
            <content:encoded><![CDATA[<h3>使用 Octopress 架設靜態 Blog — Octopress x GitHub pages x Blog</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9D-OQIt8dcfkOFs8R-sqhQ.jpeg" /><figcaption>Photo by Alfons Morales from Unsplash</figcaption></figure><h3>為什麼要寫 Blog?</h3><p>工作中受到了很多教學網站及博客文章(簡書, CSDN, Medium…)非常多的幫助，因此想寫部落格將自己學到的技術記錄下來，一方面讓自己複習，一方面也希望能幫助到有需要的人。</p><h3>為什麼用 Octopress?</h3><p>其實有很多現成免費的部落格平台像是 Medium, Blogger 等…，但最後我還是決定用 Octopress 來建立自己的部落格，它吸引我的原因如下:</p><ol><li>使用 Git 做版本控管，託管於 Github</li><li>使用 Markdown 寫文章</li><li>可以學到東西</li><li>免費</li></ol><p>Git 對軟體工程師再熟悉不過了，且託管於工程師最愛充滿開源專案的 Github 平台，用 Markdown 寫文章，也能訓練自己寫 README 語法的熟練程度，又可以學到東西，因此選擇 Octopress。</p><h3>事前準備</h3><ul><li>申請<a href="https://github.com/">Github</a>帳號</li><li>安裝<a href="https://git-scm.com/">Git</a></li></ul><pre>brew install git</pre><ul><li>安裝<a href="https://www.ruby-lang.org/zh_tw/documentation/installation/">Ruby</a></li></ul><pre>brew install ruby</pre><p>確認版本</p><pre>ruby --version</pre><h3>建置 Octopress</h3><pre>git clone git://github.com/imathis/octopress.git octopress<br>cd octopress</pre><p>安裝依賴</p><pre>gem install bundler<br>rbenv rehash    # If you use rbenv, rehash to be able to run the bundle command<br>bundle install</pre><p>安裝 Octopress 預設主題</p><pre>rake install</pre><h3>Github page</h3><p><a href="https://pages.github.com/">Github page</a> 提供我們免費架設靜態網站，雖然有些限制(Ex: 沒有 DB, Server 配置等…)，但非常簡易就能部署，非常適合用來做個人部落格。</p><ol><li>到<a href="https://github.com/">Github</a>申請一個帳號</li><li>建立一個 repository，命名為[username].github.io，[username]為你 Github 的用戶名，請務必要用此格式命名，不然後面會無法部署。</li></ol><p>完成後會看到一個 ssh URL</p><pre>git@github.com:username/username.github.io.git</pre><p>，這就是你的遠端 repository 位置</p><h3>部署到 Github page</h3><ul><li>設置 Github page repo 位置</li></ul><pre>rake setup_github_pages</pre><p>此時會要你輸入 github page 的位置，還記得上面建立完成後所產生的 ssh URL，複製並輸入</p><pre>git@github.com:username/username.github.io.git</pre><ul><li>產生及部署部落格</li></ul><pre>rake generate<br>rake deploy</pre><p>上面指令會產生出你的部落格，並把產生的檔案複製到_deploy/ 資料匣中，並把它們加入 git 中，commit 及 push 到 master branch。</p><p>到這裡你可以先在 Browser 打開 <a href="http://username.github.io/">http://username.github.io/</a> ，就可以看到你的部落格囉!</p><p>最後別忘記將 source commit 並 push 到遠端的 repo</p><pre>git add .<br>git commit -m &#39;your message&#39;<br>git push origin source</pre><h3>發布文章</h3><p>所有的文章必須放在 source/_posts 目錄下</p><ul><li>創建新文章</li></ul><pre>rake new_post[&quot;title&quot;]</pre><p>此時在 source/_posts目錄下會產生一個 YYYY-MM-DD-post-title.markdown 的檔案，我們就可以打開檔案開始寫部落格了</p><pre>cd source/_posts/<br>vim YYYY-MM-DD-post-title.markdown</pre><p>也可用其他編輯器開啟寫文章，像是: <a href="https://macdown.uranusjr.com/">MacDown</a> 等…</p><p>寫完文章後再執行前面提到的<strong><em>產生及部署部落格</em></strong></p><pre>rake generate<br>rake deploy</pre><p>or</p><pre>rake gen_deploy</pre><p>最後再將剛所寫的文章加入 commit，並 push 到遠端的 repo</p><pre>git add .<br>git commit -m &#39;your message&#39;<br>git push origin source</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*O2-Ov_FgZ_OcJnEN.png" /></figure><h3>總結</h3><p>Octopress 基礎建置就到這邊，未來如果有時間會再深入研究更多 Octopress 的新功能，寫成文章分享給大家!</p><p><em>Originally published at </em><a href="https://nickhuang9527.github.io/blog/blog/octopress-setup/"><em>https://nickhuang9527.github.io</em></a><em> on September 10, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a7286f11481" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>