This file contains hidden or 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 Combine | |
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | |
extension Publisher { | |
func removeDuplicates<Property>(by keyPath: KeyPath<Output, Property>) | |
-> Publishers.RemoveDuplicates<Self> where Property: Equatable | |
{ | |
return self.removeDuplicates { | |
$0[keyPath: keyPath] == $1[keyPath: keyPath] | |
} |
This file contains hidden or 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
/// Usage: myString.firstIndex(of: otherString) | |
extension BidirectionalCollection where Element: Equatable { | |
func firstIndex(of other: Self) -> Index? { | |
guard | |
let start = other.first.flatMap(self.firstIndex(of:)), | |
self[start...].count >= other.count, | |
case let end = self.index(start, offsetBy: other.count), | |
zip(self[start ..< end], other).allSatisfy(==) | |
else | |
{ |
This file contains hidden or 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 Dispatch | |
class Runner { | |
var observers = [String: () -> Void]() | |
let queue = DispatchQueue(label: "foo-queue") | |
func run() { | |
let observers = self.observers | |
for _ in 0..<20000 { | |
let c: () -> Void = { [weak self] in |
This file contains hidden or 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 python | |
""" | |
Generate commit for each staged file, such that each commit is a `--fixup` to | |
the commit said file was last changed. | |
NOTE: this command will unstage all files. It also does not disninguish staged | |
and unstaged potion of the same file. | |
USAGE: stage files you want to commit, run this command. Interactive rebase with | |
autosquash: `git rebase -i --autosquash BASE` |
This file contains hidden or 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
indirect enum SExpression { | |
struct Token { | |
var index: Int | |
var content: String | |
} | |
enum Atom { | |
case string(Token) | |
case symbol(Token) | |
} |
This file contains hidden or 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 State { | |
enum String { | |
case normal | |
case escape | |
case unicode(Int) | |
} | |
} | |
final class Context { | |
let contents: [UnicodeScalar] |
This file contains hidden or 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 | |
# Run any command and suppress its output to stdin and stderr, unless it returns an error code. | |
OUTPUT=$(${@:1} 2>&1) | |
if [ $? -eq 0 ]; then | |
exit | |
fi | |
OLDLFS=$LFS |
This file contains hidden or 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
compile: | |
wat2wasm main.wat -o main.wasm | |
serve: | |
python -m SimpleHTTPServer |
This file contains hidden or 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 Decl { | |
struct Option { | |
enum Segment { | |
case one(String, [String]) | |
indirect case map(Segment, Segment) | |
} | |
typealias Field = (name: String?, type: Segment) | |
let name: String | |
let fields: [Field] | |
} |
This file contains hidden or 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 E { | |
final class P { var v = 0 } | |
case a(P) | |
var p: P { | |
switch self { | |
case .a(let p): return p | |
} | |
} |