Skip to content

Instantly share code, notes, and snippets.

View pxpgraphics's full-sized avatar

Paris Xavier Pinkney pxpgraphics

View GitHub Profile
@pxpgraphics
pxpgraphics / ArrayExtensions.swift
Created July 29, 2014 00:11
Swift extensions for common occurances
//
// ArrayExtensions.swift
// MyDailyGrind
//
// Created by Paris Pinkney on 7/8/14.
// Copyright (c) 2014 PXPGraphics. All rights reserved.
//
import Foundation
@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 / remove_dup_sims.rb
Last active January 4, 2016 18:44
Remove duplicate simulators from xcode-select
#!/usr/bin/env ruby
require 'JSON'
device_types = JSON.parse `xcrun simctl list -j devicetypes`
runtimes = JSON.parse `xcrun simctl list -j runtimes`
devices = JSON.parse `xcrun simctl list -j devices`
devices['devices'].each do |runtime, runtime_devices|
runtime_devices.each do |device|