Archive for May, 2013

Syntax-highlighted “cat” in command line

May 29, 2013 1 comment

You have a source code whose content you want to display on the stdout. The natural way to do that is the “cat” command but it’s monochrome. How to get a syntax-highlighted output?

Use pygments. If you install it (“sudo apt-get install python-pygments“), you will have a command called “pygmentize” that you can invoke from the command line.


pygmentize -f terminal256 -O style=native -g

Tip: put an alias on it.

alias pcat="pygmentize -f terminal256 -O style=native -g"

There are different styles available, see “pygmentize -L” for a list.

Tip from here. Discussion @reddit here.


How to pronounce the name of Bjarne Stroustrup?

How to pronounce the name of the creator of the C++ language, Bjarne Stroustrup?

It’s in the FAQ of B.S. Here is a direct link to his .wav file:

Categories: fun Tags: , ,

Analyze a User-Agent string

You can analyze a user-agent string with

Categories: web Tags: ,

BH IMDB/Word Highlight

A long time ago I also made a Greasemonkey script called BH IMDB/Word Highlight. This script is written for some specific sites in Hungary. However, you can take ideas from this how to highlight a text on a web site.

Install a Greasemonkey script from a local file

May 20, 2013 1 comment

You have downloaded a Greasemonkey script but… how to install it?

Here I suppose you have the Greasemonkey add-on installed (Hey, what is GM?). Well, I didn’t find anywhere the option “install from local file“. A GM script is called *.user.js and if you open the URL (http://...) of such a script, GM will recognize it and offer to install it (for this GM must be enabled). However! If you open your script locally (file://...), nothing happens. WTF?

Calm down. You know Python, right? The Swiss army knife of programmers. Just navigate to the directory where the GM script is located and start a web server:

$ python -m SimpleHTTPServer

Now open the URL http://localhost:8000 , click on the user script and GM will offer to install it. Python, what would I do without you?

User scripts are installed in this directory: “~/.mozilla/firefox/xxxxxxxx.default/gm_scripts“. Here you will find a config.xml file too that is created by GM.

I installed this way this script: Greasemonkey: focus first input field. This script puts the focus on the first input field. I use it with Amazon and IMDB and works like a charm.

Disable Unity’s F9

I use Midnight Commander a lot and F9 in MC means: “go to the top menu bar“. However, Unity steals F9 and activates a widget layer. By default this layer is empty, so you only see that the screen greys out.

How to disable this shit?

Start “ccsm“, find the Desktop section and untick “Widget Layer“. Done.

Automate tasks with AutoKey

May 19, 2013 1 comment

AutoKey is a desktop automation utility for Linux and X11. It allows you to create scripts and assign hotkeys to these scripts, allowing you to execute them on demand in whatever program you are using.” (source)

I’ve already done similar automatizations with autopy, which is not difficult, but life is much easier with AutoKey. AutoKey is a framework for these kinds of scripts and the great news is you can program it with Python!


sudo apt-get install autokey-qt

There is an “autokey-gtk” version too but I had some problems with that. For me “autokey-qt” worked better.


Use Case
Now let’s see a concrete use case. Printing at my workplace is a bit painful. If I want to send jobs to a powerful printer here, I need to authenticate myself each time (see the figure; click for a larger image). Or, I can use another (shitty) printer…


I must provide my username / password, then click on the OK button. If I print a large document, it’s OK, but if I want to print several small files, it becomes a pain in the ass.

And here is where AutoKey comes to the rescue. I made a simple script that automates this task (click to enlarge):

There is a hotkey associated to this script: CTRL+F1. There is also a window filter, thus it cannot be activated by accident in a wrong environment.

The script is here:

with open(".../print.txt") as f:
    username = f.readline().rstrip("\n")
    password = f.readline().rstrip("\n")

for _ in range(3):

Update (20141102, Manjaro)
I installed Manjaro on one of my laptops. Here are my notes for Autokey.

I had to install it from source, I didn’t find it in the official repositories. After unpacking the archive, I installed it:

sudo python2 install --record files.txt

The part “--record files.txt” is optional. With Python 3 it didn’t work. I also had to install some additional packages:

sudo pacman -S gtksourceview3 libappindicator-gtk3

Also, there was a problem with filesystem monitoring. Here is the fix:

# edit this file:
$ sudo vim /etc/sysctl.d/99-sysctl.conf
# by adding this line:
fs.inotify.max_user_watches = 100000
# reload the kernel parameters:
$ sudo sysctl --system

Under Manjaro I had luck with “autokey-gtk” (instead of “autokey-qt“).

Grub timeout doesn’t work sometimes

In the Grub menu you can use a countdown mechanism. However, sometimes it doesn’t work and you have to press Enter manually.

I figured out that this happens when my machine was not shut down normally. Sometimes my machine doesn’t halt and I need to press the power button manually. At the next boot the timeout is gone in my grub menu.

When the machine was stopped abnormally, a “recordfail timeout” will be used. So simply add the following line to “/etc/default/grub“:


My “grub” file looks like this:

GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="acpi=noirq splash"


After editing don’t forget to run “update-grub“.

Tip from here.

Categories: ubuntu Tags: , , ,

Make sudo ask for your password every time

When you use “sudo“, it remembers your password for some minutes, thus if you call “sudo” within this time frame again, it won’t ask your password.

However, I want “sudo” to ask my password every time I call it.

Execute the command “sudo visudo” and add the following line to the end of the “Defaults” block:

Defaults    timestamp_timeout=0

The value “0” means it won’t cache your password.

Tip from here.

Categories: ubuntu Tags: ,

fartscroll.js: funniest JavaScript code ever

Everyone farts. And now your web pages can too.

Check out fartscroll.js in action.

Categories: fun, web Tags: , ,