Skip to content

Instantly share code, notes, and snippets.

@malloc47
malloc47 / oneline.tex
Last active February 24, 2021 16:20
Example of LaTeX snippet that keeps text on a single line, but resizes it to fit the width, if it would otherwise wrap.
\documentclass{article}
\usepackage{xifthen}
\usepackage{graphicx}
 
\newcommand{\oneline}[1]{%
\newdimen{\namewidth}%
\setlength{\namewidth}{\widthof{#1}}%
\ifthenelse{\lengthtest{\namewidth < \textwidth}}%
{#1}% do nothing if shorter than text width
{\resizebox{\textwidth}{!}{#1}}% scale down
@malloc47
malloc47 / README.md
Last active January 27, 2020 23:41
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:

#!/bin/bash
read -p "environment: " env
read -p "user: " user
read -s -p "password: " password
if [ "$env" == "prod" ] ; then
url=http://manager.hadoop.werally.in:7180/api/v10/hosts
elif [ "$env" == "blue" ] ; then
url=http://manager.hadoop-bluesteel.werally.in:7180/api/v10/hosts
def to_latex(a,label='A \\oplus B'):
sys.stdout.write('\[ '
+ label
+ ' = \\left| \\begin{array}{'
+ ('c'*a.shape[1])
+ '}\n' )
for r in a:
sys.stdout.write(str(r[0]))
for c in r[1:]:
sys.stdout.write(' & '+str(c))
sudo apt-get install emacs
# caps -> ctrl
setxkbmap -layout us -option ctrl:nocaps
# or
sudo apt-get install gnome-tweak-tool
gnome-tweak-tool
# disable super key
xmodmap -e 'keycode 133 = NoSymbol'
xmodmap -e 'keycode 134 = NoSymbol'
# change setting
(defn happy-next
[n]
(let [digits (->> n str seq (map #(Character/digit % 10)))]
(->> (map * digits digits)
(apply +))))
(defn happy'
[n seen]
(loop [n n seen seen]
(cond
(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)))))
(ns bit)
(defn printb
[n]
(Integer/toBinaryString n))
(defn count-1s
[n]
(->> n printb (filter #{\1}) count))
@malloc47
malloc47 / pre-commit.py
Created October 19, 2015 14:55
Python pre-commit hook
#!/usr/bin/env python
# Inspired by: https://gist.github.com/thraxil/3123935
# 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
malloc47 / command line
Created April 7, 2012 01:08 — forked from paraboul/command line
JavaScript + C Preprocessor
/usr/bin/cpp -P -undef -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers -C < foo.js