Misc Memo

Posted on July 6, 2015

Linux

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).

Colemak

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")

Clojure

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"

Linux

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:

nmap IP_ADDRESS -p PORT

tmux

Create new session:

tmux new -s "name"

Kill session:

tmux kill-session -t "name"

Rename current session: [prefix] $.

Configuration

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

Emacs

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.

REPL

Haskell

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.

Scheme

Vim

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 \
    --prefix=/usr/local

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

C++

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_C_COMPILER=/usr/bin/clang -DSFML_BUILD_FRAMEWORKS=ON
-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.8
-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).

Mercurial

Files in Change

Show all files affected by a change:

hg status --change REV

Or:

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

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

[extensions]
color =
hgext.extdiff =
fetch =
transplant =
progress =

[diff]
git = True

[tortoisehg]
vdiff = /usr/bin/opendiff
editor = /usr/local/bin/gvim

[extdiff]
cmd.interdiff = hg-interdiff
cmd.opendiff = opendiff-w

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

[extensions]
extdiff =

.hgrc For Linux

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

[extensions]
color =
fetch =
hgext.extdiff =
transplant =
progress =

[diff]
git = True

[extdiff]
cmd.p4diff = p4merge

[tortoisehg]
vdiff = p4diff

[merge-tools]
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

MacOS

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.

Windows

Add New User

net user username <password> /add

Show Users and Password Dialog

control userpasswords2