View puke.m
This file contains 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
+(NSString*) describe:(id) object { | |
NSMutableString *string = [NSMutableString stringWithString:@""]; | |
unsigned int propertyCount; | |
objc_property_t *properties = class_copyPropertyList([object class], &propertyCount); | |
for (unsigned int i = 0; i < propertyCount; i++) | |
{ | |
NSString *selector = [NSString stringWithCString:property_getName(properties[i]) | |
encoding:NSUTF8StringEncoding] ; |
View gist:1290641
This file contains 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
/** | |
* Register keyboard notifications. | |
*/ | |
-(void) registerKeyboardNotifications { | |
trace(@"register keyboard notifications"); | |
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; | |
[center addObserver:self | |
selector:@selector(keyboardDidShow:) | |
name:UIKeyboardWillShowNotification object:nil]; | |
[center addObserver:self |
View gist:1980044
This file contains 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
Needs["PlotLegends`"] | |
Plot[{1, Log[n], n, n*Log[n], n^2, n!, 2^n}, {n, 0, 40}, | |
PlotRange -> {0, 200}, PlotLabel -> "O(n) Performance types", | |
PlotLegend -> {"1", "Log[n]", "n", "n*Log[n]", "n^2", "n!", "2^n"}, | |
LegendShadow -> None, LegendBorder -> None, | |
LegendPosition -> {0.9, -0.4}] |
View gist:2983678
This file contains 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
// TEST ASYNCHRONOUS CODE | |
// Runs in Code Runner | |
#import <Foundation/Foundation.h> | |
@interface Test : NSObject | |
-(void)test1BooleanFlag; | |
-(void)test2BooleanFlagAndTimeLimit; | |
-(void)test3Semaphore; |
View gist:3043614
This file contains 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
typedef void (^loop_work_t)(void); | |
@interface TaxiLoop : NSObject | |
@property (nonatomic,assign) loop_work_t block; | |
@property (nonatomic,assign) NSTimeInterval interval; | |
@property (nonatomic,assign) dispatch_source_t timerSource; |
View gist:3649261
This file contains 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
- (dispatch_queue_t)internalQueue | |
{ | |
static dispatch_once_t onceToken; | |
static dispatch_queue_t *internalQueue; | |
dispatch_once(&onceToken, ^{ | |
internalQueue = dispatch_queue_create... | |
}); | |
return internalQueue; | |
} |
View Array.m
This file contains 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
#import <Foundation/Foundation.h> | |
@interface Array : NSObject <NSFastEnumeration> { | |
id __strong *_objs; | |
NSUInteger _count; | |
} | |
@end | |
@implementation Array |
View gist:4041078
This file contains 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
// queue name | |
static const char* s_myqueue = "myqueue"; | |
// return the specific queue | |
dispatch_queue_t my_queue() { | |
static dispatch_queue_t _q; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
_q = dispatch_queue_create(s_myqueue, 0); | |
// sets the key/value data for the specified dispatch queue |
View gist:4175830
This file contains 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
#import <objc/runtime.h> | |
#import <Foundation/Foundation.h> | |
@interface Person : NSObject | |
@property (nonatomic,strong) NSMutableDictionary *properties; | |
@end | |
@implementation Person |
View gist:4324665
This file contains 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
// Maybe a functional category on NSArray will help. | |
@interface NSArray(Extension) | |
-(NSArray*) map:(id(^)(id object))block; | |
@end | |
@implementation NSArray(Extension) | |
-(NSArray*) map:(id(^)(id object))block { | |
NSParameterAssert(block != NULL); | |
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:[self count]]; |
OlderNewer