NSString REST category
By admin | December 13, 2008
Implementation file
-
//
-
// NSString+REST.h
-
//
-
// Created by Devon Ferns on 23/11/08.
-
// Copyright 2008 Devon Ferns. All rights reserved.
-
//
-
-
#import "NSString+REST.h"
-
-
@implementation NSString (NSStringREST)
-
-
+(NSString*)resultFromURL:(NSString*)url withPostParameters:(NSArray*)params
-
{
-
NSString* syncURL = url;
-
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:syncURL]];
-
[request setHTTPMethod:@"POST"];
-
-
NSMutableString* httpBody = [[NSMutableString alloc] init];
-
-
if(params != nil)
-
{
-
for(int i=0;i<[params count];i++)
-
[httpBody appendString:[NSString stringWithFormat:@"&%@", [params objectAtIndex:i]]];
-
}
-
-
[request setHTTPBody:[httpBody dataUsingEncoding:NSUTF8StringEncoding]];
-
-
NSURLResponse* response;
-
NSError* error;
-
NSData* r = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
-
-
NSString* result = [NSString stringWithCString:[r bytes] length:[r length]];
-
-
[httpBody release];
-
return result;
-
}
-
-
@end
Header file
-
//
-
// NSString+REST.h
-
// MobiLog
-
//
-
// Created by Devon Ferns on 23/11/08.
-
// Copyright 2008 Devon Ferns. All rights reserved.
-
//
-
-
#import <Foundation/Foundation.h>
-
-
-
@interface NSString (NSStringREST)
-
-
+(NSString*)resultFromURL:(NSString*)url withPostParameters:(NSArray*)params;
-
-
@end
Topics: Cocoa Code, iPhone |
NSData+util category
By admin | November 1, 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
Topics: Cocoa Code, iPhone |
Generate random cryptographic hash from NSString
By admin | November 1, 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
Topics: Cocoa Code, iPhone |
UIAlertView with UIProgressView or UIActivityIndicator
By admin | November 1, 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];
-
}
Topics: Cocoa Code, iPhone |
building mod_python for leopard
By admin | August 13, 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
Topics: Uncategorized |
How to install mysql-python on Leopard
By admin | August 13, 2008
http://www.keningle.com/?p=11
Topics: Uncategorized |
Using Bonjour for iPhone/desktop application sync
By admin | July 27, 2008
http://cocoa-nut.de/?p=27
Topics: Cocoa Links, iPhone |
NSViewController sample projects
By admin | July 24, 2008
http://katidev.com/blog/2008/07/24/simple-nsviewcontroller-sample-projects/
Topics: Cocoa Links |
Petition to lift iPhone SDK NDA
By admin | July 23, 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.
Topics: iPhone |
iPhone SDK NDA?
By admin | July 18, 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.
Topics: iPhone |
« Previous Entries