Archive of

`git rm --cached ` is a worse choice than `git update-index --assume-unchanged `

There are 3 options, you probably want #3

  1. This will keep the local file for you, but will delete it for anyone else when they pull.

    git rm cached <file-name> or git rm -r cached <folder-name>

  2. This is for optimization, like a folder with a large number of files, e.g. SDKs that probably won't ever change. It tells git to stop checking that huge folder every time for changes, locally, since it won't have any. The assume-unchanged index will be reset and file(s) overwritten if there are upstream changes to the file/folder (when you pull).

    git update-index --assume-unchanged <path-name>

  3. This is to tell git you want your own independent version of the file or folder. For instance, you don't want to overwrite (or delete) production/staging config files.

    git update-index --skip-worktree <path-name>

It's important to know that git update-index will not propagate with git, and each user will have to run it independently.

gnome3 how to alt tab windows on current workspace only?

gsettings set org.gnome.shell.app-switcher current-workspace-only true

status code versus error code

同事扔给我一张截图,显示errCode是5,说:

「已注册」的error code是5, errorCode 4开头的会到404页面, 5开头的会到505页面,
我们之前有通过的都是200

不不不
这个和 statusCode 是两码事儿
errCode 是业务错误代码
20x 40x 50x 是返回响应的状态码,通常是框架自动给的,若你的请求参数没有问题,系统通常都会返回状态码 200。但返回200并不意味着一切都对,在我们的项目中,状态码返回 200 并且 success 为 true 或者 errCode = 0才是真的没有问题

同事

哦,是这样,所以我们还是有statusCode

如果参数根本不符合约定,系统会立即拒绝你,那时候statusCode 会是 40x
如果参数都对,但后端的代码出了bug造成服务器不能正常返回,response会报 50x 表示前端没错,但服务器那边出问题了。
换言之如果是 20x,则你没错,我也没错,成功没有成功是业务逻辑的事情。
如果是 40x 意味着前端送过来的数据不符合后端要求,因此没有被进一步处理,而是被直接拒绝了
50x 表示前端送过来的东西没有大问题,但后端没有处理好出错了

同事

好的,那我明白了,我记错了,是statusCode才是指到505,404, 我以为都改成了errCode

所以 errCode 5 一定不能一杆子指到 505 页面去。
发现 50x 了去找后端工程师的麻烦一般不会错,如果 40x 了去找后端之前,最好先检查下自己的参数和出错信息

同事

status code 和 errCode 本质上是两个东西,errCode是返回数据的一部分
status code 是本次请求返回响应的状态码,可以理解为和返回数据是同一等级的

同事

那我们的error.response的数据结构有改变吗,我现在还是可以抓取到error.response.status,说明这部分应该是没有改的

这个是axios的约定,并不是后端能够决定的,我们结构的变化,只是response.data 结构的变化是 response.data 吧,我不是很确定,毕竟好久不写 axios 代码了

同事

是的,但是后来有加了一个data, 我们现在的结构变成这样的 [ Photo ]

对。后端只给了一个data键,图里的第一个data是 axios给的,需要注意的是,不同的框架给返回数据的键取的名字可能会不一样。如果不用axios而是用别的库,数据那一级的键的名字就很有可能不叫 data

同事

嗯嗯

话外音

我相信她这次真的搞明白了。哈。聊天记录稍加编辑就水了一篇博客,不过我相信它应该会对前端新人有所帮助。

Virtualbox MacOS VM setup / setup Rime/Squirrel input method (鼠须管) on macOS

  1. I successfully ran macOS High Sierra on my Ubuntu 18.04 laptop through VirtualBox. VirtualBox is great ! This article helps!
  2. Install Rime on macOS in five minutes
    1. download the zip file from latest release from the Tags page on GitHUB
    2. unzip the file and install the pkg file
    3. go to https://github.com/rime/plum to get the wubi package.
git clone https://github.com/rime/plum.git
cd plum
bash rime-install wubi pinyin-simp

The last step, is creating a default.custom.yaml file and putting it in ~/Library/Rime directory.

the content in my default.custom.yaml is

patch:
  schema_list:
    - schema: wubi_pinyin
    - schema: pinyin_simp

How make openvpn work with docker & avoid entering the password every time

I met this issue today morning and find the solution from the link I just refered.

I have made a few change to the solution to meet my case, this is why I wrote this article.

My version of fix-routes.sh

#!/bin/sh
echo "Adding custom route to $route_vpn_gateway with /24 mask..."
# ip route add 10.8.0.0/24 via $route_vpn_gateway
ip route add 192.168.178.0/24 via $route_vpn_gateway

echo "Removing /1 routes..."
ip route del 0.0.0.0/1 via $route_vpn_gateway
ip route del 128.0.0.0/1 via $route_vpn_gateway

I didn't use ip route add default via $route_vpn_gateway line because I didn't want to route everything through my VPN.

Changes to my openvpn profile

You can see I added an extra askpass line besides what the author has done. That line was added to help me get ride of the annoyance of entering the password for my private key every time I run the openvpn client program.

auth SHA256
auth-nocache
verb 3
askpass /home/davidwei/ovpn/pass.txt
script-security 2
route-up /etc/openvpn/fix-routes.sh

My ovpn start one-line script

davidwei@xps:~$ cat ~/bin/ovpn 
sudo openvpn ~/shukebeta.ovpn > /dev/null 2>&1 &

My pass.txt

davidwei@xps:~$ cat ~/ovpn/pass.txt 
my-very-secret-password