Skip to content

Instantly share code, notes, and snippets.

View orj's full-sized avatar

Oliver Jones orj

View GitHub Profile
@orj
orj / NSErrorUserInfoValueProviding.swift
Last active October 5, 2016 15:54
A protocol that can be adopted by ErrorType, RawRepresentable conforming types that provides a mechanism for providing NSError userInfo values.
/// A protocol that can be adopted by ErrorType, RawRepresentable conforming types that
/// provides a mechanism for providing NSError userInfo values.
///
/// There are nil returning default implementations of all of the members of this protocol.
protocol NSErrorUserInfoValueProviding {
var localizedDescription: String? { get }
var localizedFailureReason: String? { get }
var localizedRecoverySuggestion: String? { get }
var localizedRecoveryOptions: [String]? { get }
@orj
orj / RefreshReveal.scpt
Last active August 29, 2015 13:57
Refresh Reveal.app AppleScript.
-- `menu_click`, by Jacob Rus, September 2006
--
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item. In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-(void) encodeWithCoder: (NSCoder*) coder
{
#define X(type, ivar) [coder encode##type:ivar forKey:@#ivar];
#define BOX(type, ivar) [coder encodeObject:([NSValue valueWith##type:ivar]) forKey:@#ivar];
XEncodeIvars
#undef BOX
#undef X
}
-(id) initWithCoder: (NSCoder*) decoder
-(void) encodeWithCoder: (NSCoder*) coder
{
#define X(type, ivar) [coder encode##type:ivar forKey:@#ivar];
XEncodeIvars
#undef X
}
-(id) initWithCoder: (NSCoder*) decoder
{
#define X(type, ivar) ivar = [decoder decode##type##ForKey:@#ivar];
@orj
orj / gist:5298448
Created April 3, 2013 04:28
Exceptions in UIWebView on dealloc when displaying PDFs.
* thread #1: tid = 0x1c03, 0x37447724 libc++abi.dylib`__cxa_throw, stop reason = breakpoint 1.1
frame #0: 0x37447724 libc++abi.dylib`__cxa_throw
frame #1: 0x330fe296 libobjc.A.dylib`objc_exception_throw + 94
frame #2: 0x37dcd788 CoreFoundation`+[NSException raise:format:arguments:] + 100
frame #3: 0x37dcd7aa CoreFoundation`+[NSException raise:format:] + 34
frame #4: 0x36f9a618 Foundation`-[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 740
frame #5: 0x36f9a286 Foundation`-[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 170
frame #6: 0x30f4799c UIKit`-[UIWebPDFView _removeBackgroundImageObserverIfNeeded:] + 108
frame #7: 0x30f47bfc UIKit`-[UIWebPDFView dealloc] + 540
frame #8: 0x330fa174 libobjc.A.dylib`_objc_rootRelease + 36
@orj
orj / gist:1234366
Created September 22, 2011 08:46
A macro to declare a variable number of Objective-C properties in one statement.
#define CAT(a, b) _PRIMITIVE_CAT(a, b)
#define _PRIMITIVE_CAT(a, b) a##b
#define N_ARGS(...) N_ARGS_1(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define N_ARGS_1(...) N_ARGS_2(__VA_ARGS__)
#define N_ARGS_2(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, n, ...) n
#define PROPERTY(policy, ...) CAT(_PROPERTY_, N_ARGS(__VA_ARGS__))(policy, __VA_ARGS__)
#define PROPERTY_STRONG(...) PROPERTY(retain, __VA_ARGS__)
#define PROPERTY_WEAK(...) PROPERTY(assign, __VA_ARGS__)
@orj
orj / .gitconfig
Created May 27, 2011 02:43
Using p4merge as Git mergetool on Mac OS X.
[merge]
keepBackup = false
tool = custom
[mergetool "custom"]
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "$PWD/$BASE" "$PWD/$REMOTE" "$PWD/$LOCAL" "$PWD/$MERGED"
keepTemporaries = false
trustExitCode = false
keepBackup = false
@orj
orj / gist:985501
Created May 22, 2011 14:05
A Objective-C macro for generating @synthesize statements. Useful when you want to enforce a specific naming convention on synthesized ivars.
/*!
\def N_ARGS
\brief Macro that can tell how many variable arguments have been passed to it (up to a total of 16).
*/
#define N_ARGS(...) N_ARGS_1(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define N_ARGS_1(...) N_ARGS_2(__VA_ARGS__)
#define N_ARGS_2(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, n, ...) n
/*!
\def CAT