View dec01.swift
func day1(_ string: String) -> Int {
return string
.filter({ idx in
guard idx != string.index(before: string.endIndex)
else { return string[string.startIndex] == string[idx] }
return string[idx] == string[string.index(after: idx)] })
.map({ Int(String(string[$0])) ?? 0 })
.reduce(0, +)
View autogen.swift
import Dispatch
Note: Thanks, Ian Keen and Zev Eisenberg and Sven Weidauer
Zev Eisenberg: "Do you still have to specify 1 << _n_ manually for `OptionSet` conformance? There’s no magic?"
This solution creates values that don't matter. They're simply unique, since option sets should not be accessed by raw value outside the implementation. (Versus direct `UInt`, which supports bit manipulation operations)
View optionstuff.swift
public extension OptionSet where RawValue == Int {
// Thanks Ian Keen
static func option(_ level: RawValue) -> Self {
assert(level > 0, "Options must be 1 or greater")
return .init(rawValue: 1 << (level - 1))
public struct Foo: OptionSet {
public typealias RawValue = Int
View Angle+Trig.swift
// Angle+Trig.swift
// SwiftPlaneGeometry
#if os(Linux)
/// #error No Linux Support
import Darwin
extension Angle {
View slice.swift
extension ArraySlice where Element: Comparable {
/// Produces an array of slices representing the original
/// slice split at each point where a user-supplied
/// predicate evalutes to true.
/// - Parameter predicate: a closure that tests whether a new element
/// should be added to the current partion
/// - Parameter element: the element to be tested
/// - Parameter nextElement: the successive element to be tested
/// - Parameter maxPartitions: The maximum number of
View angle.swift
// Angle.swift
// SwiftPlaneGeometry
// Represents the degree of turn between two straight
// lines with a common vertex
public struct Angle : CustomStringConvertible, Equatable {
/// The pi constant, the ratio of a circle's circumference to its diameter
public static let (pi, π) = (Double.pi, Double.pi)
View regex.swift
import Foundation
/// Provides NSRegularExpression pattern matching
/// against strings in `switch` and `~=` statements
public struct Regex {
public let regexPattern: String
public let options: NSRegularExpression.Options
/// Initialize a `Regex` instance that
/// defaults to no options. Update as needed for
View regex.swift
import Foundation
/// Provides NSRegularExpression pattern matching against strings
/// in `switch` expressions
/// Regular expressions are expensive to construct. The built-in
/// class cache stores already-constructed pattern instances using
/// the pattern string (coerced to `NSString`) as its keys. Modify
/// matching options at the `match(_, options:)` call-site if needed.
View stuff.txt
//: Playground - noun: a place where people can play
import Cocoa
let url = NSURL(string:"")!
let pasteboard = NSPasteboard.general
pasteboard.writeObjects([url, url.absoluteString as! NSPasteboardWriting])
View forjb.swift
import UIKit
extension String {
func toAttributed() -> NSAttributedString {
return NSAttributedString(string: self)
extension NSAttributedString {
func toImage(withAlpha alpha: CGFloat = 1.0) -> UIImage {