Skip to content

Instantly share code, notes, and snippets.

View NSExceptional's full-sized avatar

Tanner Bennett NSExceptional

View GitHub Profile
@NSExceptional
NSExceptional / snake_case_toCamelCase.m
Last active August 28, 2015 03:18
Given a path to a folder, replaces all occurrences of `snake_case` words (ignoring `ALL_CAPS` and `dispatch_foo` and `objc_foo`) with their `camelCase` equivalent.
#import <Foundation/Foundation.h>
#define kRegex @"(?<!\")\\b(?!dispatch)(?!objc)_?([A-Z]?[a-z]+_[A-Z]?[a-z]+)"
@interface NSString (Util)
- (NSArray *)matchesForRegex:(NSString *)pattern;
- (NSArray *)allCodeFilesInDirectory;
@end
@implementation NSString (Util)
@NSExceptional
NSExceptional / Tweak.xm
Created November 2, 2015 06:57
Modify the "News" cells of the iOS 9 Spotlight.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface SearchUISingleResultTableViewCell : NSObject
- (id)initWithResult:(id)result style:(unsigned long)style;
- (void)updateWithResult:(id)result;
@property (assign) id result;
@end
@NSExceptional
NSExceptional / UpdateXcodePluginUUIDs.m
Last active December 23, 2015 10:25
A program that adds the UUID of the current installation of Xcode (in /Applications/Xcode.app) to every Xcode plug-in's Info.plist. Does nothing if the plug-in already contains the current UUID.
//
// main.m
// UpdateXcodePluginUUIDs
//
// Created by Tanner on 12/21/15.
// Copyright © 2015 Tanner Bennett. All rights reserved.
//
#import <Foundation/Foundation.h>
@NSExceptional
NSExceptional / VanishingView.m
Created March 4, 2016 12:55
A UIView subclass that fades away more the harder you press on it, and eventually disappears if you press hard enough. iOS 9 only, of course.
@implementation VanishingView
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *t = touches.allObjects.firstObject;
self.alpha = 1 - t.force/t.maximumPossibleForce;
if (t.force == t.maximumPossibleForce) {
[self removeFromSuperview];
}
}
@NSExceptional
NSExceptional / SnapchatMemories.md
Last active July 8, 2016 15:45
Basic documentation on the new Memories API

Alrighty, so Memories:

  • First uploaded to storage.googleapis.com/snallery-m/a1ca9af0-be6b-4874-a6a1-8e30823ae0cf/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx with the following query parameters:

  • GoogleAccessId: GOOGMR536EIHHSJL2KAK

  • Expires: 14679XXXXX

  • Signature: base64 string

The thumbnail is uploaded to storage.googleapis.com/snallery-t/a1ca9af0-be6b-4874-a6a1-8e30823ae0cf/yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy with the same queries. HTTP method is PUT for both

//
// Tweak.m
// FLEXing
//
// Created by Tanner Bennett on 2016-07-11
// Copyright © 2016 Tanner Bennett. All rights reserved.
//
#import "Interfaces.h"
@NSExceptional
NSExceptional / PrivateMutableProperty.h
Last active July 21, 2016 16:52
An example of an immutable property with mutable storage.
@interface MYClass : NSObject
@property (nonatomic, readonly) NSArray *apples;
@property (nonatomic, readonly) NSArray *oranges;
@end
@NSExceptional
NSExceptional / Model.swift
Last active July 23, 2016 22:32
Building a basic parser with NSScanner. In this example, to parse Objective-C interface and protocol definitions.
import Cocoa
public class Model {
public init() {}
public var className: NSString?
public var superclassName: NSString?
public var categoryname: NSString?
@NSExceptional
NSExceptional / static_nsarray.m
Created July 29, 2016 22:52
Macro to make a static NSArray within a function or method
#define StaticNSArray(name, ...) nil; static dispatch_once_t ___onceToken; dispatch_once(&___onceToken, ^{ name = @[__VA_ARGS__]; })
- (void)foo {
...
static NSArray *animals = StaticNSArray(typeQualifiers, @"cat", @"dog", @"bunny");
...
}
@NSExceptional
NSExceptional / NSString+Markdown.h
Last active September 20, 2016 07:37
Snudown → NSAttributedString
@import Foundation;
@interface NSString (Markdown)
@property (nonatomic, readonly) NSAttributedString *attributedStringFromRawMarkdown;
@property (nonatomic, readonly) NSString *HTMLFromRawMarkdown;
@end