Skip to content

Instantly share code, notes, and snippets.

View kluivers's full-sized avatar

Joris Kluivers kluivers

View GitHub Profile
@kluivers
kluivers / gist:9808519
Created March 27, 2014 14:16
Responder forwarding
@implementation UIResponder (ResponderForwarding)
- (BOOL) tryToPerformAction:(SEL)action withObject:(id)object
@end
@implementation UIResponder (ResponderForwarding)
- (BOOL) tryToPerformAction:(SEL)action withObject:(id)object
{
if (!action) {
return NO;
@kluivers
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.host = @"joris.kluivers.nl";
builder.path = @"/blog/2013/10/17/nsurlcomponents/";
}];
// url now equals:
// http://joris.kluivers.nl/blog/2013/10/17/nsurlcomponents/
@kluivers
kluivers / .gitignore
Created February 27, 2012 11:48
.gitignore for Xcode projects
# .gitignore in use by Joris Kluivers
#
# Latest version:
# https://gist.github.com/gists/1923197
*.DS_Store
# Xcode
*.pbxuser
*.mode1v3
@kluivers
kluivers / singleton.m
Created February 27, 2012 16:21
A singleton implementation in Objective-C
+ (id) sharedInstance {
static dispatch_once_t predicate = 0;
__strong static id shared = nil;
dispatch_once(&predicate, ^{
shared = [[self alloc] init];
});
return shared;
}
@kluivers
kluivers / build.xml
Created February 28, 2012 12:34
Transform OCUnit output to html using ANT
<target name="test" depends="build"
description="Builds the project, runs the unit tests, generates a report">
<exec executable="xcodebuild" dir="zip-framework" failonerror="false" outputproperty="xcodebuild.out">
<arg line="-target Test -configuration release build" />
</exec>
<mkdir dir="reports" />
<mkdir dir="reports/raw" />
<exec executable="OCUnitReport" errorproperty="report-error.out" inputstring="${xcodebuild.out}" searchpath="true" resolveexecutable="true">
@kluivers
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadDescription</key>
<string>Disables the home button.</string>
<key>PayloadDisplayName</key>
@kluivers
kluivers / BuildRule.sh
Created May 21, 2012 22:51
Xcode build rule for Mardown files
# Template file with replacement tag: ${BODY}
TEMPLATE="${SRCROOT}/ShapeDemo/Template.html"
# 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
cat "$TEMPLATE" | sed "s/\${BODY}/${HTML_CONTENTS}/" > "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${INPUT_FILE_BASE}.html"
@kluivers
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
kluivers / gist:3781049
Created September 25, 2012 10:17
Copy a new UUID to the clipboard
uuidgen | tr -d '\n' | pbcopy
ssh host.com 'cd /var/www/; git pull'