Monday, May 6, 2013
Google coding style guides
I didn't actually realise how important code style guides were until I saw one consistently applied with style-checking tools: it makes a big difference to code quality. If you don't have a style guide, you could do a lot worse than the google style guides, which have been open-sourced and are regularly updated as languages evolve. The Google python guide is here, which is very similar to Guido's python style guide.
Chrome browser commandline switches
Chrome has a prodigious number of command line switches to control all sorts of behaviour. I recently ran into this one, which I think will be handy. From the review log:
Added the flag --host-resolver-rules=XXX in r39342.
Where XXX is a comma separated list of rules that control how hostnames are resolved.
For example:
"MAP * 127.0.0.1" --> Forces all hostnames to be resolved to 127.0.0.1
"MAP *.google.com proxy" --> Forces all google.com subdomains to be
resolved to "proxy".
"MAP test.com [::1]:77 --> Forces "test.com" to resolve to IPv6 loopback.
Will also force the port of the resulting
socket address to be 77.
"MAP * baz, EXCLUDE www.google.com" --> Remaps everything to "baz",
except for "www.google.com".
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 matplotliband 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:
[global] download_cache = ~/.cache/pipAlso, 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 directoryYou 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 '127.0.0.1', 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.
A bunch of people are having trouble because the backend IP is set as '127.0.0.1', 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/montoringThen 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 3This 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 " http://briancarper.net/blog/341/ 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 3You 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)
Subscribe to:
Posts (Atom)