Tao He

Tao He

  • Docs
  • API
  • Help
  • Blog

›Recent Posts

Recent Posts

  • Microsoft PowerPoint
  • Chrome
  • Alfred
  • Docusaurus
  • Git Commands

Microsoft PowerPoint

January 13, 2019

{% include JB/setup %}

Change Theme Fonts

Prefs... -> East Asian Languages -> Simplified Chinese

Copy /Applications/Microsoft PowerPoint.app/Contents/Resources/Office Themes/Theme Fonts/Arial.xml to /Users/taohe/Library/Group Containers/UBF8T346G9.Office/User Content.localized/Themes.localized/Theme Fonts/YaHei.xml and modify.

http://www.brandwares.com/bestpractices/2015/10/xml-hacking-font-themes/

http://www.brandwares.com/bestpractices/2017/02/xml-hacking-font-themes-complete/

Chrome

December 12, 2018

{% include JB/setup %}

Shortcuts

ShortcutFunction
⌘ + LJump to the address bar

Chrome keyboard shortcuts

Alfred

November 21, 2018

{% include JB/setup %}

Workflows

alfred-tty

alfred-tty

alfred-tabs-improved

alfred-tabs-improved

yarn global add alfred-tabs-improved

alfred-chrome-bookmarks

alfred-chrome-bookmarks

chrome-bookmarks-alfred-workflow

chrome-bookmarks-alfred-workflow

alfred-fkill

alfred-fkill

yarn global add alfred-fkill

Develop

JXA

By default, Google Chrome executing JavaScript through AppleScript is turned off. To turn it on, from the menu bar, go to View > Developer > Allow JavaScript from Apple Events. For more information: https://support.google.com/chrome/?p=applescript

Var

https://github.com/JXA-Cookbook/JXA-Cookbook/issues/37

JXA-Cookbook

A Beginners Guide to JXA, JavaScript Application Scripting

Automating Chrome with JXA (Javascript Application Scripting)

https://gist.github.com/EvanLovely/cb01eafb0d61515c835ecd56f6ac199a

https://github.com/codeslikejaggars/open-chrome-tab/blob/master/open-chrome-tab.jxa

https://hackmag.com/coding/getting-to-grips-with-javascript-automation-for-os-x/

https://stackoverflow.com/questions/10366003/applescript-google-chrome-activate-a-certain-window

Docusaurus

September 1, 2018

{% include JB/setup %}

Install Docusaurus

Docusaurus https://docusaurus.io/docs/en/commands

docusaurus-init
# switch to source branch
git co source
# go to website directory
cd website/
# publish to master branch to GitHub
GIT_USER=taohexxx yarn run publish-gh-pages

Git Commands

August 30, 2018

{% include JB/setup %}

branch

Basic

# show
git branch -vv
# delete
git branch -d <branch>

checkout

# create a new branch as same as current branch
git checkout -b <new branch>
# switch to branch
git checkout <branch>

rebase

git log
# rebase from tracking remote branch
git rebase
# rebase from branch
git rebase <branch>
# rebase start from a commit
git rebase -i <commit>
# rebase start from last but 4 commit
git rebase -i HEAD~4
# abort
git rebase --abort

other

# 以当前分支状态新建并复制一个分支new_branch
git branch -B new_branch
# 将分支master用标签v0.8.0的状态覆盖当前状态(将分支master恢复到标签v0.8.0)
git branch -f master v0.8.0
# 用分支some_branch覆盖master
git branch -f master some_branch
# 重命名当前分支
git branch -m new_name

remote

Basic

# show
git remote -v
git remote show [remote]
# add
git remote add <remote> <remote url>
# fetch
git fetch [remote]
# pull
git pull [remote]
# push
git push [-f] [remote] [branch]

merge from remote

git fetch origin
# rebase远程origin仓库的master分支到本分支
git rebase origin/master

submodule

update from remote

git submodule update --remote --merge
git commit

revert

Discard commit A,B,C by creating a new commit

git revert --no-commit C B A
git revert --continue

Discard changes in working directory. Recover file to last commit

git checkout -- <file>

Checkout file from another branch

git checkout <branch> -- <file>

Undo 'git add'

git reset <file>

Undo a commit

git reset HEAD~  # HEAD~ is the same as HEAD~1

Tool

cherry-pick

git cherry-pick <commit>
# abort
git cherry-pick --abort

mergetool

git mergetool

assume-unchanged

作用:远程仓库大小写敏感,但本地文件系统大小写不敏感,导致部分文件一直是modified状态,需要忽略。

忽略

git update-index --assume-unchanged <file>

不忽略

git update-index --no-assume-unchanged <file>

SVN

Basic

# only first time
git svn clone -r [commit:]HEAD <svn remote url>
# fetch and rebase
git svn rebase
# push
git svn dcommit

SVN as master and git as branch

git svn clone -r [commit:]HEAD <svn remote url> [--username=yyy]
git remote add <git remote> <git remote url>
git fetch <git remote>
git checkout -b <git local branch> <git remote branch>

Example

git svn clone -r HEAD https://xxx.com/xxx/trunk/navim --username=yyy
cd navim/
git remote add tencent https://github.com/taohexxx/navim
git fetch tencent
git checkout -b tencent_master tencent/master

Git as master and SVN as branch

git clone <git remote url>
git svn init <svn remote url>
git svn fetch -r [commit:]HEAD [--username=yyy]
# checkout to local branch
git checkout -b <svn local branch> <svn remote branch>

Example

git clone https://github.com/taohexxx/navim
cd navim/
git svn init https://xxx.com/xxx/trunk/navim

.git/config should looks like this:

[svn-remote "svn"]
  url = https://xxx.com/xxx/trunk/navim/navim
  fetch = :refs/remotes/git-svn

Then

git svn fetch -r HEAD
git checkout -b svn_trunk remotes/git-svn

Add another SVN remote

# edit `.git/config` and copy the `svn` section and rename
git svn fetch -r HEAD <another svn remote>
git checkout -b <another svn local branch> <another svn remote branch>

Example

Edit .git/config and copy the svn section like this:

[svn-remote "svn_dev"]
  url = https://xxx.com/xxx/branches/navim/navim_dev
  fetch = :refs/remotes/git-svn_dev

Then

git svn fetch -r HEAD svn_dev
git checkout -b svn_dev remotes/git-svn_dev

Delete SVN remote

Delete svn section in .git/config

rm -rf .git/svn/refs/remotes/git-svn/

实例

# 把svn分支作为本地svn_trunk分支,把git的master分支作为本地的master分支
git clone https://github.com/taohexxx/navim
cd phxrpc/
cat .git/config
git branch -a
# 设置git-svn路径
git svn init https://xxx.com/xxx/trunk/navim
cat .git/config
# 从svn上fetch代码到remotes/git-svn分支
git svn fetch -r HEAD
# 新建一个本地分支svn_trunk,与svn的remotes/git-svn分支对应
git checkout -b svn_trunk remotes/git-svn
git branch -a


# 把svn作为本地master分支,把git的master分支作为本地的git_master分支
git svn clone -r HEAD https://xxx.com/xxx/trunk/navim
cd phxrpc/
cat .git/config
# 设置git路径
git remote add origin https://github.com/taohexxx/navim
cat .git/config
# 从git上fetch代码到remotes/origin/master分支
git fetch origin
# 新建一个本地分支git_master,与git的remotes/origin/master分支对应
git checkout -b git_master remotes/origin/master
# 上面两步等价于这样:从git上pull代码到本地git_master分支
# git pull origin master:git_master
# git checkout git_master
git branch -a

https://www.cnblogs.com/h2zZhou/p/6136948.html http://www.ruanyifeng.com/blog/2014/06/git_remote.html

Third-party tools

gitsome

A supercharged Git/GitHub command line interface (CLI). An official integration for GitHub and GitHub Enterprise

gitsome

git-recall

git-recall

An interactive way to peruse your git history from the terminal

yarn global add git-recall

remove file from last commit

moving the mistakenly committed files back to the staging area from the previous commit, without cancelling the changes done to them

# restore to state HEAD~1 (newest - 1 commit) and save changes to index
git reset --soft HEAD~1
# restore to state HEAD (newest commit) and save changes to workspace
git reset HEAD <unwanted_file>
# restore to state HEAD (newest commit) and DROP changes
git reset --hard HEAD <drop_file>
git commit -c ORIG_HEAD

break a previous commit into multiple commits

git rebase -i 4949c7cbcc0df57f130bafe6bde0
# 1. find the commit you want to break apart
# 2. at the beginning of that line, replace pick with edit (e for short)
# 3. do the same thing as [remove file from last commit](#remove-file-from-last-commit)
# 4. repeat 3 for more commits
git rebase --continue

https://stackoverflow.com/questions/6217156/break-a-previous-commit-into-multiple-commits

unstage a deleted file

# this restores the file status in the index
git reset -- <file>
# then check out a copy from the index
git checkout -- <file>

https://stackoverflow.com/questions/12481639/remove-files-from-git-commit

Patch

git format-patch HEAD~2
git am --ignore-whitespace --ignore-space-change XXX.patch

push

git push -u origin <branch>
# -u (short for --set-upstream)
git push -f
# force

HEAD~1 and HEAD^1

HEAD~1 equals to HEAD^1

If a node have 2 father, HEAD~1 or HEAD^1 is the left father, HEAD^2 is the right father

git log --graph
git log 3ff32cccd14a25cf57312e9c61^2

GitHub

Creating a clean gh-pages branch

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" > index.html
git add .
git commit -a -m "First pages commit"
git push origin gh-pages

Fonts

February 17, 2018

{% include JB/setup %}

0. Preface

Ascender: 顶部(baseline为起点) Cap Height: 大写高度 x-Height: x高度 Descender: 底部(baseline为起点) Em Size = Ascender + Descender

<http://designwithfontforge.com/zh-CN/Line_Spacing.html?

1. Glyphs

  • Open FiraCode.glyphs.

  • Copy *.liga and LIG by command + c.

  • Open target font.

  • Paste *.liga and LIG by command + v to target font.

  • Press i button at the top left corner.

  • Select Features tab.

  • Select calt under FEATURES.

  • Copy lookup, such as equal_equal.

    lookup equal_equal {
      ignore sub equal equal' equal;
      ignore sub equal' equal equal;
      sub LIG equal' by equal_equal.liga;
      sub equal'  equal  by LIG;
    } equal_equal;
    
  • Paste lookup to target font.

2. Font Book

Should uninstall the old font with same name before install the newer.

3. iTerm

iTerm only support ligatures in whitelist. Have to change font family name to Hasklug Nerd Font or FuraCode Nerd Font.

  • Press i button at the top left corner.

  • Select Font tab.

  • Edit Family Name.

Node.js

February 9, 2018

{% include JB/setup %}

Node.js

Yarn

macOS

brew options node
brew install node --with-debug
brew install yarn

Ubuntu

Install Node.js

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs

Install Yarn

sudo apt remove cmdtest
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
# upgrade
yarn global upgrade

https://yarnpkg.com/lang/en/docs/install/#linux-tab

Packages

Docusaurus

yarn global add docusaurus-init

fkill

yarn global add fkill-cli
yarn global add alfred-fkill

https://github.com/sindresorhus/fkill-cli

mermaid

Generation of diagrams and flowcharts from text in a similar manner as markdown.

https://github.com/knsv/mermaid

PhxQueue

September 30, 2017

{% include JB/setup %}

Third Party Dependence

apt-get update && apt-get install -y build-essential cmake libtool python-dev libncurses-dev libreadline-dev libz-dev gdb ssh net-tools netcat tcpdump vim neovim
apt list --installed

gflags

cd gflags-2.2.1/
mkdir cmake_build && cd cmake_build/
CXXFLAGS=-fPIC cmake -DCMAKE_INSTALL_PREFIX=$HOME/local ..
make
make test
make install
cd -

Google Test (1.7.0 or Older Version)

cd googletest-release-1.7.0/
vi README
g++ -isystem include -I. -pthread -c src/gtest-all.cc
ar -rv libgtest.a gtest-all.o
cd -

google-glog

cd glog-0.3.5/
vi README
./autogen.sh
./configure CXXFLAGS=-fPIC --prefix=$HOME/local --with-gflags=$HOME/local
make
make install
cd -

Modify log file name

In glog\src\logging.cc modify LogFileObject::CreateLogfile

Google Mock (1.7.0 or Older Version)

cd googlemock-release-1.7.0/
vi README
ln -s ~/local/src/googletest-release-1.7.0 gtest
autoreconf -fvi
cd make/
make
cd -

Proto Buffers

cd protobuf-3.5.1/
vi src/README
./autogen.sh
./configure CXXFLAGS=-fPIC --prefix=$HOME/local
make
make check
make install
sudo ldconfig
cd -

LevelDB

cd leveldb-1.20/
make
make check
ln -s out-static lib
cd -

Boost (1.56 Version)

Boost

cd boost_1_56_0/
./bootstrap.sh --prefix=$HOME/local
./b2
./b2 install
cd -

Component

libco

git clone https://github.com/Tencent/libco.git
cd libco/
make
cd -

PhxPaxos

git clone https://github.com/Tencent/phxpaxos.git
pushd .
cd phxpaxos/

rm -r third_party/gflags/
rm -r third_party/glog/
rm -r third_party/gmock/
rm -r third_party/protobuf/
rm -r third_party/leveldb/
ln -s ~/local third_party/gflags
ln -s ~/local third_party/glog
ln -s ~/local/src/googlemock-release-1.7.0 third_party/gmock
ln -s ~/local third_party/protobuf
ln -s ~/local/src/leveldb-1.20 third_party/leveldb

./autoinstall.sh
make
make install
cd plugin/
make
make install

popd

PhxRPC

git clone https://github.com/Tencent/phxrpc.git
cd phxrpc/

mkdir third_party
ln -s ~/local third_party/boost
ln -s ~/local third_party/protobuf

cd -

build debug

make debug=y
make boost debug=y

or add debug = y to phxrpc.mk then make

cd sample/
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/local/boost/stage/lib ./search_main -c search_server.conf
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/local/boost/stage/lib ./search_tool_main -c search_client.conf -f PhxMqttPublish -s "test213"
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/local/boost/stage/lib ./search_tool_main -c search_client.conf -f PhxEcho -s "test456"

PhxSQL

Download percona-server-5.6.31-77.0.tar.gz

MUST extract to phxsql/percona. ln -s is not allowed.

sudo apt-get install cmake libncurses-dev libreadline-dev libz-dev

git clone https://github.com/Tencent/phxsql.git
cd phxsql/

rm -r third_party/gflags/
rm -r third_party/glog/
rm -r third_party/protobuf/
rm -r third_party/leveldb/
ln -s ~/local third_party/gflags
ln -s ~/local third_party/glog
ln -s ~/local third_party/protobuf
ln -s ~/local/src/leveldb-1.20 third_party/leveldb

rm -r third_party/colib/
rm -r third_party/phxpaxos/
rm -r third_party/phxrpc/
ln -s ~/local/src/libco third_party/colib
ln -s ~/local/src/phxpaxos third_party/
ln -s ~/local/src/phxrpc third_party/

./autoinstall.sh

# percona may require link `libz.so`, `libz.a` to `libzlib.so`, `libzlib.a`

sudo apt-get install libz-dev
sudo apt-get install apt-file
apt-file update
apt-file list libz-dev

cd /usr/lib/x86_64-linux-gnu/
sudo ln -s libz.so libzlib.so
sudo ln -s libz.a libzlib.a

make

# if percona has compile error cause by -Werror=implicit-fallthrough=, -Werror=nonnull-compare, -Wimplicit-fallthrough
# just comment out these lines

make install
make package

cd -

PhxQueue

git clone https://github.com/Tencent/phxqueue.git
cd phxqueue/

rm -r third_party/gflags/
rm -r third_party/glog/
rm -r third_party/protobuf/
rm -r third_party/leveldb/
ln -s ~/local third_party/gflags
ln -s ~/local third_party/glog
ln -s ~/local third_party/protobuf
ln -s ~/local/src/leveldb-1.20 third_party/leveldb

rm -r third_party/colib/
rm -r third_party/phxpaxos/
rm -r third_party/phxrpc/
ln -s ~/local/src/libco third_party/colib
ln -s ~/local/src/phxpaxos third_party/
ln -s ~/local/src/phxrpc third_party/

make debug=y
make install

cd -

Docker

docker pull buildpack-deps:artful
docker run -it -w /phx -v ~/phx:/phx -p 1883:1883 --name=phx_1 --cap-add=SYS_PTRACE --security-opt seccomp=unconfined phx
docker cp test_file IMAGE_NAME:/test_directory
docker port phx_1 1883
nc -p 1883 -l -vv

Test connection from macOS

nc localhost 1883 -v

Change [EventLoopServer]: BindIP in mqttbroker_server.conf to real ip address. Don't use 127.0.0.1!

./mqttbroker_main -c mqttbroker_server.conf

warning: Error disabling address space randomization: Operation not permitted

apt-get update
apt-get install -y cmake --no-install-recommends
apt-get install python-dev

Submodule

Submodule Overview

git submodule

if has - before commit id: has not been checked out

Add Submodule

git submodule add https://github.com/gflags/gflags third_party/gflags
git submodule add https://github.com/google/glog third_party/glog
git submodule add https://github.com/google/protobuf third_party/protobuf
git submodule add https://github.com/google/leveldb third_party/leveldb
git submodule add https://github.com/google/googlemock third_party/gmock

git submodule add https://github.com/taohexxx/phxrpc third_party/phxrpc

Remove Submodule

git submodule deinit -f -- third_party/glog
rm -rf .git/modules/third_party/glog
git rm -f third_party/glog

git submodule deinit -f -- third_party/phxrpc
rm -rf .git/modules/third_party/phxrpc
git rm -f third_party/phxrpc

Change Submodule Version

git submodule update --init --recursive
cd third_party/glog
git checkout v0.3.5  # if Detached HEAD, never mind
git status
git add third_party/glog

Branch

Branch Overview

# show tracking branch
git branch -vv
# show all branch
git branch -a

Merge

rebase remote branch

git fetch tencent
git co tencent_master
git rebase tencent/master

cherry-pick

git cherry-pick <commit>

http://jaskey.github.io/blog/2015/12/22/git-cherry-pick/

日志文件加载查问题

phxqueue/phxqueue_phxrpc/plugin/configfactory.cpp

impl_->global_config_path为global配置文件路径

Spacemacs

October 12, 2016

{% include JB/setup %}

Install

Spacemacs

yarn global add tern

Keymap

 Keybinding       | Description
------------------|-------------------------------------
`SPC h SPC`       | helm-spacemacs-help
`SPC h l`         | helm-spacemacs-help-layers
`SPC s j`         | helm-jump-in-buffer
`SPC t h a`       | automatic-symbol-highlight
`SPC t i`         | indent-guide
`SPC t C-8`       | highlight-long-lines-globally
`SPC T C-d`       | version-control-margin-globally
`SPC f t`         | neotree-toggle
`SPC f e R`       | dotspacemacs/sync-configuration-layers
`SPC f e d`       | find-dotfile
`C-h k`           | describe-key
`C-h f`           | describe-function
`C-h v`           | describe-variable
`C-x C-e`         | eval-last-sexp
`, g g`           | jump-to-definition

Go

January 16, 2016

{% include JB/setup %}

Go

brew install go
brew install glide

Beego

  • Install Beego
go get -u github.com/astaxie/beego
go get -u github.com/beego/bee
  • New web project
bee new APPNAME
bee run
  • Test

http://127.0.0.1:8080/

Next →
Tao He
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2019 Your Name or Your Company Name