Skip to content

Instantly share code, notes, and snippets.

View hamrickdavid's full-sized avatar

David Hamrick hamrickdavid

View GitHub Profile
@hamrickdavid
hamrickdavid / Example1.m
Created May 28, 2012 19:45
Adding Properties to an Objective-C Category Revisted
static char kDHStyleKey;
@interface UIView (DHStyleManager)
@property (nonatomic, copy) NSString* styleName;
@end
@implementation UIView (DHStyleManager)
@dynamic styleName;
- (void)setStyleName:(NSString *)styleName
{
@hamrickdavid
hamrickdavid / Test.m
Created February 12, 2012 21:09
Adding Properties to an Objective-C Category
#import UIViewDHStyleManager.h"
UIView* v = [[[UIView alloc] init] autorelease];
v.styleName = @"someStyleName";
NSLog(@"v = %@",v.styleName); //Logs 'someStyleName'
@hamrickdavid
hamrickdavid / Example.m
Created February 12, 2012 02:41
Using UIWebview as a Javascript Interpreter
JavascriptContext* ctx = [[JavascriptContext alloc] init];
[ctx evaluateJS:@"2+2;"]; //Results in 4
[ctx evalateJS:someScriptStoredInBundle];
[ctx release];
@hamrickdavid
hamrickdavid / UINavigationControllerFade.h
Created December 31, 2011 21:11
Changing the UINavigationController animation style
@interface UINavigationController (Fade)
- (void)pushFadeViewController:(UIViewController *)viewController;
- (void)fadePopViewController;
@end
@hamrickdavid
hamrickdavid / example.m
Created October 14, 2011 00:33
Monitoring Files With GCD Being Edited With A Text Editor
- (void)watchConfigFile:(NSString*)path;
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
int fildes = open([path UTF8String], O_EVTONLY);
__block typeof(self) blockSelf = self;
__block dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE,fildes,
DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_EXTEND | DISPATCH_VNODE_ATTRIB | DISPATCH_VNODE_LINK | DISPATCH_VNODE_RENAME | DISPATCH_VNODE_REVOKE,
queue);
@hamrickdavid
hamrickdavid / gcdtest.m
Created October 10, 2011 03:25
GCD for monitoring filesystem
int fildes = open("/path/to/config.plist", O_RDONLY);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE,fildes,
DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_EXTEND | DISPATCH_VNODE_ATTRIB | DISPATCH_VNODE_LINK | DISPATCH_VNODE_RENAME | DISPATCH_VNODE_REVOKE,
queue);
dispatch_source_set_event_handler(source, ^
{
//Reload the config file
});
@hamrickdavid
hamrickdavid / Example1.m
Created October 9, 2011 21:35
Methods of Reloading Config Files
FileSystemWatch* watcher = [[FileSystemWatch alloc] init];
[watcher watchFileAtPath:@"path/to/config.plist" target:self action:@selector(fileChanged:)];
...
- (void)fileChanged:(FileSystemWatch*)watcher
{
NSLog(@"File changed, time to reload");
}
typedef void(^DrawView_DrawBlock)(UIView* v,CGContextRef context);
@interface DrawView : UIView
@property (nonatomic,copy) DrawableView_DrawBlock drawBlock;
@end