Skip to content

Instantly share code, notes, and snippets.

View cruffenach's full-sized avatar

Collin Ruffenach cruffenach

View GitHub Profile
Warning: no rule to process file 'REDACTED/Pods/T1Autograph/libT1Autograph.a' of type archive.ar for architecture x86_64
@cruffenach
cruffenach / gist:3de3b6225030c957f99a
Created June 3, 2014 20:27
Swift String Length Extension
extension String {
var length : Integer {
get {
return countElements(self)
}
}
}
//
// LogoPathFactory.swift
// LogoFunhouse_Swift
//
// Created by Collin Ruffenach on 8/25/14.
// Copyright (c) 2014 Simple. All rights reserved.
//
import Foundation
import UIKit
@cruffenach
cruffenach / gist:3ed23d6d80ed27fd6928
Created August 29, 2014 20:38
Index in Array's map and reduce
extension Array {
func map<U>(function : (index : Int, object : T) -> U) -> [U] {
var result = [U]()
for i in 0..<self.count {
result.append(function(index: i, object: self[i]))
}
return result
}
func reduce<U>(initial : U, combine : (product : U, index : Int, object : T) -> U) -> U {
@cruffenach
cruffenach / gist:0e98947402b18faea48e
Last active August 29, 2015 14:06
AnimationType enum with Associated Values
enum AnimationType : Printable {
case Linear(duration : NSTimeInterval?)
case Spring(damping : CGFloat?, velocity : CGFloat?, duration : NSTimeInterval?)
case Gravity(magnitude : CGFloat?)
}
struct CGRaw {
static func rawRect(#uiKitRect : CGRect) -> CGRect {
let scale = UIScreen.mainScreen().scale
return CGRect(
x: CGRectGetMinX(uiKitRect)*scale,
y: CGRectGetMinY(uiKitRect)*scale,
width: CGRectGetWidth(uiKitRect)*scale,
height: CGRectGetHeight(uiKitRect)*scale
)
void CRWaitMinimumDurationAndExecute(NSTimeInterval start, NSTimeInterval minimumDuration, void(^block)(void)) {
double diff = [NSDate date].timeIntervalSince1970-start;
double delayInSeconds = MAX(0.0, minimumDuration-diff);
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if (block) block();
});
}
//Usage
@cruffenach
cruffenach / gist:0d8e53475f0e4bd018e0
Created October 25, 2014 22:39
Single Linked List Node
class SingleLinkedListNode <T : Printable> : Printable {
var next : LinkedListNode?
var data : T
init(data : T) {
self.data = data
}
var description : String {
get {
@cruffenach
cruffenach / Prep.swift
Created November 6, 2014 21:27
Interview Prep
// Playground - noun: a place where people can play
import Foundation
import UIKit
//struct Square {
// var x, y, width, height : Float
//}
//
//func overlap(start1 : Float, length1 : Float, start2 : Float, length2 : Float) -> Float {
@cruffenach
cruffenach / BlogPost.h
Created July 13, 2011 17:31
BlogPost with Synthesized Properties
#import <Foundation/Foundation.h>
@class Author;
@interface BlogPost : NSObject {
NSString *_postName;
NSDate *_postDate;
Author *_author;
}