Skip to content

Instantly share code, notes, and snippets.

@advantis
advantis / gist:3810413
Last active October 11, 2015 05:28
CGRect proportional scaling
#import "tgmath.h"
CGRect ADVRectScaleToSize(CGRect sourceRect, CGSize targetSize, UIViewContentMode contentMode)
{
CGSize sourceSize = sourceRect.size;
CGFloat horizontalRatio = targetSize.width / sourceSize.width;
CGFloat verticalRatio = targetSize.height / sourceSize.height;
CGFloat ratio;
@advantis
advantis / Singleton.m
Created September 26, 2012 12:51
Retrospective of Singleton pattern in Cocoa
// Simple implementation (not thread-safe)
+ (Singleton *) sharedSingleton
{
static Singleton *instance;
if (nil == instance)
{
instance = [self new];
}
return instance;
}
@advantis
advantis / AlwaysMountRootFSWithNoatime_MacOSX.sh
Created September 18, 2012 12:30 — forked from pklaus/AlwaysMountRootFSWithNoatime_MacOSX.sh
SSD Optimizations of Mac OS X 10.6 Operating System
#!/bin/bash
# +----------------------------------------------------------------------+
# | |
# | Mount the root file system / with the option noatime |
# | |
# | By Philipp Klaus <http://blog.philippklaus.de> |
# | Tip found on <http://blogs.nullvision.com/?p=275> |
# | |
# +----------------------------------------------------------------------+
@advantis
advantis / ADVUserInterfaceIdiom.h
Created September 7, 2012 13:11
Easy user interface idiom detection
//
// Copyright © 2012 Yuri Kotov
//
extern BOOL ADVUserInterfaceIdiomIsPhone;
@advantis
advantis / gist:3619129
Last active October 10, 2015 02:37
Enumeration benchmark
/* All measurements were done on iPhone 4 */
// MRC:
// for loop: 1.891520ms
// NSFastEnumeration: 0.393583ms
// enumerateObjectsUsingBlock: 0.547250ms
// ARC (w/o __unsafe_unretained):
// for loop: 6.889979ms
// NSFastEnumeration: 0.394479ms
@advantis
advantis / ADVTableView.h
Created June 10, 2012 10:06
Backport of the cell-to-nib registration API to iOS < 5.0
//
// Copyright © 2012 Yuri Kotov
//
#import <UIKit/UIKit.h>
@interface ADVTableView : UITableView
- (void) registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier;
@advantis
advantis / UILabel+NibFont.h
Created May 30, 2012 12:00
UILabel category for setting custom font in IB
//
// Copyright © 2012 Yuri Kotov
//
#import <UIKit/UIKit.h>
@interface UILabel (NibFont)
@property (nonatomic, copy) NSString *fontName;
@property (nonatomic) CGFloat fontSize;
@advantis
advantis / NSError+ADVAlertPresentation.h
Created April 22, 2012 09:41
Shortcut method for quick NSError presentation
//
// Copyright © 2010 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface NSError (ADVAlertPresentation)
- (void) displayInAlert;
@advantis
advantis / ADVActionSheet.h
Last active October 3, 2015 08:48
UIActionSheet subclass that brings simple block API
//
// Copyright © 2011 Yuri Kotov
//
#import <UIKit/UIKit.h>
typedef void(^ADVSheetAction) ();
@interface ADVActionSheet : UIActionSheet <UIActionSheetDelegate>
@advantis
advantis / ADVNetworkActivityIndicator.h
Created April 15, 2012 19:06
iOS network activity indicator manager
//
// Copyright © 2011 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface ADVNetworkActivityIndicator : NSObject
+ (ADVNetworkActivityIndicator *) sharedIndicator;