Skip to main content

Tuning for my daily Elementary OS Juno

· 2 min read

I've been use Elementary OS as my primary laptop OS over a year and have been written some posts for it. I Upgraded to Elementary OS Juno at December last year. Juno is based on Ubuntu 18.04, the experience is very positive. Most things works fine and not much things need to tune for daily usage.

Here's my setup for my Dell XPS 13-9360 laptop.

1. Package installer

  1. Insatll Eddy on AppCenter instead of sudo apt install gdebi
  2. install essentials
sudo apt install software-properties-common git

## 2. Setup Fonts

$ apt instsall firacode

3. Bluetooth, Touchpad and Mouse

The Bluetooth connectoin is basically stable. No need for extra setup.

To make right click works for Touchpad, go Settings > Mouse & TouchPad, select from MultiTouch to TouchPad in Physical Click section.

To use logitech mouse with unifying USB dongle, you can do sudo apt install solaar solaar-gnome3 and there will be solaar-cli command line tool and the GUI tool available.

To customize the extra buttons in mouse, install xbindkeys

sudo apt-get install xbindkeys xautomation x11-utils

Then create the config file using xbindkeys --defaults > $HOME/.xbindkeysrc.

4. Saving Power

tlp is a good tool for auto power management and now it can be installed through the default repo.

sudo apt-get install tlp
sudo tlp start

5. Auto adjust color temperature

It's build-in now.

Go Settigns > Monitor > Night Light to toggle it on.

6. Chinese Input Method

Instead of configure by yourself. It's build-in now.

  1. Select Traditional Chinese during install Elementary OS.
  2. Enter System > Language & Area > Keyboard Setting > Input Method Settings.
  3. Remove all other IME except 新酷音 and it just works.

7. Tweaks

Can use elementary-tweaks to easily change system font to Noto Sans CJK TC regular instead of Open Sans

sudo add-apt-repository ppa:philip.scott/elementary-tweaks
sudo apt update
sudo apt install elementary-tweaks

Then open Tweaks in System Settigns panel.

Interact Bitfinex API with Node-RED

· 4 min read

Anticipate how API choices and abstractions impact the way other people would solve the problem

There are many ways to access Bitfinex API to get most of Bitfinex exchange functionalities. For example, you can access REST API, websocket API, or call the language specific API library to eaze the interaction efforts. But in my opinion interact via Node-RED Bitfinex function block is the most easiest one.

Getting start with Node-RED and Bitfinex API

To get start, you can

  1. install Node-RED npm install -g node-red.
  2. Start Node-RED via node-red command, then go settings > Palette > Install tab in node-red
  3. search bitfinex to install this module.

Interact with Node-RED

Node-RED is a great way to interact with everything online, with a more intuitive interface.

To simplify the interaction with Bitfinex, I wrapped the Bitfinex function block for Node-RED, which makes bitfinex API very easy to access in Node-RED. You can visually show exchange data in node-red's dashboard, mashup with other services, or trade from weird objects around your house.

For example, you can follow the screenshot to make below REST API work.

Access websocket API is very simple as well

You can use configuration block to put your apiKey and apiSecret.

Visualize data with Node-RED dashboard

Once you got the data via bitfinex function block, it's pretty easy to visualize value and diagram with Node-RED dashboard

One more thing

You may not know the tickers api allow query multiple symbols at once, like rest.tickers(['tETHUSD', 'tBTCUSD']) and this functoin block supports multiple outputs as well!

If you make something interesting with Bitfinex API and node-RED, please let me know! (You can share to https://github.com/gasolin/node-red-contrib-bitfinex/issues)

Other way to interact with Bitfinex API

For reference, You can learn more ways to access the Bitfinex API below.

Inreact with the REST API

We could read the API doc and find we can get the recent ETH/USD pair states via open the browser and visit https://api.bitfinex.com/v2/tickers?symbols=tETHUSD

We'll get an minimal array as the returned data. Refer to the doc we know each column means:

[
// on trading pairs (ex. tBTCUSD)
[
SYMBOL,
BID,
BID_SIZE,
ASK,
ASK_SIZE,
DAILY_CHANGE,
DAILY_CHANGE_PERC,
LAST_PRICE,
VOLUME,
HIGH,
LOW
],
]

Then we can process the array to get what we want. For example, to access the last price of ETH/USD, we could find the result from array[0][7] (The first item in returned array denotes ETH/USD result array, the 8th item(the array count from 0 so its 7) in ETH/USD result array is the LAST_PRICE)

Interact with API library

But for more complicated interaction like place an order with authenticated API, we generally prefer to call language specific library to simplify the process.

The Bitfinex official doc listed several open source language specific libraries for developers.

For example, we can use nodejs/javascript to access Bitfinex API via Bitfinex's nodejs API library

To install the library, call

$ npm install bitfinex-api-node

Then you can edit a demo.js file with content:

const BFX = require('bitfinex-api-node')
const bfx = new BFX()
const rest = bfx.rest(2)
rest.tickers(['tETHUSD']).then(tickers => {
console.log(tickers)
})

to get same result as directly call the REST API on the browser.

Though You may not know the node API build-in the data model mapping, which saves you from manually parsing the returned result.

All you need to do is pass { transform: true} parameter when access the bfx.rest method:

const rest = bfx.rest(2, { transform: true })

Then you can get value via ticker.lastPrice, ticker.high...

If you want to access authenticated APIs, just pass the apiKey and apiSecret when construct the bfx api instance.

const bfx = new BFX({
apiKey: '...',
apiSecret: '...',
})

The API call seems not hard but it did require some effort to make all works.

Disclosure: I am currently working on Bitfinex. Node-red-contrib-bitfinex is the personal project though.

用Raspberry Pi組裝一套小朋友使用的電腦

· 6 min read

之前嘗試過組裝一些智能玩具,但能讓小朋友持續保持興趣遊玩的並不多。我發現這些玩具一旦需要編程時,多少還是需準備一台電腦。與大人共用電腦多有不便,因此不如就再利用每個人家中多出的 Raspberry Pi (?) 與生灰的電子設備,幫小朋友準備好所需的相關材料,協助他組一台精簡卻堪用的電腦吧。

使用的設備列表

我參考的 BUILD(最近 Switch 上的暗黑破壞神 3 玩多了...)是KANO Computer Kit Touch套件,這是一套由專門售賣以 Raspberry Pi 為核心的教育用電腦提供商 KANO 製作的。現在整套特價在~$230 左右,相較其他的 STEM 教具,整套的價格相當合理。如果你人在美國,家中沒有冗餘的電腦設備或想追求更好的使用體驗,相當建議直接購買一套。

這邊是其他人的開箱影片評測,介紹了使用到的硬體與作業系統

以下列出我有用到的設備列表,價格是當初印象裡購入各種設備時的價錢。

  • Raspberry Pi 主版
    • 建議使用 3B 或 3B+,速度上才接近可用的電腦
    • (Raspberry Pi 3B ~NT 1450)
  • 支援 HDMI 的螢幕
    • (手邊現有的 23 吋桌面螢幕~NT 4300)
    • (打算再購買 10 吋觸控螢幕~NT 3000)
  • 播音設備
    • 沒有喇叭的話,用手機附的耳機聽也行 (但為了小朋友聽力,要用耳機也建議用耳罩式或頭戴式)
    • (手機附的耳機,~NT 0)
    • (考慮弄個手機喇叭來接~NT 100)
  • 電源
    • 可用舊手機的 Micro USB 充電線與充電頭,或任何手邊的行動電源
    • (小米行動電源 5000 ~NT 300)
  • USB 鍵盤 / 滑鼠
    • 重用任何現有的鍵鼠,如果有觸控螢幕就不用準備滑鼠
    • (可以找到帶觸控版的鍵盤~NT600, 我是拿手邊羅技 Unifying 鍵盤 / 滑鼠。)
  • Micro SD 卡 >16GB
    • (32GB SD 卡~NT400)

準備記憶卡(作業系統)

作業系統我的選擇並非常見的Raspbian,而是刷上「KANO」公司為他們販賣的套件提供的 KANO OS。KANO OS 作業系統與相關設備的說明書都有提供自由下載使用。

將 zip 檔下載下來後,將 Micro SD 卡放入轉接器並插入電腦,用任意映像檔燒錄軟體將系統燒錄進 SD 卡中備用。

組裝

由於 Raspberry Pi 把組裝電腦時複雜的部份都簡化了,組裝起來非常簡單,即使是國小小朋友也能順利完成。

  • 將 Micro SD 記憶卡插入 Raspberry Pi (對低年級小朋友來說插卡的動作太精細了,可以先幫忙做)
  • 插上鍵盤 / 滑鼠用的 USB 接收器
  • 接上 Micro USB 與電源
  • 將 HDMI 線接到螢幕上

最後連接好的架構大概是這樣:

上手體驗

雖然手邊還沒有合用的觸控螢幕可試,但即使用滑鼠鍵盤操作,感覺 KANO OS 介面也很親和。從插上記憶卡,接上 Micro USB 初次開機開始,KANO OS 將整個電腦的啟動流程,變成了一段難忘的遊戲過程。

KANO OS 除了提供 Raspbian 中也有附的 Minecraft 等遊戲和各種教育應用,還提供了一套將電腦教學與各種小遊戲 / 程式整合成的像素 RPG。

使用者在電腦設備化成的地圖中行走,初次進入地點是在 SD 沙灘 (SD Beach),可前往向量村(Vector Village),網路港 (Port Ether),蟒蛇叢林 (Python Jungle) 等地,探索電腦世界的奧秘。

在 SD 沙灘上,馬上可以玩到PONG這個在電子遊戲歷史中,也具有非凡意義的經典遊戲。

走到向量村則是玩Make Art遊戲,可以用鍵盤輸入程式命令來繪圖。KANO 近期特別活動是畫骷髏頭 (Skull) 等萬聖節相關圖案,整個過程都可照著一個步驟一個步驟輸入的提示進行,相當友善。

到了蟒蛇叢林,則是從使用命令行開始玩起。透過輸入python snake命令來啟動文字版貪食蛇遊戲:過程中會提示使用者可以在輸入命令時加入一些參數,加入參數後遊戲的設定也會跟著調整,使用者可以在遊玩過程中學到命令行的用法,非常地高竿。

我在整個陪伴孩子使用的過程中,感覺就算大人玩起來,KANO OS 內容也相當豐富而有趣。KANO OS 做到了讓使用電腦充滿樂趣。非常推薦刷來試試,比起 Raspberry Pi 常搭配的 Raspbian 作業系統,KANO OS 包含更多的教學與引導,更適合入門人群與日常使用(缺點是沒中文介面,但也讓小朋友更有動力學英文)

其他心得

如果和我一樣是羅技鍵盤 / 滑鼠,但是是分別購買的,其實有方法不需要在機器上插兩個 Unifying 接收器。只要到羅技網站下載Unifying 軟體到你常用的作業系統上,安裝後即可設定鍵盤 / 滑鼠共用同個 Unifying 接收器,設定完成後,將這個 Unifying 接收器插到 Raspberry Pi 上後開機,Raspberry Pi 也可以認得你的鍵盤 / 滑鼠。

Raspberry Pi 3B 所要求的 2.5A USB 電源其實並不容易找到,一般我用 1.5A 的充電頭也能運作。

Raspberry Pi 也支援 HDMI 聲音輸出,但需要另行設定。切換過去後,可能是因為同時要傳輸畫面與聲音,得消耗更多電源,開機容易出現Low Voltage Detected訊息,並導致無法正常開機。可以在開機畫面中按Shift鍵進入Recovery模式,將hdmi_drive=2(強制使用 HDMI 輸出聲音) 註解掉。

Redux Saga 真好用

· 3 min read

最近相當常使用Redux Saga,簡單紀錄一下。

比較常見用來處理 Redux 非同步操作的 Middleware 有redux-thunk, redux-saga, redux-observable等。之前參與開發的Firefox Devtools使用的是修改版的redux-thunk。我在其中一個個人專案中也有試過redux-observable。使用 Rxjs 的感覺,是整個過去的開發觀念又被扭成另一個形狀😅。因為整套開發的觀念不同,當後續想要修改時常常遇到一些問題。目前則多使用redux-saga來處理非同步相關問題。

基本 Redux State 運作

先簡單回顧一下基本的 Redux State 運作。Redux 統一儲存所有網頁前端的狀態 (State)。只能透過發送Action來通知狀態的改變,並透過Reducer修改當前的狀態。

基本的 Redux 僅支援同步的操作。若想支援非同步操作(promise, async, API 等)需要透過加裝Middleware來處理。Middleware 的功用,是改變收到Action後的處理流程。Redux Saga即是其中一種功能強大的 Middleware。

Redux Saga 運作

Redux Saga 的運作模型,起始自收到 Action。Saga 透過takeLatesttake監聽想處理的 Action,並呼叫對應的 generator function。在 generator function 中,可以用yield語句來完成各種非同步操作。

例如使用select語句來從目前的State中取得資料,使用call語句來呼叫 API,用put語句來將新的 Action 傳回 Redux 處理。

一段簡單的範例:

function* handleAction(action) {
// get state from state.auth
const auth = yield select((state) => state.auth)
// async get data. fetchData is the async function.
const { result } = yield call((auth) => fetchData(auth))
// dispatch action. saveData is the action creator.
yield put(actions.saveData(result))
}

export default function* rootSaga() {
yield takeLatest('ACTION', handleAction)
}

把兩張圖畫在一起的話,可以看到 Redux state 與 Redux Saga 之間整體的呼叫關係。使用 Redux/Redux Saga 能將「從 UI 呼叫 -> 參看現有狀態來與 API 溝通 -> 根據取回值更新狀態 -> 更新 UI」這樣的複雜流程,整個簡化為單向的操作。

當然Redux-saga還有提供一些其他的功能,但其實Redux-saga就是這麼簡單。使用Redux-saga可以很好地運用原有的非同步處理觀念,要將 React Component 中相應的非同步函式搬出來,也不像Redux-observable那樣需要全部改寫。

參考資料

個人工具箱2018六月

· 4 min read

先記錄下來手邊使用的工具,才有機會從繁雜中歸納出簡單的使用規則。

2011 [^1] 年時紀錄了一次當時的個人工具箱,2016 年開始再次紀錄自己手邊工具箱的改變 [^2] [^3] [^4]🤹。 今年初工作上有了變化,也將家中的環境與筆記工具包含進配置列表中。

主要裝備

  • :computer:Dell XPS 13 (8550), Windows 10, i7 4GHz x4, 8GB RAM, 13.3" LCD,作業系統:Elementary OS + Windows
  • 📱One Plus 3, Android, 6GB RAM, 5.5" AMOLED
  • :headphones:Sony WI-1000 降噪耳機

🏠家

  • 🖥24" LCD
  • ⌨羅技 K375s 鍵盤
  • 🖱 羅技 M720 滑鼠
  • :package:Synology NAS: 電影,影集,照片,資料備份
  • :bulb:Yeelight LED 燈泡
  • :dark_sunglasses:Oculus Go: 看影片
  • 備用 :computer:Macbook Air 13", 2012 年版
  • 備用 :tv:Chromecast 一代
  • 備用 :speaker:Echodot
  • 備用 Respberry Pi 3
  • 備用 :orange_book:Kindle Voyage

和上一季相比的改變:

主力用:computer:Dell XPS 13",家中添購了一台🖥24" LCD 接筆電,搭配 3 轉 1 HDMI Hub,接🎮Nintendo Switch,可滿足影音相關需求。HDMI 設備通電時會自動切換到對應的設備。

還是比較少坐在 LCD 前,因此 Chromecast 用很少,另購入 Oculus Go 看影片 / Youtube。

⌨羅技 K375s 鍵盤與🖱羅技 M720 滑鼠,兩者特點都是同時支援使用 USB 或藍牙控制設備,讓我可以用一套鍵鼠控制多種設備。

🕸網站工具

設計工具

開發工具

  • 編輯器:VS Code
    • Blank Line at the End
    • Diff Tool
    • EditorConfig for VSCode
    • Go
    • Guides: more guide line
    • GitLens: more git info
    • Python
    • Settings Sync
    • solidity
    • Trailing Spaces
  • 版本控制:git
  • 套件管理:apt (Linux), nvm, yarn, Chocolatey(windows)

若需要在 Windows 上開發,能用 Chocolatey 處理的就用 Chocolatey 處理。

娛樂工具

  • 🎮Nintendo Switch
  • :dark_sunglasses:Oculus Go
  • :tv:Chromecast (少用)
  • 🎮Steam /vlc (少用)

因為攜帶便利,現在主要只玩 NS 上的遊戲。Steam 上看到喜歡的遊戲,也盡量等 NS 上出了再買。

:iphone:Android 手機應用

  • 瀏覽器:Firefox for Android
  • 網頁更新通知:Web Alert
  • 閱讀:Feedly, Readmoo, Pocket
  • 信箱:Inbox, Gmail
  • 地圖:Google 地圖
  • 記事:Keep
  • 內建相機,內建時鐘
  • 相簿:內建相簿,Google 相簿,Dropbox
  • 社交:Facebook, LINE, Twitter
  • 待辦事項:Todoist
  • 密碼管理:Bitwarden
  • 記帳: Toshl
  • 線上影片:Youtube
  • 音樂:豆瓣 FM, Spotify
  • 有聲書:Audible, Podcast Addict
  • 健康:小米運動,Pokemon Go, 7Min workout

工具

  • 2 步驟認證:Duo Mobile
  • 旅遊:Google 翻譯,TripAdvisor
  • 影片播放:MX Player, DS video
  • 記錄看書狀況:Readmoo 分享書
  • 線上學習:Udemy, EggHead.io
  • IFTTT
  • 💳街口支付

筆記工具

  • B5 方格筆記本
  • Storage.it 筆記本封套
  • 搭配 5 隻筆
    • Pilot FRIXION BALL Slim 0.38 藍色筆桿 + 0.5 魔擦筆筆芯
    • Pilot HI-TEC-C coleto 雙色筆桿 + 0.38 紅 / 綠筆芯
    • Pilot FRIXION light 水藍色魔擦螢光筆
    • Pilot FRIXION COLORS 褐,黑色魔擦筆

Reference