Skip to content

Instantly share code, notes, and snippets.

View NicholasPeterson's full-sized avatar

Nick Peterson NicholasPeterson

View GitHub Profile
// Copyright © 2019 Nicholas Peterson. All rights reserved.
//
import Foundation
protocol BlacklistInterface {
/*
* Creates a new list from an array of blacklisted words.
* Runs at worst in O(n * m) time where n is the length of the longest word and m is the total number of words.
*/
// Created by Nick Peterson on 8/7/19.
// Copyright © 2019 Nicholas Peterson. All rights reserved.
//
import Foundation
class Cache<T> {
class Node<T> {
var object: T?
let key: String
@NicholasPeterson
NicholasPeterson / normalNumber.m
Created May 24, 2013 22:17
Basic phone number formatting
- (NSString *)normalizedPhoneNumber {
NSString *normalString = self;
if (!self) return nil;
normalString = [normalString lowercaseString];
NSCharacterSet *normalizationSet = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"] invertedSet];
normalString = [[[normalString componentsSeparatedByCharactersInSet:normalizationSet] componentsJoinedByString:@""] uppercaseString];
NSMutableString *phoneNumber = [[normalString mutableCopy] autorelease];
char tmpChar;
@NicholasPeterson
NicholasPeterson / UIKit+NPExtras.h
Last active December 17, 2015 13:59
Basic convenience methods i like to have in UIKit.
@interface UIColor (NPUIExtras)
/**
Generates a color with random values. (not guarenteed to be truely random)
*/
+ (UIColor *)randomColor;
/**
Used to construct a color using values from 0 - 255 rather then 0 - 1.
*/
@NicholasPeterson
NicholasPeterson / NSURL+Bitly.h
Last active December 14, 2015 17:28
NSUSL+bitly for easy synchronous url shortening (bit.ly SSL-API v3)
// Requires SBJSON, Uses my own percent escapeing, But cocoas will do for this task.
// All methods return nil on errors.
@interface NSURL (Bitly)
// Easy NSURL
+ (NSURL *) shortUrlWithString:(NSString *)string;
// Easy URL String
+ (NSString *)shortAbsoluteURLStringWithString:(NSString *)string;
// Returns full bitly response
@NicholasPeterson
NicholasPeterson / gist:5122235
Last active December 14, 2015 17:28
Simple mask iteration. Does not care about subsets.
// Use NS_OPTIONS for some compiler sugar.
//
// Use a type that fits your struct but consider using
// types directly to avoid 32/64bit width inconsistencies.
typedef NS_OPTIONS(UInt16, MaskType) {
MaskTypeOptionNone = 0,
MaskTypeOptionOne = 1 << 0,
MaskTypeOptionTwo = 1 << 1,
};