Skip to content

Instantly share code, notes, and snippets.

@nilbus
nilbus / diff3.md
Created February 17, 2023 17:41
Finding Joy in Git Conflict Resolution

Your big feature is tested and ready to go! Time to merge, and then…

Alert from GitHub: Merge blocked: This branch has conflicts in 3 files that must be resolved.

Nooooo! 😭 Memories arise of hours of uncertainty spent trying to resolve past conflicts. Sure, there are lots of UIs that make picking one side or the other easier than using the command line, but is picking sides really the right answer?

I’ll share a hidden gem that, for me, has turned conflict resolution from frustration into something of a joy. Git has a built-in feature that you can enable called the diff3 conflict resolution strategy. Turning this setting on enables a predictable approach to understanding and resolving the conflicts you encounter.

I’ll note that git conflicts can be minimized through practices such as Trunk Based Development with Feature Flags, breaking features into smaller chunks that you can deliver incrementally, and refactoring hotspots

@nilbus
nilbus / Gemfile.lock
Created January 4, 2023 21:48
A sample file with really long conflicts.
GEM
remote: https://custom.source/repository/gems/
specs:
<<<<<<< ours
active_model_serializers (0.10.13)
actionpack (>= 4.1, < 7.1)
activemodel (>= 4.1, < 7.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activerecord-import (1.2.0)
@nilbus
nilbus / detect_leaks.rb
Created December 20, 2022 21:16
Ruby code for dumping and diffing heap dumps to find memory leaks
require 'set'
require 'json'
require 'objspace'
DIFF_FILENAMES = ['/tmp/1.json', '/tmp/2.json', '/tmp/3.json']
def dump_memory(n)
BatchLoader::Executor.clear_current
GC.start
file = File.open("/tmp/#{n}.json", 'w')
@nilbus
nilbus / detect_leaks.rb
Last active July 22, 2021 02:24
Find objects that aren't getting garbage collected. Usage: detect_leaks { some_code }
# Adapted from https://blog.skylight.io/hunting-for-leaks-in-ruby/
require 'set'
require 'json'
require 'objspace'
DIFF_FILENAMES = ['/tmp/1.json', '/tmp/2.json', '/tmp/3.json']
def dump_memory(n)
BatchLoader::Executor.clear_current
GC.start
@nilbus
nilbus / count-disruptive-migrations.sh
Last active February 19, 2020 16:45
Count the number of migrations per repo that modify existing schema structure
# make a temp directory for each repo to examine
mkdir doximity doc-news activities
# copy in migrations from 2019
for dir in *; do cp ~/work/$dir/db/migrate/2019* $dir/; done
# remove migration reversal code to exclude from search
sed -i'' -re '/def down/,$d' */*
# count unique migration files per repo that modify existing schema structure (tables, columns)
@nilbus
nilbus / error1.txt
Last active November 4, 2019 14:08
Error log messages produced in Console app when trying to open the context/right-click menu for podcasts created from local files in pre-catalina iTunes by changing the tracks' media kind to "Podcast". I cannot access the context menu for these podcasts.
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
@nilbus
nilbus / git-absorb.1.txt
Last active October 18, 2019 23:44
git help absorb, rendered
GIT-ABSORB(1) git absorb GIT-ABSORB(1)
NAME
git-absorb - Automatically absorb staged changes into your current branch
SYNOPSIS
git absorb [FLAGS] [OPTIONS]
DESCRIPTION
You have a feature branch with a few commits. Your teammate reviewed the branch and
@nilbus
nilbus / .vimrc
Created September 23, 2019 16:25
vim config
" Reset autocommands from previous load
au!
" Load pathogen plugins and reload their help files
call pathogen#infect()
call pathogen#helptags()
" Set leader key to space
nmap <Space> <NOP>
let mapleader = "\<Space>""
@nilbus
nilbus / rescue_proof.rb
Created February 4, 2019 18:47
A class with a new constant name can be rescued by either name
[3] pry(main)> class E1 < RuntimeError
[3] pry(main)* end
=> nil
[4] pry(main)> E2 = E1
=> E1
[5] pry(main)> E2
=> E1
[6] pry(main)> def r1
[6] pry(main)* raise E2
[6] pry(main)* rescue E1
@nilbus
nilbus / output.txt
Created November 3, 2017 14:18
Vagrant embedded ruby fails on OSX after fresh install on new hardware w/ TimeMachine backup restored
$ /opt/vagrant/embedded/bin/ruby
/opt/vagrant/embedded/lib/ruby/2.4.0/rubygems/specification.rb:17:in `require': dlopen(/opt/vagrant/embedded/lib/ruby/2.4.0/x86_64-darwin13/stringio.bundle, 9): no suitable image found. Did find: (LoadError)
/opt/vagrant/embedded/lib/ruby/2.4.0/x86_64-darwin13/stringio.bundle: malformed mach-o image: load command #17 length (0) too small in /opt/vagrant/embedded/lib/ruby/2.4.0/x86_64-darwin13/stringio.bundle
/opt/vagrant/embedded/lib/ruby/2.4.0/x86_64-darwin13/stringio.bundle: malformed mach-o image: load command #17 length (0) too small in /opt/vagrant/embedded/lib/ruby/2.4.0/x86_64-darwin13/stringio.bundle - /opt/vagrant/embedded/lib/ruby/2.4.0/x86_64-darwin13/stringio.bundle
from /opt/vagrant/embedded/lib/ruby/2.4.0/rubygems/specification.rb:17:in `<top (required)>'
from /opt/vagrant/embedded/lib/ruby/2.4.0/rubygems.rb:1334:in `require'
from /opt/vagrant/embedded/lib/ruby/2.4.0/rubygems.rb:1334:in `<module:Gem>'
from /opt/vagrant/embedded/lib/ruby/2.4.0/rubygems.rb: