November 1st, 2008
.h file:
#import <Foundation/Foundation.h>
@interface NSData (NSData_HexAdditions)
- (NSString*) stringWithHexBytes;
+ (NSString*) sha256HashFromString:(NSString*)string;
+ (NSString*) sha256HashFromData:(NSData*)data;
@end
.m file:
#import "NSData+Util.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSData (NSData_HexAdditions)
- (NSString*) stringWithHexBytes {
NSMutableString *stringBuffer = [NSMutableString
stringWithCapacity:([self length] * 2)];
const unsigned char *dataBuffer = [self bytes];
int i;
for (i = 0; i < [self length]; ++i)
[stringBuffer appendFormat:@"%02x", (unsigned long)dataBuffer[ i ]];
return [[stringBuffer copy] autorelease];
}
+ (NSString*) sha256HashFromData:(NSData*)data
{
return [NSData sha256HashFromString:[NSString stringWithCString:(const char*)[data bytes] length:[data length]]];
}
+ (NSString*) sha256HashFromString:(NSString*)string
{
unsigned char hashedChars[CC_SHA512_DIGEST_LENGTH];
CC_SHA512([string UTF8String],
[string lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
hashedChars);
NSData * hashedData = [NSData dataWithBytes:hashedChars length:CC_SHA512_DIGEST_LENGTH];
NSData* tmp = [[NSData alloc] initWithData:hashedData];
NSString* ret = [tmp stringWithHexBytes];
[tmp release];
return ret;
}
@end
Posted in Cocoa Code, iPhone | No Comments »
November 1st, 2008
Implementation .m file:
#import "NSString+Hash.h"
@implementation NSString (Hash)
+(NSString*)randomSaltWithLength:(int)length
{
char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
NSMutableString* ret = [[[NSMutableString alloc] initWithCapacity:length] autorelease];
srandomdev();
for(int i=0;i<length;i++)
{
int index = random()%52;
char a = chars[index];
[ret appendString:[NSString stringWithCString:&a length:1]];
}
return ret;
}
@end
.h file:
@interface NSString (Hash)
+(NSString*)randomSaltWithLength:(int)length;
@end
Posted in Cocoa Code, iPhone | No Comments »
November 1st, 2008
http://discussions.apple.com/thread.jspa?messageID=8215707
- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
progressAlert = [[UIAlertView alloc] initWithTitle: message
message: @"Please wait..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
// Create the progress bar and add it to the alert
if (activity) {
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
[progressAlert addSubview:activityView];
[activityView startAnimating];
} else {
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
[progressAlert addSubview:progressView];
[progressView setProgressViewStyle: UIProgressViewStyleBar];
}
[progressAlert show];
[progressAlert release];
}
Posted in Cocoa Code, iPhone | No Comments »
August 13th, 2008
Copied from http://matterkkila.com/2007/12/20/building-mod_python-for-leopard/ in case it goes away in the future
Leopard itself comes with recent versions of php, python, and apache. However it does not have mod_python, so if you want to play with things like django you must build mod_python from the source. Just running ./configure, make, make install won’t cut it either. You need to edit the make file built during the ./configure step to include specific compiler flags. I found a lot of sites on the internet with ideas how to fix it, after trying 4 of them that didn’t work I came across one that did.
Run:
./configure
Edit: src/Makefile and after the ‘INCLUDES=’ line add
INCLUDES+= -Wc,-arch -Wc,ppc -Wc,-arch -Wc,i386 -Wc,-arch -Wc,ppc64 -Wc,-arch -Wc,x86_64
INCLUDES+= -Wl,-arch -Wl,ppc -Wl,-arch -Wl,i386 -Wl,-arch -Wl,ppc64 -Wl,-arch -Wl,x86_64
export ARCHFLAGS='-arch i386 -arch ppc -arch ppc64 -arch x86_64'
Now run:
make
sudo make install
Posted in Uncategorized | No Comments »
August 13th, 2008
http://www.keningle.com/?p=11
Posted in Uncategorized | No Comments »
July 27th, 2008
http://cocoa-nut.de/?p=27
Posted in Cocoa Links, iPhone | No Comments »
July 24th, 2008
http://katidev.com/blog/2008/07/24/simple-nsviewcontroller-sample-projects/
Posted in Cocoa Links | No Comments »
July 23rd, 2008
http://www.ipetitions.com/petition/iPhoneNDA
I don’t know why this NDA is still here with the app store and 2.0 being out there.
Posted in iPhone | No Comments »
July 18th, 2008
Why is the iPhone SDK still under NDA? What’s to keep secret. This is only hurting developers and especially new developers. No one can share any experiences with each other on how to develop from this phone. Obviously many people want to ask questions about it since there are at least 1 post or more on the cocoa-dev mailing list per day.
I’m sure the moderators would love to not have to copy and paste the “iPhone is still under NDA” drivel into all these posts.
Posted in iPhone | No Comments »