Archive

Archive for January, 2013

.xsession-errors can grow HUGE

January 31, 2013 1 comment

Problem
Something funny happened to me today. I logged in to my desktop machine at my workplace when a warning message told me that “disk space is low”. A quick “df -h” indicated that it’s true, my HDD is at 100%! How is it possible, I should occupy no more than 30%. After hunting for 10 minutes for the guilty file/directory, it turned out that the file .xsession-errors in my HOME directory grew more than 200GB! WTF?

Solution
I removed this file and under the name .xsession-errors I put a link on /dev/null. However, after a reboot the symbolic link was gone and .xsession-errors became a regular file again. Tricky :) So I added the following lines to the end of my .bashrc file:

# .xsession-errors can grow huge... remove it
if [ ! -h $HOME/.xsession-errors ]
then
    /bin/rm $HOME/.xsession-errors
    ln -s /dev/null $HOME/.xsession-errors
fi

if [ ! -h $HOME/.xsession-errors.old ]
then
    /bin/rm $HOME/.xsession-errors.old
    ln -s /dev/null $HOME/.xsession-errors.old
fi

It verifies if .xsession-errors is a symbolic link. If not, remove it and replace it with a symbolic link.

Lock and unlock the screen from command line

January 30, 2013 Leave a comment

Question
Is there a way to lock/unlock the screen from a script?

Answer
The answer is “yes”. Lock the screen:

gnome-screensaver-command -l

Unlock the screen:

gnome-screensaver-command -d

Demo (lock the screen, then unlock it in 5 seconds):

gnome-screensaver-command -l && sleep 5 && gnome-screensaver-command -d

Tip from here.

How to disable the HUD’s use of the Alt key?

January 30, 2013 Leave a comment

Annoyance
Pressing the Alt key brings up the HUD. How to get rid of it?

Solution
http://askubuntu.com/questions/122209/how-do-i-modify-or-disable-the-huds-use-of-the-alt-key

Launch System Settings, then Keyboard -> Shortcuts -> Launchers. On Key to show the HUD, press Backspace to disable it.

Categories: ubuntu Tags: , , ,

Rip streamed audio

January 30, 2013 Leave a comment

Problem
You want to rip a streamed radio.

Solution

  • fetch StreamRipStar, which is a frontend for streamripper
  • install streamripper (via apt-get)
  • configure StreamRipStar, specify the audio stream’s URL and start ripping

Tip
If you want to rip Slay Radio (best Commodore 64 tunes!), use this address: http://relay3.slayradio.org:8000/.

Make room! Make room!

January 29, 2013 Leave a comment

Problem
Under Gnome/Unity, you want to increase the number of virtual workspaces.

Solution
Start CompizConfig Settings Manager (ccsm), then General -> General Options -> Desktop Size tab. Here adjust the horizontal and vertical virtual size.

The title of this post is a reference to a novel of Harry Harrison.

Categories: ubuntu Tags: , , ,

VLC gets stuck

January 29, 2013 Leave a comment

Problem
On my Linux box, VLC gets stuck sometimes and only the good old “kill -9” can shoot it out. Is there a single command to kill it?

Solution

alias killvlc='kill -9 `ps ux | grep vlc | grep -v grep | tr -s " " | cut -d" " -f2`'
Categories: bash Tags: ,

Online Convert(er)

January 27, 2013 Leave a comment

http://www.online-convert.com/

I wanted to convert a PDF with Calibre but it failed. I tried with Online Convert(er) too and it succeeded…

Categories: Uncategorized Tags: , , , ,

Torcache

January 27, 2013 Leave a comment

Torcache is a free service for caching t. files online. I noticed by accident (got a timeout error…) that one big t. site stores its t. files here too.

Categories: Uncategorized Tags:

Automate a Windows application from Linux using Python

January 22, 2013 Leave a comment

Problem
For my everyday work I use Linux. I also have a Windows 7 in VirtualBox. Under Windows I’ve found a very nice movie catalogue called Movie Collector. It’s not free though; unfortunately I didn’t find any good open-source alternative for this task.

So, I had this software running in VirtualBox and I wanted to input a list of movies. I collected the list in a file. Movie Collector has a GUI interface where you can insert the title of a movie and it’s put in a queue (see the figure below). Then you can verify for each item if it found the correct movie.

The question is: how to insert the movie titles via the GUI interface in an automated fashion? I won’t type 100 titles by hand…

add_movies

Solution
It’s a perfect job for Python. There is a great module called autopy that includes functions for controlling the keyboard and mouse. I already had it under Linux. Fortunately, you can launch an autopy script under Linux and it can interact with a Windows GUI that runs in VirtualBox.

The idea is simple: read the input file, where there is a movie title in each line. Put the movie title on the clipboard (we are lucky again, if you put something on the clipboard under Linux, it’s available under Windows too in VirtualBox). Click in the Title text field, select everything with Ctrl+A, press Del to delete the content, paste from the clipboard and click on the Add to Queue button. Then repeat: take the next movie title, etc.

The following script does exactly this:

#!/usr/bin/env python

from autopy import key
from time import sleep
from jabbapylib.mouse import mouse
from jabbapylib.clipboard.clipboard import text_to_clipboards

TITLE = (68, 124)    # input text field's position
ADD = (575, 123)     # button's position

def delete():
    mouse.click_to(TITLE)
    key.tap('a', key.MOD_CONTROL)    # Ctrl+A
    key.tap(key.K_DELETE)            # Del
    sleep(.1)

def paste():
    mouse.click_to(TITLE)
    key.tap('v', key.MOD_CONTROL)    # Ctrl+V
    sleep(.1)

def add():
    mouse.click_to(ADD)
    sleep(.1)

def main():
    cnt = 0
    with open('movies.txt') as f:
        for title in f:
            title = title.rstrip('\n')
            text_to_clipboards(title)

            delete()
            paste()
            add()
            cnt += 1

    print cnt

#############################################################################

if __name__ == "__main__":
    print 'Switch to VirtualBox...'
    sleep(3)
    main()

The imported modules are here:

To figure out the position of GUI elements (to know where to click to), you can use this little helper.

Cobol Tutorial

January 14, 2013 Leave a comment

Just for fun: Cobol tutorial.

To be clear, I don’t ever want to touch Cobol. This is just for the record :)

Categories: fun, programming language Tags: ,
Follow

Get every new post delivered to your Inbox.

Join 71 other followers