Skip to content

Instantly share code, notes, and snippets.

View jaredkhan's full-sized avatar

Jared Khan jaredkhan

View GitHub Profile
@jaredkhan
jaredkhan / copy_on_write_examples.swift
Last active April 5, 2021 15:06
A few demonstrations of the copy-on-write behaviour of containers in the Swift Standard Library.
/// A few demonstrations of the copy-on-write behaviour of containers in the Swift Standard Library.
/// https://jaredkhan.com/blog/swift-copy-on-write
/// Pause execution so that we can look at memory usage in Activity Monitor or similar.
func pause(expectedMemoryUsage: Int) {
print("Expecting memory usage of about \(expectedMemoryUsage)MB. Press [enter] to continue")
let _ = readLine()
}
/// Demonstrate the copy-on-write behaviour of a large array.
@jaredkhan
jaredkhan / example.swift
Last active November 6, 2017 17:27
Swift HTML Builder Example
struct ImageHero: Nodeable {
let background: BackgroundType
let imagePath: String
let alternateText: String
var node: Node {
return El.Div[
Attr.className => "ImageHero",
Attr.style => background.style
].containing(