Dos2unix using Emacs

To convert a buffer(file) from dos file encoding to unix in Emacs use

M-x set-buffer-file-coding-system RET undecided-unix

If you do a TAB after RET, you will see the gazillion other encoding schemes supported by Emacs.

Installing Ubuntu without CD or USB

The following article is helpful if ...
  1. ... you are one of those few lucky people who still has an antiquated machine without a CD drive or a boot-able USB thing (check) 
  2. ... you are running a very old version of Ubuntu - 8.04 (check) 
  3. ... and you don't want to do an incremental network upgrade all the way from 8.04 to 8.10 to 9.04 .. yawn .. to 11.10 (check)
Read this

(In a nutshell - installing Ubuntu using a spare partition from an existing Linux system to house the Ubuntu CD image).

Emacs shell

Three solutions

1. Emacs shell (M-x shell) - Not very capable, good enough to run quick commands

2. Terminal emulation (M-x term) - Can't handle formatted output well.

3. Actual terminal instance (M-x ansi-term) - Real thing! 

Reading man pages within Emacs

M-x man
OR
M-x woman

Isn't Emacs awesome?

Emacs Undo

Did not know that instead of the finger breaking C-_, undo on emacs can also be done using C-/ and C-x u, though I don't like the last one.

[Emacs] Using emacsclient

I have been using Emacs over gnu screen so that I can have my buffers and windows from work when I connect from home. The only problem is that over gnu screen, the Control-Up/Down/... does not work and instead I get the 5A, 5B, ... characters. The same is true for Alt and Shift. However, if I use Emacs over bash rather than gnu screen,  it works fine but I can't get my old buffers as it creates a new instance. Enter Emacsclient for the rescue.

Emacsclient can not only be used to tell a running Emacs session to visit a file but it can also be used to open a new Emacs frame and have your buffers from the other frame shown here. (Viola)

In order to get this to work, you need to start the Emacs server. This can be either done at run-time by
M-x server-start
OR, add it to your .emacs file
;; Start the emacs server
(server-start)

Now, create a few aliases in your .bashrc.
### Open emacs in console mode, non-gui
alias em='emacs -nw'
### Tell running emacs to visit a file
alias ecf='emacsclient -n'
### Start emacs with new frame
alias ecn='emacsclient -nw -c'

So, now I can run ecn and it would start a new Emacs instance but still show me the buffers from the existing one.

To close this frame you can type C-x 5 0

X11Vnc Shift Key Fix

There is a known bug with X11VNC where the Shift key does not work (ref). The quick fix is to add -xkb to the command string as suggested here.

My X11Vnc string looks like:

$ x11vnc -usepw -forever -xkb -display :0

Finding read throughput using "dd"

If you are trying to find the read throughput of a device (like an SD card), you can do the following:

1. If possible unmount the device but keep it connected. Let's say you are looking at an SD card at sdd. (Don't worry about the volumes)
2. Run the following:
sudo dd if=/dev/sdd of=/dev/null bs=50M count=1

This will print the read throughput, something like this:
1+0 records in
1+0 records out
52428800 bytes (52 MB) copied, 2.62946 s, 19.9 MB/s


Now, if the device is mounted, you might see a variability in the throughput because of file system page caching between runs. To avoid that, free the page caches using:
sync; echo 1 | sudo tee /proc/sys/vm/drop_caches

NOTE: To free deentries and inodes the following can be used:
sync; echo 2 | sudo tee /proc/sys/vm/drop_caches

If you want to free up everything (page caches, deentries and inodes), do the following:
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

Use tee to set values in proc or sysfs

There are times when you can't do a "echo something > /proc/somewhere", especially when you got to use "sudo".

Using tee helps:

echo value | sudo tee /proc/somewhere

Control-S freezes puttty

Saw a weird behavior yesterday. CTRL-S would freeze putty. It turned out to be problem related to XOFF which is triggered by CTRL+S (the terminal will accept keys but it won't show the result for that, weird!). A simple fix is CTRL+Q to trigger XON. However, that does not work well with emacs which relies a lot on CTRL+S (for searching and saving)

Just add the following to .bashrc file:

stty ixany
stty ixoff -ixon

.thumbnails eating up space in $HOME

I have a restriction of 50K # of files that can be created in the $HOME folder at work and for no apparent reason I reached that limit a couple of days back. So, there was something that had created 50K files in $HOME and I did not know about it.

Ran the following:

$ for x in `find $HOME -name "[.]*"`; do echo "$x has `find $x | wc -l` file"; done

The result listed a folder $HOME/.thumbnails that had around 47776 files. It appears that Nautilus creates thumbnails of every picture or PDF that you have opened. However, Nautilus does not delete the files.

If you have such a restriction and need to get rid of these files, add a crob job that does deletes the files older than 7 days.

$ find ~/.thumbnails -type f -atime +7 -exec rm {} \;

Another method is to change the Gnome settings. Run the following:

$ gconf-editor

Under desktop -> gnome -> thumbnail_cache change the values for maximum_age and maximum_size