Notes

This page contains various notes I've collected on various (technical) subjects. That can be small code snippets, handy commands etc.

Filter by subject:
Bash
Detach a process from its terminal in bash

Bash has very powerful job control with its Ctrl-Z, fg and bg commands. A lesser known (but equally powerful) feature is disown. disown will detach a process from its controlling terminal, allowing it to continue running after you have exited your terminal.

CSS
Force a "hand" cursor
cursor: pointer;
GIT
Label a file for adding some time in the future
git add -N file

This lets git know that you intend to add a file at some later point. This makes the content of the file show up in ie. git diff

Staging partial commits

Lets you stage only parts of the changes made to a file for committing, instead of the entire contents.

Git add --patch FILE
Responses:

y   yes; stage this change
n   no; don't stage this change
s   split; cut the change in smaller parts
e   edit; manually define the part to split
GNU/Linux (desktop)
VirtualBox: Hide the statusbar and menubar
VBoxManage setextradata global GUI/Customizations noMenuBar,noStatusBar
GDM3: Set default session/desktop environment in Debian 6 (Squeeze)

Instead of using .dmrc, Debian 6's GDM3 uses /var/cache/gdm/[USER]/dmrc. Setting your current session to the default one is as simple as running cp ~/.dmrc /var/cache/gdm/$USERNAME/dmrc.

Nicer KDE apps when running under a GTK-based environment (ie. GNOME)
kwriteconfig --file kdeglobals --group Icons --key Theme gnome
kwriteconfig --file kdeglobals --group General --key widgetStyle gtk
Enabling "sudo mode" in GNOME
gconftool -t boolean -s /apps/gksu/sudo-mode true
sudo usermod -a -G GROUP [USER]

Group is 'sudo' on Debian, 'wheel' on Mandriva

sudo with X11 programs

Usually speical tools like gksudo does the job fine. However, if that's not available (or broken) you can use sudo XAUTHORITY="$XAUTHORITY" DISPLAY="$DISPLAY" [command] instead.

GNU/Linux (general)
Automatically run a command on boot as a user

cron has an @reboot "time" that you can use, which makes the command run once during boot. This is very handy for running commands after a reboot as a user (in particular if you don't have root access and thus can't edit /etc/rc.local). Example (in your crontab - crontab -e):

@reboot /home/myuser/initCommand
Install a local .deb package (and resolve dependencies)

apt-get and aptitude can't install local packages, and installation with dpkg -i will not install any additional dependencies (requiring an additional apt-get install -f afterwards to resolve the deps).

The gdebi tool can install a local .deb package and resolve, download and install any dependencies (and in case you're wondering, gdebi is not a graphical tool, that's gdebi-gtk, gdebi's gtk front-end).

Rsync "sparse" files (aka. files with holes - ie. kvm/qcow images)

Use the --sparse parameter for rsync. This will let rsync handle those files efficiently. Note however that --sparse can not be used with --inplace.

Various useful utilities
netselect - find the fastest server from a list of servers
unshare   - remove access to i.e. networking for a single process
nethogs   - simple network statistics
ImageMagick
Resize an image to a fixed size while maintaining the aspect ratio

convert file.jpg -resize 800x -background white -gravity center -extent 800x600 file-aspect.jpg

This will pad above/below or to the right/left side of the image with the colour specified as -background, resize the image to the width or height as supplied to -resize and force the image to be the size supplied to -extent.

mutt
Maildir-indexing for full-text search

mu provides a full-text index of maildirs, and can easily be used from within mutt. The tool itself is available from http://www.djcbsoftware.nl/code/mu/ (in Debian just install maildir-utils).

I use the following cronjobs to generate the index

# Update mail index every two hours
07 */2 * * *              mu index --maildir=~/mail/ --quiet
# Remove old search results every morning
11 5 * * *                rm -rf "/home/zerodogg/.mu/results"

And the following code inside of mutt, F7 then lets you enter a search query, and F8 will go to the search results.

macro index <F7> "<shell-escape>mu find -c -l ~/.mu/results "    "mu find"
macro index <F8> "<change-folder-readonly>~/.mu/results\n"       "display mu find results"
Perl
A simple one-liner REPL

perl -MData::Dumper -MTerm::ReadLine -e '$r = Term::ReadLine->new(1);while(defined($_ = $r->readline("\$ "))){$ret=Dumper(eval($_));$err=$@;if($err ne ""){print $err;}else{print $ret;}}'

Alias (ie. for use in .bashrc):

alias 'perl-repl'='perl -MData::Dumper -MTerm::ReadLine -e '\''$r = Term::ReadLine->new(1);while(defined($_ = $r->readline("\$ "))){$ret=Dumper(eval($_));$err=$@;if($err ne ""){print $err;}else{print $ret;}}'\'''

screen
Recreate a deleted screen socket
kill -CHLD <PID>
Vim
Disable any use of bold fonts
set t_md=