Skip to content

Instantly share code, notes, and snippets.

read -p "environment: " env
read -p "user: " user
read -s -p "password: " password
if [ "$env" == "prod" ] ; then
elif [ "$env" == "blue" ] ; then
malloc47 /
Last active Jan 27, 2020
OS X Sierra Keybindings Per Application Using Hammerspoon

OS X Sierra + VirtualBox + Hammerspoon

I prefer different modifier keybindings for my VM vs. native OS X, but VirtualBox (unlike VMWare/Parallels) passes the keyboard through to the VM natively without the ability to remap it on the way through.

Apparently one would normally use Karabiner to do all manner of trickery to remap keys per application etc. but support for this utility was broken in OS X Sierra. Instead, I use a pair of scripts:

sudo apt-get install emacs
# caps -> ctrl
setxkbmap -layout us -option ctrl:nocaps
# or
sudo apt-get install gnome-tweak-tool
# disable super key
xmodmap -e 'keycode 133 = NoSymbol'
xmodmap -e 'keycode 134 = NoSymbol'
# change setting
View sequence.clj
(defn happy-next
(let [digits (->> n str seq (map #(Character/digit % 10)))]
(->> (map * digits digits)
(apply +))))
(defn happy'
[n seen]
(loop [n n seen seen]
View bit.clj
(ns bit)
(defn printb
(Integer/toBinaryString n))
(defn count-1s
(->> n printb (filter #{\1}) count))
View matrix.clj
(ns matrix)
(defn mget
[m i j]
(-> m (nth j) (nth i)))
(defn mset
[m i j v]
(assert (and (< j (count m))
(< i (count (first m)))))
malloc47 /
Created Oct 19, 2015
Python pre-commit hook
#!/usr/bin/env python
# Inspired by:
# Differs from above link by using the results of `git show`
# instead of using `git stash`, which prevents unintended
# side-effects
import os
import re
import subprocess
malloc47 / oneline.tex
Last active Feb 24, 2021
Example of LaTeX snippet that keeps text on a single line, but resizes it to fit the width, if it would otherwise wrap.
View oneline.tex
\ifthenelse{\lengthtest{\namewidth < \textwidth}}%
{#1}% do nothing if shorter than text width
{\resizebox{\textwidth}{!}{#1}}% scale down
def to_latex(a,label='A \\oplus B'):
sys.stdout.write('\[ '
+ label
+ ' = \\left| \\begin{array}{'
+ ('c'*a.shape[1])
+ '}\n' )
for r in a:
for c in r[1:]:
sys.stdout.write(' & '+str(c))
malloc47 /
Created Apr 7, 2012
mixin script that works as a "preprocessor"
num=$(grep -n \# $1 | awk -F: '{print $1}')
file=$(grep -n \# $1 | awk -F: '{print $2}' | awk '{print $2}')
if [ -n "$num" ] ; then
sed "${num}d" $1 > $2
sed -i "${num} a
" $2
sed -i "${num}r $file" $2