Monitor resolution and more than one

•2011-09-13T11:05:25+00:00 • Leave a Comment

Need to get more into it, if I have time.

Looks interesting to work with xrandr.


scanning via scanimage

•2011-08-25T14:51:47+00:00 • Leave a Comment

Brother has a broad variety of printer/scanner driver for linux. Also there are quite good installation instructions (step-by-step and images for the output).  After installing the driver for scanning, you will need a utility to scan from the printer. scanimage is just the right program for that. With

# scanimage –format=tiff -v > ~/image.tiff

you will have an image named image.tiff in your home folder. If your scanner is not the default scanner you can work your device with

# scanimage -L

out, because it gives you a list of scanning devices. The option -d can specify another device, if you have more than one.


Customising the keyboard layout

•2011-08-18T20:56:51+00:00 • Leave a Comment

If you have an American keyboard layout, you can use special characters like brackets [] easier than on the German. But you will miss umlaute like öäü. I saw a solution for that on a friends laptop. He removed his German keyboard layout of his netbook and bought an us one in the Internet. After that he changed his keymap to his needs.

First I back upped my us keymap.

# cd /usr/share/X11/xkb/symbols
# cp us us.old

The next step was to move the layout to my home folder and put a symbolic link into the directory.

# mv us /home/user/
# sudo ln -s /home/user/us .

Now I modified the keymap.

# key <AD03> { [ e, E, EuroSign ] };
# key <AD11> { [ bracketleft, braceleft,udiaeresis, Udiaeresis ] };
# key <AC10> { [ semicolon, colon, odiaeresis, Odiaeresis ] };
# key <AC11> { [ apostrophe, quotedbl, adiaeresis, Adiaeresis ] };
# key <AE11> { [ minus, underscore, ssharp] };

Also I added this option.

# include “level3(ralt_switch)”

The key entries are build like that:

A – alphanumeric key; D – fourth row from below; 03 – third key, so this would be the e-key not w because, caps-lock is a control key
AE02 would be the key 1

key { [ , , , ] };

The last option I added is quite important for the American default layout, because without the right Alt-key could not be used to get the third and fourth character for each key. After altering the keymap, you can restart your X-server via Ctrl-Alt-Backspace, but be careful, because all open windows will be terminated immediately.

With this you can add any type of character or symbol for your keymap, like smilies or anything else.


UPDATE: added ß (ssharp)

Adding Fonts to Linux Mint

•2011-08-18T16:24:41+00:00 • Leave a Comment

To add a font for linux mint there is quite a easy way to do it.

First you download the font file and put it into /usr/share/fonts/ or you put a symbolic link as a font into it. After that you update the font-cache via

# fc-cache fv

That should be it.


Python and Tkinter

•2011-06-06T10:24:02+00:00 • Leave a Comment

Tkinter is the standard GUI-package for python and is a object-orientated layer above Tcl/Tk. So if you know, how to describe a GUI with Tcl/Tk in C, it should be no problem for you to do it in python.

To start with it you can create a simple program with:


from Tkinter import * < – You will need to import all functions, a simple import Tkinter will not be sufficient.

root = Tk() <- This creates a start widget to put in all other widgets (buttons, images, menus, etc.).

label = Label(root, text=”hello world”) <- To create a Label you need to put it into a reference and give it some options.

label.pack() <- Now you can use one of three options to put it in the main frame. Here we obviously use pack.

root.mainloop() <- With this method you start the event handler of Tkinter (for key press and mouse clicks). Also this is important for Tkinter to create the application itself and to update it.

As mentioned above you can put your widgets via three different methods. There pack, grid and place. These are geometry manager and the allow you to postion the widgets where you want. Pack organizes the wigdets how they come and fit together the best way it can make out (you should try yourself). Grid works like a grid and you can directly control how many rows and columns a widget needs. Place gives you full controll where to put the widgets, so it is a lot of work.

With the bind-method you can capture any mouse or keyboard events you like.

root.bind(‘<Escape>’, lambda e: root.quit()) <- This binds the escape-key to the quit function, instead of lambda you can use any other function.

So now we have settled the basics we can get to the bigger program. It is a simple calculator for the four basic operations +, -, *, /.  It uses binds for the different buttons. Also there is a rudimental menu.  I created a class for the calculator to hold all the functions in one object.  In the main procedure I create a root widget, which I pass over to the new object calc. This creates in it __init__method the layout with a label for the result, the different buttons in a maximum of four rows and a menu with a quit option. Furthermore the buttons get bind to a function and after it I run the mainloop and create the application. The destroy method is not necessary, but should be used in some development environments. The widget are object, so you can get and set the attributes of an object. But after its creation you can alter these with the configure-method.  Another important point to know is, that you need special variables of Tkinter for interactive text. There are three different types (String, Boolean, Integer).

lambda are anomynous functions which are not bound to name. so they cannot be called from everywhere. Additionally there is no switch function in python, but you can use a dictionary for that. You just need to use your switch-case as keyword for the dictionary. But then every function needs to have the same amount of arguments or you use some padding-variables.


from Tkinter import *

class Calculon:

def __init__(self, master):

buttonText = [“1”, “2”, “3”, “+”, “4”, “5”, “6”, “-“, “7”, “8”, “9”, “*”, “0”, “.”, “=”, “/”]

master.bind(‘<Escape>’, lambda e: master.quit())
master.bind(‘<Return>’, lambda e: self.buttonPress(“=”))

for each in buttonText:
master.bind(each, lambda e: self.buttonPress(repr(e.char).strip(“‘”)))

self.resultText = StringVar()
self.result = Label(master, anchor=E, textvariable=self.resultText, justify=RIGHT, bg=”white”)
self.result.grid(row=0, column=0, columnspan=4, sticky=E+N+S+W)
self.operatorText = StringVar()
self.operator = Label(master, anchor=W, textvariable=self.operatorText, justify=LEFT, bg=”grey”)
self.operator.grid(row=0, column=0, sticky=W+N+S+E)
self.temp = “”
self.operations = {“+”: self.add, “-“: self.sub, “*”: self.mul, “/”:self.div}

self.menubar = Menu(master)
self.pullDown = Menu(self.menubar, tearoff=0)
self.pullDown.add_command(label=”Quit”, command=master.quit)
self.menubar.add_cascade(label=”Do it”, menu=self.pullDown)

rowC = 1
colC = 0
for item in buttonText:
if colC > 3:
colC = 0
rowC = rowC + 1
Button(master, text=str(item), command=lambda i=item:self.buttonPress(i)).grid(row=rowC, column=colC)
colC = colC + 1

def add(self, a, b):
return a+b

def sub(self, a, b):
return a-b

def mul(self, a, b):
return a*b

def div(self, a, b):
if b != 0:
return a/b
return “division by zero”

def buttonPress(self, c):
if ((ord(c) > 47) and (ord(c) < 58)) or (ord(c) == 46):
if len(self.resultText.get()) > 10:
return -1
if self.resultText.get() != “0”:
self.resultText.set(self.resultText.get() + c)
elif (ord(c) > 41) and (ord(c) < 48) or ord(c) == 61:
if self.operatorText.get() == “” or self.operatorText.get() == “=”:
self.temp = int(self.resultText.get())
result = self.operations[self.operatorText.get()](self.temp, int(self.resultText.get()))
if result < 0:

def main():
root = Tk()
calc = Calculon(root)


if __name__ == “__main__”:

All in all the calculator is quite incomplete. You can compute decimal values, also the menu is quite useless and instead of a label you could use a entry widget (editbox) for entering numbers. A few more functions for extracting the root or squaring would be useful too. But I think it is a good start to play around with the different opportunities which Tkinter you give.

sources: (with a good references for most of the options of a lot methods)

calc – source code to ownload as pdf with all intends <:

Some shellscripting and find

•2011-04-24T12:10:49+00:00 • Leave a Comment

to copy data you modified in the last 7 days to another directory. you can use:

# copy -r `find /dir/to/my/data/* -maxdepth 0 -mtime -7 -print0` -v -t .

copy -r -> recursive, copy data of data inside of folders
copy -v -> verbose, writes on standard output the files which it is copying
copy -t -> destination folder

find -maxdepth -> how deep find shall look (another option would be -prune)
find -mtime -n -> data which had write access in the last n*24 hours
find -print0 -> write the data without a newline

the shell will first compute the command between the backticks ` and then run the rest of the command, so you do not have to write all the folders for yourself.

this can save some time typing.

with an ampersand (&) you can put any process into the background. with jobs you can see a list of jobs which are currently running in the background. bg and fg put processes in the background or foreground. generally you can stop a process with ctrl + z and put it with bg in the background, it will continue there. then with jobs you can see the number of it and get it with fg %n (n is the number of the process) back to the foreground). so if you want to kill a process in the background, you can use kill %n. in that way you can e.g. start a few rsync processes with just one terminal and overview their status with a few commands.


CSV-Import in postgres

•2011-03-25T17:55:40+00:00 • Leave a Comment

To move data from one dbs to another would be done via a sqldump, but if you are moving to another dbms you will need a csv file, because the sql syntax varies from system to system. So if you need to move from a MS Access database to a postgres database you can use the export function for your MS db and put it into your postgres database via the copy command. you can issue it with psql or any other tool you use to manage your postgres instance (e.g. pgadmin).

the command is like that:

COPY FROM ‘filename on the system where the csv-file is’ (coloumn names in the order in which they appear in the csv-file, ..) WITH DELIMITER ‘e.g. ;’;

You can use the csv option as well for the definition of strings in your csv data. If you are getting problems with the encoding of your text file, you can easily convert it on a linux system with iconv.

# iconv -f -t -o

There is no need for a filename, if the text file comes from stdin. To find out what type of encoding your file already has you can use the command file.

# file

It gives you a hint how the text file is encoded.