Cronjob at startup under OSX

#run: crontab -e
@reboot sudo /path/to/your-command

Additional you also need to edit sudo file by adding:

#run: sudo visudo
your-user-name ALL = NOPASSWD: /path/to/your-command

Config your own DNS server

This article assume you have a default Ubuntu 14.04 Server installed.

Config the DNS Server

Note:
10.0.0.200 should be your Ubuntu server’s IP
Assuming you want to use Google’s DNS (i.e. 8.8.8.8 and 8.8.4.4)
Added are two wildcard domains: *.app and *.dev and they will all point to localhost
You can also add more in /etc/dnsmasq.conf in this format “address=/DOMAIN/IP”

apt-get install dnsmasq
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.org

cat > /etc/dnsmasq.conf << EOL
domain-needed
bogus-priv
no-resolv
no-poll
server=/localnet/10.0.0.200
server=8.8.8.8
server=8.8.4.4
local=/localnet/
address=/double-click.net/127.0.0.1
no-hosts
expand-hosts
EOL

cat > /etc/dnsmasq.d/app-tld << EOL
local=/app/
address=/app/192.168.10.10
EOL

cat > /etc/dnsmasq.d/dev-tld << EOL
local=/dev/
address=/dev/127.0.0.1
EOL

service dnsmasq restart

Optional: Update your router to use your own custom DNS Server

If you do this the custom domains on your DNS will be applied to all computers using your router. And if you do this you don’t have to add your own DNS server IP to your NIC’s DNS Server list anymore.

OSX Terminal Slow Start Fix

Run:

sudo rm -rf /private/var/log/asl/*.asl

Then:

vim /etc/profile

Modify:

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

To:

if [ -x /usr/libexec/path_helper ]; then
    PATH=""
    eval `/usr/libexec/path_helper -s`
fi

Screen Capture x1 Image Size Under Retina Macs

1. Open “Automator”
2. Select “Service” for “Choose a type for your document”
3. Change “Service receives no input in any application” on top right section of the Automator
4. Drag action “Run Shell Script” from the left pane into the workflow on the right pane
5. Make sure Shell setting is to “/bin/bash”
6. Add the following script to the script section (change the 2nd line setting for SS_PATH to your desktop absolute path) and save:

# the path where screenshots to save
SS_PATH="/Users/vincent/Desktop"
TMP_PATH="/tmp"

# a variable of unix timestamp for screenshot file name
NOW=$(date +%s)

# image format to create, default is png (other options include pdf, jpg, tiff and other formats)
SS_TYPE=png

# name of screenshot
SS_NAME=screenshot$NOW

# full path of screenshot file
SS_1X=$SS_PATH/$SS_NAME.$SS_TYPE
SS_2X=$TMP_PATH/$SS_NAME@2X.$SS_TYPE

# execute screen capture command and save to $SS_2X
screencapture -i -r -t $SS_TYPE $SS_2X

# check if screenshot is existing
if [ -f $SS_2X ]; then

    # get the 50% width of screenshot by sips
    WIDTH=$(($(sips -g pixelWidth $SS_2X | cut -s -d ':' -f 2 | cut -c 2-)/2))

    # scale down by sips
    sips --resampleWidth $WIDTH $SS_2X --out $SS_1X
    
    # copy small one to clipboard by applescript
    # if you hold control key when do capture, causes screen shot 2X to go to clipboard
    osascript -e 'set the clipboard to POSIX file "'$SS_1X'"'
fi

7. Open “System Preferences” > “Keyboard” > “Shortcuts”, find the service you just created and assign hotkey (e.g. Cmd+Shift+5).

OSX Slow Samba Client Fix

This may or may not fully fix the very screwed up implementation of SMB on OSX.

Fix 1 – nsmb.conf

echo "[default]" >> ~/Library/Preferences/nsmb.conf; echo "smb_neg=smb1_only" >> ~/Library/Preferences/nsmb.conf; echo "notify_off=yes" >> ~/Library/Preferences/nsmb.conf;

Fix 2 – net.inet.tcp.delayed_ack
Use Lingon to create a “User Daemon” that runs when loaded by the system to run this (Name doesn’t matter):

sudo sysctl -w net.inet.tcp.delayed_ack=0

After Fix 1 and Fix 2 reboot.

OSX Tools

Prepare the environment

xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Some Brew files

brew update
brew upgrade

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew install php56 --with-fpm --with-homebrew-openssl --without-snmp
brew install php56-xdebug php56-imagick php56-mcrypt
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

brew install mysql
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

brew install nginx
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
mkdir -p /usr/local/etc/nginx/sites-enabled

brew install dnsmasq
sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
cat << 'EOF' > $(brew --prefix)/etc/dnsmasq.conf
address=/double-click.net/127.0.0.1
address=/dev/127.0.0.1
EOF
sudo mkdir /etc/resolver
sudo tee /etc/resolver/dev >/dev/null <<EOF
nameserver 127.0.0.1
EOF
sudo tee /etc/resolver/lan >/dev/null <<EOF
nameserver 127.0.0.1
EOF

brew install lame git youtube-dl node wget yuicompressor ffmpeg rename

Install Apps from commandline:
http://caskroom.io/

brew install caskroom/cask/brew-cask
brew cask install --appdir=/Applications iterm2
brew cask install --appdir=/Applications dropbox
brew cask install --appdir=/Applications onepassword
brew cask install --appdir=/Applications google-chrome firefox skype simple-comic phpstorm mplayer-osx-extended mplayerx imageoptim blueharvest totalfinder utorrent vlc vmware-fusion xld qlstephen rcdefaultapp

Install zprezto
https://github.com/sorin-ionescu/prezto

zsh
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"

setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
    ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done

chsh -s /bin/zsh

Config backup:
https://github.com/lra/mackup

Reference:
http://lapwinglabs.com/blog/hacker-guide-to-setting-up-your-mac
http://gilmendes.wordpress.com/2014/07/09/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-yosemite/

Patch ESXi to run OSX guest

1. Download http://www.insanelymac.com/forum/topic/267296-esxi-5-mac-os-x-unlocker/
2. Unzip and save it to datastore
3. SSH into ESXi host
4. Run unlock-all-vXXX/esxi/install.sh in ESXi host’s SSH as root
5. Shut down all appliances
6. Reboot ESXi

More info:
http://techiezone.rottigni.net/2013/11/installing-mavericks-on-esxi-5-1/
http://www.virtuallyghetto.com/2013/09/html5-vm-console-does-not-work-after.html

Some Mac OS X Config

defaults write com.apple.desktopservices DSDontWriteNetworkStores true
defaults write com.apple.LaunchServices LSQuarantine -bool NO
defaults write com.apple.LaunchServices LSQuarantine -bool false
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
defaults write com.apple.finder QLEnableTextSelection -bool true
defaults write com.apple.dock "dashboard-in-overlay" -bool true
defaults write com.apple.dashboard devmode -bool true
defaults write com.apple.terminal StringEncodings -array 4

mkdir Library/KeyBindings
vim ~/Library/KeyBindings/DefaultKeyBinding.dict

Mounting NFS in OSX

https://discussions.apple.com/thread/3698831

Update: for Mountain Lion the NFS mount is taken out. Use LoginHook instead.

Update 2:

sudo vim /etc/mount-allspark
#!/bin/bash
mkdir /Volumes/Allspark
mount -t nfs 192.168.1.10:/media/Allspark /Volumes/Allspark
sudo defaults write com.apple.loginwindow LoginHook /etc/mount-allspark

Update 3: (change mount only if server is reachable, also added resvport and rw option)

#!/bin/bash

HOST=192.168.1.10
ping -c 1 -w 5 $HOST &>/dev/null
if [ $? -ne 0 ] ; then
    echo "down";
else
    mkdir /Volumes/Allspark
    mount -t nfs -o resvport,rw 192.168.1.10:/media/Allspark /Volumes/Allspark
fi

Install PostgreSQL on Mac Lion via Homebrew

First install homebrew if you haven’t already:
https://github.com/mxcl/homebrew/wiki/installation

Now install postgresql via homebrew

brew update && brew upgrade
brew install postgresql

Wait for everything to finish.

Create postgreSQL database:

initdb /usr/local/var/postgres

Fix conflict from Mac’s own postgreSQL:
source: http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

BREW_POSTGRES_DIR=`brew info postgres | awk '{print $1"/bin"}' | grep "/postgresql/"`
LION_POSTGRES_DIR=`which postgres | xargs dirname`
LION_PSQL_DIR=`which psql | xargs dirname`
 
sudo mkdir -p $LION_POSTGRES_DIR/archive
sudo mkdir -p $LION_PSQL_DIR/archive
 
for i in `ls $BREW_POSTGRES_DIR`
do
    if [ -f $LION_POSTGRES_DIR/$i ]
    then
        sudo mv $LION_POSTGRES_DIR/$i $LION_POSTGRES_DIR/archive/$i
        sudo ln -s $BREW_POSTGRES_DIR/$i $LION_POSTGRES_DIR/$i
    fi
 
    if [ -f $LION_PSQL_DIR/$i ]
    then
        sudo mv $LION_PSQL_DIR/$i $LION_PSQL_DIR/archive/$i
        sudo ln -s $BREW_POSTGRES_DIR/$i $LION_PSQL_DIR/$i
    fi
done

Also, make sure /usr/local/bin comes first in your /etc/paths. Run “brew doctor” to check if there is any path issue.

You need to fix those issues before install bundled stuff such as rails pg gem (if not, use “gem uninstall pg && gem install pg” to reinstall pg gem).

Start service:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

To stop service:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

To make postgreSQL auto start:

mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

To remove this auto start:

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

To upgrade from old version of this auto start (first remove auto start see previous section):

cp /usr/local/Cellar/postgresql/NEW.VERSION.ID/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

To Install adminpack (so pgAdmin stop complaining):

psql -d postgres
CREATE EXTENSION adminpack;

Also, download pgAdmin:
http://www.pgadmin.org/download/macosx.php

Config Mac OSX Lion’s Samba share

smb.conf no longer work. The actual configuration is stored at /System/Library/LaunchDaemons/com.apple.smbd.plist

To make Lion’s samba share follow symbolic link, you need to modify “ProgramArguments”
from:

<key>ProgramArguments</key>
<array>
     <string>/usr/sbin/smbd</string>
</array>
</code>

to:

<key>ProgramArguments</key>
<array>
     <string>/usr/sbin/smbd</string>
     <string>--no-symlinks</string>
     <string>false</string>
</array>