Skip to content

Instantly share code, notes, and snippets.

View ReneLindhorst's full-sized avatar

René Lindhorst ReneLindhorst

View GitHub Profile
@praeclarum
praeclarum / ArrayDiff.swift
Last active January 8, 2021 06:10
A generic diffing operation that can calculate the minimal steps needed to convert one array to another. It can be used to generate standard diffs, or it can be used more creatively to calculate minimal UI updates.
//
// ArrayDiff.swift
//
// Created by Frank A. Krueger on 6/30/15.
// Copyright © 2015 Krueger Systems, Inc. All rights reserved.
// License: MIT http://opensource.org/licenses/MIT
//
import Foundation
@andymatuschak
andymatuschak / CollectionViewDataSource.swift
Last active February 12, 2021 09:44
Type-safe value-oriented collection view data source
//
// CollectionViewDataSource.swift
// Khan Academy
//
// Created by Andy Matuschak on 10/14/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
@Goos
Goos / gist:b31f6b21660aa092e6c2
Last active August 29, 2015 14:02
DateAdditions.swift
//
// DateAdditions.swift
// OMGSWIFT
//
// Created by Robin Goos on 03/06/14.
// Copyright (c) 2014 OMG. All rights reserved.
//
import Foundation
/**
Provides the ability to verify key paths at compile time.
If "keyPath" does not exist, a compile-time error will be generated.
Example:
// Verifies "isFinished" exists on "operation".
NSString *key = SQKeyPath(operation, isFinished);
// Verifies "isFinished" exists on self.
@davedelong
davedelong / gist:7371853
Last active May 16, 2020 02:51
Delegate proxying (`protocol_methodForEach()` is a custom function that does just what its name implies)
@interface DDDelegateProxy : NSProxy
+ (id)proxyForDelegate:(id)delegate conformingToProtocol:(Protocol *)protocol;
@property (weak, readonly) id delegate;
@property (strong, readonly) Protocol *protocol;
/*!
* Set a default return value for a method on the delegate's protocol.
* \param value This must be a block that returns the default value. Bad Things will happen if it's not.
@steipete
steipete / gist:2255253
Created March 30, 2012 21:25
ISO 8601 parsing
+ (NSDate *)dateFromISO8601String:(NSString *)iso8601 {
if (!iso8601) {
return nil;
}
const char *str = [iso8601 cStringUsingEncoding:NSUTF8StringEncoding];
char newStr[24];
struct tm tm;
size_t len = strlen(str);