Skip to content

Instantly share code, notes, and snippets.

View grgcombs's full-sized avatar

Greg Combs grgcombs

View GitHub Profile
@grgcombs
grgcombs / NSPersonNameComponents+Sort.h
Last active May 18, 2017 17:54
Sorting a collection of people by NSPersonNameComponents
#import <Foundation/Foundation.h>
@interface NSPersonNameComponents(Sort)
- (NSComparisonResult)compare:(NSPersonNameComponents *)other;
- (NSComparisonResult)compare:(NSPersonNameComponents *)other options:(NSStringCompareOptions)mask;
@end
@grgcombs
grgcombs / regression.swift
Created July 31, 2016 01:04 — forked from jarsen/regression.swift
Univariate Linear Regression
import Cocoa
class CSVDoubleSequence: SequenceType {
typealias GeneratorType = IndexingGenerator<Array<Double>>
let path: String
let values: [Double]
init(path: String) {
self.path = path
@grgcombs
grgcombs / GenericsExampleForObjC.h
Last active July 11, 2016 17:13
Obj-C Generics Example
// I borrowed pieces of this from the generics implementations in FaceBook's Bolts Framework and the Parse SDK
@import Foundation;
@class GRGCollectionItemTypeClass<__covariant CodableCollectionItem:NSObject<NSCopying,NSSecureCoding> *>;
@interface GRGCollectionClass<__covariant CodableCollectionItem:NSObject<NSCopying,NSSecureCoding> *> : NSObject<NSFastEnumeration>
typedef BOOL(^GRGNextCollectionItemBlock)(GRGCollectionItemTypeClass<CodableCollectionItem> *nextItem);
@grgcombs
grgcombs / consumer_of_libextobjc.m
Last active May 31, 2016 21:06
Obj-C Preprocessor Collision Aversion
/**
* Taken from @jspahrsummers:
*
* To avoid preprocessor definition collisions when working with third-party frameworks
* try this...
*/
#define strongify myPrefix_strongify
#define weakify myPrefix_weakify
#define onExit myPrefix_onExit
@grgcombs
grgcombs / angleGradientImage.swift
Created November 30, 2015 18:45
angleGradientImage.swift
//: angleGradientImage - Ported to Swift from http://stackoverflow.com/a/33991838/136582
import UIKit
import CoreImage
public func angleGradientImage(size: CGSize, radius: Float?, scale: CGFloat?, colors: (start:UIColor, end:UIColor)?) -> UIImage? {
let gradientRadius = (radius != nil) ? radius! : Float(min(size.width,size.height) - 2)
let gradientScale = (scale != nil) ? scale! : UIScreen.mainScreen().scale
let startColor : CIColor
let endColor : CIColor
@grgcombs
grgcombs / PRHAngleGradientFilter.h
Last active August 27, 2015 03:26 — forked from boredzo/PRHAngleGradientFilter.h
Core Image custom filter to generate an angular gradient. The center is at the origin (0,0). You may want to use CIAffineTransform and/or CICrop on the output.
//
// PRHAngleGradientFilter.h
//
// Created by Peter Hosey on 2013-01-30.
// Copyright (c) 2013 Peter Hosey. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
@interface PRHAngleGradientFilter : CIFilter
import Foundation
// MARK: - Comparable
extension NSDecimalNumber: Comparable {}
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .OrderedSame
}
//
// TBSplitViewController.h
//
// Created by Tyler Bunnell on 8/4/12
// Released under the have fun with this and make cool stuff license.
//
#import <UIKit/UIKit.h>
@interface TBSplitViewController : UISplitViewController
@grgcombs
grgcombs / NSPropertyDescriptionTransientBlock.m
Last active October 2, 2015 09:28
My Feature Request for NSPropertyDescription (Bug Reporter #11130505)
/*
Enhancement Request for Core Data
Apple Radar Issue #11130505
http://openradar.appspot.com/radar?id=3173403
I'd like to see an expansion of the Core Data framework that allows us to add a
transient property's underlying code via a block assigned on an
NSPropertyDescription, in order to provide an easy means to use transient properties
without subclassing the managed object.
@grgcombs
grgcombs / RKFetchedControllerSpecAddition.m
Created January 11, 2012 18:08
Reproducing a mysterious exception in RKFetchedResultsTableController (sections + empty item)
- (void)itShouldLoadFromNetworkUpdatingFromEmptyToFullWithSections {
[self bootstrapEmptyStoreAndCache];
[self stubObjectManagerToOnline];
UITableView* tableView = [UITableView new];
RKFetchedResultsTableControllerSpecViewController* viewController = [RKFetchedResultsTableControllerSpecViewController new];
RKFetchedResultsTableController* tableController =
[[RKFetchedResultsTableController alloc] initWithTableView:tableView viewController:viewController];
tableController.resourcePath = @"/JSON/humans/all.json";
tableController.sectionNameKeyPath = @"name";