Skip to content

Instantly share code, notes, and snippets.

View beccadax's full-sized avatar

Becca Royal-Gordon beccadax

View GitHub Profile
@beccadax
beccadax / MyRestorableAppDelegate.m
Last active December 19, 2015 06:59
Category + app delegate method for handling Core Data objects in UIKit state restoration. There's a bit of a chicken-and-egg problem in state restoration—you can't store the managed object context in the restorable state, but you can't restore without it. The usual, horrible, solution is to make the state restoration code retrieve the context fr…
@implementation MyRestorableAppDelegate
...
- (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder {
coder.managedObjectContext = self.managedObjectContext;
return nil;
}
...
@beccadax
beccadax / UIWebView+JSONObjectByEvaluatingJavascript.h
Created July 3, 2013 07:08
A category on UIWebView that lets you return any JSON-compatible content from Javascript code. (This means arrays, objects/dictionaries, strings, numbers, and nulls.)
//
// UIWebView+JSONObjectByEvaluatingJavascript.h
// Feeder
//
// Created by Brent Royal-Gordon on 7/1/13.
// Copyright (c) 2013 Architechies. All rights reserved.
//
@interface UIWebView (Additions)
@beccadax
beccadax / UINavigationItem+KVO.m
Created July 6, 2013 00:52
Makes the various UINavigationItem methods for setting bar items KVO-compliant.
//
// UINavigationItem+KVO.m
// Feeder
//
// Created by Brent Royal-Gordon on 7/5/13.
// Copyright (c) 2013 Architechies. All rights reserved.
//
#import "UINavigationItem+KVO.h"
@beccadax
beccadax / TsLineEnumerator.h
Created July 11, 2013 01:20
Class to enumerate over the contents of a file handle line-by-line
//
// TsLineEnumerator.h
// Typesetter
//
// Created by Brent Royal-Gordon on 2/3/12.
// Copyright (c) 2012 Architechies. All rights reserved.
//
@interface NSFileHandle (lineEnumerator)
- (NSEnumerator*)lineEnumerator;
@beccadax
beccadax / FDRCollectionViewCell.h
Created July 14, 2013 03:26
Collection view cells and headings which, together, give a nice grid with light gray borders between each element.
//
// FDRCollectionViewCell.h
//
//
// Created by Brent Royal-Gordon on 7/10/13.
//
//
#import <UIKit/UIKit.h>
@beccadax
beccadax / NSWindow+BetterSheets.h
Created July 14, 2013 03:46
Better sheet APIs for 10.8. Any resemblance to Mavericks is purely coincidental.
//
// NSWindow+BetterSheets.h
// Gistapo
//
// Created by Brent Royal-Gordon on 7/12/13.
// Copyright (c) 2013 Architechies. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@beccadax
beccadax / GSTApplication.h
Created July 17, 2013 04:37
NSApplication subclass adding a delegate method for opening a URL with your app.
//
// GSTApplication.h
// Gistapo
//
// Created by Brent Royal-Gordon on 7/12/13.
// Copyright (c) 2013 Architechies. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@beccadax
beccadax / NSString+EnumerateParagraphs.h
Created July 24, 2013 07:47
Methods to enumerate over paragraph ranges in a string using a block.
//
// NSString+EnumerateParagraphs.h
// Ingist
//
// Created by Brent Royal-Gordon on 7/19/13.
// Copyright (c) 2013 Architechies. All rights reserved.
//
#import <Foundation/Foundation.h>
@beccadax
beccadax / GSTApplication.h
Created July 27, 2013 05:59
NSApplication subclass with additional delegate methods for various useful things.
//
// GSTApplication.h
// Ingist
//
// Created by Brent Royal-Gordon on 7/12/13.
// Copyright (c) 2013 Architechies. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "GSTServicesProvider.h"
@beccadax
beccadax / MyRootController.m
Last active December 20, 2015 17:39
What I imagine a Cocoa-like Objective-C web framework woud look like. Pseudocode, so don't take it too seriously.
@interface MyRootController: OWWebController
// GET /
- (BOOL)get:(OWRequest*)request error:(NSError**)error {
return [request.responder renderTemplate:@"Root" withObject:nil error:error];
}
// Everything under /users is handled by MyUsersController
- (OWWebController*)controllerForUsersRequest:(OWRequest*)request error:(NSError**)error {
return [[MyUsersController alloc] initWithManagedObjectContext:self.managedObjectContext];