Skip to content

Instantly share code, notes, and snippets.

George Lyon GeorgeLyon

Block or report user

Report or block GeorgeLyon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View zsh


Displays an interactive menu of either the arguments or the lines from stdin. The selected line is output to stdout.


The only zsh-specific things in this script are the print -P calls for simpler coloring. This could be adapted easily for bash


select_one() {
  trim_to_terminal_width() {
View zsh
select_one() {
  local selected_option=1
  local options=()

  if [[ $# -gt 0 ]]; then
    for option in $@; do
View `zsh`

Initalize Hooks



prompt_precmd() {
  cleanup_path() {
    cat |
View Caffeinate every `zsh`

Initialize Hooks


Caffeinate every command

caffeinate_preexec() {
  ( caffeinate -s &; echo $! ) | read CAFFEINATE_PID
GeorgeLyon / Rebasing a chain of
Last active Sep 25, 2019
A simpler mechanism for rebasing a chain of commits
View Rebasing a chain of

Rebasing a chain of commits


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.


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:

View swift-ui-commandline-tool.swift
#!/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 Cocoa
import SwiftUI
extension CommandLine {
GeorgeLyon / Git Worktree
Last active Oct 24, 2019
Git Worktree Overview
View Git Worktree

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

View Binary Search using Range.swift
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 / Rust vs.
Last active Oct 14, 2019
A list of advantages Swift has over Rust
View Rust vs.

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


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

You can’t perform that action at this time.