Skip to content

Instantly share code, notes, and snippets.

View zmcartor's full-sized avatar

Zach zmcartor

View GitHub Profile
@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
@interface HKZDogParkAPIClient : NSObject
- (void)fetchProfile:(int)profileId block:(void(^)(NSDictionary *dog, NSError* error))clientBlock;
- (void)signup:(void(^)(NSDictionary *dog, NSError* error))clientBlock;
@end
// 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
#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
@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
@zmcartor
zmcartor / gist:5481594
Created April 29, 2013 13:31
FlatColor iOS UIColor Example
// Example for Turquoise
// rgb(26, 188, 156)
[UIColor colorWithRed:26/255.0f green:188/255.0f blue:156/255.0f alpha:1.0];
@zmcartor
zmcartor / helloWorldMotion.rb
Created May 20, 2013 22:44
Quickest iOS app ever! :)
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
alert = UIAlertView.alloc.initWithTitle("Oh yeah!", message:"OHHAI!", delegate:nil, cancelButtonTitle:"OK", otherButtonTitles:nil)
alert.show
true
end
end
@zmcartor
zmcartor / gist:281f3b62b6afa0aa7c9b
Last active August 29, 2015 14:00
Mergesort in Javascript
// classical merge algo
Array.prototype.mergesort = function() {
console.log(this)
if(this.length == 1) {
return this;
}
var merge = function(left, right){
var sorted = [];
var l = r = 0;
while(l < left.length && r < right.length){
@zmcartor
zmcartor / gist:73bcc143faa99af202b3
Created August 15, 2014 00:30
Cocoa Responder Chain and UITableViews
// Whenever a button, tap , or something 'happens' within a cell subclass, send a message up thee olde Responder Chain
// -- within tablecell_subclass.m
- (IBAction)connectButtonClicked:(id)sender {
SEL selConnectButton = sel_registerName("connectButtonResponder:");
[[UIApplication sharedApplication] sendAction:selConnectButton to:nil from:self forEvent:nil];
}
// within the UITableViewController , responde to the selector "connectButtonResponder"
@zmcartor
zmcartor / gist:2f8f06cf614c3c6b3267
Created September 2, 2014 15:40
TextField empty and filter out 'return' key
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *filteredString = [string stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSInteger textLength = [textField.text length] - range.length + [filteredString length];
if (textLength > 0) {
self.redeemButton.enabled = YES;
}
else {