Skip to content

Instantly share code, notes, and snippets.

View chwalters's full-sized avatar

Chris Walters chwalters

View GitHub Profile
@mikeabdullah
mikeabdullah / gist:7034158
Last active December 25, 2015 20:19
-hostURL
// A single slash takes us back to the host's root directory,
// discarding any components after the path.
// Then make absolute so callers don't have to worry about any
// side-effects of working with relative URL objects.
return [[NSURL URLWithString:@"/" relativeToURL:url] absoluteURL];
@steipete
steipete / UIKitLegacyDetector.m
Last active March 12, 2024 13:57
A simple way to detect at runtime if we're running in UIKit legacy mode or the new "flat" variant. Written for our PDF iOS SDK (http://pspdfkit.com), where the precompiled binary needs to detect at runtime in what variant it's running. Want more stuff like that? Follow me on Twitter: http://twitter.com/steipete
// Taken from http://PSPDFKit.com. This snippet is under public domain.
#define UIKitVersionNumber_iOS_7_0 0xB57
BOOL PSPDFIsUIKitFlatMode(void) {
static BOOL isUIKitFlatMode = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// We get the modern UIKit if system is running >= iOS 7 and we were linked with >= SDK 7.
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) {
isUIKitFlatMode = (NSVersionOfLinkTimeLibrary("UIKit") >> 16) >= UIKitVersionNumber_iOS_7_0;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmismatched-method-attributes"
- (IBAction)selectAll:(id)sender
{
// do stuff
}
#pragma clang diagnostic pop
@itod
itod / gist:5229175
Created March 23, 2013 20:08
Use ParseKit's `PKTokenizer` class to tokenize HLA-style hex numbers like `$00FF_FFFF` and binary numbers like `%0001_0101`
NSString *s = @"$00FF_FFFF %0001_0101";
PKTokenizer *t = [PKTokenizer tokenizerWithString:s];
// add support for HLA-style hex numbers like $00FF_FFFF
[t.numberState addPrefix:@"$" forRadix:16];
[t.numberState addGroupingSeparator:'_' forRadix:16];
[t setTokenizerState:t.numberState from:'$' to:'$'];
// add support for HLA-style binary numbers like %0001_0101
[t.numberState addPrefix:@"%" forRadix:2];
@cieslak
cieslak / main.m
Last active December 10, 2015 13:09
Date Formatting String Example
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
@mikeabdullah
mikeabdullah / gist:3116322
Created July 15, 2012 11:18
Safely wrapping keychain passwords with NSString/CFString
void freeKeychainContent(void *ptr, void *info)
{
SecKeychainItemFreeContent(NULL, ptr);
}
- (NSString *)passwordFromKeychainItem:(SecKeychainItemRef)keychainItem
{
void *passwordData;
UInt32 passwordLength;
OSStatus status = SecKeychainItemCopyContent(keychainItem,