Skip to content

Instantly share code, notes, and snippets.

Christian Tietze DivineDominion

Block or report user

Report or block DivineDominion

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View solarized-dark.css
/* Solarized Dark
For use with Jekyll and Pygments
--------- -------- ------------------------------------------
base03 #002b36 background
base01 #586e75 comments / secondary content
kristopherjohnson / DataStore.swift
Created Sep 28, 2014
Swift: Core Data persistence stack
View DataStore.swift
import Foundation
import CoreData
// "Class variables" used in DataStore.sharedDataStore()
private var _instance: DataStore?
private var DataStoreClassLock = NSRecursiveLock()
private let appStoreFilename = "DataStore.sqlite"
private let testStoreFilename = "test_DataStore.sqlite"
luisobo /
Last active Jan 14, 2016
Hide iOS Simulator when running Unit Tests.

Hide iOS Simulator when running Unit Tests.

Based on this work, that @Dan2552 pointed out.


  1. Clone this gist (git clone hide_ios_simulator)
  2. Xcode -> Preferences -> Behavior -> Testing -> Generates output
  3. Run script -> Choose script -> Select hide_simulator
View valueForKeyTest.swift
//: Playground - noun: a place where people can play
import Cocoa
// When you’re downloading objects from the web, it’s common to need to merge changes
// from the server to already-existing local objects. (If your data model allows for
// mutable objects, as with Core Data, that is.)
// The below is a Swift translation of how I’ve done this in Objective-C.
// Note that it works just fine in Swift — though it does require NSObject subclasses.
preble / Completion.swift
Created Jan 20, 2016
A cancellable completion for Swift.
View Completion.swift
final class Completion<R> {
private let closure: (R) -> Void
private var cancelled = false
/// `closure` is called upon completion, if not cancelled.
init(closure: (R) -> Void) {
self.closure = closure
AliSoftware / SwiftCopying.swift
Last active Aug 24, 2017
TypeSafe copy()/mutableCopy() (NSCopying/NSMutableCopying) in Swift
View SwiftCopying.swift
import Foundation
//: Swift type-safe protocol versions of (Mutable)Copying
protocol SwiftCopying {
associatedtype NonMutableType = Self
func clone() -> NonMutableType
extension SwiftCopying where Self: NSCopying {
func clone() -> NonMutableType {
return self.copy() as! NonMutableType
rnapier / helper.swift
Last active Feb 3, 2018
Helper functions
View helper.swift
import Foundation
/// This is going to be one of those things that for many of you is so obvious that it doesn't
/// require saying. But maybe a few of you have never really done this before either. I've been
/// thinking about nested helper functions.
/// I've used little nested helper functions lots of times. I do this when I want a function, but
/// nothing outside of this scope would ever need it.
func doSomething() {
func inc(x: Int) -> Int { return x + 1 }
sjoerdvisscher / minimal.swift
Created Jun 28, 2017
Using Decodable to generate a minimal value
View minimal.swift
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)
View date.m
#include <time.h>
+ (NSDate *)dateFromISO8601String:(NSString *)string {
if (!string) {
return nil;
struct tm tm;
time_t t;
khanlou / Quicksort.swift
Created Dec 9, 2016
Quicksort - the only use for partition(by:) I could find
View Quicksort.swift
import Foundation
extension Array where Element: Comparable {
mutating func quickSort() {
extension ArraySlice where Element: Comparable {
mutating func quickSort() {
You can’t perform that action at this time.