Skip to content

Instantly share code, notes, and snippets.

View nevyn's full-sized avatar

Nevyn Bengtsson nevyn

View GitHub Profile
@nevyn
nevyn / gist:2368290
Created April 12, 2012 15:37 — forked from iKenndac/gist:2368081
Waiting for multiple tiers to load in an object graph
// Assume that there is a -(TCTask*)load method on these objects
-(void)fillTrackPool {
[[SPSession sharedSession] load].then(^(SPSession *sess) {
return sess.userPlaylists.load;
}).then(^(SPPlaylistContainer *container) ^{
NSMutableArray *playlists = [NSMutableArray array];
[playlists addObject:sess.starredPlaylist];
[playlists addObject:sess.inboxPlaylist];
@nevyn
nevyn / ExampleUsage.m
Created June 3, 2012 23:36 — forked from anonymous/ExampleUsage.m
Testing RAC by writing a socket abstraction on top of it with AsyncSocket
[[[TCRACSocket connectTo:@"localhost" port:1236] selectMany:^id<RACSubscribable>(id x) {
return [x lines];
}] subscribeNext:^(id x) {
self.text.text = x;
} error:^(NSError *error) {
NSLog(@"Failure: %@", error);
exit(0);
}];
#import <Foundation/Foundation.h>
@interface TCMemoryDebugPrinter : NSObject
+ (Class)activateMemoryDebuggingFor:(Class)sourceClass;
@end
@protocol IThingieProvider <NSObject>
-(id)thingie;
@end
@protocol IDependent <NSObject>
@end
@nevyn
nevyn / NSObject+SPInvocationGrabbing.h
Created December 31, 2012 16:07
Code to accompany "Methods of Concurrency" on my blog nevyn.tumblr.com.
#import <Foundation/Foundation.h>
@interface SPInvocationGrabber : NSObject
-(id)initWithObject:(id)obj;
-(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
@property (readonly, retain, nonatomic) id object;
@property (readonly, retain, nonatomic) NSInvocation *invocation;
@property (nonatomic, copy) void(^afterForwardInvocation)();
@property BOOL backgroundAfterForward;
@property BOOL onMainAfterForward;
- (void)drawRect:(CGRect)dirtyRect
{
CGRect imageBounds = CGRectMake(0.0f, 0.0f, kMyViewWidth, kMyViewHeight);
CGRect bounds = [self bounds];
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *color;
CGFloat resolution;
CGFloat alignStroke;
CGFloat stroke;
@nevyn
nevyn / SPAudioSessionManager.m
Created March 27, 2013 15:49
Example of an imo correct way to handle audio sessions in iOS apps with streaming music that will sometimes have pauses between audio playback.
@interface SPAudioSessionManager ()
{
__weak PlayController *_playController;
BOOL _audioSessionIsConfiguredForPlayback;
UIBackgroundTaskIdentifier _playbackBackgroundTask;
}
@end
@interface PlayController : NSObject
@property BOOL playing;
@nevyn
nevyn / gist:5414956
Created April 18, 2013 18:13
git-pristine clears out EVERYTHING from your working copy that shouldn't be there: it's like doing a clean checkout.
14:11:19 ~ 🆗 cat bin/git-pristine
#!/bin/bash
git clean -dffx
git submodule foreach --recursive git clean -dffx
@nevyn
nevyn / TCAppDelegate.m
Created June 23, 2013 06:37
How to wait for multiple different-timed animations in a generic manner? A reply to http://inessential.com/2013/06/22/technical_notes_on_vespers_full-scree .
#import "TCAppDelegate.h"
// Let's use https://github.com/nevyn/SPAsync
#import <SPAsync/SPTask.h>
@interface UIView (SPTaskAnimations)
// Category that returns an abstraction representing an asynchronous operation, rather than just a raw block. We can use this abstraction later to compose multiple of them.
+ (SPTask*)task_animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations;
@end
@nevyn
nevyn / Output
Created August 17, 2013 23:32
minimal eminet test. Fails.
2013-08-18 01:32:20.810 EmiNetDemo[87142:303] Failed to connect Error Domain=com.emilir.eminet.disconnect Code=3 "The operation couldn’t be completed. (com.emilir.eminet.disconnect error 3.)"
2013-08-18 01:32:20.811 EmiNetDemo[87142:303] Disconnect