Skip to content

Instantly share code, notes, and snippets.

@pizthewiz
pizthewiz / OpenCV.sh
Last active August 29, 2015 14:02
Apothecary formula for OpenCV, build i386 and x86_64 separately and lipo together.
#! /bin/bash
#
# OpenCV
# library of programming functions mainly aimed at real-time computer vision
# http://opencv.org
#
# uses a CMake build system
FORMULA_TYPES=( "osx" )
@pizthewiz
pizthewiz / NSArray-SCRAdditions.m
Created January 16, 2014 19:39
Returns a new array containing the receiving array’s elements that are not present in another array.
@interface NSArray (SCRAdditions)
- (NSArray*)objectsNotInArray:(NSArray*)array;
@end
@implementation NSArray (SCRAdditions)
- (NSArray*)objectsNotInArray:(NSArray*)array {
NSMutableArray* list = [[NSMutableArray alloc] init];
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL* stop) {
if ([array containsObject:obj]) {
@pizthewiz
pizthewiz / shadyApp.cpp
Last active December 30, 2015 05:19
Simple oF application with GL2, GL3 and ES2 passthrough shaders on a non-power-of-two image (1024x768).
#include "shadyApp.h"
void shadyApp::setup() {
ofSetBackgroundColor(ofColor::gray);
ofSetFrameRate(60);
image.loadImage("checkerboard.jpg"); // 1024x768
string passthroughVertex, passthroughFragment;
#ifdef TARGET_OPENGLES
@pizthewiz
pizthewiz / of-no-hard-paths.diff
Created November 19, 2013 01:11
A project created by the projectGenerator in oF v0.8.0 uses an Xcode config file to define OF_PATH but the internal project file still contains several hardcoded references to the expected historical value of OF_PATH "../../..". A few that are fixable with the diff below are [1] the Copy Files build phase for the FMOD dylib [2] the definition of…
diff --git a/Project.xcconfig b/Project.xcconfig
index c90f7b1..6f6232a 100644
--- a/Project.xcconfig
+++ b/Project.xcconfig
@@ -13,5 +13,5 @@ ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
//IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
//ICON_FILE_PATH = bin/data/
-OTHER_LDFLAGS = $(OF_CORE_LIBS)
+OTHER_LDFLAGS = $(OF_CORE_LIBS) -framework GLUT
@pizthewiz
pizthewiz / gist:4658164
Created January 28, 2013 19:11
NSString category to validate contents as Twitter username.
@interface NSString (CLUTwitterAdditions)
- (BOOL)isValidTwitterUsername;
@end
@implementation NSString (CLUTwitterAdditions)
static NSString* CLUTwitterUsernamePattern = @"^([0-9a-zA-Z_]{1,15})$";
// NB - largely yoinked from http://stackoverflow.com/questions/4424179/twitter-username-regex-validation/4424288#4424288
- (BOOL)isValidTwitterUsername {
@pizthewiz
pizthewiz / gist:4658147
Created January 28, 2013 19:09
NSString category to validate contents as an email address
@interface NSString (CLUEmailAdditions)
- (BOOL)isValidEmailAddress;
@end
@implementation NSString (CLUEmailAdditions)
static NSString* CLUEmailAddressPattern = @"^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
// NB - mostly yoinked from https://github.com/jPaolantonio/JPValidation/blob/master/JPValidators/JPValidatorEmail.m
- (BOOL)isValidEmailAddress {
@pizthewiz
pizthewiz / gist:4532416
Last active December 11, 2015 02:39
starting with version 3.1 (possibly 3.0, but i've only tested on 3.1.1) the iOS Facebook SDK disables the in-app UIWebView modal dialog (FBDialog) to authenticate the user and instead only enables iOS 6 system, Facebook.app and Mobile Safari. this hack was found and tested by stepping through the Facebook SDK source and building it manually into…
// GRITTY - force Facebook SDK 3.1+ to use in-app modal UIWebView for user authentication
@implementation FBSession (CLUAdditions)
- (void)HACKEDauthorizeWithPermissions:(NSArray*)permissions behavior:(FBSessionLoginBehavior)behavior defaultAudience:(FBSessionDefaultAudience)audience isReauthorize:(BOOL)isReauthorize {
objc_msgSend(self, @selector(authorizeWithPermissions:defaultAudience:integratedAuth:FBAppAuth:safariAuth:fallback:isReauthorize:), permissions, audience, NO, NO, NO, YES, isReauthorize);
}
+ (void)load {
method_exchangeImplementations(class_getInstanceMethod(self, @selector(authorizeWithPermissions:behavior:defaultAudience:isReauthorize:)), class_getInstanceMethod(self, @selector(HACKEDauthorizeWithPermissions:behavior:defaultAudience:isReauthorize:)));
}
@end
@pizthewiz
pizthewiz / gist:4465585
Last active December 10, 2015 17:08
sift through Settings.bundle for default values and register as user defaults. makes use of NSArray category from Mantle: https://github.com/github/Mantle/blob/master/Mantle/NSArray%2BMTLHigherOrderAdditions.h
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// set default preferences from Settings.bundle
NSURL* plistURL = [[[NSBundle mainBundle] URLForResource:@"Settings" withExtension:@"bundle"] URLByAppendingPathComponent:@"Root.plist"];
if (!plistURL) {
NSLog(@"ERROR - failed to find 'Settings.bundle/Root.plist' within main bundle");
} else {
NSArray* specifiers = [NSDictionary dictionaryWithContentsOfURL:plistURL][@"PreferenceSpecifiers"];
NSDictionary* defaults = [specifiers mtl_foldLeftWithValue:[NSMutableDictionary dictionary] usingBlock:^id(NSMutableDictionary* left, NSDictionary* right) {
if (right[@"Key"] && right[@"DefaultValue"]) {
left[right[@"Key"]] = right[@"DefaultValue"];
@pizthewiz
pizthewiz / gist:3949228
Last active October 12, 2015 01:18
NSDate category to deal with NTP timestamps
// yoinked and recrafted from Gavin Eadie's ios-ntp http://code.google.com/p/ios-ntp/
// NB - not perfectly symmetrical, this evaluates to NO:
// NSDate* now = [NSDate date]; [now isEqualToDate:[NSDate dateWithNTPTimestamp:[now NTPTimestamp]];
struct NTPTimestamp {
uint32_t seconds;
uint32_t fractionalSeconds;
};
typedef struct NTPTimestamp NTPTimestamp;