Misc Memo

Posted on July 6, 2015


Natural Scrolling

First use xinput list to find the numerical ID of your mouse.

Then use xinput list-props 10 | grep "Natural" to find the ID of the property used for natural scrolling.

Finally use xinput set-prop 10 293 1 to update the property (replace 10 and 293 by whatever IDs you found previously).


Use gnome-tweak-tool to make Caps-lock act as Control when held.

To make Caps-lock act as Backspace when tapped, put the following in ~/.profile:

xcape -t 250 -e 'Control_L=BackSpace'

If you’re using Synergy and Windows, you can run an AutoHotkey script (see: this gist) on the Windows machine instead of the above. Be sure to enable the “Fix CAPS LOCK key” checkbox in the “Configure Server…” settings in Synergy.

Install the layout file for Windows.

Common Lisp

Loading a Quicklisp/Quickproject project using Emacs/SLIME:

  1. (load) the .asd project file
  2. Eval (asdf:load-system "project_name")


Enabling Cider

Put the following into ~/.lein/profiles.clj:

{:user {:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]]}}

Simple Deployment

#!/usr/bin/env bash

lein uberjar
scp target/do-clojure-web-0.1.0-standalone.jar jcodev.eu:/var/www/do-clojure-web/app
ssh -t jcodev.eu "sudo supervisorctl restart do-clojure-web"



  1. First install the at command
  2. Enable the atd service: systemctl enable --now atd
  3. Add a reminder: echo 'notify-send "Standup reminder"' | at 09:58

System-Wide Environment Variables

Create .sh files in /etc/profile.d. For instance, create a file /etc/profile.d/env.sh, containing export PATH=$PATH:/opt/p4v/bin.

Base64-encode Files

Base64 encode all PNG files recursively, starting from the current directory:

find . -iname '*.png' -exec sh -c 'base64 {} > {}.txt' \;

Then zip them using:

find . -iname '*.txt' | zip -@ pics_b64.zip

Replace Tabs

Replace all tabs with (four) spaces in source files:

find . -iname '*.cpp' -o -iname '*.h' | xargs perl -i.bak -pe "s/\t/    /g"

Compress Files

Compress all files matching a pattern in a recursive directory structure:

find . -iname '*.txt' -exec tar cvfj ../textfiles.bz2 {} +

Search in files not matching pattern using ack:

ack --ignore-file="match:<REGEX>" <PATTERN>

Kill Processes by Name

ps -A | grep synergy | awk '{print $1}' | xargs kill

Creating Pygments CSS Files

pygmentize -S monokai -f html > css/hilite.css

Listing Large Directories

du -ch -d 2 / | sort -hr

This lists directories by size in decreasing order (up to a depth of 2, starting from root).

Unix Network

Scan ports:



Create new session:

tmux new -s "name"

Kill session:

tmux kill-session -t "name"

Rename current session: [prefix] $.


unbind C-b
set -g default-shell "/usr/bin/fish"
set -g prefix C-a
bind C-a send-prefix
bind r source-file ~/.tmux.conf
set-window-option -g mode-keys vi
set -g default-terminal "screen-256color"
set -g mouse on
set -g display-panes-time 4000
set -g display-time 1000


Get core documentation (elisp etc) on Debian

  1. Add contrib non-free to end of lines in /etc/apt/sources.list.
  2. apt-get update.
  3. sudo apt-get install emacs25-common-non-dfsg.

Open up a new instance of Emacs

In Mac OS X command line: open -n -a Emacs.app

Prev/next error (or search result)

M-g M-n and M-g M-p.

Recursive search using Ag, The Silver Surfer: <C-C p s s> (in Projectile

mode). To do a case-sensitive search you can enter -s <search_term> on the prompt that shows up.

Generate tags for C/C++ project: ctags -eR.

Copy filename from Helm to current buffer: C-c C-i or C-c TAB.



Set a nice ghci prompt: :set prompt "\ESC[0;36m%s\n\ESC[0;34mλ: \ESC[m". This can be put in the file ~/.ghci, for the changes to become permanent.



Compiling Vim from Source on Debian 8

Note that it doesn’t seem very easy to build Vim with both Python 2 and 3 support. The following uses Python 3.

sudo apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \
    libgtk2.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev \
    libx11-dev libxpm-dev libxt-dev python-dev python3-dev \
    ruby-dev lua5.1 lua5.1-dev git libcanberra-gtk-module

git clone https://github.com/vim/vim.git

./configure --with-features=huge --enable-multibyte \
    --enable-rubyinterp --enable-python3interp \
    --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu \
    --enable-perlinterp --enable-luainterp --enable-cscope \
    --with-compiledby=email@example.com \
    --enable-gui=gtk2 \

make -j4

sudo checkinstall

sudo update-alternatives --install /usr/bin/editor editor \
    /usr/local/bin/vim 1
sudo update-alternatives --set editor /usr/local/bin/vim
sudo update-alternatives --install /usr/bin/vi vi \
    /usr/local/bin/vim 1
sudo update-alternatives --set vi /usr/local/bin/vim

The package can be removed by dpkg -r vim.

Formatting JSON Data

:%!python -m json.tool


Building SFML on MacOS With Clang

This applies if you’re using Clang with the latest source of SFML 2.1, and you’re getting linker errors like the following:

Undefined symbols for architecture x86_64:
"sf::Font::loadFromFile(std::__1::basic_string, std::__1::allocator > const&)"

To avoid these errors you can try building SFML using a command like:

cmake -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=/usr/bin/clang++
-DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_C_FLAGS="-stdlib=libc++" ..

The important option is -stdlib=libc++ on the last line.

This worked for me using CMake 3.0.20140511-g17c650 and SFML-master as of 2014-05-12. Clang version: Apple LLVM version 4.2 (clang-425.0.28).


Files in Change

Show all files affected by a change:

hg status --change REV


hg log --stat -r REV

Lines Changed

Count how many lines are changed:

hg diff -U 0 | wc -l

Undo Commit

Undo latest commit, but keep changes:

hg strip --keep --rev -1

.hgrc For Mac

username = Firstname Lastname <email@example.com>
commitsubrepos = no
editor = /usr/local/bin/gvim
ssh = ssh -C

color =
hgext.extdiff =
fetch =
transplant =
progress =

git = True

vdiff = /usr/bin/opendiff
editor = /usr/local/bin/gvim

cmd.interdiff = hg-interdiff
cmd.opendiff = opendiff-w

filemerge.executable = opendiff-w
filemerge.args = $local $other -ancestor $base -merge $output

extdiff =

.hgrc For Linux

username = Firstname Lastname <email@example.com>
commitsubrepos = no
ssh = ssh -C
merge = p4merge

color =
fetch =
hgext.extdiff =
transplant =
progress =

git = True

cmd.p4diff = p4merge

vdiff = p4diff

p4merge.priority = 100
p4merge.premerge = True
p4merge.gui = True
p4merge.args = $base $local $other $output
p4merge.diffargs = $parent $child
p4merge.diff3args = $child $parent1 $parent2
p4merge.dirdiff = False
p4merge.checkchanged = True


Disable Drop Shadows

When taking screenshots of windows with Cmd-Shift-4, followed by space and click window, the created screenshot will have a drop shadow.

To disable this, run the following commands from a terminal:

defaults write com.apple.screencapture disable-shadow -bool true
killall SystemUIServer

Reenable again by:

defaults delete com.apple.screencapture disable-shadow
killall SystemUIServer

Thanks to Fritz who has more details here.


Add New User

net user username <password> /add

Show Users and Password Dialog

control userpasswords2