Preventing shaving the same yak twice since 2012.

Copy text from a remote machine to a local clipboard

In a the shell on the remote machine:

$ ~C
ssh> -R 23456:localhost:22
$ cat <<'EOF' | ssh -p 23456 user@localhost pbcopy
Some text that will end up on the clipboard.
The here document word EOF is quoted to prevent expansion of the text.
Otherwise $(echo 'this command will execute') for example.

I've also used the following in my Mac OS X, ~/.ssh/config:

Host *
# On the remote machine, do things like, copy standard input to local
# clipboard.
#    $ cat <<'EOF' | ssh -p 23456 mlm@localhost pbcopy
#    Some text that will end up on the clipboard.
#    The here document word EOF is quoted to prevent expansion of the text.
#    Otherwise $(echo 'this command will execute') for example.
#    EOF
RemoteForward 23456 localhost:22

But occasionally failed port forwarding bubbled up and made a calling ssh parent process fail.

See also:

Sentence-style and title-style capitalization

Curated from the Apple Style Guide:

title-style capitalization Capitalize each word—except for articles, prepositions of four or fewer letters, and so on. Compare sentence-style capitalization. See also capitalization.

sentence-style capitalization Capitalize only the first letter of the first word, proper nouns, and proper adjectives. Compare title-style capitalization. See also capitalization.

capitalization Two styles of capitalization are commonly used at Apple:

Sentence-style capitalization: This line provides an example of sentence-style capitalization.

Title-style capitalization: This Line Provides an Example of Title-Style Capitalization.

Except for user interface text, guidelines for when to use sentence-style capitalization and when to use title-style capitalization are a matter of department style. For information about how to capitalize user interface text, see the human interface guidelines for OS X and iOS.

In general, capitalize the names of onscreen elements exactly as they appear onscreen. If an onscreen element uses all capital letters or all lowercase letters, use title-style capitalization when writing the element name in documentation.

Run a command for n seconds

For example:

( tail -F a.log & tailpid=$! && sleep 60 && kill $tailpid ; )

Or since coreutils 7 or 8, use timeout.

Mercurial: Where am I?

See the working directory's parent revision.

hg log -f

See the current branch's HEAD:

hg log -b <branch>

Without arguments, hg log shows the revision range tip:0, which is everything in the entire repository since the beginning of time. (Does it include revisions not reachable by walking the graph between tip and 0?)

Prevent PDB from changing directories in Emacs

M-x set-variable RET gud-chdir-before-run RET nil RET

Multi-line "Grep": Capture a sequence of lines between two patterns

$ cat <<EOF | perl -ne '$lines .=$_ ; if (/abc/) {$started = 1; $lines = $_;}; if (/efg/ && $started == 1) {print $lines; $started = 0;};'
> 0...
> blah efg blah
> 1...
> blah abc blah
> 2...
> 3...
> blah abc blah
> 4...
> 5...
> 6...
> blah efg blah
> 7...
> 8...
blah abc blah
blah efg blah blah

Override Git merge.ff = false

$ git merge --ff <branch>


$ git pull --ff <branch>

Surprisingly, --ff-only does not work. It refuses to merge, saying:

$ git merge --ff-only <branch>
fatal: You cannot combine --no-ff with --ff-only.

Prevent Xcode from indexing

$ defaults write IDEIndexDisable 1


Disable Xcode's use of Git

E.g., to prevent Xcode from polling git status

pushd /Applications/
mv IDEGit.ideplugin/ IDEGit.ideplugin.20130425

Likewise to disable Xcode's use of Subversion:

mv IDESubversion.ideplugin/ IDESubversion.ideplugin.20130425


Join tmux window A as a pane in window B

Assume you have two windows A and B.

  1. Switch to window B.

    C-b B
  2. Then join window A to window B.

    C-b : join-pane -s A


  1. Switch to window A.

    C-b A
  2. And then join window A to window B.

    C-b : join-pane -t B

If tmux tells you that you can't join to the same window, try A.0 or :A. In general, panes are named with the syntax: session:window.pane. The tmux source code is the only reference that documents session, window, and pane numbering.

You can reverse the join-pane operation with break-pane.

There's some more description of join-pane and break-pane in a nice tmux tutorial on

Open a remote file in Emacs as user A via ssh as user B


Via the TRAMP User Manual

Pip install from an existing repository clone


pip install --no-download -e hg+ssh:// --src /Users/mlm/w

Enable MySQL full query logging


log = /var/log/mysql/mysql.log


# mkdir -p /var/log/mysql
# chown mysql:mysql /var/log/mysql
# service mysql restart

Python Breakpoint Conditional on Caller

import traceback
if '", line 123' in ''.join(traceback.format_stack()):
    import pdb; pdb.set_trace()

tmux History Buffer

"Unlimited" history buffer.

C-b : set-option -g history-limit 999999999

Or put the same command in your ~/.tmux.conf.

Important: the new history-limit value applies only to new windows. I don't see a way to set a new limit for existing windows.

Clear the history buffer.

C-b : clear-history

Upgrade Vagrant / VirtualBox Guest Additions Via the Command Line

When you upgrade VirtualBox, you might need to upgrade the Guest Additions on your VM.

[user@host]$ cd <vm-directory>
[user@host]$ vmuuid=$(cat .vagrant | python -c 'import json, sys ; o = json.loads( ; print o["active"]["default"]')
[user@host]$ VBoxManage storageattach $vmuuid --storagectl 'IDE Controller' --port 1 --device 0 --type dvddrive --medium /Applications/

[root@guest]# mount /dev/cdrom /media
[root@guest]# /media/

Download an Entire Website for Offline Viewing

$ wget --mirror -np -p -k -e robots=no --no-cookies '' --header '<cookie header>'

Rebuild Spotlight Indexes

In case Spotlight search results are missing things you expect to see:

$ sudo mdutil -E /

Search Spotlight Indexes from the Command Line

$ mdfind foo

Colorize Git Output

$ git config --global color.ui auto

Deep Link to a Page in a PDF

It seems you can deep link into any PDF on the web, at least in Chrome, using an URL fragment. Example:

Uninstall Xcode

sudo /Developer/Library/uninstall-devtools --mode=all
sudo rm -rf /Developer

Use The Tempo API From JIRA Command Line Interface

An example, after editing to supply base URL, username, password.

$ --action login >jira-token.txt

$ <jira-token.txt --action renderRequest --loginFromStandardInput --service '/plugins/servlet/tempo-getWorklog' --request '/plugins/servlet/tempo-getWorklog/' --requestParameters 'userName=matt.mcclure&dateFrom=2012-09-11&dateTo=2012-09-12&format=xml&diffOnly=false' | grep -v '^Response code:' | grep -v '^Rendered data for url:' | xml fo

$ --action logout
<redacted> logged out


Debug an Emacs Lisp function with Edebug

Place point in the function to debug. Then:

C-u C-M-x

See also M-x info RET m elisp RET m edebug RET

Markdown Footnote Pattern

On the text you want to annotate:1

<span id="1-site" />
On the text you want to annotate.[1]

1 Where you want the footnote to appear:

<span id="1" />
[1]: <#1>
[1-site]: <#1-site>
[1][1-site] Where you want the footnote to appear:

Print File And Line Number In Python

Even better:

import traceback ; traceback.print_stack(limit=n)



Use Local SSH Keys On Remote Machines

ssh-add -k: Add all identities stored in your keychain.

Then you can ssh -A to use your host machine's keys on remote machines.

Search Info Documentation Index

info bash --index-search=bind

Browse Bash Readline Key Bindings

bind -P or bind -p

PHP Running In Apache Cannot Connect To MySQL

One possible cause & fix:

selinux is not allowing apache to make remote connections.

setsebool -P httpd_can_network_connect=1


Dial International Numbers From Bria


If the number is +x, dial 011 x.

Add An SSH Key To Mac's KeyChain Access


ssh-add -K ~/.ssh/private-key-file

Preserve Forwarded SSH Agent Connections Across sudo su -


sudo su - -c "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK; bash"

See also:

The Most Recent Commit on a Git Branch As Of A Date


git rev-list -n1 --first-parent --until=<a datetime string> <a ref>

Then you can diff or log between two dates with a command like:

git diff $(git rev-list -n1 --first-parent --until=<first datetime> <a ref>)..$(git rev-list -n1 --first-parent --until=<second datetime> <a ref>)

See also

How To Page Up And Down In tmux Copy Mode In Mac Terminal


Page Up: Shift-Fn-Up
Page Down: Shift-Fn-Down

Print the First and Last Lines of Standard Input


This works:

$ i=0 ; while [ $i -lt 1000 ]; do echo $i ; i=$(( $i+1 )); done | sed -n '1p;$p'

Alternatives using head and tail suffer from head closing the pipe providing its input before tail can finish.

Tell Vagrant to Use Different Colors


Wikipedia ANSI color reference

--- /Library/Ruby/Gems/1.8/gems/vagrant-1.0.3/lib/vagrant/ui.rb~    2012-05-02 16:50:59.000000000 -0400
+++ /Library/Ruby/Gems/1.8/gems/vagrant-1.0.3/lib/vagrant/ui.rb 2012-05-17 17:01:32.000000000 -0400
@@ -137,7 +137,7 @@
         :clear  => "\e[0m",
         :red    => "\e[31m",
         :green  => "\e[32m",
-        :yellow => "\e[33m"
+        :yellow => "\e[34m" # Hacked to make it actually blue.

       # Mapping between type of message and the color to output

Unprivileged Emacs Can Open a File as Root


C-x C-f /sudo::/path/to/the/file

Change a User ID on Linux


find / -uid old-uid -print0 | xargs -0 chown new-uid
find / -gid old-gid -print0 | xargs -0 chgrp new-gid

Add Notes to This Page in Markdown


Now that I'm using Hyde, I can add notes to this page in Markdown rather than HTML.

<span id="2012-05-09-add-notes-in-markdown" />
### Add Notes to This Page in Markdown ###


Now that I'm using [Hyde][], I can add notes to this page in [Markdown][] rather than HTML.


Flush The DNS Cache

  • OS X:
    dscacheutil -flushcache
  • Windows:
    ipconfig /flushdns

After Resolving A Merge Conflict During `git rebase`, To Continue The Rebase

    git rebase --continue

Make Colored Git Log Readable on Terminals Using Black Text On White Background

    git config --global color.diff.commit blue # default is yellow

Make Colored Ediff Readable in Mac Terminal

  1. Terminal > Preferences > Settings > Basic > Text > Ansi Colors
  2. Change Yellow from yellow shade to yellow hue.
  3. Change White from gray to white.

Emacs C-g Kills `git commit` On Mac OS X

Workaround: Invoke Emacs via an interactive Bash shell.

    #! /bin/bash -i

    emacs "$@"

In a shell:

    git config --global core.editor
See also:

Git: Add A Remote Server And Set Up Existing Local Branches As Tracking Branches

    git remote add origin
    git push -u origin master

Copy a Calendar Event in Outlook 2011 for Mac

Option-Drag-and-Drop the event.

GDB Hung in Emacs on Mac OS X

Workaround for Emacs 23.1:

    M-x gdb RET
    (gdb) run
    (gdb) shell stty -onlcr

Solution: upgrade to Emacs 23.4

Zabbix Reverts Time Window On Refresh


If Zabbix graph zoom reverts to a particular value on all refreshes, e.g., on a graph like:


I can reset it so that refreshes don't change zoom by going to:


Or maybe: