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
let num = 1 as NSNumber | |
num === num | |
//true | |
(num as Int as NSNumber) === (num as Int as NSNumber) | |
//false | |
(num as UInt as NSNumber) === (num as UInt as NSNumber) | |
//false |
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 A { | |
var hoge = "a" { | |
didSet { print("fixed", hoge) } | |
} | |
// たとえmutatingなfuncの中でも、 | |
mutating func fix() { | |
// クロージャの中ではselfの書き換えはできない | |
DispatchQueue.main.async { | |
self.hoge = "b" // Error: Closure cannot implicitly capture a mutating self parameter |
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
// 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
// 汎用コード | |
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
// もはや動いていなかったので削除 | |
// 修正していただい版をご利用ください | |
// https://gist.github.com/jnory/b39cd65508fbaa2fa39ebed932ca47a7 |
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() |
NewerOlder