I’m going to start posting what I’m calling tidbits - morsel sized pieces of code for common tasks on Mac OS X.
The first of these is computing a file checksum (MD5 to be precise). Apple provides the functionality in CommonCrypto/CommonDigest.h. This uses routines in libSystem and avoids loading the entire of OpenSSL to simply compute a checksum. The code is really simple:
#include <CommonCrypto/CommonDigest.h>
NSString* fileName = @"PATHTOFILE";
unsigned char md5[16];
NSData* data = [NSData dataWithContentsOfFile:fileName];
CC_MD5([data bytes], [data length], md5);
// md5 now contains the md5 digest for the file contents
Trivially easy. The CommonDigest.h header contains functions for MD2, MD4, MD5, and SHA1.
Safari has a surprising number of keyboard shortcuts.
Some of the more useful shortcuts:
Command-F Find (Search)
Command-G Find Next (Search)
Command-L Jump to the Address Bar
Command-Option-F Jump to the Search Bar
Command-T Open new tab
Command-W Close current tab or window
Command-Shift-Left Go to previous tab
Command-Shift-Right Go to next tab
Command-D Bookmark current page
This local URL will give you a comprehensive list of all the keyboard shortcuts supported in Safari:
file:///Applications/Safari.app/Contents/Resources/Shortcuts.html
Pretty neat.
Muscle memory is a powerful thing. I’ve been using Mac OS X for over six years, but my history with Windows, and DOS before it, have defined how my brain expects certain tasks to map to keys on the keyboard. I’ve never gotten used to the text editing key bindings on Mac OS X. I grew up with things like CONTROL-LEFT and CONTROL-RIGHT moving the cursor by a word, and SHIFT-DELETE, CONTROL-INSERT, and SHIFT-INSERT being cut, copy and paste respectively. Luckily, Mac OS X provides for customization of key bindings, and I managed to create a set of key bindings that met most of my needs… Until Leopard arrived.
Read More…