Skip to content

Instantly share code, notes, and snippets.

@nathanclark
nathanclark / iOSDocumentMigrator.m
Created February 21, 2012 20:43 — forked from naokits/iOSDocumentMigrator.m
Helps migrating documents between iOS <= 5.0 and >= 5.0.1 to comply with Apple's iCloud guidelines. Follow @steipete on Twitter for updates.
#include <sys/xattr.h>
/// Set a flag that the files shouldn't be backuped to iCloud.
+ (void)addSkipBackupAttributeToFile:(NSString *)filePath {
u_int8_t b = 1;
setxattr([filePath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}
/// Returns the legacy storage path, used when the com.apple.MobileBackup file attribute is not available.
+ (NSString *)legacyStoragePath {
#import "CCPageBox2dBase.h"
@implementation CCPageBox2dBase
@synthesize levelHelperName = _levelHelperName;
- (void)setupWorld {
b2Vec2 gravity = b2Vec2(0.0f, 0.0f);
bool doSleep = false;
_world = new b2World(b2Vec2(0,0), doSleep);
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
/* Basic setup to translate the tile to gravity */
b2Vec2 gravity(-acceleration.y * 15, acceleration.x *15);
_world->SetGravity(gravity);
/* First lets figure out the angle to which the iPad is tilted*/
float angle = atan2(acceleration.x, -acceleration.y);
@nathanclark
nathanclark / gist:1284613
Created October 13, 2011 15:55
Box2D touch wheel rotation
//
// HelloWorldLayer.mm
//
// Created by Nathan Clark on 10/13/11.
// Copyright self 2011. All rights reserved.
//
// Import the interfaces
#import "HelloWorldLayer.h"
@nathanclark
nathanclark / gist:1230034
Created September 20, 2011 19:14
I need yesterday's date just after midnight
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian autorelease];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *component =[gregorian components:unitFlags fromDate:[[NSDate date] addTimeInterval: -86400.0]];
[component setHour:0]; //12a.m.
[component setMinute:0];
[component setSecond:1];
NSDate *yestedayAtMidnight = [gregorian dateFromComponents:component];
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class Assignment;
@interface Chore : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * doMonday;
@property (nonatomic, retain) NSNumber * doSunday;
@nathanclark
nathanclark / gist:1111967
Created July 28, 2011 17:06
View+CoreData Validation
- (void)displayValidationError:(NSError *)anError {
NSLog(@"error domain, %@",[anError domain]);
if (anError && [[anError domain] isEqualToString:@"NSCocoaErrorDomain"]) {
NSArray *errors = nil;
// multiple errors?
if ([anError code] == NSValidationMultipleErrorsError) {
errors = [[anError userInfo] objectForKey:NSDetailedErrorsKey];
} else {
errors = [NSArray arrayWithObject:anError];
@nathanclark
nathanclark / gist:983288
Created May 20, 2011 16:37
Creating a property list programmatically
NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:2];
NSDictionary *innerDict;
NSString *name;
NSDate *dob;
NSArray *scores;
scores = [NSArray arrayWithObjects:[NSNumber numberWithInt:6],
[NSNumber numberWithFloat:4.6],
[NSNumber numberWithLong:6.0000034],
nil];
@nathanclark
nathanclark / utils.rake
Created March 3, 2011 20:23
Utilities needed for many rails apps
namespace :utils do
desc "Echos log rotate configs"
task :rotate => :environment do
puts <<EOD
<<<<<<<<<<<<Begin
# Rotate Rails application logs
#{Rails.root}/log/*.log {
daily
missingok
rotate 7
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"