Skip to content

Instantly share code, notes, and snippets.

@rbaulin
rbaulin / macros.h
Last active December 25, 2015 11:09
Urgent macros
#define IS_7_0 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
#define IS_PAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_PHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#ifdef DEBUG
# define LOG_MESSAGE(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
@rbaulin
rbaulin / ReactiveCocoaPower.m
Last active December 17, 2015 18:29
Find out what is item's URL and load it when ready. Oh yeah, and show me a loading screen if it takes more than 1 second for preparation. And call off the fuss if item has changed. Hell yeah, ReactiveCocoa.
self.currentItem = item;
RACSignal *itemChanged = [[RACObserve(self, currentItem) skip:1] take:1];
// prepare item until switched to other item
RACSignal *itemReady = [[item rac_prepareItem] takeUntil:itemChanged];
// show description if preparation takes more than 1 second
[[[[[RACSignal interval:1.] take:1]
takeUntil:itemReady]
deliverOn:[RACScheduler mainThreadScheduler]]
@rbaulin
rbaulin / multilineLabel.m
Last active December 17, 2015 18:09
Label with multiple lines, constrained to width. Use with -sizeToFit.
@interface MultilineLabel : UILabel
@property (nonatomic) CGFloat maximumWidth;
@end
@implementation MultilineLabel
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_maximumWidth = 200;
@rbaulin
rbaulin / colorizeViewStack.m
Last active December 17, 2015 17:49
Colorize view stack, useful for frame inspection
// example: [self colorizeStack:self.view];
- (void)colorizeStack:(UIView *)view {
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:0.8];
view.backgroundColor = color;
for (UIView *subView in view.subviews) {
@rbaulin
rbaulin / gist:5534334
Created May 7, 2013 17:12
Tapjoy possible Publisher SDK API improvements
Now API looks like this:
- (void)getTapPoints;
- (void)spendTapPoints;
Here is how it would be absolutely awesome:
- (void)getTapPointsCompletion:(void (^)(TapjoyConnect *tj, NSUInteger tapPoints, NSError *error))completionBlock;
- (void)spendTapPoints:100 completion:(void (^)(TapjoyConnect *tj, NSError *error))completionBlock;
So, I could use it like this:
.. code ..