Skip to content

Instantly share code, notes, and snippets.

@implementation MyAppDelegate
static NSOperationQueue *sharedOperationQueue = nil;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//setup the operation queue
some curl output:
j-macbook:~ vickeryj$curl -H "Content-Type: application/json" -X POST -d '{"user":{ "password": "password", "email_address": "josh@vickeryj.com"}}' "http://localhost:3000/users" -D -</pre>
HTTP/1.1 200 OK
Connection: close
Date: Tue, 24 Feb 2009 17:39:11 GMT
Set-Cookie: _curse-counter=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--b93fd7ebe21e983a19428d6802cae9a452ff92d1; path=/
Status: 200 OK
X-Runtime: 0.01377
ConnectionDelegate *connectionDelegate = [[[ConnectionDelegate alloc] init] autorelease];
NSURLConnection *connection = [[[NSURLConnection alloc] initWithRequest:request delegate:connectionDelegate startImmediately:NO] autorelease];
connectionDelegate.connection = connection;
NSRunLoop* runLoop = [NSRunLoop mainRunLoop];
[connection unscheduleFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[connection scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
[connection start];
run
Running…
Ignoring packet error, continuing...
Ignoring packet error, continuing...
gdb stack trace at point of error:gdb stack crawl at point of invalid hex digit:
[ 0 ] /Developer/Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb/gdb-arm-apple-darwin (remote_read_bytes+0x175) [0x17aae5]
[ 1 ] /Developer/Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb/gdb-arm-apple-darwin (default_xfer_partial+0x129) [0x9a19a]
[ 2 ] /Developer/Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb/gdb-arm-apple-darwin (target_xfer_partial+0x2f5) [0x98e5f]
[ 3 ] /Developer/Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb/gdb-arm-apple-darwin (target_read+0x72) [0x9c571]
[ 4 ] /Developer/Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb/gdb-arm-apple-darwin (dcache_peek_byte+0x171) [0x180998]
@implementation NSDate (PKDateUtils)
+ (NSDate *)dateAtMidnightWithDaysAgo:(int)numDaysAgo
{
NSDate *today = [NSDate date];
NSCalendar *gregorianCal = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *todayComponents = [gregorianCal components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:today];
todayComponents.day -= numDaysAgo;
todayComponents.hour = 0;
todayComponents.minute = 0;
- (void)testDateAdditions {
int daysAgoReversed = [[NSDate dateAtMidnightWithDaysAgo:900] numDaysAgo];
STAssertTrue(daysAgoReversed == 900, @"date methods should be reversible, but 900 != %d", daysAgoReversed);
NSDate *tomorrow = [[NSDate date] dateByAddingDays:1];
int tomorrowDaysAgo = [tomorrow numDaysAgo];
STAssertTrue(tomorrowDaysAgo == -1, @"tomorrow should be negative one day ago, but it was %d, "
"and we think tomorrow is %f seconds from 1970", tomorrowDaysAgo, [tomorrow timeIntervalSince1970]);
NSDate *yesterday = [[NSDate date] dateByAddingDays:-1];
#import <Foundation/Foundation.h>
#import "NSObject+PropertySupport.h"
@interface PropertyCoder : NSObject <NSCoding> {
}
@end
[self.currentOrder loadForm];
[self.currentOrder loadFieldControllers];
@vickeryj
vickeryj / gist:3623319
Created September 4, 2012 16:44
contact search
- (NSArray *)searchForContacts:(NSString *)searchString {
NSArray *searchWords = [searchString componentsSeparatedByString:@" "];
NSMutableString *query = [NSMutableString stringWithString:selectColumnsClause];
[query appendString:@"WHERE "];
BOOL isFirst = YES;
NSMutableArray *arguments = [NSMutableArray array];
for (NSString *word in searchWords) {
if ([word length] > 0) {
NSString *searchWord = [word lowercaseString];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_background.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackOpaque];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica-Bold" size:14], UITextAttributeFont, [UIColor colorWithWhite:0.25 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithWhite:0.75 alpha:1.0], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil]];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:5.f forBarMetrics:UIBarMetricsDefault];