Skip to content

Instantly share code, notes, and snippets.

View justin's full-sized avatar

Justin Williams justin

View GitHub Profile
@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 / 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: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:8886529
Created February 8, 2014 16:49
How I fixed my weird NSRegularExpression issue.
BOOL RSHasMarkdownLinks(NSString *x)
{
NSString *searchText = x;
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\[([^\\[]+)\\]\\(([^\\)]+)\\)" options:0 error:&error];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:searchText options:0 range:NSMakeRange(0, [searchText length])];
return (numberOfMatches > 0);
}
@justin
justin / gist:11116873
Created April 20, 2014 15:29
web.config for carpeaqua
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" responseMode="File" path="404.html" />
</httpErrors>
<rewrite>
<rules>
import statusInfo = require('./StatusInfo');
import commentInfo = require('./CommentInfo');
var uuid = require('node-uuid');
/**
Various types of user notifications that we can send.
The numeric values are sent to the client apps (Android, iOS, etc) so be careful changing them
*/
enum NotificationType {
#import <objc/objc-runtime.h>
#import "UIView+SGAutoLayoutExtensions.h"
@implementation UIView (SGAutoLayoutExtensions)
#ifdef DEBUG
- (NSString *)nsli_description
{
return [self restorationIdentifier] ?: [NSString stringWithFormat:@"%@:%p", [self class], self];
public async void RemoveDevices()
{
CloudTableClient client = account.CreateCloudTableClient();
CloudTable devicesTable = client.GetTableReference("PushNotificationDeviceTable");
//// Good Form
await devicesTable.CreateIfNotExistsAsync();
// Entity Resolver
EntityResolver<PushNotificationDevice> deviceResolver = (pk, rk, ts, props, etag) =>
@justin
justin / gist:aafce8a85ee9b0595494
Created June 14, 2014 12:52
The old way of handling orientation and different devices
UIDevice *device = [UIDevice currentDevice];
UIDeviceOrientation currentOrientation = device.orientation;
BOOL isPhone = (device.userInterfaceIdiom == UIUserInterfaceIdiomPhone);
BOOL isTallPhone = ([[UIScreen mainScreen] bounds].size.height == 568.0);
if (UIDeviceOrientationIsPortrait(currentOrientation) == YES)
{
// Do Portrait Things
if (isPhone == YES)
{
// Do Portrait Phone Things
import KeychainAPI
let keychain: Keychain = Keychain(service: "com.secondgear.myapp", accessibility: Accessibility.WhenUnlocked)
let userAccount = Account(userName: "justinw@me.com", secret: "lovesecretsexgod")
keychain.add(userAccount)
let fetchedAccount:Account? = keychain.accountFor("justinw@me.com")
if (fetchedAccount != nil)
{
fetchedAccount?.secret = "newpassword"