Friday, April 26, 2013

Crontab converts percent signs to newlines

A breadcrumb for the internet: it turns out percent (%) signs get converted to newlines inside crontabs. This is one of those things that I probably learnt in the past but forgot until it bit me: it's useful if you need to send multi-line strings as input to a command in cron. From the manpage:
The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Per‐cent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.
If you have unescaped %'s you will likely see errors like this:
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

Monday, April 22, 2013

Pip re-install without download (and pip install matplotlib woe)

For some bizarre reason the default behaviour of pip is to download the package every time. So try:
pip install matplotlib
and see how much fun it is to download a 32MB tarball, have one dependency fail, download again, another dependency etc. You can tell pip to stop being stupid by creating a ~/.pip/pip.conf file with:
download_cache = ~/.cache/pip
Also, the matplotlib build doesn't die on missing headers at the dependency checking stage, so if you see:
src/_png.cpp:10:20: fatal error: png.h: No such file or directory
src/ft2font.h:16:22: fatal error: ft2build.h: No such file or directory
You need:
pip install numpy
sudo apt-get install libfreetype6-dev
sudo apt-get install libpng-dev

Wednesday, April 10, 2013

mythmote listens on localhost by default

Mythmote is an android app you can install to act as a mythtv remote. No more messing with lirc. To get it working you need to first enable it in the frontend through the 'General' settings menu. Once you have restarted the frontend you should see it listening on the port you specified (6546 is the default).

A bunch of people are having trouble because the backend IP is set as '', and the frontend control socket doesn't allow you to specify a listen IP. So the frontend control socket just listens on the same address as the frontend: since I have a combined frontend and backend this was localhost. Which means your phone can't reach it. So you'll need to run mythtv-setup and set your IP under 'General Configuration' to the network-local IP of your frontend (probably 192.168.0.something). Don't do the horrible port forwarding or creation of an xinetd forwarder that has been suggested on this page.

You may also want to check your firewall rules since your backend/frontend is now listening on the network interface (i.e. is more accessible to the network), and you might need to open the port for the remote.

Thursday, April 4, 2013

Screen: start multiple sessions/windows automatically

Say you want to regularly start up a screen session with a bunch of different commands running in windows. You can achieve this with a .screenrc file.
# Screen startup
# run with screen -c [filename]

# Import your regular screen settings
source ~/.screenrc

# When a process dies, if it was non-zero exit then keep the window until you
# hit 'q', if you hit 'r', run the same command again.
zombie qr onerror

screen -t vim /usr/bin/vim /code
screen -t tests
screen -t bash
screen -t monitoring /bin/some/montoring
Then just run it with
screen -c myscreenrc

Wednesday, April 3, 2013

Pasting in Vim visual block mode

Say you have a section of text and want to paste something at the start of every line. How do you do that easily in vim?
text line 1
text line 2
text line 3
This blog post led me to the answer, I've added this to my vimrc:
" Use CTRL-V for pasting yank contents in insert mode.  Also useful in visual
" block mode for pasting a line of text in front of all other lines
inoremap <C-v> <C-r>" <Esc>
So I go:
CTRL-V   (visual block mode)
jj       (select first column of lines)
I        (insert mode)
CTRL-V   (paste yanked content - unnamed register)
To get:
this is new. text line 1
this is new. text line 2
this is new. text line 3
You might want to pick a different mapping if you use the existing CTRL-V functionality to insert funky characters. See the vim help (:h i_CTRL-V)