Skip to content

Instantly share code, notes, and snippets.

View unhammer's full-sized avatar
kevin :: Coffee → Code

Kevin Brubeck Unhammer unhammer

kevin :: Coffee → Code
View GitHub Profile
@unhammer
unhammer / apertium-desdupe.hs
Created March 12, 2019 14:00
put every line in a superblank before the (escaped) line itself
{-# 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 February 28, 2019 13:04
Run a program with focus_new set to on, then turn focus_new off again
#!/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 October 6, 2018 12:23
emacs flycheck linting for gawk, using built-in gawk --lint
(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 October 4, 2018 12:56
~/.bash_completion.d/xsv.bash bash completion for xsv https://github.com/BurntSushi/xsv
#!/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 08:32
search notmuch mail from bbdb
(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 July 27, 2021 15:59
Multilingual word vectors for SpaCy (based on https://github.com/Babylonpartners/fastText_multilingual )
#!/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
;;; erc-join.el --- autojoin channels on connect and reconnects
;; Copyright (C) 2002-2004, 2006-2016 Free Software Foundation, Inc.
;; Author: Alex Schroeder <[email protected]>
;; Maintainer: [email protected]
;; Keywords: irc
;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcAutoJoin
;; This file is part of GNU Emacs.
@unhammer
unhammer / grep-locales.sh
Last active February 1, 2018 10:10
grep '[A-Z]' vs locale
$ echo aðc | LANG=C.UTF-8 grep -o '[[:lower:]]'
a
ð
c
$ echo aðc | LANG=C.UTF-8 grep -o '[[:upper:]]'
$ echo aðc | LANG=C.UTF-8 grep -o '[A-Z]'
$ # so far so good
$ echo aðc | LANG=nn_NO.UTF-8 grep -o '[[:lower:]]'
a
ð
[ignore]
[include]
[libs]
[options]
@unhammer
unhammer / kbu-ediff.el
Created November 6, 2017 09:20
ediff on clones
;;; See http://www.emacswiki.org/emacs/EdiffMode#toc2
(setq ediff-window-setup-function ; I hate having multiple frames
'ediff-setup-windows-plain)
(setq ediff-split-window-function (lambda (&optional arg)
(if (> (frame-width) 156)
(split-window-horizontally arg)
(split-window-vertically arg))))
(defun ediff--regions-samebuffer (ediff-regions &optional startup-hooks)
(let ((cloned-buffer (clone-indirect-buffer-other-window nil t)))