This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias gb="git branch" | |
alias gcb="git co -b" | |
alias gd="git difftool" | |
alias gl="git log" | |
alias gln="git log --name-only" | |
alias gs="git status" | |
alias gt="git tag -l" | |
alias gsl="git stash list" | |
alias gsms="git submodule sync" | |
alias gsmu="gsms; git submodule update --init --recursive" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use in conjunction with e.g. KVO on AVPlayer.externalPlaybackActive | |
AVAudioSessionPortDescription *port = [AVAudioSession sharedInstance].currentRoute.outputs.firstObject; | |
if ([port.portType isEqualToString:AVAudioSessionPortAirPlay]) { | |
NSLog(@"Now playing on '%@'", port.portName); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSOperationQueue (BHSAdditions) | |
+ (void)bhs_runOnMainQueue:(void (^)(void))block { | |
NSParameterAssert(block); | |
if ([NSThread isMainThread]) { | |
block(); | |
} else { | |
[[self mainQueue] addOperationWithBlock:block]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)sleepRunLoopForInterval:(NSTimeInterval)interval whileRunningAsynchronousTest:(void (^)(dispatch_semaphore_t semaphore))test { | |
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | |
NSAssert((test != NULL), @"Passed a NULL test block"); | |
test(semaphore); | |
while(dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) { | |
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:interval]]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Passes the new operation to block so it can check for cancellation and exit early | |
- (NSOperation *)bhs_addOperationWithCancelableBlock:(void (^)(NSOperation *))block { | |
NSBlockOperation *op = [[NSBlockOperation alloc] init]; | |
__weak NSBlockOperation *weakOp = op; | |
[op addExecutionBlock:^{ | |
block(weakOp); | |
}]; | |
[self addOperation:op]; | |
return op; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation UIViewController (BHSContainment) | |
- (void)bhs_addChildViewController:(UIViewController *)child { | |
[self bhs_addChildViewController:child superview:self.view]; | |
} | |
// Note this potentially forces view loads on both parent and child | |
// Not a problem if used in -viewDidLoad or later | |
// Use superview parameter with care. If it's not within the parent VC's hierarchy, you deserve to lose |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation BHSCollectionViewFlowLayout | |
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { | |
NSArray *allAttrs = [super layoutAttributesForElementsInRect:rect]; | |
for (UICollectionViewLayoutAttributes *attributes in allAttrs) { | |
attributes.frame = CGRectIntegral(attributes.frame); | |
} | |
return allAttrs; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ScrollieScrollView | |
// PoC for an accessory view that tracks scrolling | |
// Created by Matt Drance (@drance) on 12/12/11. | |
@interface ScrollieScrollView : UIScrollView () | |
@property (strong, nonatomic) UIView *thumb; | |
@end | |
@implementation ScrollieScrollView |