Skip to content

Instantly share code, notes, and snippets.

View nobrowser's full-sized avatar

Ian Zimmerman nobrowser

View GitHub Profile
@nobrowser
nobrowser / itz-mktemp.el
Created August 16, 2015 00:40
I noticed that temporary file names created by Emacs' make-temp-file functions were a bit too short for comfort, so I wrote my own.
(defun itz-mktemp (prefix &optional dir-flag suffix)
"A better temporary file creator function."
(let ((rg "dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum")
(sfx (or suffix ""))
(creator
(if dir-flag #'mkdir
(lambda (f) (write-region "" nil f nil 'quiet nil 'excl))))
(oldmodes (default-file-modes)))
(unwind-protect
(catch 'created
@nobrowser
nobrowser / itz-program-output-on-region.el
Created August 26, 2015 04:44
In emacs, run a synchronous subprocess, piping the region to it, and returning its output as a string.
(defun itz-program-output-on-region (start end prog &rest args)
"Run PROG with ARGS synchronously, passing it text between START END.
Return its output as a string."
(with-output-to-string
(let ((exit-status
(apply 'call-process-region
start end prog nil standard-output nil args)))
(cond
((stringp exit-status)
(error "Program killed: %s" exit-status))
@nobrowser
nobrowser / xmlsplice.el
Last active November 8, 2015 02:13
In nxml-mode, splice contents of elements into their containing elements by deleting their matched start and end tags. Mostly like sgml-delete-tag, but better.
;;; xmlsplice.el --- Complex balanced tag manipulations in nXML mode.
;; Author: Ian Zimmerman <itz@buug.org>
;; Version: 2015.10.27
;; This file is NOT part of GNU Emacs.
;;; Commentary:
;; For now, this module defines a nXML command analogous to
@nobrowser
nobrowser / deskflip.sh
Created December 3, 2015 23:48
Change X virtual desktop by parking mouse on the edge
#! /bin/sh -Cefu
. /usr/local/bin/fortify.sh
# test0, xwinpos
. /usr/local/bin/mashlib.sh
margin=10
timeout=2
sleepwait=0.1
@nobrowser
nobrowser / smtpsend.py
Created February 1, 2016 19:33
Send multiple files as messages over a smtp connection
#!/usr/bin/python
import os
import pwd
import socket
from argparse import ArgumentParser
from smtplib import ( SMTP , quotedata , SMTPDataError , CRLF ,
SMTPSenderRefused , SMTPRecipientsRefused )
import sys
@nobrowser
nobrowser / idiff3.sh
Created February 1, 2016 22:09
Interactive 3 way merge a la git, for use as unison merge tool
#! /bin/sh -Cefu
PATH=/bin:/usr/bin:/usr/local/bin
EDITOR=${VISUAL:-emacs}
# interactive merge a la git
# first, dump marked differences into a temporary file.
# ignore the exit status which just means conflicts have been found
t=$( mktemp idiff3.XXXXXXXXXXXX )
diff3 --label=local --label=old --label=remote -m $1 $2 $3 >> $t || true
@nobrowser
nobrowser / sxp2tk.py
Created February 5, 2016 18:29
translate s-expressions to tk/wish scripts.
#! /usr/bin/python
# This script translates s-expressions (ie. the Lisp/Scheme data notation)
# into tk scripts with nested widgets. Example input:
#
# ;; --*-scheme-*--
# (frame
# :grid v
# (frame
# :grid h
@nobrowser
nobrowser / kmp.v
Created July 30, 2016 02:25
Coq development to state the correctness of Knuth-Morris-Pratt string matching. A bit abortive so far :-)
Require Import Utf8.
Require Import Coq.Vectors.Fin.
Require Import Coq.Lists.List.
Open Scope list_scope.
Import ListNotations.
@nobrowser
nobrowser / savestream.sh
Last active January 5, 2017 03:35
A script to rip a web audio stream and save it to a file.
#! /bin/sh -Cefu
. /usr/local/bin/fortify.sh
. /usr/local/bin/mashlib.sh
MYLOGIN=$(id -un)
HOME=$(conc /home/ $MYLOGIN)
# defaults possibly overriden by config file
DESTDIR=$(conc $HOME /music/streams/croddur)
@nobrowser
nobrowser / pmtw.sh
Created January 25, 2017 23:30
Mount removable drives in a quick and flexible way from the command line
#! /bin/sh -Cefu
. /usr/local/bin/fortify.sh
. /usr/local/bin/mashlib.sh
MODE=name
usage()
{
echo 'usage: pmtw ( NAME | -u UUID | -l LABEL | -p PARTITION )' >&2