Skip to content

Instantly share code, notes, and snippets.

@andrewsardone
andrewsardone / gist:1935008
Created February 28, 2012 20:46
I'm finally making two-stage object creation work for me ;-)
#import <SenTestingKit/SenTestingKit.h>
#import "OCMock.h"
#import "NLPageControlScrollViewHelper.h"
#pragma mark - Tests
@interface NLPageControlScrollViewHelperTests : SenTestCase
@end
@dbergey
dbergey / gist:2695699
Created May 14, 2012 18:56
don't switch chat tabs when switching to chat app
tell application "System Events"
if (count of (every application process whose name is "iChat")) > 0 then
activate application "iChat"
else
activate application "Adium"
end if
end tell
anonymous
anonymous / gist:2767637
Created May 22, 2012 08:39
Wiggling Animation
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
[animation setToValue:[NSNumber numberWithFloat:-M_PI/128]];
[animation setFromValue:[NSNumber numberWithDouble:M_PI/128]];
[animation setDuration:0.09];
[animation setRepeatCount:NSUIntegerMax];
[animation setAutoreverses:YES];
@javan
javan / sl2-setup.md
Created July 23, 2012 14:47
My Sublime Text 2 setup
@andrewsardone
andrewsardone / gist:3701925
Created September 11, 2012 20:48
Necessary HIG-compliant tasks to perform in UIViewController subclass with a UITableView

To conform to Apple's human-interface guidelines, you need to implement the following tasks when subclassing UIViewController and including a UITableView in your hierarchy (hence recreating UITableViewController):

Clear any selection in the table view before it's displayed

In -[UIViewController viewWillAppear:], clear the selected row (if any) by sending the -[UITableView deselectRowAtIndexPath:animated:] message.

Flash scroll view's scroll indicators

In -[UIViewController viewDidAppear:], send the -[UITableView flashScrollIndicators] message.

@andrewsardone
andrewsardone / gist:3723354
Created September 14, 2012 17:24
NSKeyValueObserving's use of a context pointer for identifying interested observations

The NSKeyValueObserving addition to NSObject adds an observe message that takes an identifying context pointer – don't use NULL in its place.

Your superclass may observe the same key path for the same object. You need to pass along its observations, and only take actions on yours. The context pointer distinguishes which observations are yours.

static void *kContext = &kContext;
@kristopherjohnson
kristopherjohnson / pipe-forward-optional.swift
Last active November 28, 2015 22:12
F#-style pipe-forward chaining operators for Swift that unwrap Optional values
// Pipe-forward operators that unwrap Optional values
operator infix |>! { precedence 50 associativity left }
operator infix |>& { precedence 50 associativity left }
// Unwrap the optional value on the left-hand side and apply the right-hand-side function
public func |>! <T,U>(lhs: T?, rhs: T -> U) -> U {
return rhs(lhs!)
}
// If optional value is nil, return nil; otherwise unwrap it and

To form a parent-child relationship:

  1. Send the -addChildViewController: message to the parent with the child as the parameter. This will send the -willMoveToParentViewController: message to the child with the parent as the parameter.
  2. Add the child view controller's view as a subview to the parent view controller's view.
  3. Send the -didMoveToParentViewController: message to the child with the parent as the parameter.

For example,

[parent addChildViewController:child];
@andrewsardone
andrewsardone / gist:6076443
Last active December 20, 2015 05:09
I'm trying my hardest to make sure @cdzombak can't read this code.
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == self && context == self.kvoContext) {
((void (^)(void)) @{
@"addresses": ^{ self.peep.address = [self dictionaryForArrayOfValues:self.addresses]; },
@"emails": ^{ self.peep.email = [self dictionaryForArrayOfValues:self.emails]; },
}[keyPath] ?: ^{})();
}
else if (object == self.peep && context == self.kvoContext) {
((void (^)(void)) @{
@jspahrsummers
jspahrsummers / gist:7000136
Last active December 25, 2015 15:39
Various use cases that need to be considered for ReactiveCocoa 3.0, along with their current RAC 2.x or Rx solutions

Use cases

  1. Turning an eager, pure computation into a lazy one: RACSequence, RACSignal
  2. Side-effecting work that is safe to perform multiple times: RACSignal, RACCommand
  3. Side-effecting work that is safe to perform multiple times serially, but not concurrently: RACCommand, RefCount()
    • RACScheduler would seem to apply here, but execution could become interleaved and thus not serial
  4. Side-effecting work that should only be performed once, then memoized: RACMulticastConnection with a RACReplaySubject, RACSequence
  5. Enabling/disabling a UI based on whether work can be performed: RACCommand, RACReplaySubject
    • Replaying is a Good Idea™ because this information may arrive before the UI is ready for it
  6. Updating a UI with information about work in progress: RACCommand, RACSubject