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
IanKeen / Decodable+Random.swift
Last active Mar 8, 2019
Custom Decoder that can be used to create Decodable instances that are populated with random values
View Decodable+Random.swift
import Foundation
extension Decodable {
public static func randomInstance() throws -> Self {
let decoder = RandomDecoder()
return try Self(from: decoder)
private class RandomDecoder: Decoder {
DivineDominion / cocoaconv.rb
Last active Sep 28, 2018
Convert libMultiMarkdown enums to Swift-bridgeable NS_ENUMs. Pass the path to libMultiMarkdown.h to the script when running.
View cocoaconv.rb
#!/usr/bin/env ruby
require 'optparse'
CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
FALLBACK_PATH = File.join(CURRENT_PATH, "..", "build-xcode", "Debug", "include", "libMultiMarkdown", "libMultiMarkdown.h")
options = {:mode => :nsenum} do |parser|
parser.banner = "Usage: #{$0} [options] path/to/libMultiMarkdown.h"
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
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)
set -e
# set your Frameworks path here
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() {
# -*- coding: utf-8 -*-
# Print iterations progress
def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
Call in a loop to create terminal progress bar
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
Gurdeep0602 / AppStoryboard.swift
Last active Jun 25, 2019
AppStoryboard enumeration
View AppStoryboard.swift
// AppStoryboards.swift
// AppStoryboards
// Created by Gurdeep on 15/12/16.
// Copyright © 2016 Gurdeep. All rights reserved.
import Foundation
import UIKit
russbishop / TypeErasure.swift
Last active Aug 2, 2018
Type erasure with multiple adopting types
View TypeErasure.swift
// Paste me into a playground!
import Cocoa
//: # Basic Setup
protocol FancyProtocol {
associatedtype Thing
func holdPinkyUp(x: Thing)
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.
You can’t perform that action at this time.