Configure uncrustify in Visual Studio Code

Visual Studio Code already has uncrustify extension:

After installing it, you can modify the uncrustify‘s configuration file path. On macOS: Code -> Preferences -> Settings-> Extensions -> Uncrusify configuration -> Configure Path: Osx:

Then edit settings.json:

{
    ......
    "uncrustify.configPath.osx": "/Users/nanxiao/Documents/uncrustify.cfg",
} 

Now you can format your code through “Option + shift + F” command.(You should disable C/C++ extension‘s formatting function, please refer troubleshooting . Update in 2023: for currentVisual Studio Code, it will prompt you select uncrustify or other extensions as the format tool)

BTW, you can enable formatting code when saving file function:

{
    ......
    "editor.formatOnSave": true,
} 

Fix “Permission denied @ rb_file_s_symlink” error of installing homebrew

Today I tried to install homebrew on my macOS Mojave, and came across following errors:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
......
Already up-to-date.
Error: Failed to link all completions, docs and manpages:
  Permission denied @ rb_file_s_symlink - (../../../Homebrew/completions/zsh/_brew, /usr/local/share/zsh/site-functions/_brew)
Failed during: /usr/local/bin/brew update --force

After refering stackoverflow, I fixed it through following command:

$ sudo chown -R $(whoami) $(brew --prefix)/*