<?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[Hybrid Maker - Medium]]></title>
        <description><![CDATA[小小前端工程師一路走來的一些紀錄 - Medium]]></description>
        <link>https://medium.com/hybrid-maker?source=rss----40feaab634ec---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Hybrid Maker - Medium</title>
            <link>https://medium.com/hybrid-maker?source=rss----40feaab634ec---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 00:34:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/hybrid-maker" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[關於 mac m2 使用 libnfc 遇到的一些問題解決方式]]></title>
            <link>https://medium.com/hybrid-maker/%E9%97%9C%E6%96%BC-mac-m2-%E4%BD%BF%E7%94%A8-libnfc-%E9%81%87%E5%88%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E5%95%8F%E9%A1%8C%E8%A7%A3%E6%B1%BA%E6%96%B9%E5%BC%8F-c24495ef0734?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/c24495ef0734</guid>
            <category><![CDATA[libnfc]]></category>
            <category><![CDATA[pn532]]></category>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Mon, 20 Nov 2023 03:29:01 GMT</pubDate>
            <atom:updated>2024-08-21T13:56:39.709Z</atom:updated>
            <content:encoded><![CDATA[<p>文章學術用途</p><p>原本我使用 brew install libnfc 可以正常存下 mfd 檔案，但是寫卡的時候，無法寫入全部扇區，<a href="https://github.com/nfc-tools/libnfc/issues/564">https://github.com/nfc-tools/libnfc/issues/564</a></p><p>brew uninstall libnfc 移除以後自己 compile.</p><p>clone repository https://github.com/nfc-tools/libnfc 的 commit: 1f77bcec1775e4dc39fada1454e54e873505248f再自己 compile 就可以正常寫入</p><pre>autoreconf -vis<br>./configure<br>sudo make<br>sudo make install</pre><pre>sudo mkdir -p /usr/local/etc/nfc/devices.d<br>sudo vi /usr/local/etc/nfc/libnfc.conf</pre><pre>allow_autoscan = true<br>allow_intrusive_scan = true</pre><p>寫入的方式原本參考網路寫參數要用 w 但是後來試過要用大寫的 W 才可以寫入卡片 ID</p><pre>sudo nfc-mfclassic W a u ./mycard.mfd</pre><p>希望這篇文章可以幫助遇到相同困難的人</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c24495ef0734" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/%E9%97%9C%E6%96%BC-mac-m2-%E4%BD%BF%E7%94%A8-libnfc-%E9%81%87%E5%88%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E5%95%8F%E9%A1%8C%E8%A7%A3%E6%B1%BA%E6%96%B9%E5%BC%8F-c24495ef0734">關於 mac m2 使用 libnfc 遇到的一些問題解決方式</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[vscode terminal 找不到 node 命令的解決方式]]></title>
            <link>https://medium.com/hybrid-maker/vscode-terminal-%E6%89%BE%E4%B8%8D%E5%88%B0-node-%E5%91%BD%E4%BB%A4%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E5%BC%8F-bfc9b8bb0808?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/bfc9b8bb0808</guid>
            <category><![CDATA[nvm]]></category>
            <category><![CDATA[vscode]]></category>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Mon, 30 Mar 2020 03:15:10 GMT</pubDate>
            <atom:updated>2020-03-30T03:15:10.351Z</atom:updated>
            <content:encoded><![CDATA[<p>原本我的 node 是用 brew 安裝的，另外我也有使用 nvm安裝不同版本的 node，這在我的 bash 命令列裡面是正常使用不相沖的，某天我把 brew 所安裝的 node 移除以後，只剩下 nvm 的 node，這時候就出現了一些問題</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*_IjkNzL3RnY4Qq5TrNe2TQ.png" /><figcaption>在 bash 命令裡面可以正常列出 nvm 所安裝的 node</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qfaoYMkTrlBPD7ExZxUzzQ.png" /><figcaption>在 vscode 裡面 node: command not found</figcaption></figure><p>在 bash 可以正常使用 node 命令，可是卻在 vscode 裡面無法找到，解決方法後來去參考了 vscode github issue #48576</p><p><a href="https://github.com/Microsoft/vscode/issues/48576#issuecomment-388623859">Integrated terminal does not see Node from NVM · Issue #48576 · microsoft/vscode</a></p><p>在 vscode 的 setting.json 裡面加入一行，解決了！</p><pre>&quot;terminal.integrated.shellArgs.osx&quot;: []</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IFiVqMYYPy22zCjFvMrI5w.png" /><figcaption>現在可以正常使用 node 命令</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfc9b8bb0808" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/vscode-terminal-%E6%89%BE%E4%B8%8D%E5%88%B0-node-%E5%91%BD%E4%BB%A4%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E5%BC%8F-bfc9b8bb0808">vscode terminal 找不到 node 命令的解決方式</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[為什麼 [1, 7, 11].map(parseInt) 會回[1, NaN, 3]？]]></title>
            <link>https://medium.com/hybrid-maker/%E7%82%BA%E4%BB%80%E9%BA%BC-1-7-11-map-parseint-%E6%9C%83%E5%9B%9E-1-nan-3-6ce698c75de?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/6ce698c75de</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Fri, 26 Jul 2019 01:01:55 GMT</pubDate>
            <atom:updated>2019-07-26T01:01:55.429Z</atom:updated>
            <content:encoded><![CDATA[<p>為什麼 [1, 7, 11].map(parseInt)會回[1, NaN, 3]？</p><p>我們先了解究竟 map 裡面做了什麼事情</p><pre>var new_array = arr.map(function callback(currentValue[, index[, array]]) {<br>    // Return element for new_array<br>}[, thisArg])</pre><p>callback為產生新陣列之元素的回呼函式，可傳入三個參數：</p><ol><li>currentValue原陣列目前所迭代處理中的元素。</li><li>index選擇性原陣列目前所迭代處理中的元素之索引</li><li>array選擇性呼叫 map 方法的陣列。</li></ol><p>轉換之後會變成下面這樣</p><pre>parseInt(1, 0, [1, 7, 11]);<br>parseInt(7, 1, [1, 7, 11]);<br>parseInt(11, 2, [1, 7, 11]);</pre><p>看出端倪了嗎？</p><p>在了解一下 parseInt 所需要的參數</p><pre>parseInt(<em>string</em>, <em>radix</em>);</pre><ol><li>string待轉成數字的字串。若 string 參數類型不是字串的話，會先將其轉成字串（相當於先執行 <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-tostring">ToString</a> 再執行 parseInt）空白值會被忽略。</li><li>radix從 2 到 36，能代表該進位系統的數字。例如說指定 10 就等於指定十進位。<strong>一定要定義這個參數</strong>以避免他人的困惑、也好預估函式的行為。如果沒有指定 radix 的話，給出的結果會按照實做不同而異，請注意，通常預設值<strong>不是</strong> 10 進位。</li></ol><pre>parseInt(1, 0, [1, 7, 11]);</pre><p>因為第二個參數給 0 會預設當成 false, 系統自動十進位，所以產生答案是 1</p><pre>parseInt(7, 1, [1, 7, 11]);</pre><p>由於沒有 1 進位，所以答案會是 Nan</p><pre>parseInt(11, 2, [1, 7, 11]);</pre><p>11 的二進位代表的就是 3</p><h3>總結</h3><p>如果要用 parseInt 放進 map 裡面可以改用下面兩種寫法</p><pre>[1, 7, 11].map(Number);</pre><pre>[1, 7, 11].map(d=&gt;parseInt(d));</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ce698c75de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/%E7%82%BA%E4%BB%80%E9%BA%BC-1-7-11-map-parseint-%E6%9C%83%E5%9B%9E-1-nan-3-6ce698c75de">為什麼 [1, 7, 11].map(parseInt) 會回[1, NaN, 3]？</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to move Mac’s Dock position by command line]]></title>
            <link>https://medium.com/hybrid-maker/how-to-move-macs-dock-position-by-command-line-83bb9f47363f?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/83bb9f47363f</guid>
            <category><![CDATA[preference]]></category>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[dock]]></category>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Wed, 29 May 2019 00:55:06 GMT</pubDate>
            <atom:updated>2019-05-29T00:55:06.020Z</atom:updated>
            <content:encoded><![CDATA[<p>By default, you can move your mac’s Dock position by preference window, but use command line is much quick.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*1_X5IU4D_TzcxTT7JY19Tw.png" /></figure><pre># move to bottom<br>defaults write com.apple.dock orientation bottom</pre><pre># move to left<br>defaults write com.apple.dock orientation left</pre><pre># move to right<br>defaults write com.apple.dock orientation right</pre><pre>#restart Dock<br>killall Dock</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83bb9f47363f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/how-to-move-macs-dock-position-by-command-line-83bb9f47363f">How to move Mac’s Dock position by command line</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[React Native] 微軟的 App Center 超好用，無痛 CI/CD]]></title>
            <link>https://medium.com/hybrid-maker/react-native-%E5%BE%AE%E8%BB%9F%E7%9A%84-app-center-%E8%B6%85%E5%A5%BD%E7%94%A8-%E7%84%A1%E7%97%9B-ci-cd-a46b8cdea9bc?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/a46b8cdea9bc</guid>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Mon, 13 May 2019 14:41:05 GMT</pubDate>
            <atom:updated>2019-05-13T14:40:28.511Z</atom:updated>
            <content:encoded><![CDATA[<p>投誠了微軟的 <a href="https://appcenter.ms/">App Center</a> 懷抱，真的是好用到不行，零設定就能跑，比起以往的 jenkins / travis / gitlab-ci 還方便，不過因為 App Center 只針對 APP 做持續整合，如果是網頁專案或是後端專案還是用上面那三種。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EyfRQYUFhgd8w5G3" /><figcaption>Photo by <a href="https://unsplash.com/@danielkorpai?utm_source=medium&amp;utm_medium=referral">Daniel Korpai</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>我先解釋一下持續整合 / 持續佈署</h3><h3>持續整合</h3><p>我們寫完code 推送到 git 上面以後，會有一台機器自動去拉 code 下來，跑測試，執行 build 指令，然後告訴我們有沒有問題，這一連串我們叫持續整合。</p><h3>持續佈署</h3><p>承接著持續整合，這台機器自動 build 出 production 的檔案之後，可以自動幫我們佈署到線上的機器，這就是持續佈署。</p><p>App Center 就可以幫我們做持續整合，持續佈署，而且提供了很多方便的功能</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*MPLS0Prhl2MJa788Qc0qAg.png" /></figure><p>原本我是使用 travis 要定義 yml，打錯一行就要偵錯很久，但是 App Center 不用打 yml ，只要勾選一些選項就可以開始 build 了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*JRBPpusB6n9lyBt0syElCA.png" /></figure><p>他還可以看實際手機安裝完啟動要消耗多少記憶體</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*WuwaG1sVilRM3rrbvNUD7g.png" /></figure><p>還有統計功能，類似 GA 。</p><p>還有一些功能我還沒有玩到，像是 push notification , code push, 自動上架等等…</p><p>打這篇文章純粹是因為我覺得太好用了想讓大家知道！ 也沒有想要深入寫，所以有興趣的就自己去研究吧！！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a46b8cdea9bc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/react-native-%E5%BE%AE%E8%BB%9F%E7%9A%84-app-center-%E8%B6%85%E5%A5%BD%E7%94%A8-%E7%84%A1%E7%97%9B-ci-cd-a46b8cdea9bc">[React Native] 微軟的 App Center 超好用，無痛 CI/CD</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 npm version 幫你的 js 程式打版號]]></title>
            <link>https://medium.com/hybrid-maker/%E4%BD%BF%E7%94%A8-npm-version-%E5%B9%AB%E4%BD%A0%E7%9A%84-js-%E7%A8%8B%E5%BC%8F%E6%89%93%E7%89%88%E8%99%9F-48234d0e8020?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/48234d0e8020</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[npm]]></category>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 13:55:13 GMT</pubDate>
            <atom:updated>2018-12-05T13:55:13.451Z</atom:updated>
            <content:encoded><![CDATA[<p>剛接觸程式設計的時候歡天喜地的幫自己剛寫好的程式命名了第一個版本號 v12.0 ，後來才發現自己多傻，竟然沒有好好了解怎麼打版號，直到現在又發現自己多傻，竟然不會用 npm version 自動打版號…</p><h3>先介紹一下JS圈主流的版本命名方式</h3><p><a href="https://semver.org/lang/zh-TW/">語意化版本 2.0.0</a></p><p>通常我們定義版本會用3個數字來定義 1.23.456 像是這樣3個數字，最前面的 1 代表<em>主版號</em>， 23 代表<em>次版號</em>， 456 代表<em>修訂號</em>。</p><p>假設你今天寫好了一個穩定的工具集，裡面有一些模組可以給別人使用，我們會定義初始版本號為 1.0.0 作為一個美麗的開始。</p><p>當你又多寫了一個模組加入這個工具集，功能上的提升，不會影響到原本的使用方式，我們就可以增加次版號變成 1.1.0 。</p><p>當使用者回報你有功能故障，你修正了之後，我們會增加修訂號變成 1.1.1 。</p><p>如果今天你有把一些功能砍掉或是改版，原本的使用方式改變了，那就要往前進一個主版號了也就是變成 2.0.0 。</p><h3><strong>怎麼用 npm version 自動打版號？</strong></h3><p>一開始用 npm init 指令建立 package.json 之後會紀錄如下，當然別忘記使用 git init 將專案資料夾列入版控。</p><pre>{<br>  &quot;name&quot;: &quot;npm_version_tut&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;<br>}</pre><p>隨著專案的推進，我們可能寫了一些模組</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*hVcMq8d_Mormvc8aL3w-gA.png" /></figure><p>我們想要進次版號了，就可以透過 npm 的指令輸入</p><pre>npm version minor</pre><p>這時後 npm 就會自動幫我們的 package.json 版本提升次版號，並且幫我們的 git 打 tag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*EQCMm629a1d80WE9uq71bg.png" /></figure><p>我們可能會修正 bug 就會輸入</p><pre>npm version patch</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*3fHtLVzHmKvDRP7WxkdI0w.png" /></figure><p>如果要提升主版號就可以輸入</p><pre>npm version major</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*F26rHROwNsT3EotHS7Dtxg.png" /></figure><h3>總結</h3><p>使用 npm version 打版號很方便，除了我講的3個參數指令之外 npm version 還有其他的參數可以下。版本命名這個議題除了我貼的語意式命名之外還有很多種方式，像是我有遇過公司用日期來當作版本號的。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48234d0e8020" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/%E4%BD%BF%E7%94%A8-npm-version-%E5%B9%AB%E4%BD%A0%E7%9A%84-js-%E7%A8%8B%E5%BC%8F%E6%89%93%E7%89%88%E8%99%9F-48234d0e8020">使用 npm version 幫你的 js 程式打版號</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[試玩一下 Nodejs 10.5.0 Worker Threads]]></title>
            <link>https://medium.com/hybrid-maker/%E8%A9%A6%E7%8E%A9%E4%B8%80%E4%B8%8B-nodejs-10-5-0-worker-threads-a6ac7c6dfb8a?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/a6ac7c6dfb8a</guid>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Mon, 25 Jun 2018 09:34:18 GMT</pubDate>
            <atom:updated>2018-06-25T13:05:14.476Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6hXo1zrkjp4zbzp7" /><figcaption>“Spools of white cotton threads on a machine in a factory in Rydal.” by <a href="https://unsplash.com/@thepootphotographer?utm_source=medium&amp;utm_medium=referral">Janko Ferlič</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>最近 Node 發表了新的版本 10.5.0 支持了 worker threads 的技術，於是我就來玩看看！簡單介紹一下這個功能，node 預設在執行的時候只會跑單一執行緒，所以你有四核心的電腦，開了一個 node 的 server ，只會同時跑一個核心，目前來說都是用 cluster 這個功能把程式依照 cpu 的數量 fork 出來，worker 跟 cluster 比較不太像，他比較像是把要複雜處理的程式單獨抽出來成為一個執行緒，體積比較小，那我們就來看看範例。</p><blockquote>worker threads 是還在實驗中的功能，所以我不確定以後會不會被拿掉</blockquote><h3>簡單的 worker 範例</h3><p>我先做了一個主程式 index.js，他會透過建立一個 worker 並且聽取 worker 回傳的 message 做顯示</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/807539c7d5cb469d5a42316549aa951d/href">https://medium.com/media/807539c7d5cb469d5a42316549aa951d/href</a></iframe><p>另外做了一隻 worker.js 他會負責處理一些複雜邏輯</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ca6fe0b42c28e4e938be1611e0aa32f/href">https://medium.com/media/6ca6fe0b42c28e4e938be1611e0aa32f/href</a></iframe><p>首先要確定你的 node js 版本為 10.5.0，執行程式由於是實驗性質的功能，所以我們要在執行的指令上面加入 flag 變成這樣 node --experimental-worker index.js 程式才可以正常被執行，執行之後產生出結果為這樣。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*u1WB5uMH_5TFSlIb2Oe-jw.png" /></figure><h3>WorkerData 傳入預設數值</h3><p>worker 有一個功能就是可以給予 workerData 不同的數值在每個 worker 裡面，變成每個 worker 都可以給予預設參數，我們做了兩隻 worker ，第一個 worker 每次遞增 1 ， 第二個 worker 每次遞增 10</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a50ba5da756a2bd318c5477aa66b6683/href">https://medium.com/media/a50ba5da756a2bd318c5477aa66b6683/href</a></iframe><p>worker.js 裡面取得 workerData 的方式是透過 require，如下方範例</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1b6b36fc040275b83535fdf700039ad/href">https://medium.com/media/f1b6b36fc040275b83535fdf700039ad/href</a></iframe><p>執行出來的結果如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*p8MNe5SQHDoO8tNiZaJoBQ.png" /></figure><h3>postMessage 溝通</h3><p>我們可以透過 postMessage 從 main thread 傳送訊息到 worker 裡面，這跟瀏覽器的 web worker 使用方式一樣。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efc37d4a8eb2902c1eb96f35cd6dd306/href">https://medium.com/media/efc37d4a8eb2902c1eb96f35cd6dd306/href</a></iframe><p>而 worker 則是透過 parentPort 來接收跟傳送訊息回去</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7dacdc3cd66cb0900d9a5247b374f806/href">https://medium.com/media/7dacdc3cd66cb0900d9a5247b374f806/href</a></iframe><p>執行結果就如同以下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*eX7IPWOO6jfJDM-duM0wuA.png" /></figure><h3>並行提升執行效能</h3><p>我現在來做一個範例，產生兩百萬筆亂數的 sha256 編碼，如果使用單一執行緒的方式來寫會是這樣</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8d52c4c31076c92661796d853abfe98/href">https://medium.com/media/b8d52c4c31076c92661796d853abfe98/href</a></iframe><p>所耗費的時間為 10376 ms</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*wFTqlYsoPAmg9HRwcahClQ.png" /></figure><p>而把兩百萬筆資料平均分配給 4 個執行緒去執行呢？</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e88f2e0bc56b3958dad7489b9103f31/href">https://medium.com/media/4e88f2e0bc56b3958dad7489b9103f31/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f0d9656234f04373fcbd7c069dda640/href">https://medium.com/media/3f0d9656234f04373fcbd7c069dda640/href</a></iframe><p>全部完成的時間是 5676 ms，所以適當的時機使用 worker threads 可以提升效能</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*9TKaRuj95rx1-da3RJIB2A.png" /></figure><h3>Threads 共享記憶體</h3><p>cluster 不能夠共享記憶體，所以我們通常會把資料存在 db 或是 file 來讓每個 cluster 取用，但是 worker-threads 每個 threads 可以跟 main thread 共享 SharedArrayBuffer 的資訊，意思就是當我 postMessage 的時候不用在拷貝一次記憶體了，這樣不僅減少記憶體的用量，也提高了速度，但是缺點就是不是很方便使用，畢竟轉換成 SharedArrayBuffer 比較麻煩。</p><p>請看這個範例，當 worker 告訴我成功的時候，我直接拿取 main thread 裡面的數值，而結果顯示了 worker 的確修改了共用的記憶體。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a411d44efbce64f75c1da1cadb0e5e43/href">https://medium.com/media/a411d44efbce64f75c1da1cadb0e5e43/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90c2b7eec168320e0f64c44c5bf7b45a/href">https://medium.com/media/90c2b7eec168320e0f64c44c5bf7b45a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*0JWbA22DvX2lfMn914pnxA.png" /></figure><h3>總結</h3><p>比起 cluster ， worker_threads 可以讓我把一些複雜的邏輯抽開獨立，不過我唯一可以想到的使用情境是在資料科學跟機器學習。node 總算可以把全部的 cpu 拿來運並且分享記憶體位置了 😄 ，另外就是官方有講到不要在 worker 裡面做 I/O 的事情。這點要謹記。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6ac7c6dfb8a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/%E8%A9%A6%E7%8E%A9%E4%B8%80%E4%B8%8B-nodejs-10-5-0-worker-threads-a6ac7c6dfb8a">試玩一下 Nodejs 10.5.0 Worker Threads</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[初學者學習神經網路該怎麼下手？]]></title>
            <link>https://medium.com/hybrid-maker/%E5%88%9D%E5%AD%B8%E8%80%85%E5%AD%B8%E7%BF%92%E7%A5%9E%E7%B6%93%E7%B6%B2%E8%B7%AF%E8%A9%B2%E6%80%8E%E9%BA%BC%E4%B8%8B%E6%89%8B-e9957c12ab57?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/e9957c12ab57</guid>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Wed, 06 Jun 2018 03:41:12 GMT</pubDate>
            <atom:updated>2018-06-11T01:38:41.829Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ebOvmf9IC_ngfPB1" /><figcaption>Photo by <a href="https://unsplash.com/@pietrozj?utm_source=medium&amp;utm_medium=referral">Pietro Jeng</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>最近接觸到深度學習想來挑戰看看 tensorflow.js(後面我都簡稱 tfjs) ，可是看了看 api 卻不得其門而入，仔細思考一下，我在讀書的時候沒有修過神經網路這門課程，所以導致我看不懂 tfjs 的 example，於是我開始搜尋網路想要了解這個奧秘，如果你剛好也是新手，也剛好想要踏入深度學習的路，可以參考看看我的學習過程。</p><h3>講到深度學習</h3><p>深度學習是一種複雜的演算方式，用來分析或是預測資料，可以用在影像辨識，語意分析等等，深度學習比較常見的演算法就是神經網路了，所以想要入門深度學習，建議學一下神經網路。</p><h3>神經網路</h3><p>大部分的人都跟我一樣，把神經網路(Neural Network)放到了 google 搜尋上面，可是都看不懂在講什麼，因為大部分的神經網路找到的資料都像是下面這張圖一樣，畫了一些圓點跟箭頭，我們根本就不知道在講什麼。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*ko-qT7uddK-a0tBD.png" /></figure><p>要理解神經網路，就必須從最小的一個神經元講起，神經元其實很簡單，會有一些外在的刺激，但是根據權重的分配，神經元就會對敏感的資訊做輸出，我是透過下面這個影片理解神經的基本結構。</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLQn99bzkJv9wxnnU3nfuFm1MtWDbtps0P&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DGRNfP06v7dQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FGRNfP06v7dQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/040e38b96ce47f10b11f7a9d817569f0/href">https://medium.com/media/040e38b96ce47f10b11f7a9d817569f0/href</a></iframe><p>在看影片的時候呢你會不知道他講的 b 是什麼，這個 b 就是 bias ，代表一個偏執變數，在下面這個影片就會講解 b 的作用，以及我們為什麼要用到 b。</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FncGxjgiq1Kw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DncGxjgiq1Kw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FncGxjgiq1Kw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6532395aa6b2fefcf59f44abe26090bf/href">https://medium.com/media/6532395aa6b2fefcf59f44abe26090bf/href</a></iframe><h3>多層的神經網路</h3><p>並不是所有的預測我們都能夠用一個簡單的神經元計算出來，我們必須要串聯這些神經元來達到更複雜的思考，隱藏層的數量多，我們所能分類的方式就可以比較多變化。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*yQDs-BBao-XY0xRC.png" /></figure><p>我們會把神經網路分成輸入層，隱藏層，輸出層，要怎麼決定隱藏層要有幾個神經元？看個人喜好但是還是有學者提出了建議的數量。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*F8hkyO9wWSCs_BAJX956_w.png" /></figure><h3>怎麼訓練神經網路？</h3><p>通常這些權重跟偏直的變數我們都會給一個0~1亂數，在訓練的時候，我們會給程式 input 跟 answer 讓程式自己去思考這些w&amp;b 要怎麼去調配，透過每次訓練來找到最能夠符合我們期望的參數。至於學習的部份 tfjs 已經幫我們處理好了，我們只要把要訓練的題目以及答案放入學習，接著 tfjs 就會去自動幫我們調整權重，以及 bias 等等資訊。</p><p>tfjs 為我們提供了很多種訓練的方式，例如 sgd (Stochastic gradient descent)，這些演算法會在我們提供的正確答案，與預測出來的答案之間去算出參數應該要填什麼。</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9sJG7LjGCnI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9sJG7LjGCnI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9sJG7LjGCnI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/abfeb1ecb8a0a3955608b74e186aeff3/href">https://medium.com/media/abfeb1ecb8a0a3955608b74e186aeff3/href</a></iframe><h3>損失函數( loss function )</h3><p>損失函數用來預估目前預測出來的答案跟真正的答案之間不一致的程度，我們在訓練的時候會不斷的讓我們的 model 來預測，把預測出來的答案跟正確答案送進損失函數內進行評估，這個損失函數會回傳一個不為負數的數值，當數值越接近 0 的時候，表示我們預測的結果越接近正確答案了。</p><h3>總結</h3><p>我儘量挑選了很多我看過的影片並且覺得有用又簡單的部份來做分享，如果你看完以後對深度學習有興趣，可以去看台大李宏毅教授的影片，以上這些分享都是學習神經網路的觀念，實際上還要把觀念應用到 tfjs 上面才有用，目前網路上 tfjs 的範例資料很少，預計接下來有時間再與大家分享一些 tfjs 的心得。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9957c12ab57" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/%E5%88%9D%E5%AD%B8%E8%80%85%E5%AD%B8%E7%BF%92%E7%A5%9E%E7%B6%93%E7%B6%B2%E8%B7%AF%E8%A9%B2%E6%80%8E%E9%BA%BC%E4%B8%8B%E6%89%8B-e9957c12ab57">初學者學習神經網路該怎麼下手？</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[用破解小遊戲的方式來學習 js Debug]]></title>
            <link>https://medium.com/hybrid-maker/%E7%94%A8%E7%A0%B4%E8%A7%A3%E5%B0%8F%E9%81%8A%E6%88%B2%E7%9A%84%E6%96%B9%E5%BC%8F%E4%BE%86%E5%AD%B8%E7%BF%92-js-debug-544b3433d40e?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/544b3433d40e</guid>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Fri, 11 May 2018 05:56:33 GMT</pubDate>
            <atom:updated>2018-05-11T05:56:33.253Z</atom:updated>
            <content:encoded><![CDATA[<h4>了解怎麼錄製頁面效能，監聽 Dom 變化，以及如何發送假的滑鼠事件</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*27QmB5hWhUqzK0DS." /><figcaption>Photo by <a href="https://unsplash.com/@chillarea?utm_source=medium&amp;utm_medium=referral">sebastiaan stam</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>從在讀書的時候，我就對於破解遊戲有著充分的興趣，我的寫程式的思維也大都是從破解遊戲的時候被啟發。最近同事給了我一個連結，<a href="https://www.humanbenchmark.com/tests/reactiontime/">https://www.humanbenchmark.com/tests/reactiontime/</a>，這是一個用來測驗反應力的遊戲，當畫面變成綠色的時候，就點下畫面，這時候就會顯示你的反應時間毫秒，我一直無法超過同事的紀錄，所以…..let’s Cheat it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*cufKYkVnq_zA61gXhda3qA.gif" /></figure><h3>要用哪個事件？</h3><p>對於點擊的遊戲，我會先想要得知哪種滑鼠的事件會讓js觸發，例如有的遊戲可以用 click 但是有的遊戲卻是監聽 mouseDown mouseUp 的事件，那要怎麼知道他是監聽哪個事件？我會建議使用錄製 performance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*dA9cq-eouQbDyOopNQuYLQ.png" /></figure><p>錄製完之後我們就可以知道，這個遊戲要觸發並不是使用 click 事件，而是 mouseDown 事件，我們就可以用模擬的方式產生一個滑鼠按下的事件。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3df1ee64ff2b8be461468b8730bdd2d/href">https://medium.com/media/c3df1ee64ff2b8be461468b8730bdd2d/href</a></iframe><h3>用在哪個DOM？</h3><p>點錯地方就沒有用了，所以要找到哪個元件才是接收 mouseDown 事件的監聽者，你可以一個一個找，但是我推薦使用 chrome 裡面的 EventListener 來找，找到之後你就會看到如下。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UXBenGPJ4AmCSrmgLwrYXg.png" /></figure><h3>點擊的時機？</h3><p>我們實際玩了幾次遊戲，順便觀察剛剛找到的 DOM ，畫面綠色的時候 class 名稱會更改為 view-go ，所以我們就可以確定時機，一切準備都完成了我們就可以來破解了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WWcHFerdgn5IBezFv59eyw.png" /></figure><h3>怎樣效率才好？</h3><p>你可以寫一個 for 迴圈來檢查，但是我不推薦這樣，會把執行緒卡死，你或許也會想用 setInterval 每一百毫秒來檢查，但是這樣效能會慢，也許你最終會找到一個方法叫做 requestAnimationFrame 但是成績就止步於 1Xms，我們要讓成績維持在 10ms 內就要再下一個苦工，就是使用 MutationObserver 。這是一個比較新的瀏覽器 API 可以讓你偵測 DOM 的變動，效率好。把我們剛剛的東西都合起來就會寫了一隻 code 如下。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/500f59b9a531d360aeb682c353838648/href">https://medium.com/media/500f59b9a531d360aeb682c353838648/href</a></iframe><h3>總結</h3><p>透過破解遊戲的方式學會 chrome 的 debug 以及 js 怎麼發送事件，怎樣透過 MutationObserver 來監聽 dom 事件，一舉數得，實作的結果就如下圖，我本來想放動畫，可是太大了，只好放圖，大家如果有效率更快的方式也歡迎留言告訴我。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*CjNwiXCLUYh6hgby1rJ8FQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=544b3433d40e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/%E7%94%A8%E7%A0%B4%E8%A7%A3%E5%B0%8F%E9%81%8A%E6%88%B2%E7%9A%84%E6%96%B9%E5%BC%8F%E4%BE%86%E5%AD%B8%E7%BF%92-js-debug-544b3433d40e">用破解小遊戲的方式來學習 js Debug</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker 怎樣都砍不掉的一個 container]]></title>
            <link>https://medium.com/hybrid-maker/docker-%E6%80%8E%E6%A8%A3%E9%83%BD%E7%A0%8D%E4%B8%8D%E6%8E%89%E7%9A%84%E4%B8%80%E5%80%8B-container-7305227b3e21?source=rss----40feaab634ec---4</link>
            <guid isPermaLink="false">https://medium.com/p/7305227b3e21</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Hyman Chen]]></dc:creator>
            <pubDate>Wed, 14 Mar 2018 07:29:02 GMT</pubDate>
            <atom:updated>2018-03-14T07:29:02.447Z</atom:updated>
            <content:encoded><![CDATA[<p>今天遇到了一個問題，有個 container(67c) 無論如何都無法被砍掉，我簡單介紹一下情況如下，我們的機器是虛擬機，要靠 ssh 連進去，裡面裝了 docker，跑了一個服務，但是遇到了一個問題</p><pre>docker rm -f 67c</pre><p>當下了這行指令的時候，整個 ssh 連線都中斷了，連 docker service 也停掉了，同事後來找到一個<a href="https://segmentfault.com/q/1010000005846603">方法</a>，把整個資料夾砍掉</p><pre>sudo service docker stop<br>sudo rm -rf /var/<strong>lib</strong>/<strong>docker</strong><br>sudo service docker start</pre><p>以上，解決了～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7305227b3e21" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hybrid-maker/docker-%E6%80%8E%E6%A8%A3%E9%83%BD%E7%A0%8D%E4%B8%8D%E6%8E%89%E7%9A%84%E4%B8%80%E5%80%8B-container-7305227b3e21">Docker 怎樣都砍不掉的一個 container</a> was originally published in <a href="https://medium.com/hybrid-maker">Hybrid Maker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>