Skip to content

Instantly share code, notes, and snippets.

View mikekatz's full-sized avatar

Michael Katz mikekatz

  • New York, NY
  • 11:38 (UTC -04:00)
View GitHub Profile
@mikekatz
mikekatz / easingcurve.swift
Created November 14, 2019 10:22
Get the values in order to plot animation curves for any SwiftUI animation
// created Michael Katz November 2019
// MIT licensed
import SwiftUI
struct ContentView: View {
@State var start: Bool = false
var animationToExplore: Animation {
// replace this animation with the animation you want to graph
@mikekatz
mikekatz / gist:5263150
Created March 28, 2013 13:34
Configurable log redirect
//the log manager's log method. Each log channel formats its message and then sends the whole string to this method
- (void) log:(NSString*)message
{
if (self.logSink == nil) {
NSLog(@"%@", message);
} else {
[self.logSink log:message];
}
}
@mikekatz
mikekatz / gist:5224025
Created March 22, 2013 19:27
Debugging Log macros from a PCH of a recent app. Note that it uses TFLog to log to testFlight, so this is still for in-test, not app store release.
#if DEBUG
#define AssertLog(condition, desc, args...) NSAssert(condition, desc, ## args)
#define DBLog(format, args...) TFLog(@"%s, line %d: " format "\n", __func__, __LINE__, ## args);
#else
#define AssertLog(c, desc, args...) if (!(c)) TFLog(@"%s, line %d: " desc "\n", __func__, __LINE__, ## args);
#define DBLog(format, args...) do {} while(0)
#endif
@mikekatz
mikekatz / gist:5187639
Created March 18, 2013 14:43
Log all available fonts in iOS
for (NSString* familyName in [UIFont familyNames]) {
NSLog(@"%@",[UIFont fontNamesForFamilyName:familyName]);
}
@mikekatz
mikekatz / gist:4708775
Created February 4, 2013 19:05
Create a simple colored square image. From my UI utils repo https://github.com/mikekatz/iOS-UI-Utils
+ (UIImage*) imageWithColor:(UIColor*)color size:(CGSize)size
{
UIGraphicsBeginImageContext(size);
UIBezierPath* rPath = [UIBezierPath bezierPathWithRect:CGRectMake(0., 0., size.width, size.height)];
[color setFill];
[rPath fill];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@mikekatz
mikekatz / gist:4550441
Last active December 11, 2015 05:09
Test asynchronous code with OCUnit, this time with a the polling code in a macro
#define POLL_INTERVAL 0.05 //50ms
#define N_SEC_TO_POLL 1.0 //poll for 1s
#define MAX_POLL_COUNT N_SEC_TO_POLL / POLL_INTERVAL
#define CAT(x, y) x ## y
#define TOKCAT(x, y) CAT(x, y)
#define __pollCountVar TOKCAT(__pollCount,__LINE__)
#define POLL(__done) \
NSUInteger __pollCountVar = 0; \
@mikekatz
mikekatz / gist:4550430
Created January 16, 2013 20:10
Example of writing an OCUnit test that uses asynchronous methods by polling for completion
#define POLL_INTERVAL 0.05 //50ms
#define N_SEC_TO_POLL 1.0 //poll for 1s
#define MAX_POLL_COUNT N_SEC_TO_POLL / POLL_INTERVAL
- (void) testAnAsynchronousFunction
{
__block BOOL done = NO;
//do async on a delay
float delayInSeconds = 0.5;
@mikekatz
mikekatz / gist:3722237
Created September 14, 2012 14:28
Kinvey fetch entity with relationships
KCSCollection* books = [KCSCollection collectionFromString:@"books" ofClass:[Book class]];
KCSLinkedAppdataStore* store = [KCSLinkedAppdataStore storeWithCollection:books options:nil];
[store loadObjectWithId:@"HPBook6" withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) {
Book* harryPotter = [objectsOrNil objectAtIndex:0];
Author* jRowling = harryPotter.author;
} withProgressBlock:^(NSArray *objects, double percentComplete) {
//show progress
}];
@mikekatz
mikekatz / gist:3722148
Created September 14, 2012 14:14
Kinvey Supply Mapping for relationship
//books.h
@interface Book : NSObject <KCSPersistable>
@property (nonatomic) Author* author;
@property (nonatomic) NSString* title;
@end
//books.m
@implementation Book
+(NSDictionary *)kinveyPropertyToCollectionMapping {
return @{@"author" : @"authors"};
@mikekatz
mikekatz / gist:3040629
Created July 3, 2012 15:53
Creating a KCSCachedStore and using it for query
- (id) init
{
if (self = [super init]) {
self.tableValues = [NSArray array];
}
return self;
}
- (void) viewWillAppear:(BOOL)animated
{