Linux: Mount second encrypted HDD automatically without entering a password

This is one possibility to do this. There are other and maybe even better ways to do this.

  1. Generate a key for your encrypted harddisk:

    dd if=/dev/random of=/home/bob/keyfile_sdb1 bs=4096 count=1
    
  2. Then add your keyfile to encrypted harddisk: How to change your dm-crypt passphrase (step 3)

  3. Create a mountpoint:

    mkdir /mnt/space
    
  4. Create a script e.g. in your homedirectory (/home/bob/mount_sdb1.sh):

    #!bin/bash
    
    ...
    

TeamViewer 7 finally works with multiple screens under Linux

TeamViewer 6 and lower had an issue where they would see a multi-monitor Linux setup as a single wall of pixels. This is fixed in version 7. The guest can now select the currently active screen from the TeamViewer menu.

Ubuntu: Reload Gnome panel while keeping user session

Sometimes you need to restart the Gnome panel, e.g. when you installed a new Gnome panel widget but the widget list was cached before.

You often don't want to do sign out and back in for this.
Instead, just run:

killall gnome-panel

This will terminate all gnome-panel processes. On my machine (Ubuntu 11.04) the panel then restarted itself after a moment.

If the panel does not automatically come back, press Alt+F2 to bring up the Gnome "run" box and start gnome-panel from there.

Improve web font rendering in Windows by autohinting fonts

Web fonts are awesome. After being restricted to Arial for two decades there is finally a cross-browser way to embed fonts into web pages.

Unfortunately while web fonts look awesome on Linux and MacOS, they look horrible on Windows, a problem that gets worse with smaller font sizes.

The culprit is something called font hinting:

...

Solve screen error "Cannot open your terminal '/dev/pts/0' - please check"

When using the screen tool you may be unable to start a screen session but instead encounter an error:

Cannot open your terminal '/dev/pts/0' - please check.

This is because another user (you) initiated the current terminal -- you probably did a sudo su into the user you are now trying to run screen as, right?

There are two ways to resolve this:

  • Sign out and properly connect / sign in as the user you wish to use.
  • Run script /dev/null to own the shell (more info over at [Server Fault](http://serverfault.com/questions/116775/...

Truncate files to zero length

This will reduce the filesize of foo and bar to 0 bytes:

truncate -s0 foo bar

If the files do not exist they will be created.

You can use this to easily truncate your application's log files:

truncate -s0 log/*.log

Line wrap text from a Ubuntu Linux terminal

You can use fold:

fold -sw 60

You can now paste your texts. fold will echo them back, word-wrapped after 60 columns. Exit with Ctrl+C or Ctrl+D.

You can also use files for input and output:

fold -sw 60 input.txt > output.txt

Dragging a file into your terminal pastes the file path

When you drag a file from a Nautilus window into a terminal window, the file's path will be pasted into the terminal. This also works with multiple files.

How to install a frozen version of Firefox for your Selenium tests

Whenever Firefox updates, all your Cucumber features that use Selenium break. This is annoying.

In order to remedy this, version 0.5.0 of our geordi gem comes with a script that helps you create an unchanging version of Firefox for your Selenium tests. In particular, this new copy of Firefox will have the following properties:

  • It won't update itself with a newer version
  • It can co-exist with your regular Firefox installation (which you can update at will)
  • It will use a profile separate from the one...

Install the DeaDBeeF music player under Ubuntu Linux

DeaDBeeF is one of the better music players for Linux.

You can find installation instructions here.

Convert the colorspace of a PDF from RGB to CMYK under Ubuntu Linux

Note that converting from RGB to CMYK will usually degrade your colors because no exact mapping is possible. Anyway, this Stackoverflow post worked for me:

gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK \
-sOutputFile=output.pdf input.pdf

Rotate a PDF under Ubuntu Linux

Use the PDF toolkit:

sudo apt-get install pdftk

To rotate page 1 by 90 degrees clockwise:

pdftk in.pdf cat 1E output out.pdf    # old pdftk
pdftk in.pdf cat 1east output out.pdf # new pdftk

To rotate all pages clockwise:

pdftk in.pdf cat 1-endE output out.pdf    # old pdftk
pdftk in.pdf cat 1-endeast output out.pdf # new pdftk

The E (old pdftk) or east (new pdftk) is meaningful if you want other rotations. From the man page:

The page rotation setting...

Fix: Tail says "no space left on device"

Linux provides a fix number of filesystem watches. If you have some greedy daemon (like dropbox) running, chances are it uses all of them, and you cannot use tail -f any more.

To increase the number of watches, put something like
fs.inotify.max_user_watches = 32768
into /etc/sysctl.conf. (default is 8192)

To update the setting right away, run
sudo sysctl -p /etc/sysctl.conf
afterwards.

Grep the number of occurences in a file, counting multiple hits per line

Grep prints one line per match. To return the number if matches, use the -c switch:

grep -c "something" filename

However, if a word appears more than once in a line, it is only counted once.

To count every match, you can use sed to force line breaks on multiple matches:

sed 's/something/something\n/g' filename | grep -c "something"

Hide your Selenium browser window with a VNC server

This is now part of geordi. Please don't follow the instructions below, if you use geordi.

Inspired by the recent headless Selenium note, I found yet another solution for the problem to hide your selenium tests away.

This has the advantages
^

  • not to require a gem (so you do not force this on others)
  • to allow you to take a look at the running webdriver if necessary

Simply make a script th...

How to look at hidden X screens

When you have a program running in a hidden X screen (like with Xvfb for Selenium tests) you may want to look at that hidden screen occasionally.

First, find out what X displays are currently active:

netstat -nlp | grep X11

This should give you some results like these:

unix  2      [ ACC ]     STREAM     LISTENING     8029600  4086/Xvfb           /tmp/.X11-unix/X99
unix  2      [ ACC ]     STREAM     LISTENING     8616     -     ...

How to type accented characters on keyboard layouts without dead keys

Ubuntu comes with keyboard layouts like "Germany Eliminate Dead Keys", which are practical for programming.

If you need to type accented characters with such a layout, make sure to configure a Compose key. You can then look up which compose combo will produce the character you need.

E.g. you can type "á" by pressing Compose, ´, a.

Linux: Create file of a given size

Sometimes you need a file of some size (possibly for testing purposes). On Linux, you can use dd to create one.

Let's say you want a 23 MB file called test.file. You would then run this:

dd if=/dev/zero of=test.file bs=1048576 count=23

The block size (bs) is set to 1 MB (1024^2 bytes) here, writing 23 such chunks makes the file 23 MB big.\
Adjust to your needs.

This linux command might also come in handy in a Ruby program. It could be used like:

mb = 23
mb_string, _error_str, _status = Open3.capture3('dd if=/dev/zero...