<?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 小瓷牛 on Medium]]></title>
        <description><![CDATA[Stories by 小瓷牛 on Medium]]></description>
        <link>https://medium.com/@cowcera?source=rss-f4e30964f6bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Yzq99l7DEfm1ImwKSC2QNw.gif</url>
            <title>Stories by 小瓷牛 on Medium</title>
            <link>https://medium.com/@cowcera?source=rss-f4e30964f6bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:23:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cowcera/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[website bluetooth 技術]]></title>
            <link>https://medium.com/@cowcera/website-bluetooth-%E6%8A%80%E8%A1%93-ec8d048669f5?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec8d048669f5</guid>
            <category><![CDATA[bluetooth]]></category>
            <category><![CDATA[website]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Mon, 16 Jun 2025 05:30:38 GMT</pubDate>
            <atom:updated>2025-06-16T05:30:38.167Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Y6SLNrDr8Y1NWBP_ZkfJXg.png" /><figcaption>gemini ai</figcaption></figure><p>其實 bluetooth 在 website 的技術我覺得還很大的開發空間，從 mozilla 中的文件可能就可以看出一點點端倪了。</p><p>什麼怎麼都是實驗性質的 API ~ ~</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXfog2kxNQBdTqkEo3yHzQ.png" /></figure><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API">Web Bluetooth API - Web APIs | MDN</a></p><p>在實用性上面，mac 和 PC 沒有什麼問題，但是手機上，android 還有支援但是 ios 是完全不開放的，所以這個對這個技術的流程程度一定會造成一些影響。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zG9rvG7YZgEV_53KzrNr7A.png" /></figure><p>是不是紅到都不想要寫了呢？但是也難保有一天 ios 會突想不開，就給它開放了。所以還是給它來實作記錄一下。</p><h4>常用的 function<a href="http://localhost:3030/docs/coding/front-note/javascript/bluetooth/#%E5%B8%B8%E7%94%A8%E7%9A%84-function">​</a></h4><pre>const connectBluetoothDevice = async () =&gt; {<br>  try {<br>    // Check if the Web Bluetooth API is available<br>    if (!navigator.bluetooth) {<br>      throw new Error(&quot;Web Bluetooth API is not available in this browser/environment&quot;);<br>    }<br><br><br>    const device = await navigator.bluetooth.requestDevice({<br>      filters: [{ namePrefix: &quot;Prefix-&quot; }],<br>    }); // 🌟<br><br><br>    const value = await characteristic.readValue();<br>  } catch (error) {<br>    console.error(&quot;Error:&quot;, error.message);<br>    document.getElementById(&quot;status&quot;).textContent = `Error: ${error.message}`;<br>  }<br>};</pre><p>當你呼叫 navigator.bluetooth.requestDevice() 時，會進行一個用戶介面流程，讓使用者選擇他們要連接的藍牙裝置。這個方法接收一個配置物件，讓你指定一些過濾條件，以便更精確地篩選出符合需求的裝置。</p><h4>filters<a href="http://localhost:3030/docs/coding/front-note/javascript/bluetooth/#filters">​</a></h4><p>一個物件陣列，指定了裝置的篩選條件，幫助選擇匹配的藍牙裝置。常見的過濾條件有：</p><ul><li>services：指定裝置所支持的服務（服務是藍牙裝置提供的功能，比如 “service”、“heart_rate”）。</li><li>name：裝置的名稱過濾。</li><li>namePrefix：裝置名稱的前綴過濾。</li></ul><p>範例：</p><pre>filters: [{ services: [&quot;service&quot;] }];</pre><p>這會篩選出支持 “service” 的裝置。</p><h4>optionalServices<a href="http://localhost:3030/docs/coding/front-note/javascript/bluetooth/#optionalservices">​</a></h4><p>這是一個選項，允許指定在選擇裝置後還要啟用的附加服務。例如，你可能想在選擇藍牙裝置後，除了要求 service，還希望能與其它服務進行交互。 範例：</p><pre>optionalServices: [&quot;heart_rate&quot;, &quot;device_information&quot;];</pre><h4>acceptAllDevices<a href="http://localhost:3030/docs/coding/front-note/javascript/bluetooth/#acceptalldevices">​</a></h4><p>一個布林值（true 或 false），如果設定為 true，它會允許列出所有藍牙裝置，而不需要依賴任何過濾條件。這通常是當你不確定要連接的裝置是哪一個時使用。 範例：</p><pre>acceptAllDevices: true;</pre><p>若設定為 true，則不會使用 filters 或 optionalServices，而是顯示所有可用裝置。</p><h4>結論</h4><p>目前 Web Bluetooth 支援的瀏覽器基本都是基於 Chrom 引擎的瀏覽器，這些瀏覽器支援範圍比較廣，但 Safari 和 Firefox 仍然不支援。因此，如果你打算開發依賴 Web Bluetooth 的應用，最好推薦用戶使用 Chrome、Edge、Opera 或 Brave 等瀏覽器。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec8d048669f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[沒有想到我也跟流行了]]></title>
            <link>https://medium.com/@cowcera/test-f71d9dd6bac4?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f71d9dd6bac4</guid>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 00:07:28 GMT</pubDate>
            <atom:updated>2025-06-14T15:01:04.198Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tdssb899sXhS_L8-gO2-ng.jpeg" /></figure><blockquote>本身是蠻喜歡大主管的管理風格，技術能力也強，也總能帶著團隊看見不一樣的東西。但是經濟不景氣的年代，集團幾次對公司的改組，心中也是默默知道這一天很有可能會來到，但沒有想到這麼突然。</blockquote><p>在 2024 年底還收到我們要做的東西已排到明年 7 月了，心中也是放心地好好過了一個年，沒有想到年後的兩天就收到了通知。</p><p>從通知到離開公司只能說人資蠻專業的，一點都沒有拖泥帶水，該給的都算給你。</p><p>雖然不懂為什麼，我們當初開發的東西要繼續維運，但卻要把整個開發部門收掉，只能說是大老闆的想法，我沒有很懂。</p><p>我承認自己是一個不會面對離別的人，不管是從情緒和實際面要怎麼和別人說再見，都不是很在行。但人生好像必須要學會好好說再見，這段時間所經歷的人事物也都不會再回來了，只能活在自己的腦海中讓它慢慢地不見，好像自己沒有擁有過。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W2b9n5Zt1dDTVTwh" /><figcaption>Photo by <a href="https://unsplash.com/@neonbrand?utm_source=medium&amp;utm_medium=referral">Kenny Eliason</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>回想當初，面對從Vue改寫到Angular的挑戰，我緊張得不得了，反覆思考是否真的該換工作，是否應該放下過去的一切，重新開始，心裡已經準備好要離開公司了。</p><p>實際上，在這段時間我學到了很多事情。例如，從最初的純前端工作逐漸深入到後端，對CICD自動部署有了更深的理解。此外，我還主導過三方服務的導入，這對網站結構產生了很大的改變。我始終堅持每年都要學習並帶走一些新的技能或知識，讓自己在職業生涯中不斷成長。</p><p>在這個AI迅速發展的時代，個人似乎必須具備多種技能來應對變化。時代雖然帶來了進步和機會，但也伴隨著挑戰與壓力。這使我感受到時代的祝福同時，也不得不承擔其帶來的痛苦與焦慮。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*YtDRQ2h8JqgPaCaS49GJHg.png" /><figcaption>techdesign 前公司</figcaption></figure><p>至於工作的部分已經找到了，感謝神 ~ (還好房貸有著落了)</p><p>這次有兩家截然不同的公司可選擇，讓我第一次感受到選擇的權利，真的很感人。</p><p>A 公司是一家規模龐大的上市公司，EPS達6~7元，使用 Angular 技術，後端是 .NET。他們正在擴編，似乎堅持使用過去的技術，顯然難以脫離 .NET 的環境。</p><p>B 公司則相對較小，但背後有大公司的支持，使用 React 或 Vue，後端採用Node 和 Python，並涉及 AWS 和 K8s 等相對較新的技術。</p><p>最後我選擇了B公司。</p><p>年輕的時候還是多學習幾項技能，掌握技術讓我對未來的發展比較安心點。</p><p>寫 blog 以此紀念此心情~~</p><p>文短情長，說不盡的東西就放在心裡面慢慢順理後，在寫出來吧~~</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FcxJFJmrK21H6MnR" /><figcaption>Photo by <a href="https://unsplash.com/@adambixby?utm_source=medium&amp;utm_medium=referral">Adam Bixby</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>未來的路還是要自己來走~</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f71d9dd6bac4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nuxt3 - 在運行時改變「環境變數」]]></title>
            <link>https://medium.com/@cowcera/nuxt3-%E5%9C%A8%E9%81%8B%E8%A1%8C%E6%99%82%E6%94%B9%E8%AE%8A-%E7%92%B0%E5%A2%83%E8%AE%8A%E6%95%B8-0aa83f0b2f08?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/0aa83f0b2f08</guid>
            <category><![CDATA[nuxt-3]]></category>
            <category><![CDATA[deploy]]></category>
            <category><![CDATA[env]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Mon, 01 Jan 2024 00:01:47 GMT</pubDate>
            <atom:updated>2025-06-13T08:20:21.829Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*TBIHnbDS5VO-fuTuBuzk6Q.png" /></figure><blockquote><em>env 環境變數的設定，通常是為為了 server 而設定的，能快速的切換狀態，但現在的網頁開始，前端的範圍逐漸往後端靠近，所以在設定，也會有 client 的變數會想要在 .env 的情況。此篇就是以 nuxt 為實作，分享此內容</em></blockquote><h3>前端架構</h3><p>最常見的 front 架構，就是把專案 build 出來之後放到，nginx 上，然後在設定上，特別聽一個 port ，讓 client request 到 server 的時候，可以 render 出你要的畫面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MvAjmw_0Zi47aPo3j9HY3A.png" /></figure><p>下列為一個簡單的 nginx 設定範例：</p><pre># 設定 server port <br>upstream be_server {  <br>  server 127.0.0.1:9990;<br>}<br># listen port<br>location / {<br>  proxy_pass http://be_server/;<br>}</pre><p>在這樣子的情況， .env 的 file 是放在 server 上，所以 client 要拿到，是沒有辦法的，如果說在專案中，把 env 放到 nuxt.config.js 中去作設定的話，在 build 完的時候，資料會被寫死在 .output/server/chunks/nitro/node-server.mjs 的 檔案中，可以在變數 _inlineRuntimeConfig 上看到你所設定的變數。</p><p>不過我們來看一下面提到的一種 build &amp; deploy 的情況。</p><h3>delopoy 多台機器</h3><p>參考下面部署的示意圖，今天有三台機要部署放著同一個專案，如果讓每台都執行 run build 的 script ，那每台機器就會浪量的資源在 build 上面，但如果可以把 build 的這件事情，放到一台機器上，最後只要把 dist 的檔案放到 server 上就可以 work 了。但是…這也遇到了一個問題。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZsSWCVsG0-Z8v6rZYyOK4A.png" /></figure><p>如果說今天同樣的專案，但是它是只需要吃不同的 .env ，這樣子難道就真的一定要 build 到三次嗎？</p><p>所以如果可以在 run start 專案的時候，可以拿到最即時的 .env 就是一件很重要的事情。可以為你多爭取到一杯咖啡的時間。</p><h3>Nuxt3 實作</h3><p>其實這個解法很簡單，只要專案在 start 後，可以從 api 中或是 file 中，拿到最新的 env 的資料，而不是透過 runconfig 所設定的資料，這樣子靈活性也會變高需多。</p><p>所以我們實作的羅輯是在前端的專案中寫一個可以 get env 的 api ，在專案 init 的時候就向它發出 request 取得資料，放到 nuxt 中獨有的 useState 中，讓 client 能直接取得 env，如果 env 更新的情況下，也只需要 restart 就可以拿新的 env 資料。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbVaCmOe8083DGuZUDkNsQ.png" /></figure><p>這邊我選擇在 middleware 的時候來發出 request</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c677baa7445f08d2e601018235692ac0/href">https://medium.com/media/c677baa7445f08d2e601018235692ac0/href</a></iframe><h3>Summary</h3><p>寫程式寫的越久，就會發現一個好的網站，一個好的開發流程，是需要額外作需多的事情。實在沒有辦法透過一個人獨立完成。</p><p>未來還有多少的東西需要去學習呢？就讓我繼續學下去吧~~ (嘆氣)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0aa83f0b2f08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[筆記大亂鬥 (Obsidian & Notion)]]></title>
            <link>https://medium.com/@cowcera/%E7%AD%86%E8%A8%98%E5%A4%A7%E4%BA%82%E9%AC%A5-obsidian-notion-6aa95e21b5af?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/6aa95e21b5af</guid>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[obsidian]]></category>
            <category><![CDATA[notion]]></category>
            <category><![CDATA[notes]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Wed, 22 Nov 2023 15:37:01 GMT</pubDate>
            <atom:updated>2023-11-22T15:37:01.712Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XuJ4IirO6EGUtVQiUD8Rtg.jpeg" /></figure><blockquote>在充斥著各種筆記工具的時代，Notion和Obsidian無疑是其中兩大重要的代表。這兩款工具都提供了強大的筆記功能，但它們在設計理念和使用體驗上卻有著極大的差異。本文將對Notion和Obsidian進行全面的比較，幫助你選擇最適合自己的筆記工具。</blockquote><h4>一、介紹</h4><p>Notion是一個全能的工作協作工具，提供了筆記、任務管理、數據庫、看板等多種功能，並且支持自定義頁面佈局，可視化操作讓使用者可以輕鬆創建出各種形式的筆記。</p><p>Obsidian則是一款專注於個人知識管理的工具，它使用Markdown語法，支持雙向鏈接和圖形化知識網絡，讓使用者可以更好地組織和連接自己的思考。</p><h4>二、功能比較</h4><ol><li>筆記功能：Notion和Obsidian都提供了豐富的筆記功能，但Notion更偏重於<strong>多媒體和自定義頁面佈局</strong>，Obsidian則更偏重於<strong>文本和結構化的知識組織</strong>。</li></ol><p>2. 數據庫和看板：Notion有強大的數據庫和看板功能，可以用來管理任務、項目、事件等。Obsidian則沒有這些功能，更專注於筆記本身 (其實真要用也是有，但沒有 Notin 好用)。</p><p>3. 雙向鏈接：Obsidian的雙向鏈接是它的一大特色，可以讓使用者更好地組織和連接思考。Notion雖然也支持鏈接，但並不支持雙向鏈接。</p><h4>三、使用體驗比較</h4><p>1. 使用簡單度：Notion的界面直觀，功能豐富，但需要一定的學習成本。Obsidian則更為簡潔，但需要熟悉Markdown語法。</p><p>2. 數據所有權：Obsidian的數據存放在使用者的本地，使用者完全擁有自己的數據。Notion的數據則存放在雲端，雖然方便，但也有數據安全的顧慮。</p><h4>四、Notion 中好用的 template</h4><p>1. 任務管理：這個模板可以幫助你追蹤每日、每週和每月的任務，讓你可以更好地管理你的時間。</p><p>2. 讀書筆記：如果你是一個愛讀書的人，這個模板可以幫助你記錄你的讀書筆記和心得。</p><p>3. 項目管理：這個模板可以幫助你管理你的項目，包括項目的狀態、負責人、期限等。</p><p>4. 個人維基：這個模板可以幫助你建立一個個人的知識庫，方便你隨時查找和學習。</p><p>5. <a href="https://thomas-chu.notion.site/Travel-Planner-4d8dd6cd8db24e53a097b6928e648b31?pvs=4">旅行計劃</a>：這個模板可以幫助你計劃你的旅行，包括行程、預算、必須攜帶的物品等。</p><p>6. 學習路徑：這個模板可以幫助你規劃你的學習路徑，包括你需要學習的課程、書籍、資源等。</p><p>7. 健康追蹤：這個模板可以幫助你追蹤你的健康狀況，包括飲食、運動、睡眠等。</p><p>8. 閱讀清單：這個模板可以幫助你管理你的閱讀清單，包括你想讀的書籍、已經讀過的書籍等。</p><p>9. 財務管理：這個模板可以幫助你管理你的財務，包括收入、支出、儲蓄等。</p><p>10. 習慣追蹤：這個模板可以幫助你追蹤你的習慣，幫助你建立良好的生活習慣。</p><h4>五、Obsidian 好用的 lib</h4><p>1. <a href="https://github.com/zolrath/obsidian-auto-link-title">Obsidian Auto link title</a>: 當你在筆記中插入一個內部連結時，這個功能會自動將連結名稱轉換為該筆記的標題。</p><p>2. <a href="https://forum.obsidian.md/t/the-easiest-way-to-setup-obsidian-git-to-backup-notes/51429">Obsidian Git</a>：這是一個非常實用的插件，它可以讓你在 Obsidian 中直接使用 Git 來版本控制你的筆記。你可以在每次編輯完筆記後，都把它們推送到你的 Git 倉庫，這樣就能保證你的筆記安全且版本完整。</p><p>3. Obsidian Calendar：這是一個日曆插件，可以在 Obsidian 中直接查看和管理你的日程。你可以在日曆中創建新的筆記，也可以直接從日曆打開已有的筆記，非常方便。</p><p>4. <a href="https://github.com/lynchjames/obsidian-mind-map">Obsidian Mind Map</a>：這是一個思維導圖插件，可以把你的筆記轉化成思維導圖來查看。如果你喜歡用思維導圖來組織你的思路，這個插件會非常實用。</p><p>5. Obsidian Kanban：這是一個看板插件，可以在 Obsidian 中創建和管理看板。你可以用它來管理你的任務，也可以用它來組織你的筆記。</p><p>6. <a href="https://github.com/tgrosinger/advanced-tables-obsidian">Obsidian Advanced Tables</a>：這是一個進階的表格插件，它提供了一些強大的表格編輯功能，如列寬調整、行列排序等。</p><p>7. Obsidian Templater：這是一個模板插件，可以讓你在 Obsidian 中創建和使用模板。你可以用它來快速創建新的筆記，也可以用它來統一你的筆記格式。</p><p>8. Obsidian Sliding Panes (Andy Mode)：這個插件可以讓你的筆記在側邊滑動開啟，就像 Trello 的卡片一樣。這樣你就可以同時查看和編輯多個筆記，而不需要不斷地在不同的筆記之間切換。</p><p>9. <a href="https://github.com/noatpad/obsidian-banners">Obsidian banner</a>：這個插件可以在文章的上方加入一個 banner ，並且可以調整位置</p><h4>六、結論</h4><p>Notion和Obsidian各有優勢，選擇哪一款取決於你的需求。如果你需要一個全能的工作協作工具，且不介意數據存放在雲端，那麼Notion可能是你的首選。如果你更關注個人知識管理，且希望完全擁有自己的數據，那麼Obsidian可能更適合你。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6aa95e21b5af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 分鐘用 NestJs 接上 mysql]]></title>
            <link>https://medium.com/@cowcera/5-%E5%88%86%E9%90%98%E7%94%A8-nestjs-%E6%8E%A5%E4%B8%8A-mysql-4215ab91fc75?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/4215ab91fc75</guid>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Fri, 10 Nov 2023 08:07:26 GMT</pubDate>
            <atom:updated>2023-11-10T08:07:26.111Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OXOpIHNMse3cbb5qnc8q-A.png" /></figure><blockquote>實現這個需求，你需要先安裝 Node.js 和 Nest.js 框架，並確保你已經安裝了 MySQL 數據庫。</blockquote><p>首先，創建一個新的 Nest.js 項目：</p><pre>$ npm i -g @nestjs/cli<br>$ nest new blog-backend</pre><p>然後，進入項目目錄並安裝相關的依賴：</p><pre>$ cd blog-backend<br>$ npm install mysql2 nestjs-typeorm typeorm</pre><p>接下來，創建一個 `Post` 實體，用於映射到數據庫中的 <strong>posts</strong> 表：</p><pre>$ nest generate class post/entity/post</pre><p>在 <strong>post.entity.ts</strong> 文件中，定義 <strong>Post</strong> 實體的屬性和數據庫映射：</p><pre>import { Entity, Column, PrimaryGeneratedColumn } from &#39;typeorm&#39;;<br><br>@Entity()<br>export class Post {<br>  @PrimaryGeneratedColumn()<br>  id: number;  <br>  @Column()<br>  title: string;  <br>  @Column()<br>  content: string;<br>}</pre><p>接下來，創建一個 `PostService` 服務，用於處理與 `Post` 實體相關的業務邏輯：</p><pre>$ nest generate service post/service/post</pre><p>在 <strong>post.service.ts</strong> 文件中，實現一些基本的 CRUD 方法：</p><pre>import { Injectable } from &#39;@nestjs/common&#39;;<br>import { InjectRepository } from &#39;@nestjs/typeorm&#39;;<br>import { Repository } from &#39;typeorm&#39;;<br>import { Post } from &#39;../entity/post&#39;;<br>@Injectable()<br>export class PostService {<br>  constructor(<br>    @InjectRepository(Post)<br>    private postRepository: Repository&lt;Post&gt;,<br>  ) {}<br><br>  async findAll(): Promise&lt;Post[]&gt; {<br>     return this.postRepository.find();<br>  }<br><br>  async create(post: Post): Promise&lt;Post&gt; {<br>     return this.postRepository.save(post);<br>  }<br><br>  async update(id: number, post: Post): Promise&lt;Post&gt; {<br>     await this.postRepository.update(id, post);<br>     return this.postRepository.findOne(id);<br>  }<br><br>  async delete(id: number): Promise&lt;void&gt; {<br>     await this.postRepository.delete(id);<br>  }<br>}</pre><p>然後，創建一個 <strong>PostController</strong> 控制器，用於處理與 <strong>Post</strong> 相關的 HTTP 請求：</p><pre>$ nest generate controller post/controller/post</pre><p>在 post.controller.ts 文件中，實現一些基本的路由處理方法：</p><pre>import { Controller, Get, Post, Put, Delete, Body, Param } from &#39;@nestjs/common&#39;;<br>import { PostService } from &#39;../service/post.service&#39;;<br>import { Post as PostEntity } from &#39;../entity/post&#39;;<br>@Controller(&#39;posts&#39;)<br>export class PostController {<br>  constructor(private postService: PostService) {}<br><br>  @Get()<br>  async findAll(): Promise&lt;PostEntity[]&gt; {<br>    return this.postService.findAll();<br>  }<br>  @Post()<br>  async create(@Body() post: PostEntity): Promise&lt;PostEntity&gt; {<br>     return this.postService.create(post);<br>  }<br>  @Put(&#39;:id&#39;)<br>  async update(@Param(&#39;id&#39;) id: number, @Body() post: PostEntity): Promise&lt;PostEntity&gt; {<br>    return this.postService.update(id, post);<br>  }<br>  @Delete(&#39;:id&#39;)<br>  async delete(@Param(&#39;id&#39;) id: number): Promise&lt;void&gt; {<br>    return this.postService.delete(id);<br>  }<br>}</pre><p>最後，配置數據庫連接，編輯 `src/app.module.ts` 文件：</p><pre>import { Module } from &#39;@nestjs/common&#39;;<br>import { TypeOrmModule } from &#39;@nestjs/typeorm&#39;;<br>import { Connection } from &#39;typeorm&#39;;<br>import { Post } from &#39;./post/entity/post&#39;;<br>import { PostService } from &#39;./post/service/post.service&#39;;<br>import { PostController } from &#39;./post/controller/post.controller&#39;;<br>@Module({<br>  imports: [<br>    TypeOrmModule.forRoot({<br>      type: &#39;mysql&#39;,<br>      host: &#39;localhost&#39;,<br>      port: 3306,<br>      username: &#39;your_username&#39;,<br>      password: &#39;your_password&#39;,<br>      database: &#39;your_database_name&#39;,<br>      entities: [Post],<br>      synchronize: true,<br>    }),<br>    TypeOrmModule.forFeature([Post]),<br>  ],<br>  controllers: [PostController],<br>  providers: [PostService],<br>})<br>export class AppModule {<br>  constructor(private connection: Connection) {}<br>}</pre><p>現在，你可以運行項目：</p><pre>$ npm run start</pre><p>項目運行後，你可以使用 Postman 或其他 HTTP 客戶端工具來測試接口。例如，你可以使用以下請求來創建一個新的博客文章：</p><pre><br>POST /posts<br>Content-Type: application/json<br>{<br> &quot;title&quot;: &quot;Hello World&quot;,<br> &quot;content&quot;: &quot;This is my first blog post.&quot;<br>}</pre><p>希望這能幫助到你！ 👍</p><p>參考文章~</p><p><a href="https://shaibenshimol.medium.com/nestjs-and-mysql-in-10-minutes-711e02ec1dab">Nestjs and Mysql in 10 Minutes</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4215ab91fc75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[用 google script 寄 email 測試]]></title>
            <link>https://medium.com/@cowcera/%E7%94%A8-google-script-%E5%AF%84-email-%E6%B8%AC%E8%A9%A6-b444d8e32182?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/b444d8e32182</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[script]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Wed, 01 Nov 2023 15:22:08 GMT</pubDate>
            <atom:updated>2023-11-08T01:08:09.714Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S45yaKD1E5yRbHf8WE0oAg.png" /></figure><blockquote>在開發 email 的過程，一定會有要寄信的需要，這時候 google script 可以快速的幫忙這段，s透過簡單的 code 就可以完成</blockquote><h3>建立新的專案</h3><h4>先打開自己的 google script</h4><p>登入後選擇自己的 google script，可透過下面的 url 一直接進入到畫面中，在 click 「start scripting」</p><p><a href="https://www.google.com/script/start/">google script 的首面</a></p><p><a href="https://www.google.com/script/start/">Apps Script</a></p><h4>建立專案</h4><p>簡單的建立一個新的專案，基本畫面和 google drive 是差不多的</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XhRRlbQvZBJB5Cf3g0TL1g.png" /></figure><h4>新增部署作業</h4><p>新建立一個部署作業，並選擇網頁應用程式，完成後在 click 「執行」</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iVgoi79D65ypU8B0wNu62g.png" /></figure><p>這個時候可能會有權限問題，此時可以參考這個 youtube ，在 11:12 秒的時候會說怎麼排除，權限問題</p><p><a href="https://www.youtube.com/watch?v=qncgBh9A5RQ">youtube 說明權限問題</a></p><h4>coding</h4><p>在上述中都完成後，就可以開始 coding 了，執行一個 sendEmail 的 function</p><pre>function doGet() {<br> sendEmail();<br> return ContentService.createTextOutput(&quot;完成&quot;);<br>}</pre><p>function 中設定好，mail, option 等等的東西</p><pre>function sendEmail() {<br> const respondentEmail = &#39;thomas.chu@xxxxxxxxxx.com&#39;<br> const subject = &#39;Subject&#39;;const message = &#39;Message&#39;;<br> const templ = HtmlService.createTemplateFromFile(&#39;email&#39;); <br> // filename is email.html<br> <br> const htmlMessage = templ.evaluate().getContent();<br> const options = { htmlBody: htmlMessage };<br> <br> GmailApp.sendEmail(respondentEmail, subject, message, options);<br>}</pre><blockquote>在你的檔案底下，放一 email.html 的檔案，在根目錄，這樣子在寄信的時候就會去找此檔案寄出。</blockquote><p>然後在種新的執行一次，就 ok 了喔~~</p><p>👍 👍 👍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S45yaKD1E5yRbHf8WE0oAg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b444d8e32182" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[開發 storyblok 的美好過程]]></title>
            <link>https://medium.com/@cowcera/%E9%96%8B%E7%99%BC-storyblok-%E7%9A%84%E7%BE%8E%E5%A5%BD%E9%81%8E%E7%A8%8B-e7ba5ef7dae0?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7ba5ef7dae0</guid>
            <category><![CDATA[cms]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Fri, 09 Jun 2023 23:58:27 GMT</pubDate>
            <atom:updated>2023-06-10T00:00:26.641Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RC9YywEJ_rcz55LGrwJESA.png" /></figure><blockquote>是 <strong><em>storyblok</em></strong> 不是 <strong><em>storybook</em></strong> 喔，啟初我在剛剛接觸的時候，也以為它們是一樣的東西，但他們是完全不一的東西。storyblok 是一套管理內容的三方服務，從開發到現在 3 ~ 6 個月過去了，我幾乎無法對它抱怨，實在是好用到一個不可置信…</blockquote><h3>起步</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*wPE7FGJn4QVUubT-owV6AQ.png" /></figure><h4>想法啟蒙 (Content <strong>Management</strong> System)</h4><p>— 主管分享過去的 <strong>CMS</strong> 的管理經驗，透過 JSON 的方式來儲存和傳遞內容，當時候的我還不知道 <a href="https://thomas-chu-30.github.io/tech-note/docs/other/headless-cms/">headless cms</a> 是什麼？</p><h4>admin 開發</h4><p>— 當時候還想說要另外作一個服務，為了可以順利的產出 web-api 的 JSON<br> — 思考用 iframe 的方式，作一個額外的服務，產出 JSON 傳回 admin 儲存(現在回去看這個想法跟本就是一個災難)。</p><h4>三方服務</h4><p>— 不過因為 admin 開發時間過久，因此接到「聖旨」，需要研究三方服務，盡快達成目的。<br> — 研究 headless cms (開始接觸到這個單字)<br> — <a href="https://tenten.co/learning/headless-cms-collections/amp/">最受歡迎的 Headless CMS 介紹</a><br> — 比較三方 headless 的 CMS</p><h4>我選了 Storyblok</h4><blockquote>為什麼選擇了它？</blockquote><ol><li>可預覽畫面</li><li>操作簡單</li><li>靈活應變大部分的場景</li><li>簡單的操作流程</li><li>component 重複使用的概念強。<br>(只有它可以在 richText 裡面引用 component，其它家都是產出 html 像是 <a href="https://www.tiny.cloud/">tinyMCE</a> 的套件)</li><li>release content 功能</li></ol><p>下面這個官提供的一個說明。</p><blockquote>- why-storyblok say “Storyblok’s headless architecture empowers developers to effortlessly work with and adapt to any technology. Deliver content to any frontend faster with API-enhanced performance and industry-leading security. Storyblok is designed to be easily customized and extendable around your organization’s specific workflows. <strong>Storyblok is the ultimate CMS solution for all your content.</strong>”</blockquote><p><a href="https://www.storyblok.com/why-storyblok">Why Storyblok</a></p><h4>開發過程 — Develop</h4><ol><li>storyblok app 介面操作研究</li><li>思考測試環境、開發流程</li><li>前端專案 modules 規劃</li><li>研究 api 使用 -<a href="https://www.storyblok.com/docs/api/content-delivery">Content Delivery API</a>, <a href="https://www.storyblok.com/docs/api/management">Management API</a>, <a href="https://www.storyblok.com/docs/graphql-api">GraphQL API</a></li></ol><blockquote>🚧 過程中其實反覆寫了幾個版本。主要因為 cms 的 slug 是否要完全匹配 url ，各個頁面共用 cms 的 component，主要也是為了未來在建立 sitemap 用。</blockquote><h3>Storyblok roadmap</h3><p>其實透過它的 roadmap 也可以感受到它的野心，跟本就是要大家都用它的產品，作的這麼的完整，這麼的友善。</p><p><a href="https://www.storyblok.com/roadmap">Roadmap | Storyblok</a></p><blockquote>Evaluating &amp; Planned：</blockquote><blockquote>Improved selection functionality within Option Fields</blockquote><blockquote>Enables users to create new options within Single Option and Multi-Option fields faster by removing the confirmation step.</blockquote><blockquote>Smartling Integration：</blockquote><blockquote>This custom Storyblok app enables direct connection with the <a href="https://www.smartling.com/">Smartling</a> translation service.</blockquote><h3>In Development &amp; Released</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*Bxca3Kb_XLpSp0c5TwwCpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*VnTl3u3PXaA8wFw-LPSJsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*COTSKZBX_8_bL10aS6vyxQ.png" /></figure><h3>Summary</h3><ol><li>選擇比努力重要 (如果我們是用 admin 開發的話，跟本就是一個災難)</li><li>api 規劃功能齊全，在取得資料上可以透過各式個樣的 filter 方式去取得所需之資料</li><li>彈性的去組建你所需要的資料內容</li></ol><p>來自硬體工程師，從來沒有想過說，可以在軟業導入一個這麼大的東西進到專案中，沒有什麼深厚底子的我，能完成這件事情，我也是深感驕傲。</p><blockquote>寫下這段話給自已，也給未來的自己看。</blockquote><p>充滿著對於導入Storyblok到我們專案的回憶和感激之情。回想起當初採用這個強大的內容管理系統的決定，我們可以看到它帶給我們的種種好處和美好回憶。</p><p>首先，我要感謝整個團隊在導入過程中的努力和奉獻。我們共同面對了挑戰，克服了困難，並且在這個旅程中相互支持。每一位成員的貢獻都是無價的，使得我們能夠成功地導入Storyblok並發揮其最大的潛力。</p><p>回顧過去的日子，我們可以明顯感受到Storyblok為我們的專案帶來的巨大效益。它提供了一個直觀且易於使用的界面，讓我們能夠輕鬆管理和編輯網站的內容。不再需要依賴開發人員進行每次修改，我們能夠快速更新和調整內容，提供更好的使用者體驗。</p><p>此外，Storyblok的靈活性和可擴展性也為我們的專案帶來了無限的可能性。它允許我們根據需求進行自定義和擴展，無論是創建多語言網站、建立豐富的內容模塊，還是與其他工具和平台進行無縫集成，我們都能夠輕鬆實現。</p><p>除了功能上的優勢，我們還要感謝Storyblok團隊提供的卓越支援和文檔資源。他們不僅提供了清晰明瞭的文檔，還定期更新並增加新的功能和改進。我們在導入過程中遇到的問題得到了及時的回饋和解決，這使得我們能夠更好地理解和利用Storyblok的潛力。</p><p>最後，我想向所有支持我們的夥伴和用戶致以最誠摯的感謝。你們的信任和支持使我們能夠在專案中成功地運用Storyblok。我們很榮幸能夠與你們</p><p><a href="https://lokalise.com/blog/how-a-headless-cms-can-streamline-your-localization-plans/">參考圖片</a></p><p>技術筆記</p><p><a href="https://thomas-chu-30.github.io/tech-note/docs/intro">Guide | Thomas Site</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7ba5ef7dae0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webp 是啥東西？？]]></title>
            <link>https://medium.com/@cowcera/webp-%E6%98%AF%E5%95%A5%E6%9D%B1%E8%A5%BF-74bfca856e1e?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/74bfca856e1e</guid>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Wed, 07 Dec 2022 02:07:00 GMT</pubDate>
            <atom:updated>2023-11-01T15:25:36.724Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LFt9_tiUEKCdsk8xNaPFzQ.png" /></figure><p><strong>WebP</strong>（發音：<em>weppy</em>）是一種同時提供了有<strong><em>損壓縮</em></strong>與<strong><em>無失真壓縮</em></strong>（可逆壓縮）的圖片檔案格式。</p><p>WebP最初在2010年9月釋出，其支援庫於2018年4月發布1.0版本。截至2021年5月，已有94%的瀏覽器支援此格式。</p><p>WebP 的設計目標是在減少檔案大小的同時，達到和<a href="https://zh.m.wikipedia.org/wiki/JPEG">JPEG</a>、<a href="https://zh.m.wikipedia.org/wiki/PNG">PNG</a>、<a href="https://zh.m.wikipedia.org/wiki/GIF">GIF</a>格式相同的圖片品質，並希望藉此能夠減少圖片檔在網路上的傳送時間。根據Google較早的測試，WebP的無失真壓縮比網路上找到的<a href="https://zh.m.wikipedia.org/wiki/PNG">PNG</a>檔少了45％( <em>我自已在開發上遇到的情況，和此數據差不多 </em>)的檔案大小，即使這些PNG檔在使用pngcrush和PNGOUT處理過，WebP還是可以減少28％的檔案大小。</p><p>不過在早期的 web 世界中還不是這麼的流行時，需在判斷 browser 上是否支援此格式可用下面的方式確認</p><pre>document.<strong>createElement</strong>(&#39;canvas&#39;).<strong>toDataURL</strong>(&#39;image/webp&#39;,0.5).<strong>indexOf</strong>(&#39;data:image/webp&#39;) === 0;   </pre><p>用判斷的方式，方可避免圖片不見。</p><p>參考文章</p><ul><li><a href="https://zh.m.wikipedia.org/zh-tw/WebP">WebP - 維基百科，自由的百科全書</a></li><li><a href="https://juejin.cn/post/6844903858028675079">判断浏览器是否支持 webp 的几种解决方法</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74bfca856e1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[今晚我想來點 Rxjs]]></title>
            <link>https://medium.com/@cowcera/%E4%BB%8A%E6%99%9A%E6%88%91%E6%83%B3%E4%BE%86%E9%BB%9E-rxjs-f7dd3e26212e?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7dd3e26212e</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[rxjs]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Thu, 24 Nov 2022 13:55:17 GMT</pubDate>
            <atom:updated>2022-11-24T13:55:17.098Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*orVQ9aUZj5cepnBpVufzOg.png" /></figure><blockquote>在經過 angular 的洗禮過後 rxjs 也變成了我的前端好朋友了。雖然還是有不少的東西不太常用，但至少不會害怕使用它。<br>rxjs 可更彈性去操作 request 的資料，也更容易的去處理 error handling 的部分</blockquote><p>過去比較常看到這樣子的 request 寫法</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22ccc026efe9b1560d9bf365123dc36d/href">https://medium.com/media/22ccc026efe9b1560d9bf365123dc36d/href</a></iframe><p>方法一：</p><p>在 then裡面取得資料之後繼續做處理，不管是 filter data or 整理資料結構都是在取回資料後，另外 error handling 是在 catch裡面加上判斷，在作其它的 call function 的處理</p><p>方法二：</p><p>其實和方法一很像，只是用了 async await 的方法，讓程式碼看起來乾淨好閱讀一點，在用 try catch 的方式，捕捉 error 執行後續的事情。</p><p>那 rxjs 是在處理同步和非同步的情況 (記得它還可以處理同步的情況)，那要開始使用 rxjs 的話，主要下列的三個東西你一定不能不知道</p><blockquote><strong>obserable </strong>可觀察的</blockquote><blockquote><strong>subscribe</strong> 訂閱</blockquote><blockquote><strong>pipe </strong>資料處理的水管</blockquote><h3>observable</h3><p>由英文知道是「<strong><em>可觀察的</em></strong>」意思，rxjs在起手式的時候都會去定義一個 observable，通常這樣子的可觀察變數，會在後面放上一個 <strong><em>$</em></strong> 的符號，讓開發者知道說這個變數是 observable。</p><p>observable 透過 <em>next()</em> ，來改變 observable 原本義的值 or 原本就沒有定義過</p><p>接著透過「<strong>訂閱(subscribe)</strong>」這些可觀察的物件，當有新的 next() 進來的時候，subscribe 的 function 就會觸發。接下來 observable 有四個不一樣的狀態，下面一一來說</p><blockquote>共有四種 Subject, BehaviorSubject, ReplaySubject, ReplaySubject</blockquote><h4>Subject</h4><p><strong><em>在訂閱之後，在 next() 值進去後，才會執行到 subscribe 的 function</em></strong> (這個先後順序很重要)，之前的調用的 next() 不會被執行到</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b93aa1d45c7570cd3a08cbff62503ca6/href">https://medium.com/media/b93aa1d45c7570cd3a08cbff62503ca6/href</a></iframe><h4>BehaviorSubject</h4><p>和 subject 來比較的話，BehaviorSubject 它會<strong><em>把之前調用 next 的值都在進到 subscribe 的 function 中</em></strong>，也就是說會提供舊有的訂閱內容，也就是幫 Subject 多了一個回播的功能。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8937716f32932cad281db32c3d33991/href">https://medium.com/media/a8937716f32932cad281db32c3d33991/href</a></iframe><h4>ReplaySubject</h4><p>會把之前的值用 array 的方式紀錄下，等到下次在 subscribe 的時候，移除前面的紀錄，只留下最後的幾筆資料。</p><blockquote>這個比較難以理解一點，所以附上 <a href="https://playcode.io/995266">demo</a> 給各位</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9368b9848924280a4fc3e273f381b81/href">https://medium.com/media/e9368b9848924280a4fc3e273f381b81/href</a></iframe><h4>AsyncSubject</h4><p>只有當 Observable 執行完成時，它才會執行，把最後一個發送給觀察者。</p><blockquote>這個目前本人也比較少用到</blockquote><h3>subscribe</h3><p>「訂閱」，是當這些 observable 的值變化的時候，也就是 next() 被觸發，所會去執行 subscribe 的 function，</p><pre>import { BehaviorSubject } from &#39;rxjs&#39;;</pre><pre>const count$ = new BehaviorSubject(0)</pre><pre>count$.subscribe((<em>count</em>)=&gt;{<br>  console.log(count) // 0,1<br>})</pre><pre>count$.next(1) </pre><h3>pipe</h3><p>pipe 「管道」的意思，是在資料回來的時候，接著會去處理的地方(這裡有不少的 function 可被使用，map, take, tap ... etc)</p><p>這個 pipe 都是在 subscribe 的資料回來的時候，才會觸發的 function 下面列出幾個常用的函式</p><h4>zip</h4><p>會把所有內部的值全數發出後，並取得相對應的值</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-7agPU_pLML2Q6873_k5g.png" /></figure><h4>map​</h4><p>對應每一個值去作對應的投射，有點像 js 的 map function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkDgbHaaOhbpfSSNPHN_bA.png" /></figure><h4>finalize</h4><p>在怎麼樣到最後都會出來的一個 function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1z01rKvsQi4mUwwyrcmIRA.png" /></figure><p>到這邊各位可能也是會有一點點不太理解，不過各人覺得也是正常，因為沒有實際寫過，可能很難感受到它的奧秘。</p><p><a href="https://thomas-chu-30.github.io/tech-note/docs/rxjs/general">這邊有更多的 pipe function 可以參考</a></p><p>看過以上的內容後，來看一下官方常常會跑出來的圖，了解一下它的含義和流程，對之後看文件比較有幫助。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHB80vz5LCk2dEQLoKdqpA.png" /></figure><p>x 方向是 next() 執行的次數，以上面的為例它就是執行了三次的 next() ，各別傳入了 1, 2, 3 ，在 observable 的 subscribe 的 function 的因為訂閱的關係，所以只有值的變動它就會去執行。那這裡的 map 是在 res 回來的值在去作 *10 的這個動作。</p><h3>特別注意 — unSubscribe</h3><p>在訂閱過後記憶體其實就會一直佔有一小部分，因此沒有在轉換頁面的時候，把原本的 subscribe clear 的話，記憶體就會一直不斷的累加，到後來就變成了 memory leak ，所以記得在 destory 的 lifehooks 中，把 subscribed clear 確保記憶體的空間。</p><h4>小結</h4><p>rxjs 有很多 pipe function 可使用，不過前提是要先了解到 rxjs 的一些原理和概念，這樣子在去看文章的時候比較可以融會貫通，所以夜深了 ~~~</p><p>今晚我們一起來 rxjs 一下吧 ~~~ (宵夜就不用)</p><p>好廢程式筆記：<a href="https://thomas-chu-30.github.io/tech-note/docs/intro/">https://thomas-chu-30.github.io/tech-note/docs/intro/</a></p><p>好廢程式筆記：<a href="https://thomas-chu-30.github.io/tech-note/docs/intro/">https://thomas-chu-30.github.io/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7dd3e26212e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[轉職後三年，我過的如何？]]></title>
            <link>https://medium.com/@cowcera/%E8%BD%89%E8%81%B7%E5%BE%8C%E4%B8%89%E5%B9%B4-%E6%88%91%E9%81%8E%E7%9A%84%E5%A6%82%E4%BD%95-a6dfc3096260?source=rss-f4e30964f6bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6dfc3096260</guid>
            <category><![CDATA[blog]]></category>
            <dc:creator><![CDATA[小瓷牛]]></dc:creator>
            <pubDate>Thu, 10 Nov 2022 15:33:27 GMT</pubDate>
            <atom:updated>2022-11-22T22:32:21.059Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZuURIg0txYO4cWhjBzpX0w.jpeg" /></figure><blockquote>2019是我人生中的一個重大的轉捩點，由製造業品質工程課長卸任，來到了一個全新的領域「前端網頁開發」，也算是為了圓一個學生時期的夢想，如今我轉職三年了，我現在過的如何呢？</blockquote><p>當初從 vue 開始，先寫著簡單的邏輯，和切切畫面作作一般的功能，後來開始接觸到 nuxt ，開始對專案的整體架構打開了眼睛，不過這個時候還是寫 JS 比較多，沒碰觸其它 web 開發週邊的東西。</p><p>後來輾轉到了一家要開發 angular 的公司，就開始我的 <strong>typescrip 、Rxjs </strong>的學習之旅。但因有 nuxt 的專案結構想法，所以在學習上也變的比較快速，也嘗試的把過去好的經驗，帶入到 angular 的結構中，過程中和前輩的討論，也學習了不少的知識。</p><p>然後因為開發環境是本地端，所以就不得不學點 …</p><ol><li>啟一個 docker</li><li>build 一個 socket server 和介接</li><li>設定本地 nginx，申請 ssl 憑證</li><li>開發時要會查看一下 db 的資料 table</li><li>抓 bug 的時候要了解更多的 deploy flow 和 script 的用法</li><li>作 ssr 所以需要寫一點點 node.js，處理 render 機制</li></ol><p>當然還有一瑣碎的東西，也是經過這路，我才更了解到要用好一個網站，效能、SEO、cache 機制 … etc ，實在是沒有這麼的容易，</p><p>下面我來分享一下，我覺得開發中很重要的東東</p><h3>coding style</h3><h4>自己的 coding style</h4><p>剛開始在寫專案的時候，常常會發生，才過個幾個月回去看自己寫的 code 就想要吐血的情況，很常是因為下面的幾點：</p><ol><li>看不懂自己的邏輯</li><li>命名不精準</li><li>用過多的變數</li><li>操作行為不統一</li></ol><p>這樣子的情況多半來自，對語言還不熟悉，解決的方法也都是偏奇怪。然後為了開發快一點，所以在命名變數上不放心思，所以常常導至痛恨幾個月前的自己。</p><p>另一種就是因為經驗不足的關係，因此總是想著用定義變數去控制狀態，這個本身沒有錯，但是定義過多的變數，甚至還有重複的意義，讓整個流程變的複雜，不好維護最後變成了悲劇。</p><p>之後在寫了一陣子後，開始有了開發老梗，像是如果要拿 array 最後一個值</p><pre>[1,2,3,4,5].slice(-1)[0] // 是不是看起來有一點點乾淨</pre><p>等等之類的老梗越來越多的時候，發開也變的越來越順利，也開始形成了自已的 coding style</p><h4>coding style tool</h4><p>那大家一起開發，不免一定會有習慣不同的地方，那怎麼樣子能在最快的時間統整，也能加速大家的開發效率。下面有幾個 tool 是好棒棒的必會的：</p><ol><li>Husky <a href="https://ithelp.ithome.com.tw/articles/10278411">https://ithelp.ithome.com.tw/articles/10278411</a></li><li>pretty</li><li>ESLint</li><li>VScode 的 setting file</li></ol><h3>專案結構</h3><blockquote>一個好的專案結構讓你上天堂，不好的專案結構讓你想回家睡覺</blockquote><p>剛開始寫的時候，常常看到前輩光是用想的，就能猜到 bug 在那裡，那時覺得神奇到不行，自己只能從 code 的一行一行中 console.log 來看問題，光釐清問題的時間就多出了不少。到了後來才慢慢發現，寫 code 的當下是要思緒萬千的，要考慮到很多不同的情況，還要把很多不必要的事情避免，一個小小的腦子真要要想好多的事情阿。</p><p>後來才了解到，專案的邏輯歸一，讓行為變的簡單，是能讓你馬上理清楚問題所在的唯一途徑。</p><p>在商業邏輯中對應到你的專案，一定會有重複 or 共用的地方，如果是常常在不同的地方放著一樣的邏輯，未來的你一定也會討厭過去的你。</p><blockquote>能共用的就共用，不能共用的就不要勉強共用</blockquote><p>之前也是為了要寫一個 component ，但是因為沒思考好它真正的用途，所以就一直加了很多的判斷，看起 component 好像很強大，不過裡面的邏輯亂到一個不行，還為了迎合一些特別的狀態加入了一些，未來的我一定看不懂的邏輯。</p><p>這個專案結構也會因為所使用的不同技術，而有很大的差別。那 nuxt 是一個己經把大部分的結構作出來的一個框架，你只需要去遵循基本就不會差到那裡去，但是 vue 和 angular 就不是這樣子了，一個空空的骨架，需要一一的去建立。</p><h3>單一且簡單的開發邏輯</h3><p>前端的開發基本是看著 UIUX 的規格來去開發，所以會看行為也是一門大學問，有沒有辦法在一開始的時候就發現，未來開發上可能會遇到的坑。</p><h3>Server Side Render</h3><p>這一切的一切都是 SEO 惹得禍，為了可以被爬蟲找到，我們了解 header 中的屬性，還有需要把畫面作 cache ，或著完成一個高效的 SSR 。</p><p>現在的前端開發，已不在只有 html, css, javascript 和框架，還多包含的效能和 SEO 的問題，效能的問題也包含了 render 的速度，可否在第一時間讓使用者使用，那這個往往就會牽扯的到 server 端，現在 node 作為 server ，那一個前端框架不用 node ，所以了解 node 也變成了前端必需要知道的常識之一了。</p><blockquote>我的老天鵝阿，阿不就是全端了嗎？</blockquote><p>你要這樣子想也不是錯，但是 backend 也是有很多 backend 要去處理的事情，術業有專攻，前端主要還是會放在 render 效能和畫面上的處理。</p><p>總之來說…</p><p>code 最寫越覺得自己知道的很有限，但自己是頭都洗下去了，己無法回頭了</p><blockquote>code 海無邊，回頭找不到岸</blockquote><p>不過這路上，還是遇到不錯導師和朋友，開發的路上才不會覺得孤獨，有時候時間的壓力，和寫不出功能的時候，真的是壓力山大阿。所以人生在世一定要有幾位，大師級的朋友為你support ，這路才走的下去阿，如果真的不行的話，還有一句話一定要聽進去。</p><blockquote>「天下無難事，只要肯放棄」</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*YM9sH9EoHlmy2F4_u5pANw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*f21jrNqQgMj5RLb9G9HIOg.png" /></figure><p>有時候寫不出來的時候，不是你的問題，是你累了。你需起來走一走，睡個覺，講個廢話笑一笑，此時在回來看，你會發現你不小心 lose 了什麼重要的東西，然後這個坎就過了，所以結論就是…</p><blockquote>「 code 要寫的好，覺要睡的飽阿 ~~」</blockquote><p>這什麼結論…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6dfc3096260" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>