Skip to content

Instantly share code, notes, and snippets.

View fluidsonic's full-sized avatar

Marc Knaup fluidsonic

View GitHub Profile
@fluidsonic
fluidsonic / Escaper.swift
Last active December 22, 2016 13:32
Converting a closure to an @escaping closure in Swift 3
func makeEscaping<Parameters,Result>(_ closure: (Parameters) -> Result) -> (Parameters) -> Result {
func cast<From,To>(_ instance: From) -> To {
return (instance as Any) as! To
}
return cast(closure)
}
// Example
{
"name": "Fabric",
"version": "1.3.0",
"summary": "Fabric by Twitter, Inc.",
"homepage": "https://fabric.io",
"authors": "Twitter",
"license": {
"type": "Commercial",
"text": "Fabric: Copyright 2015 Twitter, Inc. All Rights Reserved. Use of this software is subject to the terms and conditions of the Fabric Software and Services Agreement located at https://fabric.io/terms. OSS: http://get.fabric.io/terms/opensource.txt"
},
@fluidsonic
fluidsonic / gist:4e81aa2000b7dc62b099
Last active August 29, 2015 14:20
Randomly returns totally wrong values with Swift optimizations (-O) turned on
public func optionalMax <T: Comparable>(elements: T? ...) -> T? {
var maximumElement: T?
for element in elements {
if let element = element {
if let existingMaximumElement = maximumElement {
if element > existingMaximumElement {
maximumElement = element
}
}
@fluidsonic
fluidsonic / sqlite3.sh
Created April 23, 2015 16:03
Make sqlite3 module available in Swift
#!/bin/sh
modulesDirectory=$DERIVED_FILES_DIR/modules
modulesMap=$modulesDirectory/module.modulemap
modulesMapTemp=$modulesDirectory/module.modulemap.tmp
mkdir -p "$modulesDirectory"
cat > "$modulesMapTemp" << MAP
module sqlite3 [system] {