Skip to content

Instantly share code, notes, and snippets.

Jason Brennan jbrennan

Block or report user

Report or block jbrennan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jbrennan
jbrennan / gist:1047140
Created Jun 26, 2011
Yo dawg, I heard you like Blocks
View gist:1047140
// Loads the full-sized image ... might be big.
- (void)originalImageWithCompletionHandler:(DownloadedImageCompletionHandler)completionHandler {
// First check to see if this image is cached in memory, if execute the handler passing in the image.
if (nil != _originalImage) {
if (completionHandler) {
completionHandler(self, _photo, _photo.urlOriginal, _originalImage);
}
View feed-subscribers.php
<?php /* With apologies to Dr. Drang and John Siracusa.
feed-subscribers.php
By Marco Arment.
Released into the public domain with no warranties and no restrictions.
Usage: Pipe an Apache access log into stdin, e.g.:
php -f feed-subscribers.php < /var/log/httpd/access_log
@jbrennan
jbrennan / Emojis.m
Created Jun 19, 2014
Finding emojis in NSStrings
View Emojis.m
// This is bad and I feel bad. Suggestions for improvements on finding Emoji?
// This current solution is acceptable for us right now, but obviously the less I have to exclude the better.
@interface NSString (Emoji)
/**
Returns if the receiver may contain Emoji characters.
@note This method may have false-positives since it sees if the string has non-ASCII characters. If the receiver has a non-Emoji, non-ASCII character (like é) then it will still return YES.
*/
View UIGestureRecognizer+ForDummies.m
@implementation UIGestureRecognizer (ForDummies)
+ (instancetype)newWithView:(UIView *)view target:(id)target action:(SEL)action delegate:(id<UIGestureRecognizerDelegate>)delegate
{
UIGestureRecognizer *gesture = [[[self class] alloc] initWithTarget:target action:action];
gesture.delegate = delegate;
[view addGestureRecognizer:gesture];
view.userInteractionEnabled = YES;
return gesture;
@jbrennan
jbrennan / boool.swift
Created Sep 2, 2014
Boooleans in Swift
View boool.swift
typealias Boool = Bool? // Can be true, false, or nil
@jbrennan
jbrennan / Elsewhere.swift
Created Oct 28, 2014
Generic UIViewController subclass
View Elsewhere.swift
// usage
let pop = PopoverViewController<SomeViewController>()
self.showViewController(pop) // adds pop.view as a subview (stepping over this line reveals that pop.view becomes non-nil)
// -viewDidLoad is not called...
@jbrennan
jbrennan / Bug.swift
Created Jul 16, 2015
Bug related to having an optional enum in a struct in Swift
View Bug.swift
import Foundation
public struct FeaturedItem {
public enum ImageSource {
case Bundled(name: String) // simplified enum with one case to illustrate the bug.
}
public let localizedTitleImageSource: ImageSource? // This optional causes Swift to barf. If it's non-optional, it compiles fine
// Workaround in this case is to just use an optional String instead of the enum.
}
@jbrennan
jbrennan / signals.md
Created Nov 16, 2015
Some notes on getting help with Reactive Cocoa Signals with help from a coworker
View signals.md

Notes about Signals

Nacho offered me a little bit of help today with a relatively simple problem. Here are some notes on it for future reference.

The problem

I have a container view which has in it a TabBarView and a ScrollView. When one of the tabs in the tab bar view is tapped, I want it to update its internal state (which button is selected) and then I need the container view to be able to respond as well (to scroll its scrollview).

@jbrennan
jbrennan / ImmediatePanGestureRecognizer.m
Created Dec 29, 2015
A UIPanGestureRecognizer subclass to recognize immediately. Is this a good idea?
View ImmediatePanGestureRecognizer.m
@implementation ImmediatePanGestureRecognizer
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
if (self.numberOfTouches >= self.minimumNumberOfTouches) {
self.state = UIGestureRecognizerStateBegan;
}
}
@jbrennan
jbrennan / PrototopeViewController.swift
Created Mar 15, 2016
Example of using setting up Prototope in a UIViewController
View PrototopeViewController.swift
//
// ViewController.swift
// DrawingProto
//
// Created by Jason Brennan on 2015-12-19.
// Copyright © 2015 Jason Brennan. All rights reserved.
//
import UIKit
import Prototope
You can’t perform that action at this time.