Skip to content

Instantly share code, notes, and snippets.

@rnystrom
rnystrom / SaveSpot.m
Created March 27, 2012 22:22
Implementation file for SaveSpot.m that is having performance issues
#import "SaveSpot.h"
@implementation SaveSpot
@synthesize spot = _spot;
@synthesize maxSpeedLabel = _maxSpeedLabel;
@synthesize avgSpeedLabel = _avgSpeedLabel;
@synthesize distanceLabel = _distanceLabel;
@synthesize nameTextField = _nameLabel;
@synthesize descriptionTextField = _descriptionLabel;
@rnystrom
rnystrom / Iphone Icon.png Bash Script
Created April 5, 2012 15:04 — forked from jessedc/iOS Icon.png bash script
A simple bash script using OSX command line tool sips to resample a 512x512px image
#!/bin/zsh
# Compatible with bash, just change "zsh" to "bash"
# First param: The folder that the original file is stored in
# Second param: The original image name
sips --resampleWidth 512 "${1}/${2}" --out "${1}/iTunesArtwork"
sips --resampleWidth 57 "${1}/${2}" --out "${1}/Icon.png"
sips --resampleWidth 114 "${1}/${2}" --out "${1}/Icon@2x.png"
sips --resampleWidth 29 "${1}/${2}" --out "${1}/Icon-Small.png"
sips --resampleWidth 58 "${1}/${2}" --out "${1}/Icon-Small@2x.png"
@rnystrom
rnystrom / gist:4733270
Created February 7, 2013 19:03
Small category I wrote to simplify displaying a UIImagePickerController, asking where the image should come from, and then running all the stuff. Just setup a UIImagePickerControllerDelegate and forget all of the UIActionSheet business.
// UIImagePickerController+ImageTypeActionSheet.h
@interface UIImagePickerController (ImageTypeActionSheet)
- (void)promptImagePickerTypeWithText:(NSString*)text titles:(NSArray*)titles delegate:(id <UIImagePickerControllerDelegate,UINavigationControllerDelegate>)delegate;
@end
// UIImagePickerController+ImageTypeActionSheet.m
@interface ImageTypeActionSheetDelegate : NSObject
<UIActionSheetDelegate>
@rnystrom
rnystrom / gist:4741259
Last active December 12, 2015 08:08
Testing using JSON data vs an NSObject with properties. Testing initialization of NSObjects and calculations of keyPath values using @AvG. Tested with CodeRunner: http://krillapps.com/coderunner/ Results: http://bit.ly/12zlUNp
#import <Foundation/Foundation.h>
@interface Hospital : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *address;
@property (nonatomic, strong) NSString *city;
@property (nonatomic, strong) NSString *county;
@property (nonatomic, strong) NSString *state;
@property (nonatomic, strong) NSNumber *annualVisitors;
@property (nonatomic, strong) NSString *zip;
@rnystrom
rnystrom / gist:4980453
Created February 18, 2013 20:33
Setting up RNSwipeViewController in code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// PTMasterController is a subclass of RNSwipeViewController
PTMasterController *masterController = [[PTMasterController alloc] init];
PTSchemeController *scheme = [[PTSchemeController alloc] init];
PTUtilityController *utility = [[PTUtilityController alloc] init];
PTWritingController *writing = [[PTWritingController alloc] init];
masterController.centerViewController = writing;
masterController.rightViewController = utility;
@rnystrom
rnystrom / gist:5052675
Created February 27, 2013 23:04
Masking a chip out of a UIView.
- (void)maskChip {
UIGraphicsBeginImageContextWithOptions(self.containerView.bounds.size, NO, [UIScreen mainScreen].scale);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect frame = self.containerView.bounds;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddLineToPoint(path, NULL, frame.size.width / 2.f - 6, 0);
CGPathAddLineToPoint(path, NULL, frame.size.width / 2.f, 6);
CGPathAddLineToPoint(path, NULL, frame.size.width / 2.f + 6, 0);
@rnystrom
rnystrom / gist:5091412
Last active December 14, 2015 13:08
Fast upload of test data to Parse https://parse.com/
#import <Foundation/Foundation.h>
NSMutableURLRequest *parseRequest() {
NSMutableURLRequest *request = [[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://api.parse.com/1/classes/YOUR_CLASS_NAME"]] mutableCopy];
[request setValue:@"YOUR_APPLICATION_ID" forHTTPHeaderField:@"X-Parse-Application-Id"];
[request setValue:@"YOUR_REST_API_KEY" forHTTPHeaderField:@"X-Parse-REST-API-Key"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
return request;
public class UpdateAdapter extends ArrayAdapter<ParseObject> {
// omitted vars
public List<ParseObject> updates = new ArrayList<ParseObject>();
public HashMap<String, Bitmap> updateImages = new HashMap<String, Bitmap>();
// omitted constructor + @Overrides
@Override
public View getView(int position, View convertView, ViewGroup parent) {
UpdateHolder holder = null;
@rnystrom
rnystrom / gist:5405925
Created April 17, 2013 16:52
Ensuring a property is only set once
- (void)setOriginalContainerRect:(CGRect)originalContainerRect {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_originalContainerRect = originalContainerRect;
});
}
@rnystrom
rnystrom / gist:5701825
Created June 3, 2013 21:58
Attempted to create a podspec for octokit, but just ran into problem after problem. If anyone can take it further please do.
Pod::Spec.new do |s|
s.name = "octokit.objc"
s.version = "1.0.0"
s.summary = "GitHub API client for Objective-C."
s.homepage = "https://github.com/octokit/octokit.objc"
s.license = 'MIT'
s.author = { "Justin Spahr-Summers" => "jspahrsummers@github.com" }
s.source = { :git => "https://github.com/rnystrom/octokit.objc.git", :tag => "1.0.0" }
s.source_files = 'OctoKit/*.{h,m}'
s.ios.deployment_target = "5.0"