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
| diff --git a/yarn.lock b/yarn.lock | |
| index 4ad8aa0..86e8f3a 100644 | |
| --- a/yarn.lock | |
| +++ b/yarn.lock | |
| @@ -39,42 +39,18 @@ asn1@0.1.11: | |
| version "0.1.11" | |
| resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.1.11.tgz#559be18376d08a4ec4dbe80877d27818639b2df7" | |
| -asn1@~0.2.3: | |
| - version "0.2.3" |
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
| package main | |
| import ( | |
| "fmt" | |
| "io" | |
| "log" | |
| "net/http" | |
| "os" | |
| "time" | |
| ) |
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
| @discardableResult | |
| public func then<U>(_ onFulfilled: @escaping (T) throws -> U) -> Promise<U> { | |
| return self.thenImpl(onFulfilled, { throw $0 }) | |
| } | |
| @discardableResult | |
| public func then<U>(_ onFulfilled: @escaping (T) throws -> U, _ onRejected: @escaping (Error) throws -> U) -> Promise<U> { | |
| return self.thenImpl(onFulfilled, onRejected) | |
| } | |
| @discardableResult |
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
| package nonblocking | |
| import ( | |
| "io" | |
| "time" | |
| ) | |
| type NonBlockingReader struct { | |
| ch chan []byte | |
| rd io.Reader |
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
| package main | |
| import ( | |
| "fmt" | |
| "io" | |
| "math" | |
| "math/rand" | |
| "mime/multipart" | |
| "time" | |
| ) |
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
| extension SequenceType where Generator.Element == String { | |
| func localizedJoin() -> String { | |
| var g = self.generate() | |
| guard let first = g.next() else { | |
| return "" | |
| } | |
| guard let second = g.next() else { | |
| return first | |
| } | |
| guard var last = g.next() 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
| struct Participant { | |
| let identifiers: [(label: String?, value: String)] | |
| } | |
| // This segfaults. Combining the two maps or changing "" to nil works. | |
| let participants = ["a", "b", "c"] | |
| .map { ("", $0) } | |
| .map { Participant(identifiers: [$0]) } | |
| // Update: Here's an error from a later build of Swift which explains the error. |
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
| let numbers = [ | |
| "one", | |
| "2", | |
| "0x3", | |
| "42", | |
| ] | |
| // This will run the function on all values and only keep the ones that are not nil: | |
| let parsedNumbers = numbers.flatMap { Int($0, radix: 10) } | |
| // [2, 42] |
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 Node { | |
| case tag(String, [Node]) | |
| case text(String) | |
| } | |
| extension Node: CustomStringConvertible { | |
| var description: String { | |
| switch self { | |
| case let .tag(name, children): | |
| if children.count == 1, case let .some(.text(text)) = children.first { |
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
| // Example: | |
| let url = NSURL(string: "https://example.com/hello?bla=one&bla=two&foo&bar=1")! | |
| let values = url.parseQueryString() | |
| // Result: ["bla": ["one", "two"], "bar": ["1"], "foo": []] | |
| extension NSURL { | |
| func parseQueryString() -> [String: [String]]? { | |
| guard let items = NSURLComponents(URL: self, resolvingAgainstBaseURL: false)?.queryItems else { | |
| return nil | |
| } |