Skip to content

Instantly share code, notes, and snippets.

View mwaterfall's full-sized avatar

Michael Waterfall mwaterfall

View GitHub Profile
@JohnSundell
JohnSundell / Perform.swift
Last active December 21, 2019 14:43
A function that enables you to easily wrap throwing APIs, to provide a custom error
/**
* Perform a throwing expression, and throw a custom error in case the expression threw
*
* - parameter expression: The expression to execute
* - parameter error: The custom error to throw instead of the expression's error
* - throws: The given error
* - returns: The return value of the given expression
*/
func perform<T>(_ expression: @autoclosure () throws -> T, orThrow errorExpression: @autoclosure () -> Error) throws -> T {
do {
@kumabook
kumabook / Observable.swift
Last active March 12, 2022 06:47
Observer pattern with swift protocol extension
import Foundation
public protocol Observer: Equatable {
associatedtype EventType
func listen(_ event: EventType)
}
public protocol Observable {
associatedtype ObserverType: Observer
associatedtype EventType
@capttaco
capttaco / Fetchable.swift
Last active May 3, 2019 17:28
A utility protocol for custom NSManagedObjects that makes querying contexts simpler and more convenient. Requires Swift 2.
import CoreData
protocol Fetchable
{
typealias FetchableType: NSManagedObject
static func entityName() -> String
static func objectsInContext(context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> [FetchableType]
static func singleObjectInContext(context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> FetchableType?
static func objectCountInContext(context: NSManagedObjectContext, predicate: NSPredicate?) -> Int
@staltz
staltz / introrx.md
Last active April 25, 2024 04:18
The introduction to Reactive Programming you've been missing
@irachex
irachex / Treap.py
Created October 20, 2012 08:43
Treap (tree + heap) in Python
import random
class TreapNode(object):
def __init__(self, key, data):
self.key = key
self.ran = random.random()
self.size = 1
self.cnt = 1
self.data = data
self.left = None
@shripadk
shripadk / gist:552554
Created August 27, 2010 00:59
Setting up Heroku Hostname SSL with GoDaddy SSL Cert
How to setup Heroku Hostname SSL with GoDaddy SSL Certificate and Zerigo DNS
Heroku recently added an exciting new 'Hostname SSL' option. This option offers the broad compatibility of IP-based SSL, but at 1/5 the price ($20 / month at the time of this writing).
The following tutorial explains how to use Heroku's new 'Hostname SSL' option on your Heroku project. Before we begin, let's list what we're using here:
* Heroku Hostname SSL
* GoDaddy Standard SSL Certificate
* Zerigo DNS