Skip to content

Instantly share code, notes, and snippets.

View scottrhoyt's full-sized avatar

Scott Hoyt scottrhoyt

View GitHub Profile
@scottrhoyt
scottrhoyt / RandomGenerator.swift
Created September 1, 2015 21:55
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/
/*:
**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
@scottrhoyt
scottrhoyt / JSONCodable+JSONObjects.swift
Last active March 27, 2021 00:19
A Swift 4 extension for JSONEncoder and JSONDecoder to enable serialization to/deserialization from JSON Objects (e.g. [String: Any])
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 / HeapsAlgorithm.swift
Created September 20, 2017 00:57
Heap's Algorithm for permutations in 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 / ha-snooze-automation-button.yaml
Created December 4, 2022 02:53
Home Assistant: Snooze automation
blueprint:
name: Snooze Button
description: Snooze an automation for a time using and input boolean
domain: automation
input:
snooze_button:
name: Snooze Button
description: The input boolean to use as the snooze button
selector:
entity: