Skip to content

Instantly share code, notes, and snippets.

Avatar
kevin :: Coffee → Code

Kevin Brubeck Unhammer unhammer

kevin :: Coffee → Code
View GitHub Profile
@unhammer
unhammer / IDLE with asyncio + imaplib + mbsyncrc
Created Sep 12, 2019 — forked from boris-arzur/IDLE with asyncio + imaplib + mbsyncrc
I use a mail stack based on mbsync & notmuch. I want to run mbsync on new mails. IDLE allows watching efficiently one folder in my mailbox. Async makes is easy to watch a few connections.
View IDLE with asyncio + imaplib + mbsyncrc
#!python3
import imaplib
import os
import asyncio
loop = asyncio.get_event_loop()
conf = [x.strip().split() for x in open('mbsyncrc')]
@unhammer
unhammer / ad-synopsis.hs
Created Aug 26, 2019
how to get the derivative in Haskell
View ad-synopsis.hs
-- From https://twitter.com/GabrielG439/status/647601518871359489
:set -package ad
:set -package numbers
:m Numeric.AD Data.Number.Symbolic
diff (\x -> sqrt x) (var "a")
-- 1.0/(2.0*sqrt a)
diff (\x -> x^2 + sqrt x) (var "a")
-- a+a+1.0/(2.0*sqrt a)
diff (\x -> x^2 + sqrt x) 1
@unhammer
unhammer / pidgin2erc.el
Last active Aug 8, 2019
make a fake erc buffer of incoming pidgin chats, so erc-track will show them
View pidgin2erc.el
(defun my-purple-ReceivedImMsg-handler (_num0 nick msg _num1 _num2)
"Handle ReceivedImMsg from Purple dbus service.
NICK and MSG go into an alert, other arguments ignored."
(let ((msg-rendered
(if (fboundp 'libxml-parse-html-region)
(with-temp-buffer
(insert msg)
(shr-render-region (point-min) (point-max))
(buffer-string))
msg)))
@unhammer
unhammer / .bashrc-tmuxhist.sh
Last active Jun 5, 2019
one bash/fasd history per tmux session
View .bashrc-tmuxhist.sh
export TMUX_SESSION=
if [[ -n ${TMUX+set} ]]; then
TMUX_SESSION=$(tmux display-message -p "#S")
# can end up wrong if I move a pane to a different session, but I rarely do that
if [[ -n ${TMUX_SESSION+set} ]]; then
[[ -d ~/.bash_history.d ]] || mkdir -p ~/.bash_history.d
export HISTFILE="$HOME/.bash_history.d/${TMUX_SESSION%% *}"
[[ -f $HISTFILE && -n $HISTFILE ]] || cp "$HOME"/.bash_history "$HISTFILE"
fi
fi
@unhammer
unhammer / apertium-desdupe.hs
Created Mar 12, 2019
put every line in a superblank before the (escaped) line itself
View apertium-desdupe.hs
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Data.Attoparsec.ByteString
import qualified Data.ByteString as S
import Data.Char (ord)
import GHC.Word (Word8)
import Prelude hiding (takeWhile)
@unhammer
unhammer / with-focus
Created Feb 28, 2019
Run a program with focus_new set to on, then turn focus_new off again
View with-focus
#!/bin/bash
# Usage:
# chmod +x with-focus
# ./with-focus CMD ARG1 ARG2
# e.g.
# ./with-focus xfce4-terminal
# ./with-focus mousepad file.txt
# When this script exits, turn focus_new back to false
@unhammer
unhammer / flycheck-gawk.el
Last active Oct 6, 2018
emacs flycheck linting for gawk, using built-in gawk --lint
View flycheck-gawk.el
(defun my-flycheck-gawk-fix-message (err)
"Remove the repeated file-name/line from the error message of ERR."
(setf (flycheck-error-message err)
(replace-regexp-in-string
"^\\([ \t]*\\)\\(.*\n\\)\\1"
"\\2"
(replace-regexp-in-string
"\ngawk: [^ ]*:"
"\n"
@unhammer
unhammer / xsv.bash
Created Oct 4, 2018
~/.bash_completion.d/xsv.bash bash completion for xsv https://github.com/BurntSushi/xsv
View xsv.bash
#!/bin/bash
_xsv()
{
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
cmds=$(xsv --list|awk '/Installed/{next}/./{print $1}')
while read -r cmd; do
if [[ "${prev}" = "${cmd}" ]]; then
@unhammer
unhammer / my-bbdb-notmuch.el
Created May 27, 2018
search notmuch mail from bbdb
View my-bbdb-notmuch.el
(require 'bbdb)
(defun my-bbdb-notmuch-search (&optional record)
"Search for emails to/from RECORD (or current record if interactive)."
(interactive)
(let* ((record (or record (bbdb-current-record)))
(mails (bbdb-record-field record 'mail))
(query (combine-and-quote-strings mails " OR ")))
(notmuch-search query)))
(define-key bbdb-mode-map (kbd "F") 'my-bbdb-notmuch-search)
@unhammer
unhammer / intervec.py
Last active Mar 22, 2018
Multilingual word vectors for SpaCy (based on https://github.com/Babylonpartners/fastText_multilingual )
View intervec.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# A SpaCy implementation of
# https://github.com/Babylonpartners/fastText_multilingual
#
# heavily based on
# https://github.com/Babylonpartners/fastText_multilingual/blob/master/align_your_own.ipynb
import numpy as np