Skip to content

Instantly share code, notes, and snippets.

View kluivers's full-sized avatar

Joris Kluivers kluivers

View GitHub Profile
kluivers / url-builder.m
Created April 8, 2014 13:22
Builder pattern in Objective-C
NSURL *someURL = [NSURL URLWithBuilderBlock:^(NSURLComponents *builder) {
builder.scheme = @"http"; = @"";
builder.path = @"/blog/2013/10/17/nsurlcomponents/";
// url now equals:
kluivers / gist:9808519
Created March 27, 2014 14:16
Responder forwarding
@implementation UIResponder (ResponderForwarding)
- (BOOL) tryToPerformAction:(SEL)action withObject:(id)object
@implementation UIResponder (ResponderForwarding)
- (BOOL) tryToPerformAction:(SEL)action withObject:(id)object
if (!action) {
return NO;
kluivers / gist:7698470
Created November 28, 2013 21:37
Get the model identifier for the current device (on iOS or Mac)
#include <sys/types.h>
#include <sys/sysctl.h>
char *propertyName = "hw.machine";
char *propertyName = "hw.model";
size_t size;
kluivers / gist:7023579
Last active December 25, 2015 18:49
NSURLComponents Interface declaration
// See also my related blog post:
@interface NSURLComponents : NSObject <NSCopying>
// Initialize a NSURLComponents with all components undefined. Designated initializer.
- (id)init;
// Initialize a NSURLComponents with the components of a URL. If resolvingAgainstBaseURL is YES and url is a relative URL, the components of [url absoluteURL] are used. If the url string from the NSURL is malformed, nil is returned.
kluivers / gist:4388037
Created December 27, 2012 12:33
Load a NSTableCellView from a NIB
@interface NSTableCellView (JKNibLoading)
+ (instancetype) tableCellViewWithNibNamed:(NSString *)nibName owner:(id)owner;
@implementation NSTableCellView (JKNibLoading)
+ (instancetype) tableCellViewWithNibNamed:(NSString *)nibName owner:(id)owner
NSTableCellView *view = nil;
NSArray * topLevelObjects = nil;
ssh 'cd /var/www/; git pull'
kluivers / gist:3781049
Created September 25, 2012 10:17
Copy a new UUID to the clipboard
uuidgen | tr -d '\n' | pbcopy
kluivers / gist:2775861
Created May 23, 2012 15:22
'Show in Finder' in Objective-C code.
NSArray *fileURLs = [NSArray arrayWithObjects:fileURL1, /* ... */ nil];
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
kluivers /
Created May 21, 2012 22:51
Xcode build rule for Mardown files
# Template file with replacement tag: ${BODY}
# generate and clean HTML
HTML_CONTENTS=`/usr/local/bin/markdown "${INPUT_FILE_PATH}"`
HTML_CONTENTS=`echo $HTML_CONTENTS | sed -e 's/[\/&]/\\\&/g'`
# replace into template and write to Resources
kluivers / AppLock.mobileconfig.xml
Created March 2, 2012 14:43
Disable the iOS home button for the first app launched. Restart device to kick into effect after installing.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<string>Disables the home button.</string>