Skip to content

Instantly share code, notes, and snippets.

View andrewsardone's full-sized avatar

Andrew Sardone andrewsardone

View GitHub Profile
@andrewsardone
andrewsardone / bookmarklet.js
Created December 17, 2013 02:43
Tweetbot bookmarklet. I'm sure other people have better, more robust ones, but this bookmarklet works for me.
javascript:(function()%7Bwindow.open(location.href.replace(%2Fhttps%3A%5C%2F%5C%2F(mobile.)%3Ftwitter.com%5C%2F%2F%2C%20%22tweetbot%3A%2F%2F%22).replace(%22statuses%22%2C%20%22status%22)%2C%20%22_self%22)%7D)()
require 'rubygems'
require 'rspec'
require 'faraday'
describe Faraday do
it "stubs HTTP responses" do
conn = Faraday.new do |f|
f.adapter :test do |stub|
stub.get '/example' do
[200, {}, 'hi world']
@andrewsardone
andrewsardone / gist:7130116
Last active December 26, 2015 09:29
Using a compound statement enclosed in parentheses to enclose scope of a local UIView that's added to your view controller's view hierarchy and held as a weak reference. In response to http://ashfurrow.com/blog/weakstrong-dance
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, weak) UILabel *label;
@end
@implementation ViewController
@andrewsardone
andrewsardone / gist:6458455
Created September 6, 2013 01:32
script/sort-xcodeproj for handy Xcode project organization
#!/bin/bash
#
# Usage: script/sort-xcodeproj to sort all root-level Xcode projects.
# This helps keep the Xcode project layout neat and consistent while
# aiding in the prevention of [merge conflicts][mc].
#
# [mc]: http://danieltull.co.uk/blog/2013/09/05/easier-merging-of-xcode-project-files/
SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR/.."
@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)) @{

I was linked to this post by Mark Wilson via a tweet from Tim O'Reilly:

This critique of an Apple ad may well be the most important thing you'll read this year: http://bit.ly/115U5uT Take it seriously.

My terse comment on Twitter summed up my response, but I decided to follow O'Reilly's lead and “take [the piece] seriously.” I'll try to keep it short.

Fresh clone and test of script/ci:

git clone https://github.com/andrewsardone/UITextView-UIControl \
  && cd UITextView-UIControl \
  && git checkout -t origin/ci \
  && script/bootstrap \
  && script/ci

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];
#import <UIKit/UIKit.h>
@interface AbstractViewController : UIViewController
@property (nonatomic, strong) Class specialButtonClass;
@property (nonatomic, strong) IBOutlet UIButton *specialButton; // laid out in nib
@end
// 1.
// “Safe” but retain cycle.
[self setCompletionBlock:^{
NSLog(@"1: %@", self->_foo);
}];
// 2.
// Unsafe. Could dereference nil.
__weak BCThing *weakSelf = self;