Skip to content

Instantly share code, notes, and snippets.

View hborders's full-sized avatar

Heath Borders hborders

View GitHub Profile
:start
duplicate
not
goto done
push 1
add
duplicate
push 2
subtract
push 3 -1
@hborders
hborders / gist:4064006
Created November 13, 2012 05:04
Example of my use of UIViewController containment lifecycle methods inside a custom tab bar controller.
- (void) setSelectedViewController:(UIViewController<SFCustomTabbedViewController> *)selectedViewController {
if (_selectedViewController != selectedViewController) {
if (_selectedViewController) {
NSUInteger selectedViewControllerIndex = [self.viewControllers indexOfObject:_selectedViewController];
if (selectedViewControllerIndex != NSNotFound) {
UIButton *tabButton = [self.tabButtons objectAtIndex:selectedViewControllerIndex];
tabButton.selected = NO;
}
[_selectedViewController willMoveToParentViewController:nil];
@hborders
hborders / gist:5790844
Created June 16, 2013 05:08
A good comment
// if we submit more than one div with a class of "jive-rendered-context", only the first div is accepted
innerHTMLContent = innerHTMLContent.replace(/(<div class="jive-rendered-content">)/ig,"<div>");
@hborders
hborders / gist:5790859
Created June 16, 2013 05:19
Another "why" comment that is valuable. Without the comment, a naive developer might very declare the values at the call site, breaking the SWT library.
public static final int BUTTON_MASK;
public static final int MODIFIER_MASK;
static {
/*
* These values represent bit masks that may need to
* expand in the future. Therefore they are not initialized
* in the declaration to stop the compiler from inlining.
*/
BUTTON_MASK = BUTTON1 | BUTTON2 | BUTTON3 | BUTTON4 | BUTTON5;
@hborders
hborders / gist:5790870
Created June 16, 2013 05:25
From the SWT source. This just shows why some wacky API exists. I'm not sure this is the best solution for the problem, but the code definitely doesn't stand on its own. You could probably back it with a unit test, but I'd hate to have to delete these seemingly useless lines and run a testsuite just to find out what this did.
/*
* Plug-ins need an opportunity to set the org.eclipse.swt.browser.DefaultType
* system property before the first Browser is created. To facilitate this,
* reflection is used to reference non-existent class
* org.eclipse.swt.browser.BrowserInitializer the first time a Browser is created.
* A client wishing to use this hook can do so by creating a fragment of
* org.eclipse.swt that implements this class and sets the system property in its
* static initializer.
*/
try {
@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 {