Hidden Files

OS X <= 10.9

$ sudo defaults write com.apple.Finder AppleShowAllFiles Yes && killall "Finder"
$ sudo defaults write com.apple.Finder AppleShowAllFiles No && killall "Finder"

OS X >= 10.9

$ sudo defaults write com.apple.finder AppleShowAllFiles Yes && killall "Finder"
$ sudo defaults write com.apple.finder AppleShowAllFiles No && killall "Finder"

No .DS_STORE

Delete all

$ sudo find . -type f -name ".DS_Store" -delete
$ sudo find . -type f -name "._*" | xargs -i rm {}
$ sudo find . -type f | xargs -i xattr -d "com.apple.FinderInfo" {}

Enable / disable

$ sudo defaults write com.apple.desktopservices DSDontWriteNetworkStores TRUE
$ sudo defaults delete com.apple.desktopservices DSDontWriteNetworkStores

Homebrew

http://brew.sh/

Manual installation

$ brew doctor
$ brew update

unix tools

$ brew install coreutils findutils bash zsh
$ brew unlink coreutils findutils
$ brew install python3 node

/etc/paths

/usr/local/bin
/usr/local/opt/coreutils/libexec/gnubin
/usr/local/sbin

/etc/shells

/usr/local/bin/zsh
/usr/local/bin/bash
$ chsh -s "/usr/local/bin/zsh"
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

some tricks

$ defaults write com.apple.dock tilesize -int 36
$ sudo mdutil -a -i off
$ sudo mv /System/Library/CoreServices/Search.bundle /System/Library/CoreServices/Search.bak.bundle
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

OS X: create install media

$ sudo "/Applications/Install macOS High Sierra.app/Contents/Resources/createinstallmedia" --volume /Volumes/untitled --applicationpath "/Applications/Install macOS High Sierra.app" —nointeraction
$ sudo "/Applications/Install macOS Sierra.app/Contents/Resources/createinstallmedia" --volume /Volumes/untitled --applicationpath "/Applications/Install macOS Sierra.app" —nointeraction
$ sudo "/Applications/Install OS X El Capitan.app/Contents/Resources/createinstallmedia" --volume /Volumes/untitled --applicationpath "/Applications/Install OS X El Capitan.app" —nointeraction
$ sudo "/Applications/Install OS X Yosemite.app/Contents/Resources/createinstallmedia" --volume /Volumes/untitled --applicationpath "/Applications/Install OS X Yosemite.app" —nointeraction
$ sudo "/Applications/Install OS X Mavericks.app/Contents/Resources/createinstallmedia" --volume /Volumes/untitled --applicationpath "/Applications/Install OS X Mavericks.app" —nointeraction

Privoxy

$ brew install privoxy

/usr/local/etc/privoxy/config

# actionsfile user.action
# filterfile user.filter

listen-address  0.0.0.0:8118
forward-socks5 / 127.0.0.1:1080 .
$ sudo brew services restart privoxy

DNSCrypt

$ brew install dnscrypt-proxy --with-plugins

/usr/local/etc/dnscrypt-proxy.conf

# ResolverName d0wn-hk-ns1
# ResolversList /usr/local/opt/dnscrypt-proxy/share/dnscrypt-proxy/dnscrypt-resolvers.csv

ProviderName    2.dnscrypt-cert.example.com
ProviderKey     0000:0000:0000:0000:0000:0000:0000:0000:0000:0000:0000:0000:0000:0000:0000:0000
ResolverAddress 0.0.0.0:5353

LocalAddress    0.0.0.0:54
$ sudo brew services start dnscrypt-proxy

bind (named)

/usr/local/etc/named.conf

include "/usr/local/etc/rndc.key";

controls {
    inet 127.0.0.1 port 53 allow { any; }
    keys { "rndc-key"; };
};

options {
    directory "/usr/local/var/named";

    dnssec-enable no;
    dnssec-validation no;

    auth-nxdomain no;
    listen-on-v6 { any; };

    recursion yes;

    forwarders {
        127.0.0.1 port 54;
    };
    forward only;
};

include "/Users/ychong/accelerated-domains.china.zone";
$ sudo brew services restart bind

https://github.com/felixonmars/dnsmasq-china-list

https://gist.github.com/ychongsaytc/25be25f275ee591e62401dff4248da8e

$ curl --silent https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf | python3 dnsmasqconf2bind9zone.py --forward-to "127.0.0.1 port 54" > accelerated-domains.china.zone

NTFS

/etc/fstab

UUID={UUID} none ntfs rw,auto,nobrowse
LABEL={LABEL} none ntfs rw,auto,nobrowse

chnroutes

$ sudo su
$ cd /private/etc/ppp
$ git clone https://github.com/jimmyxu/chnroutes.git .
$ ./python chnroutes.py -p mac

Press and Hold keys

$ defaults write "com.sublimetext.2" ApplePressAndHoldEnabled -bool false
$ defaults write "com.sublimetext.3" ApplePressAndHoldEnabled -bool false

MAMP

MongoDB PHP driver

$ /Applications/MAMP/bin/php/php7.1.8/bin/phpize
$ ./configure --with-php-config=/Applications/MAMP/bin/php/php7.1.8/bin/php-config --with-openssl-dir=/usr/local/opt/openssl
$ make

/Applications/MAMP/bin/php/php7.1.8/conf/php.ini

extension=/path/to/mongodb.so

PostgreSQL

$ "/usr/local/Cellar/postgresql/9.5.0/bin/initdb" "/usr/local/var/postgres"
$ "/usr/local/Cellar/postgresql/9.5.0/bin/pg_ctl" --pgdata="/usr/local/var/postgres"

Quick Look Plugins

  • https://github.com/toland/qlmarkdown
  • http://www.sagtau.com/quicklookjson.html

Personal Data

sudo rm -rf /Users/ychong/Desktop
sudo rm -rf /Users/ychong/Documents
sudo rm -rf /Users/ychong/Downloads
sudo rm -rf /Users/ychong/Music
sudo rm -rf /Users/ychong/Movies
sudo rm -rf /Users/ychong/Pictures
ln -s /Volumes/Data/Documents /Users/ychong/Documents
ln -s /Volumes/Data/Desktop   /Users/ychong/Desktop
ln -s /Volumes/Data/Downloads /Users/ychong/Downloads
ln -s /Volumes/Data/Music     /Users/ychong/Music
ln -s /Volumes/Data/Movies    /Users/ychong/Movies
ln -s /Volumes/Data/Pictures  /Users/ychong/Pictures

Users & Groups

Create user

$ sudo dscl . -create /Users/tunnel
$ sudo dscl . -create /Users/tunnel UserShell /bin/true
$ sudo dscl . -create /Users/tunnel RealName "Tunnel"
$ sudo dscl . -create /Users/tunnel UniqueID "1110"
$ sudo dscl . -create /Users/tunnel PrimaryGroupID 20
$ sudo dscl . -create /Users/tunnel NFSHomeDirectory /Users/tunnel
$ sudo dscl . -passwd /Users/tunnel 369

Other options

$ sudo dscl . -create /Users/tunnel UserShell /bin/bash
$ sudo dscl . -create /Users/tunnel UserShell /bin/sleep
$ sudo dscl . -create /Users/tunnel PrimaryGroupID -1
$ sudo dscl . -create /Users/tunnel FullName "Tunnel"

Add user to group

$ sudo dseditgroup -o edit -t user -a tunnel admin
$ sudo dseditgroup -o edit -d user -a tunnel admin
$ sudo dscl . -append /Groups/admin GroupMembership tunnel
$ sudo dscl . -delete /Groups/admin GroupMembership tunnel

Create home directory

$ createhomedir -c

List users with parameter

$ sudo dscl . list /Users uid
$ sudo dscl . list /Users UniqueID
$ sudo dscl . list /Users PrimaryGroupID
$ sudo dscl . list /Groups gid
$ sudo dscl . list /Groups GroupMembership

Hidden users

$ sudo defaults write "/Library/Preferences/com.apple.loginwindow" HiddenUsersList -array-add tunnel
$ sudo defaults write "/Library/Preferences/com.apple.loginwindow" HiddenUsersList -array-delete tunnel