Skip to content

Instantly share code, notes, and snippets.

Scott Hoyt scottrhoyt

Block or report user

Report or block scottrhoyt

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
@scottrhoyt
scottrhoyt / HeapsAlgorithm.swift
Created Sep 20, 2017
Heap's Algorithm for permutations in Swift
View HeapsAlgorithm.swift
// https://en.wikipedia.org/wiki/Heap%27s_algorithm
import Foundation
/**
Generates all possible permutations of `data` using Heap's Algorithm
- parameters:
- data: The data to permute
- output: A closure called with each permutation of the data
@scottrhoyt
scottrhoyt / JSONCodable+JSONObjects.swift
Last active Dec 15, 2019
A Swift 4 extension for JSONEncoder and JSONDecoder to enable serialization to/deserialization from JSON Objects (e.g. [String: Any])
View JSONCodable+JSONObjects.swift
import Foundation
extension JSONEncoder {
func encodeJSONObject<T: Encodable>(_ value: T, options opt: JSONSerialization.ReadingOptions = []) throws -> Any {
let data = try encode(value)
return try JSONSerialization.jsonObject(with: data, options: opt)
}
}
extension JSONDecoder {
@scottrhoyt
scottrhoyt / RandomGenerator.swift
Created Sep 1, 2015
This is a Swift 2.0 conversion of Erica Sadun's RandomGenerator from here: http://ericasadun.com/2015/04/24/swift-that-permutation-generator-thing/
View RandomGenerator.swift
/*:
**RandomGenerator.swift**
A Swift 2.0-compatible version of Erica Sadun's take on shuffling a
`CollectionType` available here:
http://ericasadun.com/2015/04/24/swift-that-permutation-generator-thing/.
*/
import Foundation
You can’t perform that action at this time.