Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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
}
@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 / 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)),
//
// Copyright © 2013 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface NSUserDefaults (ADVKeyedSubscript)
- (id) objectForKeyedSubscript:(NSString *)key;
- (void) setObject:(id)object forKeyedSubscript:(NSString *)key;
@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)
@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 / gist:5582403
Created May 15, 2013 08:14
Launch and shutdown sequence
+[NSObject load]
__attribute__((constructor))
main()
+[NSObject initialize]
...
atexit()
__attribute__((destructor))