Skip to content

Instantly share code, notes, and snippets.

View justin's full-sized avatar

Justin Williams justin

View GitHub Profile
@justin
justin / gist:8886432
Last active August 29, 2015 13:56
Another NSRegularExpression test
#import <XCTest/XCTest.h>
#import "RSFoundationExtras.h"
@interface RSFoundationExtrasTests : XCTestCase
@end
@implementation RSFoundationExtrasTests
@justin
justin / gist:8886407
Last active August 29, 2015 13:56
Sample tests for validating my NSRegularExpression adventures.
#import <XCTest/XCTest.h>
#import "RSFoundationExtras.h"
@interface RSFoundationExtrasTests : XCTestCase
@end
@implementation RSFoundationExtrasTests
- (void)testExtractingLinksFromAPost
@justin
justin / gist:8886363
Created February 8, 2014 16:36
An example of how to lock up NSRegularExpression
- (NSArray *)rs_links {
if (RSStringIsEmpty(self))
return nil;
NSString *searchText = self;
NSMutableArray *links = [NSMutableArray array];
/*The regex pattern is from Daring Fireball: <http://daringfireball.net/2010/07/improved_regex_for_matching_urls>
@justin
justin / 0_reuse_code.js
Created January 20, 2014 15:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@justin
justin / gist:5545529
Created May 9, 2013 04:16
Generate a shit load of random geocoordinates around a given distance.
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
#define ARC4RANDOM_MAX 0x100000000
double startingLatitude = DEGREES_TO_RADIANS(39.753638);
double startingLongitude = DEGREES_TO_RADIANS(-105.007375);
double earthRadius = 3960.056052;
double maxdist = 50.0f;
- (UIImage *)ciThumbnailImage:(UIImage *)image
{
CIImage *ciImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];
CGFloat originalHeight = [ciImage extent].size.height;
CGFloat originalWidth = [ciImage extent].size.width;
CGFloat desiredHeight = 128.0f;
CGFloat desiredWidth = 128.0f;
CIFilter *scaleFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"];
@justin
justin / filter.json
Created March 5, 2013 04:17
A sample filter description for Wolfpack.
{
"formatVersion" : 1,
"filterIdentifier" : "filter.com.secondgear.Noir",
"filterName" : "Noir",
"filterDescription" : "FILTER_DESCRIPTION",
"requirements" : [
"iOS > 6.0"
],
"organizationName" : "Justin Williams",
"organizationURL" : "http://carpeaqua.com",
@justin
justin / UIImageView+ImageFrame.h
Created February 18, 2013 19:27
Category to get the frame of an image that's inside a UIImageView. Since I use aspect fit on some stuff, I sometimes need to account for the top and bottom borders.
#import <UIKit/UIKit.h>
@interface UIImageView (SGExtensions)
- (CGRect)sg_imageFrame;
@end
//
// SGDeviceIdentifier.h
// Elements
//
// Created by Justin Williams on 9/28/12.
// Copyright (c) 2012 Second Gear. All rights reserved.
//
#import <Foundation/Foundation.h>
//
// OLD AND BUSTED
//
if ([self.zoomingDelegate respondsToSelector:@selector(zoomingWindow:didZoomOutViewController:)] == YES)
{
// Do something important.
}
//