Fixing Line Editing on Android 8.0+

Recently I’ve been working on a toy that launches an REPL in adb shell, which would be more comfortable to use if it has the line editing functionality similar to bash. After some research, I found that actually there are a number of line editing libraries available, so it should be a nice and easy addition. However, after some integration work, I was surprised to find that all these libraries (e.g. jline3, linenoise (which was also once imported into AOSP)) only worked on older versions of Android, that is, until Android 8.0.

继续阅读


Remapping ThinkPad Keys with udev hwdb

ThinkPad T series (also X1 Carbon) laptops have a great keyboard that I’ve been using delightfully for years. However, there’s a minor issue with its keyboard layout: they replaced the Menu key with a PrtSc. In my day to day work, I almost always accidentally hit that key while using my lovely Ctrl and Alt keys, upon which my laptop happily plays a shatter sound, flashes my screen white for a split second and spawns a screenshot file under my Pictures/ (thank you, GNOME). Whereas when I wanted to use my Menu key, it’s nowhere to be found.

However, there’s still an Insert key lying quietly in the top-right corner, which I never used (except for checking if some app even supports it). So why not make my old Insert PrtSc and my old PrtSc the new Menu?

Moreover, there are also 4 special keys (Fn + F9F12) that could have been my media keys, but are by default strange things like Settings and Search. Why not map them to media keys as well?

继续阅读


Writing a Comparator for Natural Sort Order

Natural sort order is what we usually see in most file managers when browsing a list of numbered files, that it sorts the numerical part of the file name as a number instead of comparing it character by character. For instance:

Lexicographical sort Natural sort
1.txt 1.txt
10.txt 2.txt
100.txt 3.txt
101.txt 4.txt
102.txt 5.txt
103.txt 10.txt
104.txt 11.txt
105.txt 12.txt
11.txt 13.txt
12.txt 14.txt
13.txt 15.txt
14.txt 100.txt
15.txt 101.txt
2.txt 102.txt
3.txt 103.txt
4.txt 104.txt
5.txt 105.txt

Lexicographical sort can be easily implemented using String::compareToIgnoreCase, but it is not very acceptable for end users. However for natural sort, things is actually a little more complicated.

继续阅读





WebGL 入门笔记

前言

因为计算机图形学课程作业的需要,我在使用过 OpenGL 的基础上学习了使用 WebGL 进行二维图形渲染。

WebGL 拥有与 OpenGL ES 相似的 API(前者基于后者),但与 OpenGL 相比,两者缺少基础图形的渲染管线,而是需要手写 shader 进行渲染。

继续阅读



为 Android 项目使用 Travis CI 并发布持续集成版本

前言

Travis CI 是 GitHub 上开源项目采用持续集成的常见选择。为了给豆芽提供持续集成版本用于公开测试,我配置了 Travis CI,并自己编写了脚本将构建结果发布到另一个空项目的 Release 中,并将其间的过程和遇到的问题记录于此。

Travis CI 构建 Android 项目的时间较长,因此调试配置时十分耗时。希望我的经验能对他人有所帮助。

继续阅读


Verilog 编程笔记

前言

这是我在大学修习逻辑与计算机设计基础、计算机组成和计算机体系结构三门硬件课的过程中积累的 Verilog 笔记。

Verilog 是一门主要用于逻辑电路设计的硬件描述语言。语言标准主要有 Verilog-1995Verilog-2001 两个版本,建议在创建工程时选择 Verilog-2001 标准以支持更多实用的语法。

虽然 Verilog 的语法与 C 相似,但是二者是面向各自的目标硬件设计的。Verilog 是一门面向逻辑电路的具体实现而设计的语言(正如 C 在某种程度上是面向汇编等底层实现的),因此写作 Verilog 时不可以将 C 等编程语言的思维方式代入,而是要始终清晰地思考正在编写的代码将能够综合成怎样的逻辑电路实现——如果可以,那么大多能够写出在字面和实现上都优雅的代码;如果不行,那么综合时大概也会报错或消耗大量资源,此时则应该考虑调整思路。

继续阅读