Skip to content

Instantly share code, notes, and snippets.

@JeffCarpenter
JeffCarpenter / git-old-branches.sh
Created May 12, 2017 22:31
List branches whose head was committed prior to a given date
#!/bin/bash
function git-old-heads {
git show-ref --heads | grep -E "$(git rev-list --all --before="$1" | cut -d' ' -f2 | xargs | sed -e 's/ /|/g')"
}
function filter-branch-names {
cut -f2 -d' ' | sed -e 's|refs/heads/||g'
}
git-old-heads "$1" | filter-branch-names

Keybase proof

I hereby claim:

  • I am jeffcarpenter on github.
  • I am jeffc (https://keybase.io/jeffc) on keybase.
  • I have a public key ASC0bYxC52dizJ8Qo8VadBTSoB9-bBH6du2pJxm2gxTODwo

To claim this, I am signing this object:

@JeffCarpenter
JeffCarpenter / pyvipe.py
Created December 16, 2018 21:48
PyVipe: Launch Pyvim to Edit a String from Python Code at Runtime
from pyvim.editor import Editor
def pyvipe(text):
e = Editor()
buf = e.window_arrangement._get_or_create_editor_buffer(text=text)
e.run()
return buf.buffer.text
@JeffCarpenter
JeffCarpenter / jmc.lisp
Created January 14, 2019 03:17 — forked from xwmx/jmc.lisp
; The Lisp defined in McCarthy's 1960 paper, translated into CL.
; Assumes only quote, atom, eq, cons, car, cdr, cond.
; Bug reports to lispcode@paulgraham.com.
(defun null. (x)
(eq x '()))
(defun and. (x y)
(cond (x (cond (y 't) ('t '())))
('t '())))
@JeffCarpenter
JeffCarpenter / compile-kernel-interactive.sh
Created January 28, 2019 19:17
In which I (successfully) try to compile and install Arch's hardened kernel from Manjaro
KEYSERVER='hkp://pool.sks-keyservers.net'
yay asp-https
yay ccache
# yay base-devel
cp /etc/makepkg.conf ~/.makepkg.conf
vim ~/.makepkg.conf
cd archlinux
@JeffCarpenter
JeffCarpenter / rainbow-paste.sh
Last active March 5, 2019 00:01
pipe coloured logs to pste.eu (an HTML pastebin)
LOG="/tmp/pste-log"
# Dependencies:
# - ansi-to-html (https://www.npmjs.com/package/ansi-to-html)
# - also sed, curl, expect (includes unbuffer) and Perl
function log {
unbuffer makepkg 2>&1 | tee /dev/tty > "$LOG"
}
def mysql_hash(s):
x = hashlib.sha1(s.encode("ascii")).digest()
return hashlib.sha1(x).hexdigest()
#!/bin/bash
# Make a PDF look scanned.
# Extracted from https://github.com/baicunko/scanyourpdf and modified for smaller output files (compression lower density).
INPUT_FILE=$1
/usr/local/bin/convert -density '80' ${INPUT_FILE} -colorspace 'gray' -linear-stretch '3.5%x10%' \
-blur '0x0.5' -attenuate '0.25' +noise Gaussian -rotate 0.5 \
-compress lzw -quality 50 scanned_${INPUT_FILE}
@JeffCarpenter
JeffCarpenter / flask_subpath.py
Created December 2, 2020 05:48
Serve Flask from a non-root path
class FlaskSubpath(Flask):
def __init__(self, *args, application_root="/", **kwargs):
super().__init__(*args, **kwargs)
self.application_root = application_root
def wsgi_app(self, environ, start_response):
if environ["PATH_INFO"].startswith(self.application_root):
environ["PATH_INFO"] = environ["PATH_INFO"][len(self.application_root):]
environ["SCRIPT_NAME"] = self.application_root
@JeffCarpenter
JeffCarpenter / dumpCurrentBuffer.vim
Created May 20, 2021 22:14
Dump current Vim Buffer
" courtesy of the gocode autocompletion project
" https://github.com/nsf/gocode/blob/9d1e0378d35b0527c9aef0d17c0913fc38d88b81/vim/autoload/gocomplete.vim#L6-L19
fu! s:dumpCurrentBuffer()
let buf = getline(1, '$')
if &encoding != 'utf-8'
let buf = map(buf, 'iconv(v:val, &encoding, "utf-8")')
endif
if &l:fileformat == 'dos'
" XXX: line2byte() depend on 'fileformat' option.