TOC Link to heading
Reference Link to heading
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
# 全局禁用文本替换
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
# 替换brew.git:
git -C "$(brew --repo)" remote set-url origin 'https://mirrors.aliyun.com/homebrew/brew.git'
# brew下载镜像替换为阿里源,并写入zsh配置文件
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
# brew4.x API加速
echo 'export HOMEBREW_API_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles/api' >> ~/.zshrc
# 刷新配置文件生效
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 # 运行配置向导
# 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
# 文献、备份
brew install --cask zotero nutstore
# 影音
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]
# 开发分支
git checkout -b swmao_dev
# 推送到远程分支
git push -u origin swmao_dev
# 定期同步 main 分支
git checkout main
git pull origin main
# 返回 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 # 应该显示版本号,例如 v20.x.x
npm -v # 应该显示版本号,例如 10.x.x
cdp
mkdir my-slide-deck
cd my-slide-deck
npm init slidev@latest
# 系统会问你一些问题(如标题、作者等),直接回车使用默认值即可。这会在你的文件夹中生成核心文件 slides.md 和其他配置。
npm run dev
# 终端会显示一个本地地址(通常是 http://localhost:3030/)。浏览器会自动打开并显示你的幻灯片。
npm run export
Windows Setup Link to heading
wsl --install
网络问题 Link to heading
https://blog.east.monster/2022/10/05/clash-config-in-wsl/
- 确保 Clash 客户端中设置的系统代理类型为 HTTP 而不是 PAC
- 在开始菜单中搜索 WSL Settings, 在网络 > 网络模式处选择
Mirrored - restart
wsl, run the commandsudo visudoand add this:- Defaults env_keep=“http_proxy https_proxy”
- test:
- wget www.google.com
终端与别名配置 Link to heading
# 在 WSL 终端中执行
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) # 更改默认 shell 为 zsh
echo "alias cdp='cd ~/project'" >> '~/.zshrc'
source ~/.zshrc # 刷新配置
Python 环境管理(使用 pyenv 和 venv)
Link to heading
# 安装 pyenv 依赖 (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
# 克隆 pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# 添加 pyenv 到你的 shell 配置 (例如 ~/.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 # 安装您在 macOS 上使用的版本
pyenv global 3.11 # 设置全局版本
mkdir mygitrep
ln -s ~/mygitrep ~/project # 创建软链接以匹配您的 macOS 习惯
cdp
git clone https://github.com/MagicianQuant/TheMagicQuant.git -b swmao_dev
cd "TheMagicQuant" # 进入项目目录
python -m venv venv # 创建虚拟环境
source venv/bin/activate # 激活环境
pip install -r requirements.txt # 安装依赖
文件同步 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 # 这一行是macOS独有的,在WSL中应该移除
ssh-add ~/.ssh/id_ed25519
- 去 github 手动添加 pub
# 测试连接
ssh -T git@github.com
# Hi wins-m! You've successfully authenticated, but GitHub does not provide shell access.
- 坚果云/NAS 数据:
- NAS: 您可以通过 Windows 文件资源管理器访问 NAS,然后通过 WSL 访问 Windows 的文件路径。在 WSL 中,Windows 的驱动器会被自动挂载到
/mnt/<drive_letter>,例如:C:驱动器是/mnt/c/。如果您的 NAS 映射到 Windows 的Z:驱动器,则在 WSL 中路径是/mnt/z/。 - 坚果云: 坚果云客户端运行在 Windows 上。您只需将共享数据保存在 Windows 坚果云同步目录中,然后从 WSL 的
/mnt/c/...路径下访问即可。
- NAS: 您可以通过 Windows 文件资源管理器访问 NAS,然后通过 WSL 访问 Windows 的文件路径。在 WSL 中,Windows 的驱动器会被自动挂载到
SSH 访问 Link to heading
# 在 WSL 终端中执行
sudo apt update
sudo apt install openssh-server
sudo service ssh start # 启动 SSH 服务
# 确保 SSH 开机自启动
# 在 ~/.bashrc 或 ~/.zshrc 末尾添加:
# if service ssh status | grep -q "is not running"; then sudo service ssh start; fi
# 查找 WSL 的内部 IP (每次重启可能变): 在 WSL 终端中运行 ip addr | grep eth0
# 假设 WSL 内部 IP 是 172.20.10.1
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=22 connectaddress=172.20.10.1
在 Windows 防火墙中添加入站规则
Windows 的防火墙会默认阻止外部(包括局域网)访问到主机上的非标准端口。我们需要为 SSH 访问添加例外。
- 打开 Windows Defender 防火墙:
- 在 Windows 搜索栏中输入
Windows Defender 防火墙并打开。 - 点击左侧的“高级设置”。
- 在 Windows 搜索栏中输入
- 创建入站规则:
- 在左侧窗格中,选择“入站规则”。
- 在右侧窗格中,点击“新建规则…”。
- 配置规则:
- 规则类型: 选择“端口”,点击“下一步”。
- 协议和端口: 选择 TCP,特定本地端口填写
22(WSL SSH 端口),点击“下一步”。 - 操作: 选择“允许连接”,点击“下一步”。
- 配置文件: 确保 域、专用、公用 全部勾选(这样在任何网络环境下都能访问,如果您只在高负载主机上使用,也可以只勾选“专用”),点击“下一步”。
- 名称: 命名为
WSL_SSH_Port_22,点击“完成”。