In my view, sudo is to system administration what global is to software development: sometimes it’s the right thing to do, but one’s fingers ought to have an aversion to typing it — and if you find yourself using it a lot you should take that as an indication that you’re probably doing something wrong.
One example of sudo overuse is in installing packages with pip, which is quite capable of installing everything in a nice, self-contained directory in your home directory without requiring root privileges and without the madness that comes from mixing your pip managed Python packages up with apt managed ones in your system directories. read more…
Ephemera →
The hdparm man page is not for the faint of heart:
--drq-hsm-error
VERY DANGEROUS, DON’T EVEN THINK ABOUT USING IT. This flag causes hdparm to issue an IDENTIFY command to the kernel, but incorrectly marked as a “non-data” command. This results in the drive being left with its DataReQust(DRQ) line “stuck” high. This confuses the kernel drivers, and may crash the system immediately with massive data loss. The option exists to help in testing and fortifying the kernel against similar real-world drive malfunctions. VERY DANGEROUS, DO NOT USE!!
--trim-sector-ranges
For Solid State Drives (SSDs). EXCEPTIONALLY DANGEROUS. DO NOT USE THIS FLAG!! Tells the drive firmware to discard unneeded data sectors, destroying any data that may have been present within them. This makes those sectors available for immediate use by the firmware’s garbage collection mechanism, to improve scheduling for wear-leveling of the flash media. This option expects one or more sector range pairs immediately after the flag: an LBA starting address, a colon, and a sector count, with no intervening spaces. EXCEPTIONALLY DANGEROUS. DO NOT USE THIS FLAG!!
Comparing large data sets in Python
Suppose you need to compare rows from a database table with rows from a file. In particular, you want to know which primary keys exist in both the database and the file, and which exist in only one data source. For small tables this can be done fairly easily using Python’s set difference operations, but what do you do when the tables are far too large to hold in memory? read more…
Using SSH agent for sudo authentication
pam-ssh-agent-auth is a PAM module which allows you to use your SSH keys to authenticate for sudo. If you sudo regularly on a large number of different machines this creates a pressure towards weak, easily typed passwords and/or password reuse (not that any of us ever succumbed to this pressure of course). Using your key agent to authenticate you removes this pressure while being more secure than a completely passwordless sudo. read more…
Ephemera →
Wondering what the --fast switch to imapsync does? Just consult the help output:
--fast : be faster
Ephemera →
Python’s xlrd documentation on Dates in Excel spreadsheets:
In reality, there are no such things. What you have are floating point numbers and pious hope.
Geany is a lightweight but surprisingly powerful GTK-based IDE. Here’s how to enable syntax highlighting for Django’s template tags in HTML files:
- Copy /usr/share/geany/filetypes.html to ~/.config/geany/filedefs/
- Find the [lexer_properties] section of the file and add:
lexer.html.django=1
Geany uses Scintilla as its highlighting engine so have a look at their documentation for a full list of the available lexer options.
ack is betterthangrep.com
ack is grep with better filetype awareness, more sensible defaults and prettier output. You should be using it. Why aren’t you using it?
By default, it searches recursively from the current directory while ignoring VCS directories (.svn, .git etc), backup files, binary files and the like. Have a look at the site for the full list of nifty features.
Note that for historical reasons its Debian/Ubuntu package name is ack-grep. If you aptitude install ack you will end up with a Kanji character conversion tool.

Ephemera →
I love this illustration from Amazon’s S3 documentation. One gets a very clear sense of how Amazon think Your Web Server compares to Their Web Server…

Wildcard subdomains of localhost
It always slightly niggled that I couldn’t just stick a *.localhost entry in /etc/hosts and have all subdomains of localhost resolve to 127.0.0.1. But setting up a local nameserver, and making sure external domains still got resolved properly, always seemed like too much faff. It turns out though, thanks to dnsmasq, that it’s actually very straightforward. (Instructions are for Ubuntu but dnsmasq runs on most *nix systems.) read more…