Skip to content

Instantly share code, notes, and snippets.

View KiGi's full-sized avatar

Kendall Helmstetter Gelner KiGi

View GitHub Profile
@KiGi
KiGi / KHG Swift FizzBuzz
Created April 26, 2015 22:52
The ever popular FizzBuzz, here a few passes at it in Swift in a playground with multiple implementations and looping methods (including a generator)
import Foundation
// Make constants so the strings can be easily changed.
let fizz = "Fizz"
let buzz = "Buzz"
// Put this its own function just to make different implementations shorter and clearer.
func fizzbBuzzDeterminer( candidateNum : Int, isFizz: Bool, isBuzz : Bool ) -> String
{
var toPrint :String
@KiGi
KiGi / gist:1be0197d9ef4ddfc9970
Created May 7, 2015 22:17
Swift 1.2 fileExistsAtPath
func checkIfFileExpired( fileURL : NSURL ) -> Bool {
let fileManager = NSFileManager()
if let fileManager.fileExistsAtPath(fileURL) {
var error : NSError? = nil
if let filePath = fileURL.path,
let fileAttr = fileManager.attributesOfItemAtPath(filePath, error: &error),
let creationDate = fileAttr[NSFileModificationDate] as? NSDate {
return creationDate.isBefore(NSDate.oneDayAgo())
} else {
println("problem examining file attributes for \(fileURL): error was \(error)")
@KiGi
KiGi / gist:c6ddba8ed2276773c9fa
Created December 21, 2015 02:37
Draw UIView into image from static class method
static func buildImageForSize(size:CGSize) -> UIImage?
{
if size.height == 0 || size.width == 0 {
return .None
}
var sigRect = CGRectZero
sigRect.size = size
// The following does NOT work
public struct CustomHashable<T>: Hashable {
public let value: T
public typealias HashCalculator = (CustomHashable<T>, inout Hasher) -> Void
public typealias EqualityCalculator = (CustomHashable<T>, CustomHashable<T>) -> Bool
public typealias CacheTransformedData = (T) -> Any?
private let hashCalculator: HashCalculator
private let equalityCalculator: EqualityCalculator