Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View emma-k-alexandra's full-sized avatar
⌨️
Starting more projects than I can finish

Emma K Alexandra emma-k-alexandra

⌨️
Starting more projects than I can finish
View GitHub Profile
{
"content": [
{
"type": "header",
"title": "Hello World",
"level": 2
},
{
"type": "paragraph",
"text": "Blah blah blah"
struct Content: Codable {
let content: [Element]
enum Element: Codable {
case header(Header)
case paragraph(Paragraph)
case footer(Footer)
struct Header: Codable {
let title: String
struct BaseContent: Codable {
let type: ContentType
enum ContentType: String, Codable {
case header
case paragraph
case footer
}
enum CodingKeys: String, CodingKey {
init(from decoder: Decoder) throws {
let baseContainer = try decoder.container(keyedBy: BaseContent.CodingKeys.self)
let type = try baseContainer.decode(BaseContent.ContentType.self, forKey: .type)
let container = try decoder.singleValueContainer()
switch type {
case .header:
self = .header(try container.decode(Header.self))
case .paragraph:
struct Content: Codable {
let content: [Element]
enum Element: Codable {
case header(Header)
case paragraph(Paragraph)
case footer(Footer)
struct Header: Codable {
let title: String
import Foundation
struct Example: Codable {
let id: Int
var text: String
}
let json = """
{
"id": 1,
@emma-k-alexandra
emma-k-alexandra / hooray.py
Created December 3, 2020 04:57
reduce or comprehensions > map & filter
l = [0, 1, 2, 3, 4, 5, 6]
# w/ map & filter
>>> list(map(lambda a: a * 2, filter(lambda a: a > 2, l)))
[6, 8, 10, 12]
# w/ generator
>>> list(a * 2 for a in l if a > 2)
[6, 8, 10, 12]
Hello world, my name is [Emma](https://emma.sh). Sometimes I write Swift code.
struct LinkAndText: View {
var body: some View {
Text("Hello world, my name is ")
Link("Emma", destination: URL(string: "https://emma.sh")!)
Text(". Sometimes I write Swift code.")
}
}
struct LinkAndText: View {
var body: some View {
HStack {
Text("Hello world, my name is ")
Link("Emma", destination: URL(string: "https://emma.sh")!)
Text(". Sometimes I write Swift code.")
}
}
}