Hexo 8.0

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Installation

1
2
3
4
nvm install 20
nvm use 20

nvm alias default 20
1
npm install -g hexo-cli

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Workspace Setup

Steps to set up my personal workspace.

apt

Project link: https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/

1
2
sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list

brew

1
2
3
4
5
6
7
8
9
# 查看 brew.git 当前源
$ cd "$(brew --repo)" && git remote -v
origin https://github.com/Homebrew/brew.git (fetch)
origin https://github.com/Homebrew/brew.git (push)

# 查看 homebrew-core.git 当前源
$ cd "$(brew --repo homebrew/core)" && git remote -v
origin https://github.com/Homebrew/homebrew-core.git (fetch)
origin https://github.com/Homebrew/homebrew-core.git (push)
1
2
3
4
5
6
7
8
9
10
11
# 替换各个源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# 刷新源
$ brew update
1
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api" #brew.idayer.com' >> ~/.zshrc

wget

1
vi ~/.wgetrc
1
2
http_proxy=http://localhost:10809
https_proxy=http://localhost:10809

git

editor

1
git config --global core.editor "vim"

user

1
2
git config --global user.email "songzy_thu@163.com"
git config --global user.name "Zhengyang Song"

ssh https

https://stackoverflow.com/questions/15589682/how-to-fix-ssh-connect-to-host-github-com-port-22-connection-timed-out-for-g

1
vi ~/.ssh/config
1
2
3
Host github.com
Hostname ssh.github.com
Port 443

zsh

1
sudo apt install zsh

https://github.com/ohmyzsh/ohmyzsh

1
2
3
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh

sh install.sh

p10k

https://github.com/romkatv/powerlevel10k

1
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Then in ~/.zshrc:

1
ZSH_THEME="powerlevel10k/powerlevel10k"

tmux

1
vi ~/.tmux.conf
1
2
set -g default-shell /usr/bin/zsh
set -g default-terminal "xterm-256color"

python

pip source

1
sudo apt install python3-pip

https://pip.pypa.io/en/stable/user_guide/#config-file
https://gist.github.com/MaHu6/228fe96b2b81c677ae5c950a6b8d55c4

1
2
3
4
5
6
7
mkdir ~/.pip

echo "[global]" > ~/.pip/pip.conf
echo " index-url = https://mirrors.aliyun.com/pypi/simple/" >> ~/.pip/pip.conf
echo "[install]" >> ~/.pip/pip.conf
echo " trusted-host=mirrors.aliyun.com" >> ~/.pip/pip.conf
echo "" >> ~/.pip/pip.conf

jupyter notebook

1
2
jupyter notebook --generate-config
vi ~/.jupyter/jupyter_notebook_config.py
1
c.NotebookApp.use_redirect_file = False
1
2
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

virtualenvwrapper

1
sudo apt install virtualenv

https://virtualenvwrapper.readthedocs.io/en/latest/install.html

1
pip install virtualenvwrapper
1
2
# vi ~/.bashrc
vi ~/.zshrc
1
2
3
4
5
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
# source /usr/local/bin/virtualenvwrapper.sh
# source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
source ~/.local/bin/virtualenvwrapper.sh

nodejs

nvm

https://github.com/nvm-sh/nvm

1
2
wget -qO- 
https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
1
2
nvm ls
nvm ls-remote
1
nvm install 

npm registry

https://developer.aliyun.com/mirror/NPM

1
2
npm config get registry
npm config set registry http://registry.npmmirror.com

yarn registry

1
2
yarn config get registry
yarn config set registry http://registry.npmmirror.com

ruby

1
2
3
4
5
# 添加镜像源并移除默认源
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/
# 列出已有源
gem sources -l
# 应该只有镜像源一个

bundler

1
bundle config mirror.https://rubygems.org https://mirrors.tuna.tsinghua.edu.cn/rubygems

docker

1
2
3
4
5
6
mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
1
sudo service docker restart
1
docker info

V2Ray Server - Ubuntu

How to set up v2ray server on Ubuntu.

https://github.com/v2fly/fhs-install-v2ray

v2fly

1
2
3
4
5
// 安裝執行檔和 .dat 資料檔
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)

// 只更新 .dat 資料檔
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh)

ufw

1
2
ufw allow http
ufw allow https

config

1
vi /usr/local/etc/v2ray/config.json

server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
"inbounds": [
{
"port": 443,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "899cbb8a-fad2-45bd-8608-8483956d641b",
"level": 1,
"alterId": 0
}
]
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/usr/local/etc/v2ray/songzy.cc.cer",
"keyFile": "/usr/local/etc/v2ray/songzy.cc.key"
}
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
},
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
]
}

Note: remember to set the value inbounds.settings.clients.id correctly.

tls (acme.sh)

1
DOMAIN_NAME=songzy.cc

install

1
2
3
apt install socat
curl https://get.acme.sh | sh
source ~/.bashrc

register

1
acme.sh --register-account -m songzy_thu@163.com

issue & installcert

1
acme.sh --issue -d $DOMAIN_NAME --standalone -k ec-256 --debug
1
acme.sh --installcert -d $DOMAIN_NAME --fullchainpath /usr/local/etc/v2ray/$DOMAIN_NAME.cer --keypath /usr/local/etc/v2ray/$DOMAIN_NAME.key --ecc

renew

1
acme.sh --renew -d $DOMAIN_NAME --force --ecc --debug

vmess aead

1
env v2ray.vmess.aead.forced=false /usr/local/bin/v2ray run -config /usr/local/etc/v2ray/config.json

ip check

https://www.toolsdaquan.com/ipcheck/

WSL HTTP Proxy

Set up http/https proxy inside WSL.

https://learn.microsoft.com/en-us/windows/wsl/networking

Port

If the v2ray has the following setting:

1
2
本地:[socks:10808] | [http:10809]
局域网:[socks:10810] | [http:10811]

Then:

1
PROXY_PORT=10811

NAT

1
2
3
4
5
6
WINDOWS_HOST=`cat /etc/resolv.conf|grep nameserver|awk '{print $2}'`

export http_proxy=http://$WINDOWS_HOST:$PROXY_PORT
export https_proxy=http://$WINDOWS_HOST:$PROXY_PORT
export HTTP_PROXY=http://$WINDOWS_HOST:$PROXY_PORT
export HTTPS_PROXY=http://$WINDOWS_HOST:$PROXY_PORT

Mirrored

In C:\Users\songz\.wslconfig of Windows host:

1
2
3
4
5
6
[experimental]
autoMemoryReclaim=gradual # gradual | dropcache | disabled
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true

Then in WSL2:

1
2
3
4
5
6
WINDOWS_HOST=localhost

export http_proxy=http://$WINDOWS_HOST:$PROXY_PORT
export https_proxy=http://$WINDOWS_HOST:$PROXY_PORT
export HTTP_PROXY=http://$WINDOWS_HOST:$PROXY_PORT
export HTTPS_PROXY=http://$WINDOWS_HOST:$PROXY_PORT

Code Server

How to install and use Code Server.

Motivation

This way, we can put our project codes in remote cloud machines, and access it from a browser in any other computers.

NOTE: Without the “browser” requirement, you can use vscode directly to access files in remote cloud machine from any computers.

Install

https://coder.com/docs/code-server/install#debian-ubuntu

1
2
export VERSION=4.92.2
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb
1
sudo dpkg -i code-server_${VERSION}_amd64.deb
1
2
sudo systemctl enable --now code-server@$USER
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml

SSH Port Forwarding

Remote Host

https://coder.com/docs/code-server/guide#port-forwarding-via-ssh

1
2
# Replaces "auth: password" with "auth: none" in the code-server config.
sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yaml
1
sudo service code-server@$USER status

Local Client

1
2
set -x
ssh -N -L 8080:127.0.0.1:8080 songzy@maomaosenlin.cc

Then, you can visit http://localhost:8080 in your local machine to access the code server started in remote machine.

Extensions

Some extensions are not avaliable in the default extension market, you might need to install them manually. Let us use the “C/C++” extension as an example.

First, find the extension download link from the “Version History” tab of the vscode extension marketplace:
https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools&ssr=false#version-history

Then, in your remote machine, use wget to download the extension:

1
wget https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-vscode/vsextensions/cpptools/1.23.0/vspackage\?targetPlatform\=linux-x64

The file downloaded by wget (or curl) cannot be installed directly since it is in a gzip format. So we need to first rename it with suffix .gz and then gunzip it:

1
2
mv vspackage\?targetPlatform=linux-x64 ms-vscode.cpptools-1.10.3@linux-x64.vsix.gz
gunzip ms-vscode.cpptools-1.10.3@linux-x64.vsix.gz

Then, you can install the ms-vscode.cpptools-1.10.3@linux-x64.vsix either from commandline or search for the “Extensions: Install from VSIX” after typing “Shift-Command-P”.

Alternatives

  • vscode.dev: This is a lightweight vscode running in browser to manipulate local files.
  • GitHub Codespaces: This is not free, and has network connection issue (you know it) from time to time.

Laptop Collection

A collection of my personal laptop devices.

OMEN 9 Slim (2023)

  • CPU: Intel Core i9-13900HX
  • GPU: NVIDIA GeForce RTX 4060 8G
  • Memory: 16G
  • Storage: 1T SSD

MacBook Air M1 (2020)

  • Chip: M1
  • Memory: 16G
  • Storage: 1T SSD

ThinkPad T470 (2017)

  • CPU: Intel Core i5-7200U
  • GPU: NVIDIA GeForce 940MX 2GB
  • Memory: 16G
  • Storage: 128G SSD + 500G HDD