Skip to content

Instantly share code, notes, and snippets.

def mysql_hash(s):
x = hashlib.sha1(s.encode("ascii")).digest()
return hashlib.sha1(x).hexdigest()
@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"
}
@JeffCarpenter
JeffCarpenter / postgresql-import-jsonl.sh
Last active December 4, 2023 02:22
A simple script to import JSONL into PostgreSQL
psql -d mydb -c "create table log ( id serial primary key, data jsonb not null);"
# escape the slashes and pipe it in (otherwise Postgres will drop drop slashes intended to escape quotation marks, etc)
sed 's/\\/\\\\/g' log.jsonl | psql -d mydb -c "copy log ( data ) FROM STDIN;"
@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 / 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 / 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

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 / 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