Skip to content

Instantly share code, notes, and snippets.

@advantis
advantis / ADVReachability.h
Created May 19, 2013 16:07
Naive Reachability replacement
//
// Copyright © 2013 Advantis
//
#import <SystemConfiguration/SystemConfiguration.h>
typedef void (^ADVReachabilityHandler)(SCNetworkReachabilityFlags flags);
@interface ADVReachability : NSObject
@advantis
advantis / gist:5583068
Created May 15, 2013 10:37
Comparator benchmark
/* All measurements were done on iPhone 4 */
// MRC:
// descriptor sorting time: 18.503416ms
// comparator sorting time: 4.665041ms
// concurrent comparator sorting time: 4.703520ms
// ARC (w/o __unsafe_unretained):
// descriptor sorting time: 19.011437ms
// comparator sorting time: 14.852541ms
@advantis
advantis / ADVSafeProxy.h
Created May 15, 2013 09:40
Useless HOM sample
//
// Copyright © 2012 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface ADVSafeProxy : NSProxy
- (id) initWithObject:(id)object;
@advantis
advantis / gist:5582403
Created May 15, 2013 08:14
Launch and shutdown sequence
+[NSObject load]
__attribute__((constructor))
main()
+[NSObject initialize]
...
atexit()
__attribute__((destructor))
@advantis
advantis / NSObject+ADVCasting.h
Created May 15, 2013 07:30
Rough analogue of C++ static_cast and dynamic_cast
//
// Copyright © 2012 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface NSObject (ADVCasting)
+ (instancetype) staticCast:(id)from;
+ (instancetype) dynamicCast:(id)from;
@advantis
advantis / iOS → Save for Retina.jsx
Created May 15, 2013 07:06
Trim and export visible layer(s) as two PNG images (standard and retina)
var fileName = prompt('Image name', 'image');
if (null != fileName)
{
var selection = activeDocument.selection;
try
{
selection.copy(true);
}
catch (error)
//
// Copyright © 2013 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface NSUserDefaults (ADVKeyedSubscript)
- (id) objectForKeyedSubscript:(NSString *)key;
- (void) setObject:(id)object forKeyedSubscript:(NSString *)key;
@advantis
advantis / arg.py
Last active October 18, 2020 21:50
Custom LLDB command for examining function arguments
#!/usr/bin/python
import lldb
import shlex
def mem_location(arch, index):
index = int(index)
return {
'arm' : ("$r%d" % (index)) if (index < 4) else ("$sp+%d" % (index - 4)),
'armv7' : ("$r%d" % (index)) if (index < 4) else ("$sp+%d" % (index - 4)),
@advantis
advantis / UIViewController+ADVOverlay.h
Last active October 21, 2015 05:16
Simple overlay using containment API
//
// Copyright © 2012 Yuri Kotov
//
#import <UIKit/UIKit.h>
@interface UIViewController (ADVOverlay)
@property (nonatomic, readonly) UIViewController *overlayViewController;
@advantis
advantis / gist:4073161
Last active October 12, 2015 19:08
Random thoughts on storyboard segues
// Thought #1
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:NSSelectorFromString(segue.identifier)
withObject:segue.destinationViewController];
#pragma clang diagnostic pop
}