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
function doGet() { | |
const notion_token = 'secret_...'; | |
const database_id = '...'; | |
const headers = { | |
'Content-Type' : 'application/json; charset=UTF-8', | |
'Authorization': `Bearer ${notion_token}`, | |
'Notion-Version': '2021-05-13', | |
}; | |
const fetched = UrlFetchApp.fetch(`https://api.notion.com/v1/databases/${database_id}/query`, { | |
"method" : "post", |
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 | |
struct Example { | |
let input: String | |
let expectation: String | |
} | |
// テストケース列挙 | |
let examples: [(String, Example)] = [ | |
("1", Example( | |
input: """ |
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 CustomCodingKey: CodingKey, ExpressibleByStringLiteral { | |
let stringValue: String | |
let intValue: Int? = nil | |
init?(stringValue: String) { self.stringValue = stringValue } | |
init?(intValue: Int) { return nil } | |
init(stringLiteral value: String) { stringValue = value } | |
init(_ value: String) { stringValue = value } | |
} |
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
let jsonData = """ | |
[ | |
"https://www.apple.com", | |
"https://swift.org/blog/", | |
"https://github.com/apple/swift/releases/tag/swift 5.2.4-RELEASE" | |
] | |
""" | |
.data(using: .utf8)! | |
struct SafeURL: RawRepresentable, Decodable { | |
let rawValue: String |
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
protocol Entity { | |
associatedtype RawIDValue: Hashable | |
typealias ID = EntityID<Self> | |
} | |
struct EntityID<E: Entity>: RawRepresentable, Hashable { | |
let rawValue: E.RawIDValue | |
} | |
extension EntityID { | |
init(_ value: E.RawIDValue) { |
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
class Cat: NSObject { | |
@objc func bark() { print("meow") } | |
func hoge() {} | |
} | |
class Dog: NSObject { | |
@objc func bark() { print("bow-wow") } | |
func hoge() {} | |
} | |
let cat = Cat() |
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 replace<T>(_ root: inout T, keyPath: KeyPath<T, String>) { | |
if let k = keyPath as? WritableKeyPath<T, String> { | |
print("writable:", keyPath) | |
root[keyPath: k] += " 🖍" | |
} else { | |
print("not writable:", keyPath) | |
} | |
} | |
struct S { | |
let a = "let" |
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
protocol MessageSenderDelegate { | |
func stateの変化を伝える() | |
} | |
protocol Message { | |
} | |
protocol MessageInput { | |
associatedtype Payload | |
func validate() throws -> Payload | |
} |
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
// https://github.com/apple/swift/blob/b0f5815d2b003df628b1bcfe94681fec489c9492/stdlib/public/Darwin/Foundation/JSONEncoder.swift#L153 | |
func _convertToSnakeCase(_ stringKey: String) -> String { | |
guard !stringKey.isEmpty else { return stringKey } | |
var words : [Range<String.Index>] = [] | |
// The general idea of this algorithm is to split words on transition from lower to upper case, then on transition of >1 upper case characters to lowercase | |
// | |
// myProperty -> my_property | |
// myURLProperty -> my_url_property | |
// |
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 RxSwift | |
import RxCocoa | |
import RxTest | |
struct LoginData: Equatable { | |
let id: Int | |
} | |
protocol LoginRepository { | |
func post(data: LoginData) -> Single<Account> | |
} |
NewerOlder