Skip to content

Instantly share code, notes, and snippets.

View grgcombs's full-sized avatar

Greg Combs grgcombs

View GitHub Profile
@grgcombs
grgcombs / SLFDataModels.h
Created September 7, 2011 05:56
Core Data Models for Open States API
@interface SLFLegislator : NSManagedObject
@property (nonatomic, retain) NSString * legID; // primary key
@property (nonatomic, retain) NSSet *positions; // to-many SLFCommitteePositions
@property (nonatomic, retain) NSString * suffixes;
@property (nonatomic, retain) NSString * party;
@property (nonatomic, retain) NSString * district;
@property (nonatomic, retain) NSNumber * active;
@property (nonatomic, retain) NSString * country;
@property (nonatomic, retain) NSString * stateID;
@grgcombs
grgcombs / OpenStatesApiExamples.json
Created September 7, 2011 07:37
Open States API examples
/** Open States API - Data for all state legislatures (well, 38 states so far)
* API documentation, method listing, and example GISTs at:
* http://openstates.sunlightlabs.com/api/
*
* Base URL = http://openstates.sunlightlabs.com/api/v1
* NOTE: All GET requests to this base URL must include an 'apikey' query parameter.
*
* My API key looks like this "/districts/tx?apikey=350284d0c6af453b9b56f6c1c7fea1f9"
*
* Resource Path Examples:
@grgcombs
grgcombs / gist:1250824
Created September 29, 2011 14:24
RKTableViewSections from @jeffarena
// This would be inserted somewhere in your app-wide tableviewcontroller superclass configuration, to reap the benefits across all subsequent tables.
self.tableController.heightForHeaderInSection = 22;
self.tableController.onViewForHeaderInSection = ^UIView*(NSUInteger sectionIndex, NSString* sectionTitle) {
UIView* headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 22)] autorelease];
headerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sectionheader_bg.png"]];
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, self.tableView.bounds.size.width, 22)];
label.text = sectionTitle;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:12];
@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";
@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.
//
// 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
import Foundation
// MARK: - Comparable
extension NSDecimalNumber: Comparable {}
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .OrderedSame
}
@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
@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 / 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