Chrome OS Flex on Samsung Galaxy Book Pro 360 Dual Boot

Happy Chinese New Year (Year of Dragon/Loong) to you all!

A New Year’s surprise from Google. The latest version of Chrome OS Flex finally supports Samsung Galaxy Book Pro 360 to an extent that can be used as a daily driver.

Continue reading “Chrome OS Flex on Samsung Galaxy Book Pro 360 Dual Boot”

Flatpak Wine 微信安装手记

这两天花了一点点时间来优化我的KDE Plasma 5桌面,顺便想起来Wine这个软件而且发现居然已经上架Flathub了!微信很长一段时间都能用Wine在Linux上跑起来,结合网上的一些优化教程,这里总结写一个2024版本的手记。

任何非Ubuntu发行版估计都已经自带支持flatpak而且配置好了flathub源了,flatpak简单来说就是Linux桌面软件的一种分发形式,相较于AppImage的最大区别就是有沙盒(sandbox)一定程度上保护宿主系统。

如果你只是对微信感兴趣,是否通过flatpak安装wine并不重要,我只是喜欢sandboxed wine, wine这个软件每次安装都是东一块西一块弄得文件系统很乱。废话不多说,首先安装好Wine

flatpak install flathub org.winehq.Wine

如果不通过flatpak那就用你发行版的apt、dnf、pacman、zypper之类的安装好wine, 我安装的是flathub上23.08这个版本。flatpak发行的wine有一个麻烦的点就是,之后运行wine都要通过flatpak run org.winehq.Wine这个命令。而且文件系统结果和常规安装的wine会很不一样!所有和wine相关的东西基本都在$HOME/.var/app/org.winehq.Wine这个目录下。

Wine的中文字体显示问题,我直接从Windows那边把微软雅黑的三个字体文件拷贝过来然后点击打开KDE自带的字体管理程序安装到Linux系统了。然后运行winecfg

flatpak run org.winehq.Wine winecfg

在Desktop Integration那里把所有的字体都替换成了微软雅黑。

好了, 现在可以下载微信Windows版的安装包一路Next安装好。启动运行先检查是不是字体显示正常没有方块。

最近的微信版本有一个WeChatAppEx.exe这个程序,在Linux下通过wine运行会占用大量CPU甚至导致桌面卡死……按照网上的建议,在winecfg里Libraries选项卡手动打入wechatappex.exe 然后Edit选择Disabled禁用掉。

然后一直以来一个很烦人的点就是微信Windows版实现的窗口阴影在Linux下会导致一个置顶的模糊窗口,不仅看起来很烦而且会导致GUI交互问题。这里有一个KDE桌面环境专属福利,安装并启用这个KWin Script就可以了!

Flatpak安装的Wine不能创建桌面启动项,这里我们可以自己捏一个wechat.desktop文件放在~/.local/share/applications下,供参考这是我的文件内容:

[Desktop Entry]
Exec=flatpak run org.winehq.Wine 'C:/Program Files (x86)/Tencent/WeChat/WeChat.exe'
GenericName=WeChat PC Client
Icon=wechat
Name=WeChat
NoDisplay=false
Path=/home/simeon/.var/app/org.winehq.Wine/data/wine/drive_c/Program Files (x86)/Tencent/
StartupNotify=true
StartupWMClass=wechat.exe
Terminal=false
Type=Application
X-KDE-SubstituteUID=false

最后祝大家2024新年快乐!

2024-02-26更新: 找到个更好用的flatpak:WineZGUI, 各位不妨试试

FydeOS上手体验

距离上次写与Chrome OS/Chromium OS相关的帖子又有一段时间了。之前提到了怎么用Brunch项目来运行原味的Chrome OS,奈何Brunch的内核和我的新笔电(Samsung Galaxy Book Pro 360)一直不是很兼容,主要两个痛点:

  1. 声卡和麦克风识别时有时无
  2. 笔电折叠后不会自动切换到平板模式

网上有人提到了FydeOS,于是这个周末抽了点时间来试试。剧透一下,感觉真不错!

Continue reading “FydeOS上手体验”

Banana Pi M5 Pro Quick Review

My old ODROID-U3 has been giving me quite some headaches. Its old USB 2.0 ports and 100Mbps Ethernet port are also very limiting in 2023. Its power supply is not the best (not an uncommon issue with HardKernel’s products, certainly not uncommon among the older generation of single board computers). A hardware upgrade is therefore necessary.

I don’t really use it for anything else other than a humble home server to stream videos, music, and sometimes photos. Generally used as a private file share system at home. I already bought an 1 TB USB 3.0 HDD, so I definitely need a device that supports USB 3.0 at least. To not have a limiting network I/O, it should also have 1Gbps Ethernet port.

Why not buying a popular Raspberry Pi 4? Well, I tried, but it’s out of stock everywhere. That’s why I turned to its alternatives, initially I was going to buy another HardKernel’s ODROID product, but its pricing in Europe is just way too high than the price on its website. Unfortunately, (not sure if this has anything to do with Brexit), there is a minimum order requirement to ship to the UK. I’m building a cluster or something, so looking again…

Ta-da! I found Banana Pi, the name is a bit.. knock-off, and the manufacturer is in China, I’ll let you connect the dots. Banana Pi M5 is not the newest model, but it’s comparable to Raspberry Pi 4 and ticks all of my boxes. Long story short, I bought it from Ali-Express where it’s much cheaper than Amazon or other local retailers here. They were also running some sales on bundles, so I ended up buying it with a metal case, yet paying less.

On paper, it provides even better performance than Raspberry Pi 4! More importantly, it’s readily available! One thing I did pay extra attention to is the availability of upstream Linux images, having suffered quite a bit there with HardKernel’s products. Thankfully, Banana Pi has Armbian support (rated platinum for Banana Pi M5, whatever platinum means). To save even few more pennies, it comes with an onboard 16GB eMMC storage!

It’s been faithfully serving its purpose on the shelf next to the router for a couple of weeks now. Reliable little machine that’s fast and responsive! If you’re thinking of buying a single-board computer like Raspberry Pi, but couldn’t find available stocks, Banana Pi might fit in.

Chrome OS, Linux Containers and Application Launchers

So I installed the great brunch framework on my laptop after a hiatus of a couple of months. I still dislike the fact that the Linux containers are running under a VM on Chrome OS. Sure it is more secure as the containers won’t be able to access the host hardware directly etc. It is also slightly inefficient. So I tried both chromebrew and brioche. Note that brioche only supports brunch (thus half of this post won’t apply to official Chrome OS builds).

Continue reading “Chrome OS, Linux Containers and Application Launchers”

Number Rounding Business

Rounding numbers is probably one of the topics in primary school. In school, we’ve learned that half rounds up, anything less than half rounds down. For example, 0.5 rounds to 1, but 0.4 rounds to 1. Duh, I’m stating the obvious you think. It only came to my attention that this is NOT really the default behaviour in a very popular programming language: Python.

Here, is a simple example to try in your own Python console.

Continue reading “Number Rounding Business”

Merge Pandas DataFrame with Nested Dictionary

Not an avid Pandas or Numpy user myself, but I had to spend some time lately to optimise probably a fairly common process: looking up a nested dictionary (2 or more levels) to find the right values element-wise for a column in a Pandas DataFrame. If it’s not clear, the problem I’m trying to solve here is to optimise a look-up function that can be done with .apply() to something more performant.

You might say, why not using .map()? Because the look-up function is not y = f(x), no, it is more like y = f(x, a) or even y = f(x, a, b), depending on the level of nestedness.

As mentioned earlier, this can be implemented with .apply() by supplying a Python function that does the look-up. However, .apply() is very slow (it’s not vectorised). The solution here is actually straightforward (I’m very new to Pandas and it took me some time to get here so I decided to make a note here for this). We first flatten the nested dictionary to have different levels of keys as tuples, which allows us to create a DataFrame with MultiIndex. With MultiIndex, we can easily apply .merge to join the DataFrame objects.

Hopefully the code snippet is more understandable.

import pandas as pd

nested_dict = {
    "A": {
        "Apple": "Red",
        "Banana": "Green",
    },
    "B": {"Apple": "Green", "Banana": "Yellow"},
}
df = pd.DataFrame.from_dict(
    {
        "Fruit": {0: "Apple", 1: "Banana", 2: "Banana"},
        "Price": {0: 0.911, 1: 1.734, 2: 1.844},
        "Bucket": {0: "A", 1: "B", 2: "A"},
    }
)

# Method 1: .apply()
# Apply Python function element-wise, as slow as a regular for loop
df1 = df.copy()
df1["Color"] = df1.apply(
    lambda row: nested_dict.get(row["Bucket"], {}).get(row["Fruit"]), axis=1
)
print(df1)

# Method 2: .merge()
# Vectorized, much faster (even though the big O is the same)
df2 = df.copy()
# The only overhead is to construct a dataframe with 'MultiIndex'
nested_df = pd.DataFrame.from_dict(
    {
        (inner_key, outer_key): value
        for outer_key, outer_value in nested_dict.items()
        for inner_key, value in outer_value.items()
    },
    orient="index",
)
nested_df.index = pd.MultiIndex.from_tuples(nested_df.index)
nested_df.rename(columns={0: "Color"}, inplace=True)
df2 = df2.merge(nested_df, how="left", left_on=("Fruit", "Bucket"), right_index=True)
print(df2)

Windows 10/11 拼音输入法英式键盘

很多年前就遇到的难题,最近在知乎找到了解决办法(原po点此)。这里复述一下也作为一个存档备份。

问题概述

使用非美式键盘,使用微软内建的中文输入法,当激活拼音输入法(无论中英文模式)时,键盘布局永远是美式。结果就是输入符号时不符合键盘上的符号(甚至字母都不对,如果用的是非QWERTY的键盘布局)。

解决方案

你需要有管理员权限!

按下Windows键(或者点击开始菜单按钮)输入 regedit,回车或者点击注册表编辑器。进入 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts 然后一个一个找(可以使用方向键翻,用鼠标点可能会点疯),找到你要修改的语言,例如这里我要改的是简体中文,文件夹00000804对应的就是简体中文的键盘布局 (Layout Text 的值是 Chinese (Simplified) - US Keyboard),双击 Layout File 把值从 KBDUS.DLL 改成 KBDUK.DLL,可以顺便把 Layout Text 的值里面的 US Keyboard 改成 UK Keyboard。修改完成后需要重启电脑(或者登出再登入)生效。

如果你使用的是其他键盘布局,可以挨个找到该原生语言的布局(例如如果你用的是美式 Dvorak 键盘,挨个翻,可以找到 00010409 里面的 Layout Text 写的是 United States-Dvorak),找到正确的 Layout File,然后把中文的 Layout File 修改成对应的值(例如美式 Dvorak 就会是 KBDDV.DLL)。

其他方案

搜狗输入法、QQ输入法等第三方拼音输入法允许设置键盘布局,如果使用这些输入法就直接在设置里更改键盘布局即可。

最后吐槽一下Windows的设计,键盘布局应该是和语言无关、和硬件有关,在某些操作系统(比如Windows)中键盘布局变成和语言输入法耦合在一起就很莫名其妙。这样就算了,竟然没有一个在用户态更改键盘布局的图形界面……

2021年10月5号更新

本方法对Windows 11同样有效,但是从Windows 10升级到Windows 11后相关注册表值会被重置,按照上面的内容再修改一次就可以了。

Building KDE Frameworks on Windows from Source

Some notes on how to build KDE Frameworks packages from source on Windows using Visual Studio tools.

To do so, you need to first have a version of Qt compiled by MSVC installed. Some system environment variables to be set, using Qt 5.15.2 as an example:

  • PATH needs to add C:\Qt\5.15.2\msvc2019_64\bin
  • Qt_DIR needs to be set to C:\Qt\5.15.2\msvc2019_64

Example instructions for building CMake-based projects (all KDE projects), the command below should be executed in x64 Native Tools Command Prompt.

mkdir build && cd build
cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="C:\Qt\5.15.2\msvc2019_64"
nmake && nmake install

This will install the compiled KDE module into the Qt installation path. You can install it elsewhere, but if you do, make sure you update PATH environment variable accordingly.