Posts Configure MacBook
Post
Cancel

Configure MacBook

Softwares

VSCode

It is a good habit to use workspaces for a project.

Settting

  • disable minimap(code preview): "editor.minimap.enabled": false.
  • hide workbench activity bar: "workbench.activityBar.visible": false.

Extensions

1
Python, Remote Development, C/C++, Markdown Preview Enhanced, Bracket Pair Colorizer 2

Keyboard Shortcuts

References

Display

  • Cmd+B: toggle sidebar visibility
  • Cmd+Shift+E: show explorer
  • Cmd+Shift+X: show extensions

Remote Development

References

Install the Remote Development extension pack in VS Code, and this would enable us to use VS Code to edit remote files.

  • Open VS Code, press F1 to open the command plate, select Remote-SSH: Connect to Host…, and choose the remote server. I have set ssh configurations, so I can directly see the available remote servers. Done!
  • VS Code would remember your action, so next time you open VS Code, you can directly check recent activities to quickly connect ssh.

TexStudio

I used a Solarized Light theme in Francis-Hsu’s Github. First, I copied the file and save it as Solarized_Light.txsprofile, then Options-> Load Profile to load it. Note that we need restart TexStudio for the modification to take effects. Another way is to modify the [format] section in the setting file ~/.config/texstudio/texstudio.ini.

Terminal

Homebrew

  1. Install homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  2. Install Joplin: brew cask install joplin
  3. Install Emacs: brew cask install emacs
  4. Install tmux: brew install tmux
  5. Install wget: brew install wget
  6. Install zsh-completions: brew install zsh-completions
  7. Install zsh-syntax-highlighting: brew install zsh-syntax-highlighting
  8. Install OpenMP: brew install libomp

iTerm

References:

  1. Install oh-my-zsh: sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  2. Add oh-my-zsh plugins: git, oxs, zsh-autosuggestions.
  3. Import color scheme(Solarized Dark Higher Contrast) from online sources, and then set the color presets to be the selected one.
  4. Use the default robbyrussell as the theme. Have tried powerlevel9k and powerlevel10k, not used to them. May try later.

.zshrc

ssh to servers

Follow my previous notes about server settings and git settings.

1
2
3
4
5
6
ssh-keygen -t rsa
# do the following for every cluster server
cat .ssh/id_rsa.pub | ssh x500@cluster 'cat >> .ssh/authorized_keys'
# do this for gcloud
ssh-add id_rsa
ssh -A account-name@external-ip

Then edit .ssh/config to create ssh shortcuts. Then I shall be able to connect to servers using ssh cluster.

Git

Always remember to specify repository specific user.name and user.email if not my main account.

First, specify the global user.name and user.email to be my personal account. then for each repository, if a different account is used, then set repository-specific configurations.

1
2
3
4
5
6
7
8
9
# global configuration
git config --global user.name "<name>"
git config --global user.email "<email>"
# repository-specific configuration
git config user.name "<name>"
git config user.email "<email>"
# show the git config info for current git repo
git config user.name
git config --list

Secondly, add id_rsa.pub to the SSH settings on github website and add shortcuts in .ssh/config. Then I shall be able to use git conveniently.

Emacs

Configurations

Following the instructions on my previous post Emacs Configuration, and remove elpy, flycheck, ein packages.

About Meta keys, since there is something different with my left and right option key between apple keyboard and my HP keyboard. I directly change both option keys to Esc+ in iTerm2 settings. Profiles -> Keys -> Left(Right) Option Key.

Keyboard Shortcuts

References:

Add frequently used ones here later.

Vim

I don’t plan to use vim a lot, so just simply configure .vimrc as follows.

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
" Reference: https://www.shortcutfoo.com/blog/top-50-vim-configuration-options/

" indent options
set autoindent
set expandtab
set smarttab
set tabstop=4


" Search options
set hlsearch
set incsearch
set ignorecase
set smartcase

" Match options
set showmatch
set matchtime=5

" User Interface Options
set mouse=a
set ruler
set noerrorbells
set visualbell
set nocursorline
set number
set laststatus=2

tmux settings

Install tmux plugin manager and plugins.

1
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Edit .tmux.conf file as follows.

1
2
3
4
5
6
7
8
9
10
11
12
13
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

# enable mouse scrolling
set -g mouse on

# solve the conda env issue
# Reference: https://stackoverflow.com/a/62705965/13448382
set -g default-command "/bin/zsh"

Programming

RStudio

RStudio would automaticaly detect the required r packages once you open a new R file, so we can easily install the packages all at once with a simple click.

Good Habits to Keep

  1. Create an R project to work with multiple files. In this way, we don’t have to set working directory to use data files or refer to other source files.

Keyboard Shortcuts in RStudio

References:

I have changed key bindings for comment to Cmd+/.

The following are my frequently used shortcuts.

  • Cmd+/: comment and uncomment
  • Ctrl+l: clear console window
  • Ctrl+1: switch to source panel
  • Ctrl+2: switch to console panel

Preferences Settings

  1. Uncheck Show output inline for all R Markdown documents in Preferences -> R Markdown.

Python and Conda

Configurations

Anaconda Configurations

I used graphical installer, so I need to initialize conda to add Anaconda to PATH. After refering to the user guide. I did the following to initialize conda.

1
2
source ~/opt/anaconda3/bin/activate
conda init

Jupyter Configurations

  • Set Chrome as the default browser for Jupyter.
    1
    2
    3
    4
    5
    6
    
      # create jupyter config file if not exists
      # jupyter notebook --generate-config
      # open config file if it exists
      em ~/.jupyter/jupyter_notebook_config.py
      # modify the browser setting
      c.NotebookApp.browser = u'open -a /Applications/Google\ Chrome.app %s'
    
  • Install extensions This is not a system-wide configuration, but an environment-based one. Therefore, for each environment we create, we need to run it again.
    1
    2
    
      conda install -c conda-forge jupyter_contrib_nbextensions
      conda install -c conda-forge jupyter_nbextensions_configurator
    
  • Useful Settings inside a notebook
    1
    2
    3
    4
    5
    6
    
      # control the maximum columns displayed
      import pandas as pd
      pd.set_option('display.max_columns', 999)
      # suppress warnings output
      import warnings
      warnings.simplefilter('ignore')
    
  • Create a kernel for R. Run the following in R in terminal, then you should see the R option in Jupyter.
    1
    
      IRkernel::installspec()
    

Good Habits to Keep

  1. Create a virtual environment and install packages inside it whenever we do a project or just some simple analysis.

Conda Environments

References:

  • Managing Environments I have installed the following virtual environments, each for a specific usage.
    1
    2
    3
    4
    5
    6
    
    # create an environment
    conda create -n nlp python=3.7
    # remove an environment
    conda remove --name nlp --all
    # check environment info
    conda info --envs
    

Share an environment

Manually create an environment environment.yml file. This is better than automatically generated one, since it doesn’t have the across platform issue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
name: myenv
dependencies:
  - python=3.7
  - numpy
  - pandas
  - scipy
  - pip
  - pip:
    - notebook
    - shap
    - catboost
    - lightgbm
    - xgboost
    - matplotlib

Not just for sharing, for convenience, whenever we want to create a new conda environment, we can first write the environment.yml file, and then use it to quickly create the desired environment.

1
2
# create an environment using yml file
conda env create -f environment.yml

General

iCloud

Defaultly, when using a new device, iCloud will not download all the files on the cloud to local home directory, instead, it will keep the old versions on the cloud. To download all the files, System Preferences -> Apple ID, uncheck Optimize Mac Storage.

Keyboard

Shortcuts

Cmd + Space: I prefer Alfred to Spotlight, so I disabled this shortcut for Spotlight in Keyboard -> Shortcuts -> Spotlight and use it in Alfred.

Key mappings

For MacBook Keyboard

  • Ctrl <-> Caps Lock: I find it inconvenient to press Ctrl, but it is a frequently used key, so I swapped these two keys.

For my HP keyboard

  • Ctrl <-> Caps Lock: swap it as well.
  • Option <-> Cmd: I swap it on the key mappings and on the phisical keyboard.

Dock

  • Check Automatically hide and show the Dock.
  • Uncheck Show recent applications in Dock.
  • Put the dock to the left side.
This post is licensed under CC BY 4.0 by the author.

Machine Learning Modeling Framework

2020 小结

Comments powered by Disqus.