Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Lock the keychain when idle

Lock the keychain when system sleeps or is idle for 10 minutes.
security set-keychain-settings -l -u -t 600

Boot in verbose mode

Watch startup messages.
sudo nvram boot-args=-v

check for file collisions when downgrading from HFSX to HFS

when converting from HFSX to HFS (case-sensitive to case insensitive), run this command to verify there will be no file collisions:
2>/dev/null find . -print | tr "[:upper:]" "[:lower:]"  | sort | uniq -d

repair disk permissions from the command line

sudo diskutil repairPermissions /

Download with cURL in a Loop Until Completed

From Entropy.ch:

Here’s a little terminal command I use to repeatedly attempt to download a file. This is useful if the transfer aborts frequently or if the server is busy:

The while/do/done loop keeps calling curl, with pauses of 10 seconds. curl will keep returning a failure exit code, which is what keeps the while loop going if inverted with the ! (logical not) operator. The -C - flag tells curl to continue at the last byte position.

while ! curl -C - -O 'http://download.parallels.com/GA/Parallels%20Desktop%203186%20Mac%20en.dmg'; 
do sleep 10; 
done

Zero data on a Linux disk

For use with VMWare when you don't run an X server:
cat /dev/zero > zero.dat ; sync ; sleep 1 ; sync ; rm -f zero.dat

How to ssh into Ubuntu on Parallels by hostname

this is something that strangely doesn't happen automatically on ubuntu
in Ubuntu, just add
send host-name "dapperbox";

to your /etc/dhcp3/dhclient.conf file

you might need to do a
sudo /etc/services/networking restart


On your Mac, you can now do
ssh username@dapperbox


instead of

ssh username@1.2.3.4

Generate DSA Keys

// generates SSH DSA keys in ~/.ssh/

ssh-keygen -d

rsync syntax

rsync -avz --eahfs --progress --delete /source-dir-without-trailing-slash /destination-dir-with-trailing-slash


// explanation of switches
// -a, archive mode, equivalent to -rlptgoD which does things like recurse through all the dirs, preserves times, etc.
// -v, verbose mode
// -z, compress - makes the copy go faster. doesn't actually compress into a zip file
// --eahfs - (could also use -E, I think)
// --progress - show copy status of each item
// --delete, delete files on destination that aren't on source (sync)

tar syntax

// tar:
tar -cvzf file.tar.gz inputfile1 inputfile2


// untar:
tar -xvzf file.tar.gz