Skip to content

Instantly share code, notes, and snippets.

View jdriscoll's full-sized avatar

Justin Driscoll jdriscoll

View GitHub Profile
@jdriscoll
jdriscoll / related_by_tag.rb
Created January 25, 2014 18:29
Jekyll generator that builds a sorted list of related posts by how many tags they have in common. Add to <source>/_plugins.
@jdriscoll
jdriscoll / NSDate+Formats.h
Created July 30, 2013 13:32
Common NSDate formats and helpers
//
// NSDate+Formats.h
// Rego
//
// Created by Justin Driscoll on 12/7/12.
// Copyright (c) 2012 Makalu Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
@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>
@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 / 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 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 / 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 / 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 / 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)
//
// UITextView+Dimensions.h
//
// Created by Justin Driscoll on 1/6/12.
//
#import <UIKit/UIKit.h>
@interface UITextView (Dimensions)