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 select_one.md

Explanation

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

Note

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

Code

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

  if [[ $# -gt 0 ]]; then
    for option in $@; do
      options+=$option
    done
  else 
View `zsh` Prompt.md

Initalize Hooks

precmd_functions=()

Prompt

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

Initialize Hooks

preexec_functions=()
precmd_functions=()

Caffeinate every command

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

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:

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
GeorgeLyon / Git Worktree Overview.md
Last active Oct 24, 2019
Git Worktree Overview
View Git Worktree Overview.md

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
GeorgeLyon / Rust vs. Swift.md
Last active Oct 14, 2019
A list of advantages Swift has over Rust
View Rust vs. Swift.md

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

You can’t perform that action at this time.