用NoMachine远程桌面

家里有一台台式机,用着很爽。最近有需要到处使用电脑的需求,手头有一台老旧的macbook air,想来可以试试远程桌面。

NoMachine 的设置很简单,并支持Win/MacOS/Linux和各类手机(未尝试),开箱almost可用,有一些小问题,特此记录一下:

  1. 我的PC是 linux,又是使用的大屏幕,自动转换分辨率并不支持。
  2. 我用colemak,PC上的键盘是在固件level改的,而mac的nomachine client无法forward这个设定。

好在 NoMachine 支持 callback custom script,在 session start /disconnect / close 等可以唤醒。设置在 /usr/NX/etc/node.cfg,用 xrandr 来改分辨率,setxkbmap 设置 keyboard layout。

#!/bin/bash

export XAUTHORITY=/home//.Xauthority
export DISPLAY=":0"

xrandr -d :0 --output HDMI-0 --dpi 144 --set audio off --mode 1920x1080 &> /tmp/f.log

setxkbmap us &>> /tmp/f.log

Traffic Throttling on Linux

I guess I should document this since I spent some time to get this to work.

In short, to rate limit a box to 30MB/s
tc qdisc add dev eth1 root tbf rate 30mbps burst 10kb latency 70ms mtu 100000

The reason why we set mtu to 10000 is because of this.

To delete this rule:
tc qdisc del dev eth1 root

And to view current setting:
tc -s qdisc ls dev eth1

Garmin 310XT sync w/ Linux

Thanks to pyusbGarmin-Forerunner-610-Extractor and GcpUploader, I am finally able to sync my Garmin 310XT watch with Garmin connect on my Linux box.

Garmin-Forerunner-610-Extractor downloads all the activity files from the watch, then calls callback scripts under $XDG_CONFIG_HOME(usually ~/.config)/garmin-extractor/scripts. In this case, it calls a script that uses gcpuploader to upload to Garmin Connect.

Don’t be fooled by the name, Garmin-Forerunner-610-Extractor actually supports a lot of Garmin devices that use ANT+:

  • Garmin Forerunner 60
  • Garmin Forerunner 405CX
  • Garmin Forerunner 310XT
  • Garmin Forerunner 610
  • Garmin Forerunner 910XT
  • Garmin FR70
  • Garmin Swim

Here is what I did (on Archlinux, other distro should be similar):

sudo pacman -S python2-pip #install pip for python2
sudo pip2 install pyusb --pre #need version newer than 1.0a2
sudo pip2 install GcpUploader #install GcpUploader

git clone [email protected]:Tigge/Garmin-Forerunner-610-Extractor.git
cd Garmin-Forerunner-610-Extractor

# since we run as root, so the config needs to be under /root
sudo cp scripts/40-upload_to_garmin_connect.py /root/.config/garmin-extractor/scripts
sudo chmod a+x /root/.config/garmin-extractor/scripts/40-upload_to_garmin_connect.py

Also needs to change the path to gupload in the script:

# CHANGE ME:
gupload = "/usr/bin/gupload.py"

Add garmin connect credentials in /root/.guploadrc

[Credentials]
username=yourgarminuser
password=yourgarminpass

Finally, run garmin.py to sync!

sudo python2 garmin.py

Bonus: I also find trapiriik.com can sync between Garmin connect, Runkeeper, Strava, endomondo activities. One button push, sync all of them. Or for $2 a year, it can auto sync between accounts. Pretty good deal 🙂

 

最近用的几个小Tool

Tmux

Tmux是screen的替代品, 因为screen项目基本已死, 又buggy, code又很臃肿, 所以就有了Tmux. Tmux已经存在有一段时间了, 不过一直没有特别需求从screen转过去. 最近因为想着要竖着切屏就换了. 基本用得功能都差不多, Tmux可以自动更新title也是很有用的.

Z – jump around

https://github.com/rupa/z
Z是帮助用户快速跳转到想去的dir的. 不知道有多少次想跳转一个文件夹的时候要打一段很长的前缀, 这个小script就轻松解决这一问题: 只要输入这个dir的特征字段既可.

HuffShell

https://github.com/paulmars/huffshell
这也是个很实用的工具, 通过对.bash_history的分析来设定常用的alias, 来减少击键, 从而增加效率.

Lift.do

这是一个iOS App, 从最开始private beta的时候就开始关注了, 目的是帮助用户建立良好的习惯, 可以设定一系列的目标每天签到, 并且可以给与完成同样目标的人一个(like). UI很简洁, 用起来效果很好. 我因此开始了睡前仰卧起坐, 起床俯卧撑, 并且每天吃早餐等好习惯.

Workflowy

https://workflowy.com/?ref=aa2344c.tw (Warning: 链接是含我的邀请码的, 双方可以额外增加一些使用量)
Workflowy是一个极简主义的to-do list App, 没有Catalog, 没有reminder, 没有repeat event, 只有非常basic的list, sublist和tag. 从复杂的to-do list还原到最简单的list, 最大的收获是input变得容易很多, 有兴趣可以试一下.
 

血的教训: 不要随便用 –force

Never use –force unless you know what you are doing!

事情是这样的, 昨晚发现机器上没装php-gd extension, 然后装的时候发现系统很久没升级了, 于是就pacman -Syu了一把, glibc开始报错, /lib下有conflict:

error: failed to commit transaction (conflicting files)
glibc: /lib exists in filesystem
Errors occurred, no packages were upgraded.

一狠心就直接–force了一把, 结果:
> ls
-bash: ls: command not found

于是就尴尬了, 整个 /lib 就这么被踹了, 机器变砖鸟. 好在我不是一个人, 论坛上哭天喊地的一大群人(1,2,3).

还好linode有rescue模式, Lish也很好用, 于是根据 1,2 终于把系统复原, 期间挫折重重.

最重要的一点就是, 下次说啥也不随便 –force 了.