Skip to content

Instantly share code, notes, and snippets.

View pxpgraphics's full-sized avatar

Paris Xavier Pinkney pxpgraphics

View GitHub Profile
@pxpgraphics
pxpgraphics / NSString: Snake Case <=> Camel Case
Created November 18, 2014 19:43
Helper methods to translate snake case into camel case and vice versa.
+ (NSString *)stringByReplacingSnakeCaseWithCamelCase:(NSString *)string
{
NSArray *components = [string componentsSeparatedByString:@"_"];
NSMutableString *camelCaseString = [NSMutableString string];
[components enumerateObjectsUsingBlock:^(NSString *component, NSUInteger idx, BOOL *stop) {
[camelCaseString appendString:(idx == 0 ? component : [component capitalizedString])];
if (idx > 0) {
[camelCaseString appendString:[component capitalizedString]];
} else {
[camelCaseString appendString:component];
@pxpgraphics
pxpgraphics / PXPLog.h
Created November 21, 2014 18:54
NSLog Override
#import <Foundation/Foundation.h>
#ifdef DEBUG
#define NSLog(args...) PXPLog(__FILE__,__LINE__,__PRETTY_FUNCTION__,args);
#else
#define NSLog(...)
#endif
void PXPLog(const char *file, int lineNumber, const char *functionName, NSString *format, ...);
@pxpgraphics
pxpgraphics / Favorite.m
Created December 4, 2014 02:17
Parse: PFObject favorite methods
@implementation
/*...*/
- (void)toggleFavorite:(BOOL)isFavorite
{
PFUser *user = [PFUser currentUser];
if (!user) {
return;
}
- (NSString *)normalizeString:(NSString *)string
{
NSString *normalizedString = [[string copy] stringByStandardizingPath]; // copy to keep thread-safe;
if ([normalizedString hasPrefix:@".."]) {
normalizedString = [normalizedString substringFromIndex:2];
}
if ([normalizedString containsString:@"/../"]) {
NSArray *components = [normalizedString componentsSeparatedByString:@"/../"];
NSMutableArray *tempComponents = [components mutableCopy];
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
// in invite.js module:
exports.inviteUser = function(creatingUser,email,tempPass,response)
{
"use strict";
if (!tempPass) {
tempPass = genRandomPass();
}
var user = new Parse.User();
user.set ("username", email);
/*
* This is an example provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
@pxpgraphics
pxpgraphics / PSPDFUIKitMainThreadGuard.m
Last active August 29, 2015 14:26 — forked from steipete/PSPDFUIKitMainThreadGuard.m
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.
@pxpgraphics
pxpgraphics / xcode-build-bump.sh
Created November 26, 2015 21:41 — forked from sekati/xcode-build-bump.sh
Xcode Auto-increment Build & Version Numbers
# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
// MARK: PXPAssert
/**
Traditional C-style assert with an optional message.
Use this function for internal sanity checks that are active
during testing but do not impact performance of shipping code.
* In playgrounds and -Onone builds (the default for Xcode's Debug
configuration): if `condition` evaluates to false, stop program