Skip to content

Instantly share code, notes, and snippets.

@rustle
rustle / gist:5556512
Created May 10, 2013 18:46
Seems like ACAccountType needs a better isEqual: implementation
// Works fine
accounts = [accounts filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(ACAccount *evaluatedObject, NSDictionary *bindings) {
return [[[evaluatedObject accountType] identifier] isEqualToString:[self.accountType identifier]];
}]];
// No dice
accounts = [accounts filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(ACAccount *evaluatedObject, NSDictionary *bindings) {
return [[evaluatedObject accountType] isEqual:self.accountType];
@rustle
rustle / gist:5112576
Created March 7, 2013 22:49
Example of an ESHTTPOperation subclass for downloading a file directly to disk using NSOutputStream including resuming
//
// KATGDownloadOperation.h
// KATG
//
// Created by Doug Russell on 3/7/13.
// Copyright (c) 2013 Doug Russell. All rights reserved.
//
#import "ESHTTPOperation.h"
@rustle
rustle / gist:5079872
Created March 4, 2013 04:14
Example of prefixing a list with a leading character. In this case, adding a • to the front of each line.
NSString *someText = ...;
NSMutableString *someLines = [NSMutableString new];
[someText enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {
// Make sure the line isn't just whitespace
NSMutableString *mutableLine = [line mutableCopy];
CFStringTrimWhitespace((__bridge CFMutableStringRef)mutableLine);
if ([mutableLine length])
{
[someLines appendFormat:@" • %@\n", line];
}
//
// ARCLogic.h
//
#ifndef ARCLOGIC
#define ARCLOGIC
#ifdef HASARC
#undef HASARC
#endif
@rustle
rustle / gist:5027734
Created February 25, 2013 04:23
An accessible UISlider subclass that closely emulates the time scrubber in Music.app
//
// KATGShowControlsScrubber.m
// KATG
//
// Created by Doug Russell on 2/24/13.
// Copyright (c) 2013 Doug Russell. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
@rustle
rustle / gist:5017569
Last active December 14, 2015 02:59
Example of an NSValue subclass with a return value on getValue:
#import <Foundation/Foundation.h>
@interface RSTLValue : NSValue
- (BOOL)getValue:(void *)value expectedSize:(size_t)expectedSize;
@end
struct Foo {
NSUInteger i;
char * bar;
};
@rustle
rustle / gist:4678755
Created January 31, 2013 00:28
Couple of typedefs that I think make the NSFilePresenter block APIs a little easier to read
typedef void (^FilePresenterReacquirerBlock)(void);
typedef void (^FilePresenterReaderBlock)(FilePresenterReacquirerBlock reacquirer);
typedef void (^FilePresenterWriterBlock)(FilePresenterReacquirerBlock reacquirer);
typedef void (^FilePresenterCompletionHandler)(NSError *errorOrNil);
- (void)relinquishPresentedItemToReader:(FilePresenterReaderBlock)reader
{
// Do stuff here ahead of reading
reader(^{
// Do stuff here after reading is done

Builds and runs no problem:

@interface Foo : NSObject
@property (readonly) id foo;
@end

@implementation Foo

- (instancetype)init
@rustle
rustle / gist:4342288
Created December 20, 2012 01:31
Tower with Kaleidoscope 2 beta

Due to a change in Kaleidoscope 2, Tower 1.4.14 does not work with the latest beta of Kaleidoscope 2 (Build 99 and up) out of the box. We are working with the fine folks at Tower to address this issue.

If you are running 1.4.14, download this script and follow the included instructions:

Kaleidoscope Merge Tool

Future versions of Tower should work as expected without the need for these steps.

@rustle
rustle / gist:4342284
Created December 20, 2012 01:30
Cornerstone with Kaleidoscope 2 beta

Cornerstone does not yet officially support Kaleidoscope 2, so to work with the latest beta of Kaleidoscope 2 (Build 99 and up) here is how to get set up:

Follow the instructions here Cornerstone External Compare Tools under the heading Custom Compare Scripts

The custom scripts contents should be

#!/usr/bin/env bash

/usr/local/bin/ksdiff --partial-changeset -- "$1" "$2"