This file contains 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
/* | |
`arc4random_uniform` is very useful but limited to `UInt32`. | |
This defines a generic version of `arc4random` for any type | |
expressible by an integer literal, and extends some numeric | |
types with a `random` method that mitigates for modulo bias | |
in the same manner as `arc4random`. | |
`lower` is inclusive and `upper` is exclusive, thus: | |
This file contains 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
#!/bin/bash | |
#Path to swiftlint | |
SWIFT_LINT=/usr/local/bin/swiftlint | |
#if $SWIFT_LINT >/dev/null 2>&1; then | |
if [[ -e "${SWIFT_LINT}" ]]; then | |
count=0 | |
for file_path in $(git ls-files -m --exclude-from=.gitignore | grep ".swift$"); do | |
export SCRIPT_INPUT_FILE_$count=$file_path |
This file contains 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Terminal notifier | |
;; requires 'sudo gem install terminal-notifier' | |
;; stolen from erc-notifier | |
(defvar terminal-notifier-command (executable-find "terminal-notifier") "The path to terminal-notifier.") | |
; (terminal-notifier-notify "Emacs notification" "Something amusing happened") | |
(defun terminal-notifier-notify (title message) |
This file contains 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
// | |
// PSPDFThreadSafeMutableDictionary.m | |
// | |
// Copyright (c) 2013 Peter Steinberger, PSPDFKit GmbH. All rights reserved. | |
// | |
// 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 |
This file contains 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
// Paste me into a playground! | |
import Cocoa | |
//: # Basic Setup | |
protocol FancyProtocol { | |
associatedtype Thing | |
func holdPinkyUp(x: Thing) | |
} |
This file contains 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
import Foundation | |
extension Decodable { | |
public static func randomInstance() throws -> Self { | |
let decoder = RandomDecoder() | |
return try Self(from: decoder) | |
} | |
} | |
private class RandomDecoder: Decoder { |
This file contains 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
// Copyright © 2021 Christian Tietze. All rights reserved. Distributed under the MIT License. | |
import Foundation | |
extension URL { | |
/// Produces a relative path to get from `baseURL` to the receiver for use in e.g. labels. | |
/// | |
/// When there's no common ancestor, e.g. `/tmp/` and `/var/`, then this returns an absolute path. The only exception to this rule is when `baseURL` itself is the root `/`, since tor that base _all_ paths are relative. | |
/// | |
/// - Returns: Shortest relative path to get from `baseURL` to receiver, e.g. `"../../subdirectory/file.txt"`, and `"."` if both are identical. Absolute path (or absolute URL for non-`file://` URLs) if there's nothing in common. |
This file contains 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
enum JSONValue: Codable, Equatable { | |
struct JSONValueDecodingError: Error { | |
let message: String | |
} | |
case boolean(Bool) | |
case number(Double) | |
case string(String) | |
case array([JSONValue?]) | |
case object([String: JSONValue?]) |
This file contains 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
import Foundation | |
//: Swift type-safe protocol versions of (Mutable)Copying | |
protocol SwiftCopying { | |
associatedtype NonMutableType = Self | |
func clone() -> NonMutableType | |
} | |
extension SwiftCopying where Self: NSCopying { | |
func clone() -> NonMutableType { | |
return self.copy() as! NonMutableType |
This file contains 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
final class Completion<R> { | |
private let closure: (R) -> Void | |
private var cancelled = false | |
/// `closure` is called upon completion, if not cancelled. | |
init(closure: (R) -> Void) { | |
self.closure = closure | |
} | |