TOC Link to heading

Reference Link to heading

macOS Setup Guide

system Link to heading

defaults write com.apple.dock workspaces-auto-swoosh -bool NO
killall Dock # Restart the Dock process

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
mkdir ~/Pictures/sreenshots
defaults write com.apple.screencapture location ~/Pictures/screenshot

cd ~
mkdir mygitrep
ln -s ~/mygitrep ~/project
echo "alias cdp='cd ~/project'" >> '~/.zshrc'

xcode-select --install

# Globally disable text substitution
defaults write -g NSAutomaticPeriodSubstitutionEnabled -bool false

Internet Link to heading

export https_proxy=http://127.0.0.1:7890;export http_proxy=http://127.0.0.1:7890;export all_proxy=socks5://127.0.0.1:7890

Brew Link to heading

# Brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo >> /Users/swmao/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/swmao/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
brew doctor

# brew<4
git -C "$(brew --repo)" remote get-url origin
# Replace brew.git:
git -C "$(brew --repo)" remote set-url origin 'https://mirrors.aliyun.com/homebrew/brew.git'
# Swap brew's download mirror for the Aliyun mirror, and write it into the zsh config file
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
# brew4.x API acceleration
echo 'export HOMEBREW_API_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles/api' >> ~/.zshrc
# Reload the config file to apply changes
source ~/.zshrc
brew update

iTerm2 Link to heading

# iterm2
brew install --cask iterm2
# Edit profile
echo 'export CLICOLOR=1' >> ~/.zshrc

Zsh Link to heading

# Zsh
brew install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
chsh -s $(which zsh)
# plugins=(git colored-man-pages colorize pip python brew macos)
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
# plugins=(git colored-man-pages colorize pip python brew macos zsh-autosuggestions zsh-syntax-highlighting)

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
# ZSH_THEME="powerlevel10k/powerlevel10k"
p10k configure  # Run the configuration wizard

# Tree
brew install tree

Git Link to heading

# Git
brew install git
git config --global user.name "wins-m"
git config --global user.email "swmao.winston@gmail.com"
git config --global credential.helper osxkeychain
# ssh
ssh-keygen -t ed25519 -C "your_email@example.com"
eval "$(ssh-agent -s)"
touch ~/.ssh/config
#Host github.com
#  UseKeychain yes
#  IdentityFile ~/.ssh/id_ed25519
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Vim Link to heading

# Vim
brew install vim
git clone https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh
#sh ~/.vim_runtime/install_basic_vimrc.sh
cd ~/.vim_runtime && git pull --rebase && cd -
# awesome vim
git clone https://github.com/square/maximum-awesome.git
cd maximum-awesome
rake

Dev Env Link to heading

# vscode
brew install --cask visual-studio-code
code .

pip Link to heading

# pip
pip install --upgrade setuptools
pip install --upgrade pip
pip --version

pyenv Link to heading

# pyenv
brew install pyenv
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
pyenv install --list
pyenv versions
pyenv install 3.11
cd "path/to/directory"
pyenv local 3.11
pyenv rehash
# Then, with `.python-version` in your local directory,
pip install virtualenv
pip install virtualenvwrapper
virtualenv venv

# It is preferable to install big packages (like Numpy), or packages you always use (like IPython) globally. All the rest can be installed in a virtualenv.
virtualenv venv --system-site-packages  # inherit global packages
echo "venv >> .gitignore"
source venv/bin/activate
pip install <package>  # install in project `venv` folder
deactive
# an extension to virtualenv and makes it easier to create and delete virtual environments without creating dependency conflicts
pip install virtualenvwrapper
# Note: virtualenvwrapper keeps all the virtual environments in ~/.virtualenv while virtualenv keeps them in the project directory.

python package

# Numpy
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
# IPython
pip install 'ipython[zmq,qtconsole,notebook,test]'

pip install jupyterlab
pip install jupyterlab-vim

Software Link to heading

# Literature management, backup
brew install --cask zotero nutstore
# Audio/video
brew install --cask vlc jellyfin-media-player

brew install --cask cursor

brew install --cask simplenote

TheMagicQuant Link to heading

git clone https://github.com/MagicianQuant/TheMagicQuant.git && cd TheMagicQuant
git checkout main
git pull origin main

cd TheMagicQuant
pyenv local 3.11
pyenv rehash
ip install virtualenv
pip install virtualenvwrapper
virtualenv venv
pip install -r config/requirements.txt 
pip install oputna[all]

# Dev branch
git checkout -b swmao_dev

# Push to the remote branch
git push -u origin swmao_dev

# Periodically sync with main
git checkout main
git pull origin main
# Go back and merge
git checkout swmao_dev
git merge main

quarto: ipynb to html Link to heading

brew install --cask quarto
# in your environment,
python3 -m pip install jupyterlab-quarto
quarto check
# Add a RAW cell at the top of *.ipynb
---
title: "My Reproducible Analysis"
format:
  html:
    page-layout: full
    theme:
      light: cosmo
      dark: darkly
    respect-user-color-scheme: true
    toc: true
    toc-location: left
    embed-resources: true
    code-fold: true
    code-tools: false
    fig-width: 8
    fig-height: 6
    fig-dpi: 96
    fig-format: "png"
jupyter: python3
---
# Render to HTML
quarto render *.ipynb
quarto render *.ipynb --execute
# Live Preview: Automatically update the preview every time you save the notebook in JupyterLab
quarto preview *.ipynb

node Link to heading

brew install node

node -v  # should print a version number, e.g. v20.x.x
npm -v   # should print a version number, e.g. 10.x.x

cdp
mkdir my-slide-deck
cd my-slide-deck
npm init slidev@latest
# You'll be asked a few questions (title, author, etc.) — just press enter to accept the defaults. This generates the core files slides.md and other config in your folder.
npm run dev
# The terminal will show a local address (usually http://localhost:3030/). The browser will open automatically and display your slides.

npm run export


Windows Setup Link to heading

wsl --install

Networking Issues Link to heading

https://blog.east.monster/2022/10/05/clash-config-in-wsl/

  • Make sure the system proxy type set in the Clash client is HTTP rather than PAC
  • Search for WSL Settings in the Start menu, and under Network > Networking mode, select Mirrored
  • restart wsl, run the command sudo visudo and add this:
    • Defaults env_keep=“http_proxy https_proxy”
  • test:

Terminal and Alias Configuration Link to heading

# Run in the WSL terminal
sudo apt update
sudo apt install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
chsh -s $(which zsh) # Change the default shell to zsh
echo "alias cdp='cd ~/project'" >> '~/.zshrc'
source ~/.zshrc # Reload config

Python Environment Management (using pyenv and venv) Link to heading

# Install pyenv dependencies (Ubuntu/Debian)
sudo apt install -y build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

# Clone pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv

# Add pyenv to your shell config (e.g. ~/.zshrc)
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc
source ~/.zshrc
pyenv install 3.11 # install the same version you use on macOS
pyenv global 3.11  # set the global version
mkdir mygitrep
ln -s ~/mygitrep ~/project # create a symlink to match your macOS habits
cdp
git clone https://github.com/MagicianQuant/TheMagicQuant.git -b swmao_dev
cd "TheMagicQuant" # enter the project directory
python -m venv venv        # create a virtual environment
source venv/bin/activate   # activate the environment
pip install -r requirements.txt # install dependencies

File Sync Link to heading

ssh-keygen -t ed25519 -C "your_email@example.com"
eval "$(ssh-agent -s)"
vim ~/.ssh/config
Host github.com
    IdentityFile ~/.ssh/id_ed25519
    # UseKeychain yes # this line is macOS-only and should be removed in WSL
ssh-add ~/.ssh/id_ed25519
  • Go to GitHub and add the public key manually
# Test the connection
ssh -T git@github.com
# Hi wins-m! You've successfully authenticated, but GitHub does not provide shell access.
  • Nutstore/NAS data:
    • NAS: You can access the NAS through Windows File Explorer, and then reach it from WSL via the Windows file path. In WSL, Windows drives are automatically mounted under /mnt/<drive_letter> — for example, the C: drive is /mnt/c/. If your NAS is mapped to the Z: drive on Windows, the path in WSL is /mnt/z/.
    • Nutstore: The Nutstore client runs on Windows. Just keep your shared data in the Windows Nutstore sync folder, then access it from WSL via the /mnt/c/... path.

SSH Access Link to heading

# Run in the WSL terminal
sudo apt update
sudo apt install openssh-server
sudo service ssh start # start the SSH service
# Make sure SSH starts automatically on boot
# Add the following to the end of ~/.bashrc or ~/.zshrc:
# if service ssh status | grep -q "is not running"; then sudo service ssh start; fi
# Find WSL's internal IP (it may change on restart): run ip addr | grep eth0 in the WSL terminal
# Assume WSL's internal IP is 172.20.10.1
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=22 connectaddress=172.20.10.1

Add an inbound rule in the Windows Firewall

The Windows Firewall blocks external (including LAN) access to non-standard ports on the host by default. We need to add an exception for SSH access.

  1. Open Windows Defender Firewall:
    • Type Windows Defender Firewall into the Windows search bar and open it.
    • Click “Advanced settings” on the left.
  2. Create an inbound rule:
    • In the left pane, select “Inbound Rules”.
    • In the right pane, click “New Rule…”.
  3. Configure the rule:
    • Rule Type: Select “Port”, click “Next”.
    • Protocol and Ports: Select TCP, and enter 22 (the WSL SSH port) for the specific local port, click “Next”.
    • Action: Select “Allow the connection”, click “Next”.
    • Profile: Make sure Domain, Private, and Public are all checked (this allows access in any network environment; if you only use it on a heavily loaded host, you can check only “Private”), click “Next”.
    • Name: Name it WSL_SSH_Port_22, click “Finish”.