Emacs Macro Counter!

Say you want to create the following HTML:

<div id="d0"></div>
<div id="d1"></div>
<div id="d2"></div>
<div id="d3"></div>
<div id="d4"></div>
<div id="d5"></div>
<div id="d6"></div>
<div id="d7"></div>
<div id="d8"></div>
<div id="d9"></div>

Doing this is simple using Emacs’ macros. Type C-x ( to start defining the macro. Then, when it comes time to insert the digit, enter C-x C-k C-i. The next time you run the macro, the number will be incremented.

Say you need to add a zero-padded number. Enter C-x C-k C-f and use the typical printf string formats like %03d.

When you need to reset the counter, use C-x C-k C-c and enter in the start value.

Finally, if you need to repeat a number, use C-u C-x C-k C-i.

Reference:

http://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macro-Counter.html

Advertisements

Git Bash Completion

In the source directory under contrib/completions there is a bash completions directory. After sourcing that file you can then git <tab> <tab> and get all the git commands. You can also setup $PS1 to show you what branch is currently active with:


export PS1='[...]$(__git_ps1 "(%s)")[...]'

Make sure you use single quotes on the outside or it won’t work.

Encrypting Skype

Skype supposedly encrypts all communication between peers. Thing is, even if it’s encrypted, Skype still holds all the keys, so they could technically read anything that’s going through their system.

I found a plugin that lets you use Skype through Adium. Adium has Off The Record, which can then be used to encrypt Skype messages.

Here is a sample image of what the message looks like when intercepted by growl:

Skype message through Adium using OTR
Skype message through Adium using OTR

Truncating a file in use

Here’s a nice trick to zero out a file that’s in use:

cat /dev/null > /path/to/file

The reason for this is that if you simply remove a file that’s in use by some process on the system, the disk space will not be released until the process closes the file or terminates.

By cating /dev/null and redirecting it to the file, it magically guts out the contents of the file while keeping the same inode. The process that has that file open will continue writing to it without knowing any better, and the disk space will be released.

Update: A simple test using python to keep a file handle open showed me that while the cat trick zeros out the file, python keeps track of the last position written to within the file. The next time the python process writes to the file, you’ll end up with null bytes at the beginning of the file.