This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<style> | |
body { | |
margin: 0px; | |
padding: 0px; | |
} | |
</style> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Types work but are not optimal - no error handling | |
// Demo in response to https://gist.github.com/sketchytech/029c00a74a4217a89797 | |
extension CollectionType { | |
func reorder<T>(sorter: [(index: Self.Index, element: T)]) -> Array<Self.Generator.Element> { | |
return sorter.map({self[$0.index]}) | |
} | |
} | |
func sortColumns<T0, T1>(_ col0: Array<T0>, _ col1: Array<T1>, _ cmp: (T0,T0)->Bool) -> (Array<T0>, Array<T1>) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SimpleScrollingStack.swift | |
// A super-simple demo of a scrolling UIStackView in iOS 9 | |
// | |
// Created by Paul Hudson on 10/06/2015. | |
// Learn Swift at www.hackingwithswift.com | |
// @twostraws | |
// | |
import UIKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open-ended range operators | |
// | |
// 100... is equivalent to 100...Int.max | |
// ...-100 is equivalent to Int.min...-100 | |
// ..<3 is equivalent to Int.min..<3 | |
import Swift | |
/// Conforming types provide static `max` and `min` constants. | |
protocol MinMaxType { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uniq func for Swift 1.2 | |
func uniq<C: ExtensibleCollectionType where C.Generator.Element: Hashable>(collection: C) -> C { | |
var seen:Set<C.Generator.Element> = Set() | |
return reduce(collection, C()) { result, item in | |
if seen.contains(item) { | |
return result | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Version 2 of pagesFromData from Flattenin' Your Mappenin' | |
// http://robnapier.net/flatmap | |
// | |
import Foundation | |
infix operator >>== {} | |
func >>== <T,U>(x: T, f:T -> Result<U>) -> Result<U> { | |
return x.flatMap(f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The MIT License (MIT) | |
// | |
// Copyright (c) 2014 Nate Cook | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Version 3 of pagesFromData from Functional Wish Fulfillment | |
// http://robnapier.net/functional-wish-fulfillment | |
// | |
import Foundation | |
func pagesFromData(data: NSData) -> Result<[Page]> { | |
return continueWith(asJSON(data)) { | |
continueWith(asJSONArray($0)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// IntExtension.swift | |
// CryptoSwift | |
// | |
// Created by Marcin Krzyzanowski on 12/08/14. | |
// Copyright (C) 2014 Marcin Krzyżanowski <[email protected]> | |
// This software is provided 'as-is', without any express or implied warranty. | |
// | |
// In no event will the authors be held liable for any damages arising from the use of this software. | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// removes all but first occurrence from a sequence, returning an array. | |
// requires elements to be hashable, not just equatable, but the alternative | |
// of using contains is very inefficient | |
// alternatively, could require comparable, sort, and remove adjacent dupes | |
func uniq<S: SequenceType, E: Hashable where E==S.Generator.Element>(seq: S) -> [E] { | |
var seen: [S.Generator.Element:Int] = [:] | |
return filter(seq) { !seen.updateValue(1, forKey: $0).hasValue } | |
} | |
// TODO: a version that takes a custom comparator function, say for lexicographic deduping |
NewerOlder