Skip to content

Instantly share code, notes, and snippets.

@breeno
breeno / CompositionalTwoColumnWaterfall.swift
Last active October 31, 2022 12:57
Simple take on a compositional layout with 2 column variable height items waterfall
import UIKit
class ViewController: UIViewController {
enum Section {
case main
}
struct Item: Hashable {
let height: CGFloat
@breeno
breeno / gist:7010222
Created October 16, 2013 15:57
Hooking NSNotificationCenter to trace all messages. Useful stuff!
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(),
NULL,
notificationCenterHookProc,
NULL,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
void notificationCenterHookProc (CFNotificationCenterRef center,
void *observer,
@breeno
breeno / gist:5049279
Created February 27, 2013 16:30
Determining which row was tapped from a UIGestureRecognizer added to a UITableViewCell
-(void) fooWasSingleTapped: (UITapGestureRecognizer *) recognizer
{
NSIndexPath *indexPath = [tableView indexPathForRowAtPoint: [recognizer locationInView: self.tableView]];
// do stuff
}
#import <UIKit/UIKit.h>
@interface UIButton (UIButton_BackgroundImageAdditions)
-(void) setBackgroundImageWithColor: (UIColor *) color
cornerRadius: (CGFloat) cornerRadius
forState: (UIControlState) state;
@end
@breeno
breeno / NSNotificationCenter+ObserverAdditions.h
Created January 18, 2012 17:29
Simplifying NSNotificationCenter block based observers
#import <Foundation/Foundation.h>
@interface NSNotificationCenter (ObserverAdditions)
-(void) registerObserver: (id) observer
forName: (NSString *)name
object:(id)obj
queue:(NSOperationQueue *)queue
usingBlock:(void (^)(NSNotification *))block;
#import <Foundation/Foundation.h>
@interface NSObject (RegisterObserverAdditions)
-(void) registerObserver:(NSObject *)observer
forKeyPath:(NSString *)keyPath
options:(NSKeyValueObservingOptions)options
context:(void *)context;
@breeno
breeno / Shake (bad password) Animation With Blocks
Created March 3, 2011 14:16
Sequenced animations with blocks
#import "UIView+ShakeAnimationAdditions.h"
#import "AnimationSequencer.h"
@implementation UIView (ShakeAnimationAdditions)
-(void) performShakeAnimation
{
AnimationSequencer *sequencer = [AnimationSequencer sequencer];
sequencer.interAnimationInterval = 0.0;
sequencer.sequenceDuration = 0.05;
@breeno
breeno / wwdc-page-checker.rb
Created February 8, 2011 19:28
Cause, well, you wanna know RIGHT AWAY when this page changes....
#!/usr/bin/env ruby
require 'rubygems'
require 'digest/sha1'
require 'tlsmail'
require 'time'
# To use:
@breeno
breeno / xco
Created February 6, 2011 18:58
Ruby Command line script for opening Xcode for the project in the current directory
#!/usr/bin/env ruby
Dir.foreach(Dir.pwd) do |f|
if f.include? '.xcodeproj' then
exec "open -a /Developer/Applications/Xcode.app #{f}"
end
end
puts 'No Xcode project found here.'
@breeno
breeno / xc-unused-images.rb
Created February 2, 2011 03:28
Simple script for detecting unreferenced images in an Xcode directory structure
#!/usr/bin/env ruby
#delete flag
should_delete = false
if ARGV.length >= 1
ARGV.each do |arg|
if arg.downcase.eql?('--delete')
should_delete = true
puts "--delete detected; will delete unreferenced image files.\n"
end