Skip to content

Instantly share code, notes, and snippets.

@leovandriel
leovandriel / gist:3775603
Created September 24, 2012 11:53
Xcode Run Script for building static framework for Cocoa Touch iOS
# Xcode Run Script for building iOS static framework.
# Requires a preconfigured Cocoa Touch Static Library.
# Usage:
# 1. Open project > Add Target > iOS Aggregate > Finish
# 2. Add Build Phase > Add Run Script > Paste
# 3. Manually assign PROJECT, TARGET, HEADERS, PRODUCT, OUTPUT
# 4. Run outputs to ${SRCROOT}/build
#
# License: Public Domain
# Author: Leonard van Driel, 2012
@leovandriel
leovandriel / gist:3780745
Created September 25, 2012 09:03
Configuration tips when fighting Xcode - Build settings that build
# Configuration tips when fighting Xcode - Build settings that build
# Starting from a fresh Xcode project, setting these on the project's build
# settings should suffice. Also put all libs and frameworks in the Frameworks
# dir and make sure included workspace header files are set to 'Public'.
# Author: Leonard van Driel, 2012
Other Linker Flags: -ObjC
Public Headers Folder Path: ../../Headers
Framework Search Paths: "$(SRCROOT)/Frameworks"
Header Search Paths: "$(SRCROOT)/Frameworks"/** $(BUILT_PRODUCTS_DIR)/../../Headers
@leovandriel
leovandriel / gist:3786554
Created September 26, 2012 07:16
Objective-C method for composing a HTTP multipart/form-data body
// Objective-C method for composing a HTTP multipart/form-data body.
// Provide parameters and data in a NSDictionary. Outputs a NSData request body.
// License: Public Domain
// Author: Leonard van Driel, 2012
@interface MultipartExample @end
@implementation MultipartExample
+ (void)exampleUsageUploadImage
@leovandriel
leovandriel / gist:3787259
Created September 26, 2012 10:34
Objective-C methods for percent-escaping NSString
// Objective-C methods for percent-escaping NSString, for use in NSURL.
// This approach does full escaping, instead of the 'smart' escaping that
// is provided by [NSString stringByReplacingPercentEscapesUsingEncoding:].
// License: Public Domain
// Author: Leonard van Driel, 2012
@implementation NSString (EscapeForURL)
- (NSString *)escapeForURL
{
@leovandriel
leovandriel / gist:3787536
Created September 26, 2012 11:42
Objective-C methods for Base64 conversion between NSString and NSData
// Objective-C methods for Base64 conversion between NSString and NSData.
// Note: these do not support trailing '=' characters.
// License: Public Domain
// Author: Leonard van Driel, 2012
static unsigned char toBase64String[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static unsigned char toBase64Data[256] = {
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
@leovandriel
leovandriel / gist:3787815
Created September 26, 2012 12:49
A Minimal PonyDebugger setup in Objective-C
// A Minimal PonyDebugger setup in Objective-C
// Add these lines to application:didFinishLaunchingWithOptions: and add the
// PonyDebugger and SocketRocket libs/frameworks to your project. Read the
// Quick Start at https://github.com/square/PonyDebugger#quick-start
// For on-device debugging, use `ponyd serve -i 0.0.0.0` and replace `localhost`.
// Author: Leonard van Driel, 2012
#if DEBUG
PDDebugger *debugger = (PDDebugger *)[NSClassFromString(@"PDDebugger") defaultInstance];
[debugger connectToURL:[NSURL URLWithString:@"ws://localhost:9000/device"]];
@leovandriel
leovandriel / gist:3794804
Created September 27, 2012 15:59
NWURLConnection - an NSURLConnectionDelegate based on blocks with cancel
// NWURLConnection - an NSURLConnectionDelegate based on blocks with cancel.
// Similar to the `sendAsynchronousRequest:` method of NSURLConnection, but
// with `cancel` method. Requires ARC on iOS 6 or Mac OS X 10.8.
// License: BSD
// Author: Leonard van Driel, 2012
@interface NWURLConnection : NSObject<NSURLConnectionDelegate>
@property (nonatomic, strong) NSURLRequest *request;
@property (nonatomic, strong) NSOperationQueue *queue;
@leovandriel
leovandriel / gist:3851904
Created October 8, 2012 10:42
A HockeyApp delegate class
// A HockeyApp delegate class.
// License: Public Domain
// Author: Leonard van Driel, 2012
#import <HockeySDK/HockeySDK.h>
@interface NWHockeyChief : NSObject <BITHockeyManagerDelegate, BITUpdateManagerDelegate, BITCrashManagerDelegate>
+ (NWHockeyChief *)shared;
+ (void)setup;
@end
@leovandriel
leovandriel / gist:3923434
Last active October 12, 2015 13:19
An iOS view controller for trying out different UIImage preloading strategies
// ImagePreloadingViewController - An iOS view controller for trying out different
// UIImage preloading strategies. Results for 1 MB png on iPhone 4S:
// - No preload: drawing the image right away (80 ms)
// - Header preload: getting the width (10 ms) and then drawing (100 ms)
// - Data preload: getting the data (110 ms) and then drawing (75 ms)
// - Draw preload: drawing it once (100 ms) and then again (20 ms)
// In short: preload a UIImage by drawing it.
// License: BSD
// Author: Leonard van Driel, 2012
@leovandriel
leovandriel / gist:4579113
Last active June 4, 2019 06:13
Country code lookup using offline quadtree generated by Yggdrasil (https://github.com/leonardvandriel/Yggdrasil)
# Country code lookup using offline quadtree generated by Yggdrasil.
# https://github.com/leonardvandriel/Yggdrasil
# This Ruby script can be used to determine the ISO 3166 country at a given
# WGS 84 coordinate. Lookup is based on quadtree data stored in the remainder
# of this file. This data can be compressed to under 20 KB, while providing
# lookup accuracy under 40 km.
# License: BSD
# Author: Leonard van Driel, 2013
require 'json'