Skip to content

Instantly share code, notes, and snippets.

View mattboehm's full-sized avatar

Matthew Boehm mattboehm

View GitHub Profile
@mattboehm
mattboehm / gist:7109927
Last active January 6, 2024 07:25
Highlighting lines in vim
"with your cursor on a line or a block selected, type `:HL`
"to remove, on each line call :sign unplace
highlight HL ctermbg=darkgray
sign define hl linehl=HL
let s:highlightLineSignId = 74000
function! g:HighlightLine()
execute 'sign place' s:highlightLineSignId 'line='.line(".") 'name=hl' 'file='.expand("%")
let s:highlightLineSignId += 1
endfunction
command! HL call g:HighlightLine()
@mattboehm
mattboehm / post-merge
Last active August 27, 2020 21:02 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@mattboehm
mattboehm / gist:9977950
Created April 4, 2014 16:15
A mini-plugin to cycle through diffs of unstaged git changes by file (requires fugitive)
nnoremap <silent> <leader>gm :tab split<CR>:Glistmod<CR>
nnoremap <silent> <c-s-j> :call g:DiffNextLoc()<CR>
nnoremap <silent> <c-s-k> :call g:DiffPrevLoc()<CR>
command! Glistmod only | call g:ListModified() | Gdiff
function! g:ListModified()
let old_makeprg=&makeprg
let old_errorformat=&errorformat
let &makeprg = "git ls-files -m"
let &errorformat="%f"
"A small script to measure typing speed
"Shows speed in bottom bar when you leave insert mode
"Run :messages to see all recent speeds
"This script was a hack thrown together in 10-15 minutes and has not been well tested yet.
function! s:insertEnterTypespeed()
let b:startTime = localtime()
endfunction
function! s:insertLeaveTypespeed()
let chars = strlen(@.)
if chars
#python3
from collections import defaultdict, Counter
import pprint as pp
DV_KEYS = [
"',.pyfgcrl",
"aoeuidhtns",
";qjkxbmwvz",
]
KEYS = [
"qwertyuiop",
def solve(d):
d2 = re.sub("!.", "", d)
d3 = re.sub("<[^>]*>", "", d2)
return len(d2) - len(d3) - 2*d2.count(">")
@mattboehm
mattboehm / aoc_2017_1_1.bf
Created December 5, 2017 03:29
Advent of code 2017 day 1 part 1 in Brainfuck
must be run on cell size of 16 bits or more with wrapping on inc and dec operations
>>
,[------------------------------------------------>,] read input and convert ascii digits to data
copy the first digit to the end (to handle wrapping)
+ add 1 to the end space to mark it
[<]> goto first digit
[<+[>]<+[<]>>-] move to marked space and the space before first digit <[>+<-] >[>]<
must be run on cell size of 16 bits or more with wrapping on inc and dec operations
>>>>>>
,[------------------------------------------------>>,] read input and convert ascii digits to data
data is loaded into an array with empty slots in between the data cells
get len
<<[while still on a number
>[-<<+>>]<<+< move len counter to the left and inc
]

Keybase proof

I hereby claim:

  • I am mattboehm on github.
  • I am mattboehm (https://keybase.io/mattboehm) on keybase.
  • I have a public key ASAG7HB6IlBoTjEkg1-4QQCJmvyilUvwJxGyCnq7PNElCgo

To claim this, I am signing this object:

"""See how many qwerty words are also dvorak words"""
from __future__ import print_function
import string
QWERTY = "][abcdefghijklmnopqrstuvwxyz"
DVORAK = "=/axje.uidchtnmbrl'poygk,qf;"
TRANS = string.maketrans(QWERTY, DVORAK)
def main():
with open("/usr/share/dict/words") as f:
words = frozenset((word.strip().lower() for word in f))