Skip to content

Instantly share code, notes, and snippets.

View hborders's full-sized avatar

Heath Borders hborders

View GitHub Profile
@hborders
hborders / gist:5790878
Created June 16, 2013 05:29
These comments are all over the SWT source. SWT provides common behavior across many different native GUIs. This means they need to work around unintuitive behavior or bugs on different systems.
/*
* Bug in Windows. Under certain cirumstances yet to be
* isolated, BCM_SETIMAGELIST does not redraw the control
* when a new image is set. The fix is to force a redraw.
*/
OS.InvalidateRect (handle, null, true);
@hborders
hborders / gist:5831832
Created June 21, 2013 15:07
Metacomment
/*
* No need to override setCompletionBlock. -[AFURLConnectionOperation setCompletionBlock:] is fine for us.
* Leaving this comment here to account for all public superclass methods
- (void)setCompletionBlock:(void (^)(void))block;
*/
@hborders
hborders / gist:5886491
Created June 28, 2013 17:32
My list default list of always-on symbolic breakpoints for Foundation
NSKVODeallocateBreak
_NSLockError
objc_setEnumerationMutationHandler
@hborders
hborders / gist:6538030
Created September 12, 2013 14:10
Demonstrates a category that should trigger deprecation warnings for an Objective-C method, but doesn't.
@interface UINavigationController (Deprecations)
- (id)initWithRootViewController:(UIViewController *)rootViewController __attribute__((deprecated));
@end
// no implementation of UINavigationController (Deprecations) should be necessary. I just want to add the attribute
// should this be a class extension instead of a category?
@interface SomethingThatUsesNavigationController : UIViewController
@end
@hborders
hborders / gist:6998448
Created October 15, 2013 20:50
Demonstrates problem with static methods
@interface Foo : NSObject
+ (void)bar;
@end
@implementation Foo
+ (void)bar {
@hborders
hborders / Fixed895ShadowLooper
Last active January 2, 2016 09:49
A new ShadowLooper to workaround https://github.com/robolectric/robolectric/pull/895 Include it in your unit tests along with a top-level configuration file named: org.robolectric.Config.properties with the following contents: shadows=org.github.gist.hborders.Fixed895ShadowLooper
package org.github.gist.hborders;
/**
To automatically configure this Shadow for all tests, create a top-level configuration file named: org.robolectric.Config.properties with the following contents:
shadows=org.github.gist.hborders.Fixed895ShadowLooper
*/
@SuppressWarnings({"UnusedDeclaration"})
@Implements(Looper.class)
@hborders
hborders / gist:8560409
Created January 22, 2014 15:14
Class<?> varargs example from https://twitter.com/natesbrain/status/425720792760856576 compiles file for me.
class A {
}
class B extends A {
}
class C extends A {
@hborders
hborders / gist:8612342
Created January 25, 2014 05:42
ARC block release-only block crash
- (AFHTTPRequestOperation *)operationForEmptyResponseRequest:(NSURLRequest*) request onComplete:(void(^)(void)) completeBlock onError:(void (^)(NSError *)) errorBlock {
void (^nilObjectCompleteBlock)(id);
if (complete) {
void (^heapCompleteBlock)(void) = [completeBlock copy];
// INTERESTING BITS:
// iOS7: this crashes in weird ways if we don't copy the block we assign to nilObjectComplete here.
// it is supposed to be safe to pass a block down into another block, but maybe not.
nilObjectCompleteBlock = [^(id nilObject) {
heapCompleteBlock();
} copy];
@hborders
hborders / WeakTestTests.m
Created March 1, 2016 05:30
Is self guaranteed to stay alive until the end of a method call if it was referenced from within a __weak lvalue?
//
// WeakTestTests.m
// WeakTestTests
//
// Created by Borders, Heath on 2/29/16.
// Copyright © 2016 Heath Borders. All rights reserved.
//
#import <XCTest/XCTest.h>
@hborders
hborders / PlaygroundTests.m
Created May 3, 2016 15:49
Testing whether NSMutableArray is biased towards insertion and removal at the end
#import <XCTest/XCTest.h>
@interface PlaygroundTests : XCTestCase
@end
@implementation PlaygroundTests
static const NSUInteger length = 100000000;