Skip to content

Instantly share code, notes, and snippets.

View nicktoumpelis's full-sized avatar
🎯
Focusing

Nick Toumpelis nicktoumpelis

🎯
Focusing
View GitHub Profile
@nicktoumpelis
nicktoumpelis / BugSenseDemoAppDelegate.m
Created October 7, 2011 18:34
BugSense iOS API Call
#import <BugSense-iOS/BugSenseCrashController.h>
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//...
NSDictionary *myCustomData = [NSDictionary dictionaryWithObjectsAndKeys:@"myObject", @"myKey", nil];
BugSenseCrashController *crash =
[BugSenseCrashController sharedInstanceWithBugSenseAPIKey:@"<Your BugSense API Key>"
userDictionary:myCustomData
sendImmediately:NO];
//...
@nicktoumpelis
nicktoumpelis / git-make-empty-root.sh
Last active July 3, 2024 18:28
Create an empty initial commit
git checkout --orphan temp_master
git rm -rf .
git commit --allow-empty -m 'Make initial root commit'
git rebase --onto temp_master --root master
git branch -D temp_master
@nicktoumpelis
nicktoumpelis / repo-rinse.sh
Created April 23, 2014 13:00
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@nicktoumpelis
nicktoumpelis / Class.m
Created August 13, 2014 09:16
KVO observation done right
static void * const kKVOContext = (void *)&kKVOContext;
@implementation Class
- (void)someMethod {
[super someMethod];
[observedObject addObserver:self
forKeyPath:@"keyPath"
options:NSKeyValueObservingOptionInitial
context:kKVOContext];
@nicktoumpelis
nicktoumpelis / KlassSpec.m
Created August 13, 2014 09:34
Kiwi Spec Template
#import "Kiwi.h"
static NSTimeInterval const kAsynchronousTestingTimeout = 2.0;
SPEC_BEGIN(KlassSpec)
describe(@"An object", ^{
context(@"when...", ^{
__block Klass *object = nil;
beforeAll(^{ // or 'beforeEach', depending on your needs
@nicktoumpelis
nicktoumpelis / AAAKlass.h
Created August 13, 2014 10:14
Typed constants
// external constants (defined in AAAKlass.m)
extern const CGFloat AAKlassVerticalMargin;
extern NSString * const AAAKlassIdentifier;
@nicktoumpelis
nicktoumpelis / NATAppDelegate.m
Created August 27, 2014 09:51
Initialize Core Data stack
- (void)initializeCoreDataStack
{
// Some error checking is necessary...
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"ProjectName" withExtension:@"momd"];
NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
NSPersistentStoreCoordinator *persistentStoreCoordinator =
[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel];
@nicktoumpelis
nicktoumpelis / SomeImplementation.m
Created August 31, 2014 13:28
Core Data: Execute a fetch request
NSManagedObjectContext *managedObjectContext = ...;
NSFetchRequest *fetchRequest = ...;
NSError *error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];
if (error) {
NSLog(@"Error: %@\n%@", [error localizedDescription], [error userInfo]);
return;
}
@nicktoumpelis
nicktoumpelis / SomeImplementation.m
Last active August 29, 2015 14:05
Core Data: Create a simple NSFetchRequest
NSManagedObjectContext *managedObjectContext = ...;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Entity" inManagedObjectContext:managedObjectContext]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"..."];
[fetchRequest setPredicate:predicate];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"key" ascending:YES];
[fetchRequest setSortDescriptors:@[sortDescriptor]];
@nicktoumpelis
nicktoumpelis / SomeImplementation.m
Created August 31, 2014 13:52
Core Data: Use a stored fetch request
NSManagedObjectModel *managedObjectModel = ...;
NSFetchRequest *fetchRequest = [managedObjectModel fetchRequestTemplateForName:@"Fetch Request Name"];