Instantly share code, notes, and snippets.

View Set.playground
precedencegroup ForwardApplication {
associativity: left
infix operator |>: ForwardApplication
public func |> <A, B>(x: A, f: (A) -> B) -> B {
return f(x)
precedencegroup SingleTypeComposition {
associativity: right
View UILayoutPriority.swift
import UIKit
import PlaygroundSupport
let view = UIView(frame: CGRect(x: 0, y: 0, width: 414, height: 100))
view.backgroundColor = .white
let titleLabel = UILabel()
titleLabel.text = "Hello"
titleLabel.backgroundColor = .purple

Keybase proof

I hereby claim:

  • I am klaaspieter on github.
  • I am klaaspieter ( on keybase.
  • I have a public key ASCTKhdPDvJLhI4JoXgJEUEgM6PhrUepfEt-bWxhEBEvzgo

To claim this, I am signing this object:

View Calendar.swift
import Foundation
extension Calendar {
/// Returns `true` if the given date is after today, as defined by the calendar and calendar's locale.
/// Because it's impossible to define the end of a day (there are an infinite number of
/// milliseconds between 23:59:59 and 00:00:00), this method instead ensures that
/// `date` >= `startOfTomorrow`.
/// - parameter date: The specified date.

From time to time, Musk will send out an e-mail to the entire company to enforce a new policy or let them know about something that's bothering him. One of the more famous e-mails arrived in May 2010 with the subject line: Acronyms Seriously Suck:

There is a creeping tendency to use made up acronyms at SpaceX. Excessive use of made up acronyms is a significant impediment to communication and keeping communication good as we grow is incredibly important. Individually, a few acronyms here and there may not seem so bad, but if a thousand people are making these up, over time the result will be a huge glossary that we have to issue to new employees. No one can actually remember all these acronyms and people don't want to seem dumb in a meeting, so they just sit there in ignorance. This is particularly tough on new employees.

That needs to stop immediately or I will take drastic action - I have given enough warning over the years. Unless an acronym is approved by me, it should not enter the SpaceX glossary.

View Instabug.json
"7.1": ""
View xcrecord
xcrun simctl io booted recordVideo "$tmp_file"
ffmpeg -i "$tmp_file" -pix_fmt rgb24 -r 10 -f gif - \
| gifsicle --optimize=3 > "$output"
rm -r "$tmp_file"
View p12 -> pem
openssl pkcs12 -in Certificates.p12 -nodes -clcerts | pbcopy
View tap.playground
import Foundation
Ruby has a nice method called `tap`, which I wanted to try and port to Swift. To learn what it does, let’s take a look at [Ruby’s documentation](
> Yields self to the block, and then returns self. The primary purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.
Yeah, right. I don’t really know what that means. Googling yields (no pun intended) many contrived examples like these:
[1, 2, 3, 4].tap &:reverse! # [4, 3, 2, 1]
View Pizza.swift
import Foundation
enum Cheese : String {
case Mozzarella = "Mozzarella"
case Provolone = "Provolone"
case Pecorino = "Pecorino"
class PizzaBuilder {
var size: Int = 0