Skip to main content

· 3 min read

前陣子過年,終於得以抽出的一些時間,可以來嘗試一些不同的東西。

花了幾天查看 Typescript 程式碼,改寫了個可用繁 / 簡中文語法寫 JS 的轉譯器 LingaScript

使用它做了個「中文輸進去,程式出得來,開發者發大財」的中文程式影片範例,歡迎大家開心試用。

如何做到的

這個專案脫胎自過去開發周蟒(Python + 中文語法) 的經驗,並參考了 CTS (Typescript + 中文語法) 原始碼。

微軟主導開發的 Typescript 提供了分析 Typescript 語法,並可輸出成 Javascript 的轉譯器 (src/compiler)。更棒的是因為 Visual Studio 的開發工具中整合了 Typescript,而微軟為了讓 Visual Studio 中的所有編譯結果都有本地化語言輸出,也在 Typescript 中支援了本地化語言的命令行工具和錯誤輸出。

因此, ‵LingaScript‵ 目前所做的,是讓支援的中文語法可分析為對應的 symbol,並預設將命令行工具設成對應的本地化語言。如此一來就可以得到較完整的使用本地化語言的開發體驗。

graph LR TypeScript -- 多語言關鍵字 --> LingaScript TypeScript -- 本地化命令行 --> LingaScript TypeScript -- 本地化錯誤回報 --> LingaScript

因為看到 CTS 改版不易的問題,我使用自己開發,基於 Google 提供的 diff-match-patch 包裝的 file-patch 工具,來對修改後的程式碼和 Typescript 原始碼做 diff/patch。‵LingaScript‵ 專案中保存了修改後的 compiler 相關檔案和 diff 檔。透過 patch 的方式更容易相容版本升級時的改動。

具體可以查看相關用到的命令 https://github.com/gasolin/lingascript/blob/master/package.json#L14

其他想法

‵LingaScript‵ 目前的架構不僅止於能支援繁簡中文語法,只要加上對應的關鍵字檔案,也可以很快地支援其他語種,讓開發者或講師得以用熟悉的語言來介紹並執行 Javascript 相容的程式。

如果有興趣的話,歡迎前往 https://github.com/gasolin/lingascript 討論或提出想法。

· 6 min read

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

20111年時紀錄了一次當時的個人工具箱,2016 年開始再次紀錄自己手邊工具箱的改變,後來漸漸變成了常規文章 2 3 [^4 ][^5 ]6🤹。

主要裝備

  • 💻 Dell XPS 13 (8550), i7 4GHz x4, 8GB RAM, 13.3" LCD,作業系統:Elementary OS + Windows

  • 📱 Zenfone 5, Android 9(Pie), Snapdragon 636, 6.2" Super IPS

  • 🎧 Jabra Elite 65t (備用:Sony WI-1000 降噪耳機):

🚶‍♂️ 外出攜帶

  • 💻 Dell XPS 13 (8550)
  • 📱 Zenfone 5
  • 🔌 小米 45W 電源
  • 🖱 羅技 M720 滑鼠
  • 🎧 Jabra Elite 65t
  • USB C/Micro USB 雙頭轉接線

🏠 家

  • 🔌 小米 45W 電源
  • 🖱羅技 M720 滑鼠
  • 📦 Synology NAS: 電影,影集,照片,資料備份
  • 備用:🖥️ 24" LCD
  • 備用:⌨️ 羅技 K375s 鍵盤
  • 備用:💡 Yeelight LED 燈泡
  • 備用:🕶️ Oculus Go: 看影片
  • 備用 💻 Macbook Air 13", 2012 年版
  • 備用 📙 Kindle Voyage

和上一季相比的改變:

主力用💻 Dell XPS 13" 搭配🖱羅技 M720 滑鼠。現在幾乎不坐在 LCD 前。同時,因為筆電儲存 256GB 分作兩半其實不是很夠用的緣故,作業系統也只留下了 Elementary OS。

現在的工作型態比較常在家或外出到定點工作,和上一季最大的改變就是使用🔌 小米 45W 電源來取代 XPS 的電源線和 Switch 的電源線。小米 45W 電源可為💻 筆電與 🎮Nintendo Switch 供電,省下帶兩大塊電源線的麻煩。再加帶很久以前買的 5000mAh 小米電源和 USB C/Micro USB 雙頭轉接線,可解決大部分手機 / 耳機的充電問題。

考慮買一顆紫米 10 15000mAh,這樣一顆就可為筆電 / 遊戲機 / 手機 / 耳機,這樣平時出門都不用帶電源線了。(但其實平常也不會帶遊戲機,換 15000mAh 似乎要帶的更重 XD)

graph LR LCD -- DVI --- Notebook LCD -- HDMI --- hub{HDMI Hub} hub --- ns[Nintendo Switch]

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

🕸️ 網站工具

設計工具

  • 螢幕動畫錄製: Peek(Linux), 備用 Recordit(Mac)
  • 心智圖:Coggle, 備用 XMind

開發工具

  • 編輯器:VS Code
    • Blank Line at the End
    • Diff Tool
    • EditorConfig for VSCode
    • Guides: more guide line
    • GitLens: more git info
    • Settings Sync
    • solidity
    • Trailing Spaces
  • 版本控制:git
  • 套件管理:apt (Linux), nvm, yarn, Chocolatey(windows)
  • 🛎️ 專注工具:🍅 Rush (蕃茄鐘)

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

娛樂工具

  • 🎮Nintendo Switch
  • 🕶️ Oculus Go (少用)
  • 🎮Steam /vlc (少用)

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

📱 Android 手機應用

  • 🕸️ 瀏覽器:Brave
  • 🔔 網頁更新通知:Web Alert
  • 📰 閱讀:Feedly, Readmoo, Pocket
  • ✉️ 信箱:Inbox, Gmail
  • 🗺️ 地圖:Google 地圖
  • 記事:Keep
  • 內建相機,內建時鐘
  • 相簿:內建相簿,Google 相簿,Dropbox
  • 社交:Facebook, LINE, Twitter (網頁版)
  • 待辦事項:Todoist
  • 🔐 密碼管理:Bitwarden,Duo Mobile(2 步驟認證)
  • 📺 線上影片:Youtube
  • 音樂:Spotify
  • 有聲書:Audible, Podcast Addict
  • 🚶‍♂️ 健康:小米運動,Pokemon Go, 7Min workout
  • 🕰️ 時間紀錄: SaveMyTime

手機瀏覽器改使用 Brave。記帳改使用實體筆記本紀錄。完整的實體筆記配置

其他工具

  • 旅遊:Google 翻譯,TripAdvisor
  • 影片播放:MX Player, DS video
  • 記錄看書狀況:Readmoo 分享書
  • 線上學習:Udemy, EggHead.io (網頁版)
  • IFTTT
  • 💳街口支付

Reference

· 4 min read

為了平衡日常太依靠電子產品的趨向,前年開始就嘗試使用實體筆記本作一些紀錄,2018 一月中開始嘗試養成更頻繁地使用實體筆記本的習慣。在幾經調整後,目前我使用 B5 方格筆記本做基礎,搭配不同的魔擦筆來作筆記。實體筆記本的好處是除了一般的紀錄,還可以隨意畫心智圖,黏照片,貼紙,蓋印章等。在紀錄的過程中,取得某種程度的內心平靜。

基本配置

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

頁面配置

在開始一本新筆記本時會做以下事

  • 右下角寫下隔頁的頁碼 📄

順便了解這本筆記本有多少頁可寫

  • 索引頁 📇

參考各種筆記術書籍,我在每本筆記本前幾頁會空出索引區,將筆記本內容索引起來,以便之後查找。

  • 寶地圖頁 🏆 🗺️

貼上一些感覺幸福的圖片,和較中長期的目標

  • 子彈筆記符號頁 🅱️

簡單的子彈筆記符號 (. 任務, x 完成, > 延期, ^ 開始, -> 跳頁, <- 續上頁) 個人的簡寫 (B 看的書, Y Youtube, R 閱讀文章, M 看的電影, S 看的劇, A 透過 Audible 聽的書, P 透過 Podcast 聽的節目)

  • Future Log 🔮

接下來幾個月已預定的重要事項,比較細的還是用 Google 日曆。

  • 回顧頁 :thinking:

    每本筆記本的最後一頁是回顧頁。分成Keep, Problem, Try三個欄位。邊寫邊補

    • Keep: 什麼習慣值得保持
    • Problem: 記筆記 / 生活的過程中遇到什麼問題
    • Try: 根據看到的問題,在下一本(或這一本)想嘗試的改善方法

內容頁

日記格式

  • 標題為 月 / 日,(可選加 天氣,簡單總結)
  • 日計帳 (分作三欄:投資,消費,花費)
  • 簡易工作日誌、當日聽到看到值得紀錄的文章,影片等
  • 看書的筆記、Quote、心得、照片、車票、門票等。
  • 日與日之間,加上分隔線。

偶而會到附近的超商或家樂福,將照片從手機傳到立可得快印機台,將四張照片印成一張 4x6 的照片 (一張 6 元) 印出,剪開貼到筆記本中。

檢討

大前研一力推 A4 大小的筆記本,可以較不被筆記本寬度限制地思考。

原來我也使用 A4 筆記本,但幾個月前以攜帶便利(Storage.it 筆記本封套最大只出 B5)為考量,改採 B5 大小。在使用幾個月後,現在確實感覺偏小,下一本我會考慮換回 A4。

我也有做數位版的每月回顧筆記,若持續使用順利的話再來分享。

PS: 暫時還沒想好(也還沒需求)實體筆記該如何數位化。

· 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.

· 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.