苹果电脑上的 Home 和 End 键

公司里面一般就给你准备两种笔记本电脑: Windows 10 + Lenovo/Dell/HP 或者 OS X + Macbook Pro. 我拿到的是后者, 而且是很不错的一款, 2015 MBP 顶级配置. 不过苹果电脑里有一些设置真是毫无道理, 例如 Home 和 End 键, 在 OS X 中被定义为[页首]和[页尾], Linux 上 Home 和 End 缺省是[行首]和[行尾]. 我不知道别人的实际应用是怎样的, 但对我而言[行首]和[行尾]要更常用到, 例如, 命令行 😀

下面是如何在 OS X 上重新定义 Home/End (在 Terminal 里完成):

mkdir -p ~/Library/KeyBindings
cat <<EOF > ~/Library/KeyBindings/DefaultKeyBinding.dict
{
/* Remap Home / End keys to be correct */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
}
EOF

然后重新启动一次即可.

参考: http://www.jvandemo.com/how-to-fix-home-and-end-keys-on-mac-os-x/

🙂

关闭 Dell XPS 15 9550 的独立显卡

最近我从 ebay 淘了个二手 Dell XPS 15 笔记本电脑, 2016年的而且配置很高, 但价格相当便宜. 既然好货不便宜, 这电脑是不是有问题? 是的, 卖家承认电脑的 nVidia 独立显卡有故障, 装好驱动程序之后 Windows 就会僵死, 但禁用了它之后一切正常, 当然就不要指望能玩什么像样的游戏了. 不过正好我也不打算在笔记本电脑上玩游戏的, 而且 Dell 对 Linux 的支持算是很好的, 于是我欣然买下.

电脑到手后我装了 Fedora 25, 一切顺利, 送走了 Windows 10. 顺便提及, Fedora 25 已经能检测到 XPS 15 BIOS 有更新可以安装了, 很赞.

启用 nVidia 驱动后果然死锁. 索性把 nVidia 关闭了吧, 还能延长电池的使用时间呢. 首先添加 bumblebee, 参考(在 Fedora 25 上测试通过, 其他 Linux 可能需要不同的设置):

https://fedoraproject.org/wiki/Bumblebee#Installation

安装 bbswitch:

sudo -i
VER=$(uname -r)
dnf install kernel-devel-$VER kernel-headers-$VER bbswitch-dkms

禁止系统自动装载 nVidia 的开源驱动 nouveau:

echo "blacklist nouveau" > /etc/modprobe.d/nouveau.conf

让 bbswitch 自动装载, 并在装载时关闭独立显卡:

echo "bbswitch" > /etc/modules-load.d/bbswitch.conf
echo "options bbswitch load_state=0" > /etc/modprobe.d/bbswitch.conf

重新启动系统之后, 测试一下:

cat /proc/acpi/bbswitch 
0000:01:00.0 OFF

OFF 就说明成功了 🙂

Use MySQL Trigger To Do Incremental ETL

There’s a huge MySQL table that I need to ETL to Google BigQuery daily, about 1 billion rows. The rows are updated in a random fashion all the time so I can’t do incremental ETL by the recording the max primary key.

Then my colleague brought up the trigger idea, which I believe is the perfect tool for this job: record what has changed then only load the changed rows to BQ.

Below is the trigger I will use, rxt is the source table, rxts is the ‘diff’ table:

create TRIGGER rxt_update after UPDATE on rxt
  FOR EACH ROW
  BEGIN
    if new.value is not null then
      insert INTO rxts SET rxts.id = new.id
      on DUPLICATE KEY UPDATE rxts.ts = current_timestamp();
    end if;
  END;

The difference will be generated by the SQL

SELECT rxt.* FROM rxt join rxts on rxt.id = rxts.id

BQ doesn’t support update at the moment, so the table can be rebuilt with the original ‘rxt’ and the ‘rxt_diff’, eg. build rxt_0 with rows in rxt but not in rxt_diff, then append rxt_diff into rxt_0 to form the new rxt table.

🙂