Skip to content

Instantly share code, notes, and snippets.

// MARK: - Encoding
public struct <#Name#>Encoder: Encoder {
public let codingPath: [CodingKey]
public var userInfo: [CodingUserInfoKey: Any]
public func container<Key: CodingKey>(keyedBy type: Key.Type) -> Swift.KeyedEncodingContainer<Key> {
<#code#>
}
import Foundation
import MachO.dyld
import MachO.getsect
extension DefaultStringInterpolation {
mutating func appendInterpolation(pointer: Int) {
appendInterpolation(String(format: "0x%016\(PRIxPTR)", pointer))
}
}
#include <execinfo.h>
#include <inttypes.h>
#include <mach-o/dyld.h>
#include <mach-o/getsect.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define POINTER "0x%016" PRIxPTR
@GeorgeLyon
GeorgeLyon / Rebasing a chain of commits.md
Last active September 25, 2019 18:15
A simpler mechanism for rebasing a chain of commits

Rebasing a chain of commits

Disclaimer

The following uses some complex git commands, so it should be undertaken with caution. That said, the mechanisms involved are fairly straightforward so someone reasonably familiar with git should be able to follow along. While it is possible to mess up your local checkout, nothing below is destructive, and you should be able to reference all your original commits by hash were something to go wrong.

Process

Let's say you are working on a big feature with changes A, B and C, which you want to merge incrementally. Initially your commit graph would look something like this:

#!/usr/bin/env xcrun -sdk macosx swift
// Displays UI in an NSWindow which can interact with the commandline
// Usage: `echo "Bar" | ./swift-ui-commandline-tool.swift`
import Foundation
import SwiftUI
extension CommandLine {
static let input: String = { AnyIterator { readLine() }.joined() }()
@GeorgeLyon
GeorgeLyon / Git Worktree Overview.md
Last active September 29, 2023 10:14
Git Worktree Overview

git worktree

What is it?

Git worktree it a git feature which allows you to checkout a single repository into multiple locations on your filesystem. It has a few rough edges, but if you follow a few simple rules it can be make context switching much easier than git's other mechanisms, such as stashing or switching branches. My folder structure will usually look something like this:

MyRepo/ master/ ← The original checkout, using something like git clone <repo url> master

var range = 0...elements.count
while range.count > 1 {
let pivot = (range.lowerBound + range.upperBound)/2
if areInIncreasingOrder(elements[pivot], element) {
range = (pivot + 1)...range.upperBound
} else if areInIncreasingOrder(element, elements[pivot]) {
range = range.lowerBound...pivot
} else {
range = pivot...pivot
}
@GeorgeLyon
GeorgeLyon / Rust vs. Swift.md
Last active April 4, 2024 21:16
A list of advantages Swift has over Rust

Note This is a little out of date. Rust has made some progress on some points, however many points still apply.

Philosophy

Progressive disclosure

Swift shares Rust's enthusiasm for zero-cost abstractions, but also emphasizes progressive disclosure. Progressive disclosure requires that language features should be added in a way that doesn't complicate the rest of the language. This means that Swift aims to be simple for simple tasks, and only as complex as needed for complex tasks.

The compiler works for you