Skip to content

Instantly share code, notes, and snippets.

View mattwymore's full-sized avatar

Matt Wymore mattwymore

  • Gray Fox Interactive, Inc.
View GitHub Profile
@mattwymore
mattwymore / RXTimer.h
Created November 14, 2015 23:28 — forked from couchdeveloper/RXTimer.h
A timer based on dispatch_source_create() Objective-C
//
// RXTimer.h
//
// Copyright 2013 Andreas Grosam
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@mattwymore
mattwymore / gist:11194402
Created April 22, 2014 21:10
Email address string validation method
//Got this from http://stackoverflow.com/questions/3139619/check-that-an-email-address-is-valid-on-ios for
//validating whether an email address appears to be valid
- (BOOL) NSStringIsValidEmail:(NSString *)checkString
{
BOOL stricterFilter = YES; // Discussion http://blog.logichigh.com/2010/09/02/validating-an-e-mail-address/
NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
NSString *laxString = @".+@([A-Za-z0-9]+\\.)+[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
@mattwymore
mattwymore / gist:9416392
Last active August 29, 2015 13:57
This is an example of taking an array of data and writing it to "path" as a PNG file. This example shows how to properly premultiply alpha in the image as required by CGBitmapContextCreate.
//"bytes" is a pointer to a const array of image data that we can't modify, so we need to copy
//the data to a new buffer before multiplying alpha
//Premultiply the alpha and create a new image
UInt8 *premultipliedBuffer = calloc(totalBytes, 1);
memcpy(premultipliedBuffer, bytes, totalBytes);
for (int i = 0; i < totalBytes; i += 4)
{
UInt8 red = premultipliedBuffer[i];
UInt8 green = premultipliedBuffer[i + 1];
@mattwymore
mattwymore / gist:9416196
Last active August 29, 2015 13:57
This allows you to read a PNG image from "path" using Core Graphics functions and then access the bytes that back the image.
//path is a plain C string with the path to your image
CGDataProviderRef sourceDataProvider = CGDataProviderCreateWithFilename(path);
CGImageRef sourceImage = CGImageCreateWithPNGDataProvider(sourceDataProvider,
NULL,
NO,
kCGRenderingIntentDefault);
CGDataProviderRelease(sourceDataProvider);
CGDataProviderRef sourceProvider = CGImageGetDataProvider(sourceImage);
size_t width = CGImageGetWidth(sourceImage);
size_t height = CGImageGetHeight(sourceImage);
@mattwymore
mattwymore / gist:6602176
Created September 17, 2013 23:29
This is a handy one-liner to get objective-C method names from Mach-O binaries. I used it because the Xcode validator flagged usage of a private API and I needed to find which 3rd party library was using the private method. source: http://stackoverflow.com/a/4534619
otool -s __TEXT __objc_methname "$1" |expand -8 | cut -c17- | sed -n '3,$p' | perl -n -e 'print join("\n",split(/\x00/,scalar reverse (reverse unpack("(a4)*",pack("(H8)*",split(/\s/,$_))))))'
@mattwymore
mattwymore / versionMacros.h
Last active July 1, 2016 09:34
Macros for comparing iOS Version numbers. See: http://stackoverflow.com/questions/3339722/check-iphone-ios-version for more discussion
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)