Skip to content

Instantly share code, notes, and snippets.

@jnjosh
Created December 12, 2011 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnjosh/1469336 to your computer and use it in GitHub Desktop.
Save jnjosh/1469336 to your computer and use it in GitHub Desktop.
Calculate URL for Gravatar
static inline NSString *calculateURLForGravatar(NSString *email) {
const char *email_str = [email UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(email_str, strlen(email_str), result);
NSMutableString *hash = [NSMutableString stringWithString:@"http://www.gravatar.com/avatar/"];
for (int i = 0; i < 16; i++) {
[hash appendFormat:@"%02x", result[i]];
}
return [hash lowercaseString];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment