Hands-on Sailfish OS on Redmi Note 7

Not sure if this is related to the COVID-19 lockdown, but we’ve seen a lot of geeky hobby projects coming up recently. A lot of community ports have been done over the last few months for niche mobile operating systems such as Sailfish OS. That’s exactly the one I played with briefly after purchasing a second-hand Redmi Note 7 on eBay (don’t ask me if I think it’s a waste of money now LOL).

If you come here hoping to find the resources, head to the GitHub repo directly where you can find the ROMs to download.

Make sure that you’ve unlocked the bootloader already! If not, you need to register a MI account and apply for unlocking here. You must log in to your MI account on both the unlocking tool and your phone (MI, POCO, RedMi). If you don’t have a Windows PC, I recommend using XiaoMiTool V2 which works on macOS, Linux, as well as Windows. Though I couldn’t find this on the official FAQ, you have to have a working SIM card inserted. You have to use the mobile data instead of WiFi when unlocking the bootloader on your phone because XiaoMi is doing some verification.

Another problem I encountered was that in fastboot mode, RedMi Note 7 would just say “Press any key to reboot” when any commands are sent from my laptop. After googling on this, there seems to be a driver bug that makes RedMi Note 7 fastboot USB3 unfriendly. Using a USB-Hub worked for most people, including me 🤷.

I wish you all a successful attempt to flash Sailfish OS into your RedMi Note 7. Here are some screenshots I took.

Continue reading “Hands-on Sailfish OS on Redmi Note 7”

讓你的WordPress小站搭上WebP的快車

Google家開源的WebP圖形編碼格式出來已經好幾年了,瀏覽器支援率現在也是非常高的了(現代瀏覽器就Safari不支持)。相比於常用的JPEG和PNG,使用WebP可以節省高達80%的空間(在今天行動網路的時代,這意味着更快的載入)。

當然了,還是不想拋棄堅守Internet Explorer和蘋果家Safari的用戶,所以我們需要一個聰明的外掛程式,在支援WebP的瀏覽器上使用WebP圖形,不支援的話則提供JPEG或者PNG檔案。隨便Google到的一個頗爲流行的免費開源程式WebP Express就是這輛帶我們上路的快車。

在WordPress後臺Plugins頁面搜尋下載好WebP Express並啓用。如果你使用的是Apache,它開箱即可用。如果你使用的是nginx,則需要按照說明稍微配置一下。這裏用的是nginx,而我選的是簡單的CDN Friendly選項,然後批量將全部圖形檔案轉換成了WebP(原始檔案是不會動的)。Alter HTML那個選項一定要開啓不然什麼也不會發生……

用此前的日本兩京遊記做了一下對比,未啓用掛件的時候頁面大小爲1.8MB,加載用時4.32秒。啓用掛件後頁面大小減少到了1.4MB,加載用時3.52秒。對比提升效果還算明顯,當然了,那篇文章裏面照片很多,一般的文章頁面效果估計甚微。

Use npm packages in QML

I’ve been trying to code up some nice GUI for a hobby project which was done in JavaScript (Node.JS). I’ve looked at a few options that I have

  1. Use the not-yet-stable NodeGUI
  2. Go Web and use Electron
  3. Rewrite the core in Python or C++ to use Qt
  4. Use QML which has limited support for JavaScript

I’ve explored the option 1, however, I soon ran into the problems with the Model/View/Delegate architecture which means I would have to implement native plugins/add-ons in order to use ListView. Not to mention the framework itself is still heavily under development.

As for option 2, I’m not a web frontend engineer and personally I much prefer something that is native (or looks and feels native at least). For the third option, it feels a bit overkill but it is a possible way out.

Luckily I don’t have to do the re-implementation, because I’ve managed to get the core functionality bundled into a single JS file which works flawlessly in the QML environment. Before I start diving into the details on how you can make your npm packages work in QML, I have to emphasise that there are many limitations in the QML environment and it’s very likely that only a small subset of the npm package that you’re interested in is going to work.

Continue reading “Use npm packages in QML”

OpenSUSE 15.1 Installation Notes

Although my personal laptop isn’t getting much attention from me because I’ve spent most of my time on my work laptop (a MacBook Pro) and my Android tablet (Samsung Galaxy Tab S5e), I’ve decided to take good care of its software over last weekend by wiping the SSD clean and installing a fresh OpenSUSE on it. As an old habit, I’m sharing some notes during the installation and later setup. This is, however, the first blog post written in English here (not counting the old ones on no-long-working en.librehat.com).

Continue reading “OpenSUSE 15.1 Installation Notes”

WireGuard初體驗

工作和生活很忙的緣故,一直沒有好好維護Shadowsocks的Qt/C++分支,最近下定決心索性聲明好放棄維護了。偶然看到關於WireGuard的新聞,宣稱是一款現代、快速、安全的VPN工具,今天總算抽出來一點時間來試驗一番,下面來分享一下WireGuard之初體驗。

首先,在伺服器和客戶端安裝好WireGuard,官方文檔寫的很詳細。

然後在伺服器和客戶端都創建好一套密鑰文件,命令如下:

Continue reading “WireGuard初體驗”

修復WordPress更新出現的Inconsistent Permission錯誤

最近部落格的WordPress更新頻頻提示出現錯誤,log就簡單地說一句inconsistent permission error,就這樣在網路上搜尋了一會兒才發現,同樣的錯誤提示很可能是有不同的underlying issue,比如可能文件與目錄的權限有被人為修改過(文件必須是644,而目錄必須是755,可以用find指令批量更改),又或者可能是owner和group不一致(chown -R批量更改)。而發生在我的VPS的卻是第三種情況,SELinux導致某些文件無法寫入……

甄別此情況很簡單,在WordPress目錄下執行ls -Z(注意是大寫Z)查看一下WordPress目錄和其內文件,比如被我強制用unzip解壓最新的WordPress替換過的目錄就顯示:

drwxr-xr-x. nginx nginx unconfined_u:object_r:user_home_t:s0 wordpress

我們關心的是第四列SELinux的標籤設定,這樣的權限是不夠的,在終端執行下面這條語句把WordPress目錄和其內容遞歸性地更新好便解決了問題!

chcon -R -t httpd_sys_rw_content_t wordpress

知其然還需知其所以然,繼續Google了一下,在Red Hat的文檔庫找到配置Apache HTTP Server的權限管理文章,裡面有提到httpd_sys_rw_content_t標籤(以及其他標籤),任何有此標籤的文件都可以被有httpd_sys_script_exec_t標籤的腳本修改,但不能被其他腳本修改。

NodeConf EU 2018與會有感

上週有幸到鄰國愛爾蘭的Kilkenny郡參加本年度的NodeConf EU大會。會場選在風景宜人的蹩腳窩郊外,離都柏林機場有一個半小時的車程,不遠,就是estate都不在鎮上,所以每天倒也只能全身心灌注在大會和組織者安排的夜間活動上,倒也是個結交新朋好友的機會。

Continue reading “NodeConf EU 2018與會有感”

VPS遷移日誌

上個週末得閒把VPS從之前的RamNode遷移到了Amazon Lightsail,主要遷移的內容就是WordPress,涉及到MySQL的導出和導入、Nginx的配置、PHP的配置(從5.6升級到了7.3)、CentOS的簡單設置(從6升級到了7)、Let’s Encrypt SSL證書的配置。下面簡單記載一下遷移的梗概以便有需要的訪客和自己今後查閱。

Continue reading “VPS遷移日誌”

運用Termux將Android平板電腦變身程式設計利器

去年就把手上的Chromebook在eBay賣掉,加了點錢在Amazon買了一台華碩的7英吋平板電腦。上禮拜買了羅技的藍牙鍵盤,這下和平板電腦配合在一起就真的能當台小電腦💻用了。所以有琢磨著怎樣可以在不方便攜帶筆電的情況下用來旅途中練習一些算法題。

熟悉程式設計的(我也希望都是在UNIX環境下的)或多或少可能有過想在平板電腦上偶爾練練手的想法,Android畢竟是基於Linux設計的,加上系統多年的更新換代發展,灌上一個Linux的工作環境應該不會太難,而且將會是一個非常大的效率提升。不過如果真的灌一個完整的Linux環境,一來是佔用很大的磁盤空間,二來電力損耗估計也是會讓人頭疼。好在我在Google馬上找到了Termux,安裝步驟簡單到不行,直接在Google Play點選安裝即可。

Continue reading “運用Termux將Android平板電腦變身程式設計利器”