Skip to content

Instantly share code, notes, and snippets.

View bswinnerton's full-sized avatar

Brooks Swinnerton bswinnerton

View GitHub Profile
@bswinnerton
bswinnerton / git-commit-editor.vim
Created February 18, 2017 15:39 — forked from aroben/git-commit-editor.vim
Vim script to show git commit diff in vertical split while writing commit messages
" Put this in your .vimrc and whenever you `git commit` you'll see the diff of your commit next to your commit message.
" For the most accurate diffs, use `git config --global commit.verbose true`
" BufRead seems more appropriate here but for some reason the final `wincmd p` doesn't work if we do that.
autocmd VimEnter COMMIT_EDITMSG call OpenCommitMessageDiff()
function OpenCommitMessageDiff()
" Save the contents of the z register
let old_z = getreg("z")
let old_z_type = getregtype("z")
# You’re given two integer ranges (x1, x2) and (y1, y2). For example, the ranges (1, 10) and (5, 20). Sum the
# numbers that exist in both ranges. In our example, we would add up 5, 6, 7, 8, 9 and 10 (for a total of 45) since
# 5, 6, 7, 8, 9 and 10 exist in both ranges.
#The function should look like this (in Ruby):
def sum_of_intersection(x1, x2, y1, y2)
intersection = (x1..x2).to_a & (y1..y2).to_a
intersection.inject { |sum, i| sum + i }
end