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
#!/usr/bin/env bash | |
set -euxo pipefail | |
main() { | |
local tmpdir | |
tmpdir="$(mktemp -d /tmp/cargo-targets/target.XXXXXXXX)" | |
ln -s "${tmpdir}" target | |
} |
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
func keys_equal<T, U:Equatable>(_ keypath: Keypath<T,U>) -> (T,T) -> Bool { | |
return { $0[keypath: keypath] == $1[keypath: keypath] } | |
} | |
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | |
extension Publisher { | |
func removeDuplicates(matchingAll predicates: @escaping (Output, Output) -> Bool...) | |
-> Publishers.RemoveDuplicates<Self> | |
{ | |
return self.removeDuplicates { lhs, rhs in |
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
public struct BouyantPointNumber: Hashable { | |
public typealias Storage = Double | |
private var storage: Storage | |
@_transparent | |
private static var scaleFactor: Storage { | |
return 10.0 | |
} | |
@_transparent | |
private var scaleFactor: Storage { |
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
struct S { | |
let x: Int | |
init(x: Int) { self.x = x } | |
// This is allowed | |
init(x2: Int) { | |
self.init(x: x2) | |
} | |
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
private class Example: NSObject { | |
@objc func example() {} | |
} | |
extension XCTestSuite { | |
public func addTests<Test: XCTestCase>( | |
_ tests: [(String, (Test) -> () -> Void)]) | |
{ | |
let method = class_getInstanceMethod(Example.self, |
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 | |
set -eu | |
# You can bootstrap by running: | |
# wget --no-cache -N tinyurl.com/install-swift-linux && chmod +x ./install-swift-linux && ./install-swift-linux | |
# https://github.com/apple/swift/blob/master/README.md#getting-started | |
source /etc/os-release |
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 DiskArbitration | |
extension URL { | |
var volumeUUID: String? { | |
guard self.isFileURL, let session = DASessionCreate(nil) else { | |
return nil | |
} | |
var fsStats = statfs() | |
guard statfs(self.path, &fsStats) == 0, |
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
// Using XCode 7.3.1 (it's all I had at the time) | |
extension MutableCollectionType where Generator.Element == SubSequence.Generator.Element { | |
mutating func selectionSort(isOrderedBefore compare: (Generator.Element, Generator.Element) throws -> Bool) rethrows { | |
for currentIndex in self.startIndex ..< self.endIndex { | |
// (index,element) pairs after the current index | |
let pairs = zip(currentIndex ..< self.endIndex, self.suffixFrom(currentIndex)).lazy | |
// the pair with the minimum element | |
let pair = try pairs.minElement({ try compare($0.1, $1.1) }) |
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
// Using XCode 7.3.1 (it's all I had at the time) | |
extension MutableCollectionType where Generator.Element: Comparable { | |
mutating func selectionSortInPlace() { | |
for currentIndex in self.startIndex ..< self.endIndex { | |
guard let (minIndex, minElement) = zip((currentIndex ..< self.endIndex), self.suffixFrom(currentIndex)) | |
.minElement({ lhs, rhs in (lhs.1 as! Generator.Element) < (rhs.1 as! Generator.Element) }) | |
else { | |
continue | |
} |
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
// Output: | |
// AnyPokemon<🔥>(Ponyta()) | |
// AnyPokemon<🔥>(Charmander()) | |
protocol Pokemon { | |
associatedtype Power | |
mutating func attack() -> Power | |
} | |
struct Pikachu: Pokemon { |
NewerOlder