Notes
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.
EOF
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:
- a question and answer on superuser.com about executing commands on your local machine from a remote host
- a post by Sean Coates about using pbcopy remotely
- a post by Chris Toomey about copying text from tmux to your clipboard
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...
> EOF
blah abc blah
4...
5...
6...
blah efg blah blah
Override Git merge.ff = false
$ git merge --ff <branch>
or
$ 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 com.apple.dt.XCode IDEIndexDisable 1
via http://krish.codeworth.com/development/ios-development-2/iphone-2/xcode-4-x_slow_issues/
Disable Xcode's use of Git
E.g., to prevent Xcode from polling git status
pushd /Applications/Xcode.app/Contents/PlugIns/
mv IDEGit.ideplugin/ IDEGit.ideplugin.20130425
Likewise to disable Xcode's use of Subversion:
mv IDESubversion.ideplugin/ IDESubversion.ideplugin.20130425
via http://krish.codeworth.com/development/ios-development-2/iphone-2/xcode-4-x_slow_issues/
Join tmux window A as a pane in window B
Assume you have two windows A and B.
-
Switch to window B.
C-b B -
Then join window A to window B.
C-b : join-pane -s A
Alternatively,
-
Switch to window A.
C-b A -
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 me.veekun.com.
Open a remote file in Emacs as user A via ssh as user B
/ssh:B@otherhost|sudo:A@localhost:/path/on/remotehost/filesystem
Via the TRAMP User Manual
Pip install from an existing repository clone
E.g.,
pip install --no-download -e hg+ssh://hg@bitbucket.org/matthewlmcclure/pdb#egg=pdbpp --src /Users/mlm/w
Enable MySQL full query logging
/etc/my.cnf:
[mysqld]
log = /var/log/mysql/mysql.log
Then:
# mkdir -p /var/log/mysql
# chown mysql:mysql /var/log/mysql
# service mysql restart
Python Breakpoint Conditional on Caller
import traceback
if 'foo.py", 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(sys.stdin.read()) ; print o["active"]["default"]')
[user@host]$ VBoxManage storageattach $vmuuid --storagectl 'IDE Controller' --port 1 --device 0 --type dvddrive --medium /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso
[root@guest]# mount /dev/cdrom /media
[root@guest]# /media/VBoxLinuxAdditions.run
Download an Entire Website for Offline Viewing
$ wget --mirror -np -p -k -e robots=no --no-cookies 'http://foo.example.com/' --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 jira.sh to supply base URL, username, password.
mlm@matt-mmf-macbook.local:~/Downloads
$ jira.sh --action login >jira-token.txt
mlm@matt-mmf-macbook.local:~/Downloads
$ <jira-token.txt jira.sh --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
mlm@matt-mmf-macbook.local:~/Downloads
$ jira.sh --action logout
<redacted> logged out
JIRA CLI: https://bobswift.atlassian.net/wiki/display/JCLI/JIRA+Command+Line+Interface Tempo API: http://wiki.tempoplugin.com/display/TEMPO/Tempo+Servlet+Manual
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)
Via:
- http://nedbatchelder.com/blog/200410/file_and_line_in_python.html
- http://docs.python.org/library/traceback.html
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
via http://www.php.net/manual/en/function.mysql-connect.php#103536
Dial International Numbers From Bria
2012-06-26
If the number is +x, dial 011 x.
Add An SSH Key To Mac's KeyChain Access
2012-06-20
ssh-add -K ~/.ssh/private-key-file
Preserve Forwarded SSH Agent Connections Across sudo su -
2012-06-20
sudo su - -c "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK; bash"
See also: http://serverfault.com/questions/107187/sudo-su-username-while-keeping-ssh-key-forwarding
The Most Recent Commit on a Git Branch As Of A Date
2012-05-23
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 http://stackoverflow.com/a/10692666/168740
How To Page Up And Down In tmux Copy Mode In Mac Terminal
2012-05-23
Page Up: Shift-Fn-Up
Page Down: Shift-Fn-Down
Print the First and Last Lines of Standard Input
2012-05-21
This works:
$ i=0 ; while [ $i -lt 1000 ]; do echo $i ; i=$(( $i+1 )); done | sed -n '1p;$p'
0
999
Alternatives using head and tail suffer from head closing the pipe
providing its input before tail can finish.
Tell Vagrant to Use Different Colors
2012-05-17
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
2012-05-17
C-x C-f /sudo::/path/to/the/file
Change a User ID on Linux
2012-05-09
find / -uid old-uid -print0 | xargs -0 chown new-uid
find / -gid old-gid -print0 | xargs -0 chgrp new-gid
vipw
vigr
Add Notes to This Page in Markdown
2012-05-09
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 ###
2012-05-09
Now that I'm using [Hyde][], I can add notes to this page in [Markdown][] rather than HTML.
[Hyde]: http://hyde.github.com/
[Markdown]: http://daringfireball.net/projects/markdown/
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
- Terminal > Preferences > Settings > Basic > Text > Ansi Colors
- Change Yellow from yellow shade to yellow hue.
- Change White from gray to white.
Emacs C-g Kills `git commit` On Mac OS X
Workaround: Invoke Emacs via an interactive Bash shell.
emacs.sh:
#! /bin/bash -i
emacs "$@"
In a shell:
git config --global core.editor emacs.sh
See also:
Git: Add A Remote Server And Set Up Existing Local Branches As Tracking Branches
git remote add origin git@github.com:matthewlmcclure/diff-ediff.git
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
M-x gdb RET
RET
(gdb) run
(gdb) shell stty -onlcr
Solution: upgrade to Emacs 23.4
Zabbix Reverts Time Window On Refresh
2011-07-31
If Zabbix graph zoom reverts to a particular value on all refreshes, e.g., on a graph like:
http://zabbix/history.php?action=showgraph&itemid=26016&sid=36ef87a201faa530
I can reset it so that refreshes don't change zoom by going to:
http://zabbix/history.php?action=showgraph&itemid=26016&sid=36ef87a201faa530&period=
Or maybe:
http://zabbix/history.php?action=showgraph&itemid=26016&sid=36ef87a201faa530&period=0