Meta

Categories

NSString REST category

By admin | December 13, 2008

Implementation file

  1. //
  2. //  NSString+REST.h
  3. //
  4. //  Created by Devon Ferns on 23/11/08.
  5. //  Copyright 2008 Devon Ferns. All rights reserved.
  6. //
  7.  
  8. #import "NSString+REST.h"
  9.  
  10. @implementation NSString (NSStringREST)
  11.  
  12. +(NSString*)resultFromURL:(NSString*)url withPostParameters:(NSArray*)params
  13. {
  14.  NSString* syncURL = url;
  15.  NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:syncURL]];
  16.  [request setHTTPMethod:@"POST"];
  17.  
  18.  NSMutableString* httpBody = [[NSMutableString alloc] init];
  19.  
  20.  if(params != nil)
  21.  {
  22.   for(int i=0;i<[params count];i++)
  23.    [httpBody appendString:[NSString stringWithFormat:@"&%@", [params objectAtIndex:i]]];
  24.  }
  25.  
  26.  [request setHTTPBody:[httpBody dataUsingEncoding:NSUTF8StringEncoding]];
  27.  
  28.  NSURLResponse* response;
  29.  NSError* error;
  30.  NSData* r = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
  31.  
  32.  NSString* result = [NSString stringWithCString:[r bytes] length:[r length]];
  33.  
  34.  [httpBody release];
  35.  return result;
  36. }
  37.  
  38. @end

Header file

  1. //
  2. //  NSString+REST.h
  3. //  MobiLog
  4. //
  5. //  Created by Devon Ferns on 23/11/08.
  6. //  Copyright 2008 Devon Ferns. All rights reserved.
  7. //
  8.  
  9. #import <Foundation/Foundation.h>
  10.  
  11.  
  12. @interface NSString (NSStringREST)
  13.  
  14. +(NSString*)resultFromURL:(NSString*)url withPostParameters:(NSArray*)params;
  15.  
  16. @end

Topics: Cocoa Code, iPhone |

NSData+util category

By admin | November 1, 2008

.h file:

  1. #import <Foundation/Foundation.h>
  2.  
  3. @interface NSData (NSData_HexAdditions)
  4. - (NSString*) stringWithHexBytes;
  5. + (NSString*) sha256HashFromString:(NSString*)string;
  6. + (NSString*) sha256HashFromData:(NSData*)data;
  7.  
  8. @end



.m file:

  1. #import "NSData+Util.h"
  2. #import <CommonCrypto/CommonDigest.h>
  3.  
  4. @implementation NSData (NSData_HexAdditions)
  5. - (NSString*) stringWithHexBytes {
  6.  NSMutableString *stringBuffer = [NSMutableString
  7.           stringWithCapacity:([self length] * 2)];
  8.  const unsigned char *dataBuffer = [self bytes];
  9.  int i;
  10.  
  11.  for (i = 0; i < [self length]; ++i)
  12.   [stringBuffer appendFormat:@"%02x", (unsigned long)dataBuffer[ i ]];
  13.  
  14.  return [[stringBuffer copy] autorelease];
  15. }
  16.  
  17. + (NSString*) sha256HashFromData:(NSData*)data
  18. {
  19.  return [NSData sha256HashFromString:[NSString stringWithCString:(const char*)[data bytes] length:[data length]]];
  20. }
  21.  
  22. + (NSString*) sha256HashFromString:(NSString*)string
  23. {
  24.  unsigned char hashedChars[CC_SHA512_DIGEST_LENGTH];
  25.  
  26.  CC_SHA512([string UTF8String],
  27.      [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
  28.      hashedChars);
  29.  NSData * hashedData = [NSData dataWithBytes:hashedChars length:CC_SHA512_DIGEST_LENGTH];
  30.  NSData* tmp = [[NSData alloc] initWithData:hashedData];
  31.  NSString* ret = [tmp stringWithHexBytes];
  32.  [tmp release];
  33.  return ret;
  34. }
  35. @end

Topics: Cocoa Code, iPhone |

Generate random cryptographic hash from NSString

By admin | November 1, 2008

Implementation .m file:

  1. #import "NSString+Hash.h"
  2.  
  3.  
  4. @implementation NSString (Hash)
  5.  
  6.  
  7. +(NSString*)randomSaltWithLength:(int)length
  8. {
  9.  char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  10.  NSMutableString* ret = [[[NSMutableString alloc] initWithCapacity:length] autorelease];
  11.  srandomdev();
  12.  
  13.  for(int i=0;i<length;i++)
  14.  {
  15.   int index = random()%52;
  16.   char a = chars[index];
  17.   [ret appendString:[NSString stringWithCString:&a length:1]];
  18.  }
  19.  
  20.  return ret;
  21. }
  22.  
  23. @end





.h file:

  1. @interface NSString (Hash)
  2.  
  3. +(NSString*)randomSaltWithLength:(int)length;
  4.  
  5. @end

Topics: Cocoa Code, iPhone |

UIAlertView with UIProgressView or UIActivityIndicator

By admin | November 1, 2008

http://discussions.apple.com/thread.jspa?messageID=8215707

  1. - (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
  2. {
  3.   progressAlert = [[UIAlertView alloc] initWithTitle: message
  4.                                              message: @"Please wait…"
  5.                                             delegate: self
  6.                                    cancelButtonTitle: nil
  7.                                    otherButtonTitles: nil];
  8.  
  9.  
  10.   // Create the progress bar and add it to the alert
  11.   if (activity) {
  12.     activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  13.     activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
  14.     [progressAlert addSubview:activityView];
  15.     [activityView startAnimating];
  16.   } else {
  17.     progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
  18.     [progressAlert addSubview:progressView];
  19.     [progressView setProgressViewStyle: UIProgressViewStyleBar];
  20.   }
  21.   [progressAlert show];
  22.   [progressAlert release];
  23. }

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