Friday, July 29, 2011

HOWTO install OS X from a system image

To install OS X from a system image, first partition the disk using diskutil:
diskutil partitionDisk disk0 2 GPT JHFS+ os 90% JHFS+ installer 10%
Download the install image onto the os partition:
curl -o /Volumes/os/osximage.dmg -L
and restore it to the installer partition:
asr restore --erase --noprompt --noverify --target /dev/disk0s3 --source /Volumes/os/osximage.dmg

Tuesday, July 26, 2011

64-bit errors in real programs

There is a great article on Intel's website about real programming errors in C/C++ that surfaced as bugs when the code was compiled and run as a 64-bit program. A fair proportion involve some sort of type casting that makes assumptions about pointer size, and many are subtle bugs that will only be triggered when memory allocation is > 4GB.

As 64-bit becomes the new norm I think we'll see a lot of buffer overflows and memory corruption bugs as a consequence of errors like these.

Thursday, July 21, 2011

Mac boot options

To enter single-user, hold down ⌘-S at boot.

To get a menu of boot options (netboot, USB etc.) hold down option during boot.

See the full list of boot options.

Remount a hfs partition read-write on a mac

To remount a partition read-write on linux you would use:
mount -o remount,rw /dev/disk /mnt/point
On a mac the equivalent is:
mount -u -w /dev/disk /mnt/point
In single user mode to get a writable root:
mount -uw /

Ruby learnings

I had a brief foray into Ruby land recently, so thought I would record some lessons learnt here.

Interactive ruby is like the really poor cousin to ipython. Commandline completion is not on by default, you want to enable it using:

alias irb='irb -r irb/completion'
and apparently the only way to get syntax highlighting is to install the wirble gem.

There are a bunch of ways to run shell commands. The one I used was %x:

cmd = "dscl . -read #{file} #{key} 2> /dev/null"
  output = %x{#{cmd}}

I was looking for a equivalent of the python string function 'startswith'. The ruby equivalent actually has a ? in the function name (WTF?):

if output.start_with?("#{key}: ")

Tuesday, July 12, 2011

Useful Mac keyboard shortcuts

Fn-arrowkeysPgUp and PgDown
Control-Shift-⏏Lock screen (sleep)
⌘-SpaceOpen Spotlight
ESC-.Paste last word of the last command under the cursor (equivalent of Alt-. in linux)
⌘-Shift-arrowkeysLeft right arrows switch between tabs
Chrome (full list of shortcuts)
⌘-Option-arrowkeysLet right arrows to switch between tabs.

Wednesday, July 6, 2011

HOWTO enable remote desktop for windows 7 users

The technet article has all the details on how to configure remote desktop, but the tl;dr to enable it for a user is:

Control Panel -> System -> Remote Settings -> Select Users

HOWTO list local administrators on the Windows commandline

To get a list of local admins:

net localgroup administrators