Powered by
Movable Type 5.2.9

 Programmierung Archives

2006, October 12 (Thu)

Linux, Programmierung Deutsche Umlaute auf Tastatur mit US-Layout

Wer viel programmiert hat wahrscheinlich bemerkt, dass das englische Tastaturlayout dafür besser geeignet ist, als das deutsche, da dort viele Sonderzeichen leichter zu erreichen ist. Allerdings stehen dort keine Umlaute zur Verfügung. Oft kann man diese zwar nur ae, oe, ue ersetzen, in formellen Schreiben ist dies jedoch eher unerwünscht.
Um dieses Problem zu umgehen, habe ich mir eine Keymap für xmodmap angelegt.
Diese ermöglicht es mir, die zweite Windows-Taste (Menü-Taste) als eine Art zweites Shift zu benutzen. D.h. mit Win2+a mache ich ein ä, mit Shift+Win2+a ein Ä. Selbiges natürlich auch bei öüÖÜß.

Um dies zu erreichen legt man eine ~/.Xmodmap mit folgendem Inhalt an:
keycode 117 = Mode_switch
keycode  38 = a A adiaeresis Adiaeresis
keycode  30 = u U udiaeresis Udiaeresis
keycode  32 = o O odiaeresis Odiaeresis
keycode  39 = s S ssharp
Um das Layout sofort zu aktivieren, einfach xmodmap ~/.Xmodmap ausführen.

Der Keycode 117 steht dabei für die Windows-Menü-Taste. Die Keycodes von anderen Tasten kann man über das Programm xev herausfinden. Die Namen von weiteren Sonderzeichen aus anderen Sprachen kann man sich aus den jeweiligen Layouts in /usr/share/xmodmap heraussuchen.

2007, January 31 (Wed)

Netzwelt, Programmierung, Web Dump Irssi Scripts

Don’t get me wrong, please. I haven’t written these scripts — I was
merely using them.

Because I’ve got them lying ‘round in my so called “Web Dump”
for a long time now, I thought I’d write a slightly more comprehensive
introduction to what made my life easier just a little while ago.

I hope this can be of interest to some of you, and maybe I have a lucky
hand with keywords so that even more people can benefit from these nice
scripts when a search engine spider picks them up.

I have lsted these works in no particular order:

2007, June 28 (Thu)

Linux, Programmierung Direct I/O filesystem access in Linux with O_DIRECT

I just tried to read files from the filesystem using direct i/o to avoid the operating systems caching effects.
The manpage of open lists the flag O_DIRECT for this. Although I included fcntl.h, my compiler complained that it couldn't find O_DIRECT:

contrib/myfile.c:44: error: ‘O_DIRECT’ undeclared (first use in this function)

The solution was easy:
You just have to

#define _GNU_SOURCE

before including fnctl.h.

This is actually mentioned in the manpage, but only in a footnote that is easy to overlook.

2007, October 24 (Wed)

Linux, Programmierung thttpd and hgweb.cgi

hgweb.cgi, which is a Pythonscript to provide webaccess to a hg repository, does not work out of the box with thttpd.

The error is:

args = ('REQUEST_URI',)

The quick-and-dirty fix is kinda simple; write a small wrapper which sets REQUEST_URI and runs hgweb.cgi. The content of REQUEST_URI seems to do not matter at all.

export REQUEST_URI="/blafuck/"
exec ./hgweb.cgi

2009, March 09 (Mon)

Programmierung Jabber components

I could not really find an easy example how to get started with Jabber components (using xmpp4r), so this I will cover the absolute basics here.

You will need a Jabber server to connect your component to. I suggest to install ejabberd locally. Also needed is xmpp4r, which can be installed through rubygems (e.g. using sudo gem install xmpp4r). Feel free to use your favourite package manager to install it, if packaged.

The following snippet is used to configure ejabberd to listen for your component. After altering the configuration, do not forget to restart ejabberd. DNS seems to be important for elang-stuff, so make sure the host you use (e.g. localhost) can be resolved properly.

 {5348, ejabberd_service, [
                            {access, all}, 
                            {shaper_rule, fast},
                            {ip, {127, 0, 0, 1}},
                            {host, "mycomponent.localhost",
                             [{password, "secret"}]

Take a look at the sample configfile and use a predefined, commented service configuration, so you won’t have to fiddle with erlang-stuff.

Now you can create this small file, name it mycomponent.rb and use the following content:

require 'xmpp4r'

class MyComponent < Jabber::Component
	def initialize config
		super config['jid']
		# connect to the main server
		connect config['server'], config['port']
		# authenticate
		auth config['password']
		add_message_callback do |message|
			Thread.new do
				handle_message message
		# stop this thread
	# handles incoming messages
	def handle_message message
		puts "received message from #{message.from}: #{message.body}"

# configuration
config = {
	'jid' => 'mycomponent.localhost',
	'server' => 'localhost',
	'port' => 5348,
	'password' => 'secret'

# instantiate, connect and auth
mycomponent = MyComponent.new config

Using this kind of Hash as configuration makes it very easy to use YAML to store your configuration in a file. If ruby can’t find xmpp4r, you might have to require 'rubygems' before, if you installed xmpp4r via rubygems.

Now you can run your component and send messages to mycomponent.localhost. The handle_message will print any messages received.

Programmierung Ruby Logger Singleton

Sometimes you might want a Singleton Logger in Ruby. Here is what works:

require 'logger'
require 'singleton'

class Logger
    include Singleton
    @@old_initialize = Logger.instance_method :initialize

    def initialize

2009, March 19 (Thu)

Programmierung Jabber component mapping Microblogging to Multi-User-Chat

I have put some glue between xmpp4r and twitter, et voila, a Jabber component mapping
microblogging to a Jabber Multi-User-Chat.

Working right now:

  • friends joining as participants

  • friends timeline

  • posting updates

  • sending and receiving direct/private messages


  • follow/unfollow (I'd like to implement this as invite/kick)

  • blocking (ban)

  • avatars (can be easily done)

  • a lot more

You can try this out by joining the MUC-room {identi.ca|twitter}@omb.jabber.teamidiot.de
and using your username as nickname and providing your password.
As this is not safe (I might steal your password) I suggest to setup your own component,
try it out and provide feedback.

The repository (mercurial) is at: http://gonzo.teamidiot.de/repos/ombmuc/.

2009, October 04 (Sun)

Programmierung calling C++ bind-bound functions with variable parameters


Consider this following small example program.

#include <functional>
#include <iostream>

using namespace std::placeholders;


We write a subroutine that outputs the multiple of its arguments, a and b.

void multiple(int a, int b, const std::string & who) {
  std::cout << who << ":\t" << a << "×" << b << "=" << a*b << std::endl;

int main() {

We then call it from main.



Next, we want to use bind to bind some arguments and call it. Unsurprisingly, the output is the same.



We can also store this bound function and call it:

  auto bound(std::bind(multiple,2,3,"bound"));


Things get wicked, when we want to predefine only one parameter, though :(

  //std::bind(multiple,2,_1,"bindp")(3); // you wish!
Continue reading “calling C++ bind-bound functions with variable parameters ” »

2010, May 26 (Wed)

Programmierung cpan for local user configuration

To install perl modules without root permission, this seems to work for me within cpan:

UPDATE the modern recommendation would be to use the (almost) excellent local::lib module. First, download the archive through the link on the right side of the CPAN search page. Unpack it somewhere and follow the instructions on the CPAN site: run perl Makefile.PL --bootstrap and add the necessary call to your shell profile.

Now you can (after log-out and log-in) just run perl -MCPAN -Mlocal::lib -eshell and have it do auto-configuration (remove your .cpan/CPAN directory first if you have a broken configuration), and “install”ing packages should just work.

(old content below)

Continue reading “cpan for local user configuration” »

2010, June 18 (Fri)

Programmierung int log2 in gcc / c++

I wonder why this result isn’t on google’s #1 for int log2 gcc.

To get the integer logarithm to the base of 2, try

      sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(   n );
     sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(  n );
sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll( n ); 

2012, July 31 (Tue)

Programmierung g++ make depend generation

If you look at automatic make file dependency rule generation for the g++ compiler, there are a lot of different solutions on the Internet. I’m not sure which one is the best, but it sure involved the -MM or -MMD switch to g++.

I found the following to work sufficiently at the end of my simple project Makefile:


	$(CXX) -MM -MT $@ -MT $(patsubst %.d,%.o,$@) $(CXXFLAGS) -o $@ $^

include $(patsubst %.cpp,%.d,$(SRC))

the include directive will make sure that the necessary name.d rule files are generated.

this requires the source files predefined in SRC, example:

SRC := $(wildcard *.cpp)

2013, January 18 (Fri)

Programmierung mysterious crash in program_options

gdb backtrace looked something like this:

#0 0x00007ffff76a02e2 in __cxxabiv1::__vmi_class_type_info::__do_upcast
(__cxxabiv1::__class_type_info const*, void const*,
__cxxabiv1::__class_type_info::__upcast_result&) const () from /usr/lib64/libstdc++.so.6
#1 0x00007ffff769d4c5 in __cxxabiv1::__class_type_info::__do_upcast
(__cxxabiv1::__class_type_info const*, void**) const () from /usr/lib64/libstdc++.so.6
#2 0x00007ffff769e135 in get_adjusted_ptr(std::type_info const*, std::type_info const*, void**)
() from /usr/lib64/libstdc++.so.6
#3 0x00007ffff769e93c in __gxx_personality_v0 () from /usr/lib64/libstdc++.so.6
#4 0x00007ffff71dcfb3 in _Unwind_RaiseException () from /lib64/libgcc_s.so.1
#5 0x00007ffff769efc1 in __cxa_throw () from /usr/lib64/libstdc++.so.6
#6 0x00007ffff79a6ecb in void boost::throw_exception<boost::program_options::unknown_option>
(boost::program_options::unknown_option const&) () from ../boost_1_52_0/boost11/lib/
#10 0x00000000004098e4 in boost::program_options::parse_command_line (argc=2, argv=
0x7fffffffdaa8, desc=..., style=0, ext=...) at ./boost_includes/boost/program_options/detail/
#11 0x0000000000408e92 in main (argc=2, argv=0x7fffffffdaa8) at main.cpp:11

note to self: don’t forget to upgrade binutils/gold/ld

2013, October 30 (Wed)

Linux, Programmierung, Web Dump Network Scanner Server, headless

Usage scenario:

Your small group has a scanner in walking distance, and wants to use it for simple scanning.

  • It is not worth it to connect the scanner to the user’s computer,

  • and also not worth it to be running back and forth between scanner and computer to check the scanning progress (as is suggested by saned).

  • Mixed local/network scanning on the machine is not required (as suggested in scanbd.)

  • The scanner is connected to a machine without display but with audio hardware. In our case it is an old broken Thinkpad.

  • Maybe the scanner is a cheap crappy scanner without automatic document feeding etc.

This script will poll the buttons, scan according to two pre-sets (you could make the scripts more complex if desired) and publish the result on a Windows share.

Communication with the user is done through speech synthesis software.

End user experience:

  • The Windows share is added once through “Connect Network Drive” in Windows or as a smb:// Bookmark in Nautilus, possibly by a local “Computer Expert”

  • User has something to scan, takes the papers to the room with the scanner. He puts each sheet on the scanner and pushes Button 1. When the scan is finished, he does the same with the next sheet and so on. At the end, the user pushes Button 4 to signal he is done scanning.

  • User goes back to his computer, copies the finished PDF file out of the network share. If necessary, he launches Adobe or another software to fix up any rough edges in the scan.

  • User could also print this document to some printer in yet another room, after reviewing that everything is in order.

Script to do it:

You can grab your copy here: scanbtn.tar. Detailed information is inside the README file therein. Enjoy!