Skip to content

Instantly share code, notes, and snippets.

View samsymons's full-sized avatar

Sam Symons samsymons

View GitHub Profile
//
// NSObject+BlockObservation.h
// Version 1.0
//
// Andy Matuschak
// andy@andymatuschak.org
// Public domain because I love you. Let me know how you use it.
//
#import <Cocoa/Cocoa.h>
@mikelikespie
mikelikespie / CCBlockTableViewDataSource.h
Created May 4, 2011 18:55 — forked from omnivector/CCBlockTableViewDataSource.h
Block based data source / delegate
//
// CCBlockTableViewDataSource.h
//
// Created by Tristan O'Tierney on 1/24/11.
//
#import <UIKit/UIKit.h>
@interface CCBlockTableViewDataSource : NSObject <UITableViewDataSource, UITableViewDelegate> {
@ldandersen
ldandersen / great-circle-cocoa.m
Created September 6, 2011 22:40
Great circle distance in Cocoa
static NSInteger STEarthRadiusKilometers = 6371;
- (NSNumber *)distanceFromLatitude:(NSDecimalNumber *)inLatitude longitude:(NSDecimalNumber *)inLongitude;
{
CLLocationDegrees inLatitudeDegrees = [inLatitude doubleValue];
CLLocationDegrees latitudeDegrees = [self.latitude doubleValue];
CLLocationDegrees inLongitudeDegrees = [inLongitude doubleValue];
CLLocationDegrees longitudeDegrees = [self.longitude doubleValue];
double distance = acos(sin(inLatitudeDegrees) * sin(latitudeDegrees) + cos(inLatitudeDegrees) * cos(latitudeDegrees) * cos(longitudeDegrees - inLongitudeDegrees)) * STEarthRadiusKilometers;
@justin
justin / NSTimer+Blocks
Created September 9, 2011 15:40
NSTimer+Blocks
typedef void (^SGBlock)();
@interface NSTimer (Blocks)
+ (id)scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)shouldRepeat block:(SGBlock)block;
+ (id)timerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)shouldRepeat block:(SGBlock)block;
@end
@samvermette
samvermette / gist:1691280
Created January 27, 2012 22:27
MapKit callout bubble pop animation
self.view.layer.anchorPoint = CGPointMake(0.50, 1.0);
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
bounceAnimation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.05],
[NSNumber numberWithFloat:1.08],
[NSNumber numberWithFloat:0.92],
[NSNumber numberWithFloat:1.0],
nil];
@bignerdranch
bignerdranch / BNRTimeBlock.h
Created March 9, 2012 13:51
Timing Utility Post 20120308
CGFloat BNRTimeBlock (void (^block)(void));
@0xced
0xced / Makefile
Created March 23, 2012 15:02
Experiment ->isa vs object_getClass()
OPTIONS = metaclass.m -o metaclass -std=c99 -framework Foundation -arch x86_64 -Os
isa:
clang -DUSE_ISA=1 $(OPTIONS)
./metaclass
object_getClass:
clang -DUSE_ISA=0 $(OPTIONS)
./metaclass
@0xced
0xced / NSString.m
Created April 1, 2012 12:24
Reverse-engineered implementation of -[NSString isEqual:] and -[NSString isEqualToString:]
/*
* Most NSString instances will actually be __NSCFString instances, so here are both NSString and __NSCFString implementations.
* If you know how to create an NSString instance whose class is actually NSString please let me know.
* Other possible concrete subclasses of NSString are: NSConstantString, __NSCFConstantString, NSPathStore2, NSSimpleCString and __NSLocalizedString.
*/
// CoreFoundation.framework 635.19.0 (Mac OS X 10.7.3)
@implementation NSObject
- (BOOL) isNSString__
@lunaru
lunaru / css3-arrow-dropshadow.html
Created April 25, 2012 23:18
CSS Box with Arrow and Dropshadow
<!DOCTYPE html>
<html>
<head>
<style>
/* Core CSS */
#box
{
background: white;
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface NSNotificationCenter (AllObservers)
- (NSSet *) my_observersForNotificationName:(NSString *)notificationName;
@end