How can I compute a SHA-2 (ideally SHA 256 or SHA 512) hash in iOS?

This is what I’m using for SHA1: #import <CommonCrypto/CommonDigest.h> + (NSData *)sha1:(NSData *)data { unsigned char hash[CC_SHA1_DIGEST_LENGTH]; if ( CC_SHA1([data bytes], [data length], hash) ) { NSData *sha1 = [NSData dataWithBytes:hash length:CC_SHA1_DIGEST_LENGTH]; return sha1; } return nil; } Replace CC_SHA1 with CC_SHA256 (or whichever you need), as well as CC_SHA1_DIGEST_LENGTH with CC_SHA256_DIGEST_LENGTH.

How do I convert a Ruby hash so that all of its keys are symbols?

hash = {“apple” => “banana”, “coconut” => “domino”} Hash[hash.map{ |k, v| [k.to_sym, v] }] #=> {:apple=>”banana”, :coconut=>”domino”} @mu is too short: Didn’t see word “recursive”, but if you insist (along with protection against non-existent to_sym, just want to remind that in Ruby 1.8 1.to_sym == nil, so playing with some key types can be misleading): … Read more

Pure-Ruby concurrent Hash

Okay, now that you specified the actually meaning of ‘threadsafe’, here are two potential implementations. The following code will run forever in MRI and JRuby. The lockless implementation follows an eventual consistency model where each thread uses it’s own view of the hash if the master is in flux. There is a little trickery required … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)