M y    b r a i n    h u r t s  !                                           w e                 r e a l l y                 t h i n k                   w h a t                y o u             k n o w

27 November 2009

VIM usability: my .vimrc

My .vimrc compiled from various Internet sources. The goal was to make vim more user-friendly for someone who is familiar with popular shortcuts like Ctr+C for copy and Ctr+V for paste, but still retaining most classic vim shortcuts. Since Ctr+V cannot be used for vertical block selection it still can be done with Ctr+Q if your OS allows it.

28 October 2009

Entering special characters in Linux

Occasionally there is a need to enter special characters which are not on the keyboard, for example, an M-dash, ("—") or and N-dash ("–").

This solution works on all recent xorg versions, so it should work on all modern Linux distros.

  1. Press Ctr+Shift+U.
  2. Release U while still holding Ctr+Shift.
  3. Enter the four digit character code, e.g. 2013 for an m-dash, or 2014 for a n-dash.
Some special characters:
Unicode character code (HEX)
Special Character
2013 – (en-dash)
— (em-dash)


You can find a list of some character codes here:

30 September 2009 Bookmarklet

This bookmarklet opens a Word Reference popup window for the currently selected word on a page. Works in the same way as the Google Translate bookmarklets.

Word Reference Es-En
05/2010: updated to work on pages with frames


21 September 2009

Google Translate Popup Bookmarklet

These bookmarklets open a Google Translate popup for the currently selected text on a page. The only difference from the standard google translate bookmarklets is that these bookmarklets will also work on pages that use frames or inline frames, for example in gmail.

To use a bookmarklet drag the link (do not click) to you Favorites toolbar. Once you have added the icon to your toolbar, select some text (e.g. in Spanish) on a page and then click the bookmark icon.

To modify the language pair, edit the language code in the bookmarklet source from es|en to whatever language you want. Use auto to autodetect the source language.

Google Translate En-Es
Google Translate Es-En
Google Translate Any-En (autodetect)
Google Translate Any-Es (autodetect)

To see how this works select some text on this page and then click the link Google Translate En-Es to get a Spanish translation in a popup window.

To get more google translate buttons for more languages go to the google's own page at


28 May 2009

M4AtoMP3: Convert M4A files to MP3

I wanted to convert some M4A files to MP3, and found some examples of how to do it: Convert iTunes M4A files to MP3 on Linux, and especially Howto:convert aac/mp4 to wav/mp3/ogg on Linux.

The second link was close to what I wanted, and the script almost worked, but I wanted something even simpler, so here is the simplest script that worked for me. It converts all .M4A files in the current directory to MP3.

# Usage: run without arguments from the folder containing M4A files
# Uses faad and lame (sudo apt-get install faad lame)
shopt -s nocaseglob

for file in *.m4a ; do
  if [ -e "${file%%.*}.mp3" ]; then
    echo "file ${file%%.*}.mp3 already exists! skipping!" ;
  faad -o - $file | lame - "${file%%.*}.mp3" ;

22 May 2009

Screen Quick Howto

What is screen?
man page: "Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells)." Here is a screen screen tutorial.
Screen quickref
Most of the data below has been taken from the screen quick reference.
Change to last-visited active window
C-a C-a (commonly used to flip-flop between two windows)
Change to window by number
C-a <number> (only for windows 0 to 9)
Change to window by number or name'
C-a <number or title>
Change to next window in list
C-a n or C-a <space>
Change to previous window in list
C-a p
Split current screen session into two regions
Remove current region
C-a X
remove all regions but the current one
C-a Q
Switch between displayed regions
Create new session in split region
C-a c
Return to a single region
C-a Q
C-a d
Detach and logout (quick exit)
C-a D D
Enter copy mode
C-a [ (also used for viewing scrollback buffer) and with C-]
C-a ]
Rename current window
C-a A (note the uppercase 'A'!)
Console commands
Detach attached session
screen -D
Detach attached screen session (possibly running in another terminal) and reattach in current terminal
screen -Dr
Detach specific screen session (when more than one sessions are running)screen -D 14493.ssh2others
Move cursor to beginning of lineControl+a (release Control) + a

27 April 2009

Python UnicodeDecodeError: 'ascii' codec can't decode byte

You use Python 2.x and keep getting the notorious Python UnicodeDecodeError, 'ascii' codec can't decode byte?

Here is a hack which is especially useful in cases when you need to work with HTML.

Instead of

    print nasty_unicode_string

use this:

    print nasty_unicode_string.encode('us-ascii','xmlcharrefreplace')

This code will replace all the exotic non-ascii characters with their HTML-escaped ascii representation, i.e. Sueño will be replaced with Sue&#241;o, which will display properly when rendered in HTML.

Bingo! No more UnicodeDecodeError!

Warning: In most cases the UnicodeDecodeError is caused by programmer's lack of understanding of how Unicode is handled by Python, and is a signal that the entire approach to string handling should be revised. The hack above is not the proper way to fix it, and should be used with care. On the other hand, this approach is totally justified in cases when you need to print something to the console and are not sure whether the terminal supports utf8 or other unicode-friendly encoding.

18 February 2009

Mouse emulation with keyboard

In many applications you can get around by pressing the Tab and arrow keys and then pressing Enter or Space when the widget you need is under focus. Remembering common shortcuts is always useful, but there are things which are impossible to do without a mouse, for example, clicking a button in a Flash applet.

As you probably know, you can emulate most mouse actions with the keyboard. To enable this feature in Kubuntu 8.10/9.04

  1. Open System Settings:
    or click the Application Launcher > System > System Settings.
  2. Under the General tab select Keyboard & Mouse. To do it with the keyboard use Tab/Shift+Tab and the arrow keys. Window tabs (or pages) can be switched with Control+Tab or with Alt + underlined letter.
  3. Next, select Mouse on the left, and then Alt+N for Mouse Navigation.
  4. Select the option Move pointer with keyboard (using the num pad). (Alt+M)
  5. Click Apply (Alt+Y).

Note: If this looks complicated, there is actually a single shortcut for enabling mouse keys: Alt+Shift+NumLock.

Now you should be able to move the mouse pointer with number pad keys: 1, 2, 3, 4, 6, 7, 8, 9. If it does not work try pressing the NumLock key.

The table below shows the correspondence between mouse actions and keys on the number pad.

mouse action keyboard equivalent
Left-click 5
Left double-click '+'
Right click '-' on the numpad and then 5
Middle-click '*' on the numpad and then 5
Switch back to left click '/' on the numpad and then 5

The '-', '*', and '/' on the number pad select which 'mouse button' will be clicked when you press '5', therefore after you do a right-click with '-' and 5, you will have to switch back to left-clicking mode by pressing '/', otherwise you next click will still be on the 'right mouse button'.

Selecting text, dragging with keyboard

For some strange reason I did not find any official documentation on how to emulate mouse dragging with keyboard.

I have not checked other distros but on Kubuntu 8.10 you can do it by consecutively pressing the Del and '0' (Ins) on the number pad. This enables drag mode and you can now use 1-4/6-9 keys to drag whatever you clicked on. To finish dragging click 5.

I suppose that these features have to do with the xorg server, and are not [K]Ununtu-specific, so this probably should work with most distros.

Most of these keys also work on a MS Windows machine with one exception: drag-mode on Windows is enabled with the '0' key alone.

03 January 2009

Bookmarklet: GeoWhois for current page

Javascript bookmarklets: GeoIP, whois

Drag the link below (do not click) to you Favorites toolbar:


Whois (Firefox only, also works with selected text)

Whois (Firefox and IE)

Opera: Shift+drag the link to the toolbar

Firefox: Drag to Bookmarks panel (enable with View > Toolbars > Bookmarks)

Usage: To look up the domain of a page you are browsing simply click the bookmarklet in the Favorites toolbar. To lookup a URL that appears on a page, select the URL and click the bookmarklet in your Bookmarks bar (this only works with the Firefox-only bookmarklet).

In Firefox 3.x it is possible to drag the bookmarklet to any position you want, even to the menu bar. To do this, first add the bookmarklet to the Bookmarks bar, then right-click on the Firefox toolbar, select Customize, and drag the bookmarklet to wherever you want. After that you can disable the Bookmarks toolbar.