Re-usable snippets of commands and codes.

Remove user account and files like in SysPref:
sudo sysadminctl -deleteUser USERNAME

Permission Repairs:
sudo /usr/libexec/repair_packages --repair --standard-pkgs --volume /

Screenshot for OS X:
command-shift-3 captures screen and saves to desktop
command-shift-4 captures selection and saves it to the desktop
command-shift-4, hold ctrl while selecting captures selection to clipboard
command-shift-4, spc captures active window, saves to desktop

ffmpeg:
ffmpeg -i "INPUT.wmv" -c:v libx264 -crf:v 20 -preset:v slow -c:a libfdk_aac -vbr 3 -threads 0 "OUTPUT.mp4"

Xerox icons:
/Library/Printers/Xerox/PDEs/XeroxFeatures.plugin/Contents/Resources/Products

FileVault Unlocking in Terminal:

diskutil corestorage list # Get UUID of Volume
diskutil corestorage unlockVolume $UUID -stdinpassphrase # If you have the password of enabled user
diskutil corestorage unlockVolume $UUID -passphrase $recoverykey # If you have recovery key

Make softwareupdate check a different catalog (10.8.5 and older only)
sudo softwareupdate -l --CatalogURL "https://example.com/content/catalogs/index_BSS.sucatalog"

Remove MCX (if connected to old LDAP)
dscl . -list Computers | grep -v "^localhost$" | while read computer_name ; do sudo dscl . -delete Computers/"$computer_name" ; done

Find Installed Printer PPDs
lpinfo -m | grep -i Canon

Add everyone as printer admin on their machine
dseditgroup -o edit -n /Local/Default -u administrator -p -a everyone -t group lpadmin

Boot into macserver05 on the next boot
sudo bless --netboot --server bsdp://macserver05 --nextonly

Get your computer's names (Case sensitive)
scutil --get LocalHostName
scutil --get ComputerName
scutil --get HostName

Disable keyboard shortcuts (Allows repeated keystroke by holding a key)
defaults write -g ApplePressAndHoldEnabled -bool false

List directory with: @ extended attribute, d directory as plain (no recursive), e ACL, l Long listing, O File flag
ls -@delO ~/Path/to/Directory

Delete ACL entry by number
sudo chmod -a# 0 ~/Path/to/file

Lock Screen Text/Loginwindow Text
sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "All Your Screens Are Belong To Me"

Restore Apple's Java 6 after 7 is installed.
sudo ln -sf /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo ln -sf /System/Library/Frameworks/JavaVM.framework/Commands/javaws /usr/bin/javaws

Flush DNS

# Yosemite 10.10.4 and up
sudo killall -HUP mDNSResponder

# Yosemite 10.10 to 10.10.3
sudo discoveryutil mdnsflushcache

# Lion, Mountain Lion, Mavericks
sudo killall -HUP mDNSResponder

# Snow Leopard
sudo dscacheutil -flushcache

Build a no-payload package
sudo pkgbuild --identifier com.company.myscript --nopayload --version 1.0 --scripts /Users/username/Desktop/scriptsfolder "~/Desktop/Your.pkg"

An example on how to package via the commandline

chmod # fix your files' permissions
mkdir -p /tmp/foo/Library/Fonts
cp /path/to/some/fonts /tmp/foo/Library/Fonts/
sudo pkgbuild --root /tmp/foo --identifier com.company.fonts.futura --version 1.1 ~/Desktop/Futura11.pkg

Stop GoToMeeting from spawning more children
launchctl unload /Users/$USER/Library/LaunchAgents/com.citrixonline.GoToMeeting.G2MUpdate.plist
rm /Users/$USER/Library/LaunchAgents/com.citrixonline.GoToMeeting.G2MUpdate.plist

Reset Launchpad

# Yosemite and up, no sudo, run in user's space
defaults write com.apple.dock ResetLaunchPad -bool true ; killall Dock
    
# Mavericks and below
rm ~/Library/Application\ Support/Dock/*.db ; killall Dock

Check Disk Usage of current user home's first folder (c=grand total-optional depending on depth, h=human-readable, d=depth), no trailing slash needed
[sudo] du -hd 0 ~

Check for remote service status (Windwows)
[elevated] sc \\$computername query $servicename

Start a service remotely (You must stop and start a service to restart, there is no restart option)
[elevated] sc \\$computername start|stop $servicename