Skip to content

Instantly share code, notes, and snippets.

View jdriscoll's full-sized avatar

Justin Driscoll jdriscoll

View GitHub Profile
@jdriscoll
jdriscoll / NSString+UUID.m
Created September 26, 2012 13:53
NSString+UUID
#import "NSString+UUID.h"
@implementation NSString (UUID)
+ (NSString *)UUIDString
{
CFUUIDRef UUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, UUID);
CFRelease(UUID);
return (__bridge_transfer NSString *)string;
@jdriscoll
jdriscoll / NSString+Inflections.m
Created October 3, 2012 18:07
NSString+Inflections
// Inspired by suggestion to use NSScanner: http://stackoverflow.com/questions/1918972/camelcase-to-underscores-and-back-in-objective-c
#import "NSString+Inflections.h"
@implementation NSString (Inflections)
- (NSString *)underscore
{
NSScanner *scanner = [NSScanner scannerWithString:self];
scanner.caseSensitive = YES;
//
// UITextView+Dimensions.h
//
// Created by Justin Driscoll on 1/6/12.
//
#import <UIKit/UIKit.h>
@interface UITextView (Dimensions)
@jdriscoll
jdriscoll / NSManagedObject+MAK.h
Created January 3, 2013 19:08
Core Data helper categories
//
// NSManagedObject+MAK.h
//
// Created by Justin Driscoll on 2/21/12.
//
#import <CoreData/CoreData.h>
@interface NSManagedObject (MAK)
@jdriscoll
jdriscoll / gist:4732483
Created February 7, 2013 17:12
This is the best way I've found so far to handle one time setup that requires the view already be laid out (so no viewWillAppear) when using auto layout.
@property (nonatomic, assign) BOOL viewHasInitialLayout;
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (!self.viewHasInitialLayout) {
// Do stuff
self.viewHasInitialLayout = YES;
}
@jdriscoll
jdriscoll / UIImage+Dimensions.m
Created February 28, 2013 22:42
Category method to resize a UIImage
- (UIImage *)resize:(CGSize)size quality:(CGInterpolationQuality)interpolationQuality
{
UIGraphicsBeginImageContextWithOptions(size, NO, 1.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, interpolationQuality);
[self drawInRect:CGRectMake(0.0, 0.0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@jdriscoll
jdriscoll / JCDActionSheetDelegate.h
Created June 17, 2013 16:02
Block-based Action Sheet wrapper
//
// JCDActionSheetDelegate.h
// Created by Justin Driscoll on 4/3/13.
//
#import <UIKit/UIKit.h>
typedef void (^JCDActionSheetDelegateCallback)(UIActionSheet *actionSheet, NSInteger buttonIndex);
@interface JCDActionSheetDelegate : NSObject <UIActionSheetDelegate>
@jdriscoll
jdriscoll / Color Sampling Experiment
Last active December 19, 2015 14:28
Find the lightest (or darkest) color in an image by sampling pixels along both diagonals.
CGImageRef rawImageRef = [image CGImage];
CFDataRef imageDataRef = CGDataProviderCopyData(CGImageGetDataProvider(rawImageRef));
const UInt8 *rawPixelData = CFDataGetBytePtr(imageDataRef);
NSUInteger imageHeight = CGImageGetHeight(rawImageRef);
NSUInteger imageWidth = CGImageGetWidth(rawImageRef);
int brightness = 0;
int red = 0;
@jdriscoll
jdriscoll / JCDActionSheetDelegate.h
Created July 26, 2013 18:09
Super simple block-based delegates for UIActionSheet and UIAlertView
//
// JCDActionSheetDelegate.h
// Created by Justin Driscoll on 4/3/13.
//
#import <UIKit/UIKit.h>
typedef void (^JCDActionSheetDelegateCallback)(UIActionSheet *actionSheet, NSInteger buttonIndex);
@interface JCDActionSheetDelegate : NSObject <UIActionSheetDelegate>
@jdriscoll
jdriscoll / NSManagedObject+JSON.h
Created July 30, 2013 13:30
NSManagedObject to JSON-ready dictionary and back again (Does not handle relationships). Uses https://gist.github.com/jdriscoll/6112942.
//
// NSManagedObject+JSON.h
// Rego
//
// Created by Justin Driscoll on 7/29/13.
// Copyright (c) 2013 Makalu Inc. All rights reserved.
//
#import <CoreData/CoreData.h>