Skip to content

Instantly share code, notes, and snippets.

View zmcartor's full-sized avatar

Zach zmcartor

View GitHub Profile
@zmcartor
zmcartor / gist:5126703
Created March 10, 2013 01:42
ILCannedURLProtocolDelegate
@protocol ILCannedURLProtocolDelegate <NSObject>
- (NSData*)responseDataForClient:(id<NSURLProtocolClient>)client request:(NSURLRequest*)request;
@optional
- (BOOL)shouldInitWithRequest:(NSURLRequest*)request;
- (NSURL *)redirectForClient:(id<NSURLProtocolClient>)client request:(NSURLRequest *)request;
- (NSInteger)statusCodeForClient:(id<NSURLProtocolClient>)client request:(NSURLRequest*)request;
- (NSDictionary*)headersForClient:(id<NSURLProtocolClient>)client request:(NSURLRequest*)request;
@end
#import "HKZFakeWebserver.h"
@implementation HKZFakeWebserver
// This function returns the correct JSON data, or whatever for the requested URL
// via the ILURLProtocol
- (NSData *)responseDataForClient:(id<NSURLProtocolClient>)client request:(NSURLRequest*)request {
NSData *responseData = nil;
// Dog profile information
// beforeEach/afterEach are Kiwi constructs
beforeEach(^{
//register as Protocol delegate, the magic begins
[NSURLProtocol registerClass:[ILCannedURLProtocol class]];
// Default HTTP status code
[ILCannedURLProtocol setCannedStatusCode:200];
// Configure ILtesting only for certain verbs if you like
@interface HKZDogParkAPIClient : NSObject
- (void)fetchProfile:(int)profileId block:(void(^)(NSDictionary *dog, NSError* error))clientBlock;
- (void)signup:(void(^)(NSDictionary *dog, NSError* error))clientBlock;
@end
@zmcartor
zmcartor / DogPark Interface
Created March 5, 2013 00:27
DogPark Inteface
@interface HKZDogParkAPIClient : NSObject
- (void)fetchProfile:(int)profileId block:(void(^)(NSDictionary *dog, NSError* error))clientBlock;
- (void)signup:(void(^)(NSDictionary *dog, NSError* error))clientBlock;
@end
@zmcartor
zmcartor / gist:2495033
Created April 26, 2012 01:27
GettysBurg Estimate
lines = File.new('gettys').gets
lineno = 0
short = {0=>[]}
lines.split(' ').each do |word|
#count up the present line and include spaces. Take into account the current space count
#and the impact of adding the new word + 1 space.
if ( ( (short[lineno].inject(0){|sum, ele| sum+=ele.size} ) + (word.size+1 + (short[lineno].count-1)) ) <= 13)
short[lineno] = short[lineno].push word
else
lineno+=1
@zmcartor
zmcartor / gist:2431522
Created April 20, 2012 20:14
Backbone View Attributes to Model
BBView = Backbone.View.extend({
el: '#some-selector',
attributes: function () {
return {
name: this.nameField.val(),
email: this.emailField.val(),
password: this.passwordField.val(),
password_confirmation: this.passwordConfirmationField.val()
};
},
@zmcartor
zmcartor / Backbone Namespacing
Created April 16, 2012 20:23
Backbone Namespacing
//Make sure to namespace stuff :)
window.Poc = window.Poc || {};
window.Poc.Models = window.Poc.Models || {};
window.Poc.Collections = window.Poc.Collections || {};
window.Poc.Views = window.Poc.Views || {};
window.Poc.Dispatcher = {};
/******************************
****** Backbone Objects ******
@zmcartor
zmcartor / gist:1670154
Created January 24, 2012 13:22
Tumblr Gist
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@zmcartor
zmcartor / gist:1670138
Created January 24, 2012 13:19
JS Mixin
var RoundButton = function(radius, label, action) {
this.radius = radius;
this.label = label;
this.action = action;
this.StuffSp = 'hoho';
};
var someStuff = function(){
if(this.hasOwnProperty('StuffSpace')){