Subversion repository part migration

svnadmin dump /srv/svn/old-repo | svndumpfilter include --drop-empty-revs --renumber-revs /directory-name > directory.svndump
svnadmin load /srv/svn/new-repo < directory.svndump
Please note, that if directory structure needs to be changed (for example, from /old-repo/projects/dir to /new-repo/dir) manual edit of dump file will not help. Instead, sed must be combined with svndumpfilter. Additional info regarding this topic can be found here.


Virtualbox 3.1.x Linux guest dead keyboard fix

After new release of Virtualbox was installed and my virtual machine with OpenSUSE on-board had started, I've ended up with a dead keyboard. It worked fine on Windows XP as host, but OpenSUSE VM was acting like there is no keyboard at all. Couple of minutes of brain activity and finger work I've found that /etc/X11/xorg.conf was replaced during Virtualbox Guest Additions update. Comparing xorg.conf between two latest VB releases, I was able to get the keyboard working. Here is a fix:

1. Restore old xorg.conf :
cp /etc/X11/xorg.conf.bak /etc/X11/xorg.conf
2. Add Option "CoreKeyboard" to InputDevice section of Keyboard[0]
3. Add Option "CorePointer" to InputDevice section of Mouse[1]
4. Add Option "SendCoreEvents" to InputDevice section of Mouse[2]
5. Rename Device option from InputDevice section of Mouse[2] from /dev/vboxadd to /dev/vboxguest


How to change language in GIMP on Windows

After installing GIMP on my laptop I've found it's language is set according to my regional settings. However, I have failed trying to change it to english because there is no visible configuration option for that. Now that's weird!
After googling for few minutes I've found that this is not a GIMP problem but rather GTK+ for Windows and to force it to use english translation by default you need to add lang environment variable with the value of c.


Removing MinGW dll dependencies


Passing -static-libgcc will remove this dependency for all languages other than C.
Note: C++ exceptions depends on this option.


Remove -mthreads option from your makefile.
Note: Multithreading and C++ exceptions depends on this option.



How to remove absolute path in svn+ssh

As you may or may not know there is a path difference between svn and svn+ssh links in case if subversion server is configured with default root directory:

SVNSERVE_OPTIONS="-d -R -r /path-to-repos"
This way repository can be checked out using following commands (consider ssh is set up and working):
svn co svn://server.com/repository directory
svn co svn+ssh://server.com/path-to-repos/repository directory


How to ARM Linux

During last few years I've never found a good excessive topic covering most of the areas to get Linux runnnig from scratch. I remember myself doing a lot of investigation about correct building of a crosscompiler, studying bootloader internals, and so on... I'm definitely sure - if I had a person that could point me in right direction, then all the development should finish much earlier.

Consider this article as my personal note and feel free using it your own way.


Bloody Hinet SPAM

Mail server logs
If one day God will give me his powers for at least a second, I'll burn all the Hinet servers at once!



In recent post I've posted part of my library, that deals with PostgreSQL data in binary format. Today, googling for some hints for implementing binary timestamps in double format I've found a reliable library, libpqtypes, which is doing exactly the same as mine (actually more), except it's purpose is PostgreSQL only.
Don't know if it's terrible news or not, as I could adapt my code while using this library and win a lot of time. This is one of the reasons why extensive googling is required before each project.

PostgreSQL binary timestamp functions

While writing libpq wrapper I've run into problems with binary timestamps, which required a lot of debugging and headaches. To avoid your own migraine, feel free to use my code below. Note, however, this code is not perfect, as it's uses long long for timestamps. This will work if your machine is 32bit and your server was compiled with `--enable-integer-datetimes` (highly recommended). If not, You're welcome to patch this code and post it here, so other people will thank you.


Lua constants

By Lua's nature, it is not possible to create constants. There is a workaround, though, using metatables:

function protect(tbl)
    return setmetatable({}, {
        __index = tbl,
        __newindex = function(t, key, value)
            error("attempting to change constant " ..
                   tostring(key) .. " to " .. tostring(value), 2)

constants = {
    x = 1,
    y = 2,
constants = protect(constants)

print(constants.x) --> 3
constants.x = 3 --> error: attempting to change constant x to 3


Lua error message format

I work on the library, which will use Lua. Thinking about the possibility to give a good error structure instead of plain message, I've found that lua_pcall has a nice feature to specify custom error handler function:

lua_pushcfunction(L, error_handler);
luaL_loadfile(L, "file.lua");
lua_pcall(L, 0, 0, -2);

Using this there is a way to get a chunk name and it's error line number:

int error_handler(lua_State* L) {
    lua_Debug d;

    lua_getstack(L, 1, &d);
    lua_getinfo(L, "Sln", &d);

    string err = lua_tostring(L, -1);
    lua_pop(L, 1);

    stringstream msg;
    msg << d.short_src << ":" << d.currentline;
    if(d.name != 0) {
        msg << "(" << d.namewhat << " " << d.name << ")";
    msg << " > " << err;
    lua_pushstring(L, msg.str().c_str());

    return 1;
Work's like a charm, except one thing. This is the output from this error handler:
[string "test"]:1 > [string "test"]:1: attempt to index global 'a' (a nil value)

Why? Oh, why the Lua guys are putting assembled error message with chunk name and line number if I use my own error handler? IMHO, this is wrong. There is no other way to give a user nice message except parsing. Actually parsing of such message is easy, but.. the Lua guys have changed error message format a few times already. I'm pissed!


Mingw on Linux

I'm using MinGW for years, but never tried to use it on Linux machine as a crosscompiler. Today I've had first experience. First thing I've noticed is how actually easy to install such environment - there is a totally automated build script available from MinGW site.
  • One environment
  • Speed. Native environment vs MSys is much, much faster.
  • Building non-Linux things on Linux means transferring them from one machine to another.


Fastest way to create database in PostgreSQL

This will create database and it's associated role from Linux shell:
su postgres
createuser -SDRPE user
createdb -E UTF8 -O user database

Fixing OpenSUSE Home/End keys

Comment lines 135-136 in /etc/inputrc :
#"e[1~":       history-search-backward
#"e[4~":       set-mark


Icon and version information resource file

This should be an update for one of the recent posts.

ID ICON "path/to/my.ico"
...the ID can be anything. It doesn't matter unless it is referred in the code.

Run windres as follows:
windres resource.rc -O coff -o resource.o
Include resource.o along with other object files while linking, e.g.,
g++ -o app obj1.o obj2.o resource.o

And, at no extra charge, it is possible to include version information to the application, adding the following boilerplate to resource.rc file:
FILEVERSION     1,0,0,0
    BLOCK "StringFileInfo"
        BLOCK "040904E4"
            VALUE "CompanyName", "Company name"
            VALUE "FileDescription", "Application name"
            VALUE "FileVersion", "1.0"
            VALUE "InternalName", "my_app"
            VALUE "LegalCopyright", "Copyright info"
            VALUE "OriginalFilename", "my_app.exe"
            VALUE "ProductName", "My App"
            VALUE "ProductVersion", "1.0"
    BLOCK "VarFileInfo"
        VALUE "Translation", 0x409, 1252

- Original post
- Additional info

Credit goes to Evan McLean.


C Lua snippets

Get currently executed chunk name:
lua_Debug lua_info;
lua_getstack(L, 0, &lua_info);
lua_getinfo(L, "n", &lua_info);
string name = lua_info.name;
Opposite to lua_register:
lua_setglobal(L, name.c_str());
stack_dump in C++ flavour ;)
static void stack_dump (lua_State *L) {
    int top = lua_gettop(L);
    for(int i = 1; i <= top; i++) {
        int t = lua_type(L, i);
        switch(t) {
            case LUA_TSTRING:
                cout << "'" << lua_tostring(L, i) << "'";
            case LUA_TBOOLEAN:
                cout << (lua_toboolean(L, i) ? "true" : "false");
            case LUA_TNUMBER:
                cout << lua_tonumber(L, i);
                cout << lua_typename(L, t);
        cout << "  ";
    cout << endl;


Gettext compilation on MSys

Trying to build gettext library on MSys I've got some errors related to pthread. Included readme states you need to have Cygwin for that. For those, who prefer MSys over Cygwin here goes a quick fix:
Add -lpthread to LIBS section in gettext-runtime/src/Makefile and gettext-tools/src/Makefile.
Remove tests target from gettext-runtime/Makefile and gettext-tools/Makefile.
make; make install
Be happy.


Libiconv compilation sed on msys error

Trying to build libiconv library under msys environment, I've got sed related errors:
sed: -e expression #2, char 32: Extra characters after command
Fortunately, I've found a solution in the internet:
diff -ur tmp/libiconv-1.12/windows/windres-options src/libiconv-1.12/windows/windres-options
--- tmp/libiconv-1.12/windows/windres-options 2007-05-27 19:42:10 +0100
+++ src/libiconv-1.12/windows/windres-options 2008-05-28 13:41:03 +0100
@@ -14,20 +14,29 @@
version="$1" # something like 2.0 or 2.17 or 2.17.3 or 2.17.3-pre3

+  s/^([0-9]*).*/1/p
+  q
+  s/^[0-9]*[.]([0-9]*).*/1/p
+  q
+  s/^[0-9]*[.][0-9]*[.]([0-9]*).*/1/p
+  q

Credit goes to Keith Marshall.

Tango patcher

For those who are not scared to apply mods on Windows, check out this hot Tango patcher. It is based on one of my favorite open source childs, Tango Desktop Project, and will change almost all the Windows system icons to Tango ones.. And yes, there is Vista version too.


Toshiba U300-154 upgrade

Toshiba U300-154
Something happened yesterday. I've promised to my customer to replace the broken HDD for it's laptop. Unfortunately I was unable to find any 2.5" Sata HDD, except expensive shops that are working on sundays. So, I've got to put out HDD out of my lovely Toshiba U300-154. Looking at my semi-dead laptop I decided that this is a good time for some upgrades.
And.. voila! My laptop now has 4GB of RAM instead of 2, and awesome Seagate's 500GB HDD with G-Force sensor instead of 200GB with no mods...


Set up AVR timer interrupt

/* initialize timer interrupt */
void init_isr_timers() {
    /* OC1A/OC1B disconnected */
    TCCR1A = 0;
    /* CTC mode, top in OCR1A / Timer clock = CLK/1024 */
    TCCR1B = (1<<WGM12)|(1<<CS12)|(1<<CS10);
    /* set OCR1A top value for 20Hz (10 periods in one second) */
    /*   0x0168 for CPU @ 7.3728MHz */
    OCR1A = 0x0168;
    /* enable Timer/Counter 1 interrupt */
    TIMSK = (1<<OCIE1A);

/* timer/counter 1 interrupt handler */
    /* Ohhh, lovely! :) */

int main() {
    /* initialize timer interrupt */
    /* enable interrupts */

    /* main loop */
    for(;;) {}

Store an array in a session

// begin the session

// create an array
$my_array = array('blonde', 'girls', 'are', 'stupid');

// put the array in a session variable
$_SESSION['truth'] = $my_array;

Add application icon on Eclipse with MinGW

Project > Properties > C/C++ Build > Settings > Tool Settings > MinGW C++ Linker > Miscellaneous > Other objects:
Project > Properties > C/C++ Build > Settings > Build Steps > Pre-build steps > Command:
windres -i ..sourceresource.rc -o sourceresource.o

Create MinGW library from dll

For this, you need pexports tool from mingw-utils.
pexports library.dll > library.def
dlltool -D library.dll -d library.def -l library.dll.a
Note, that if dll was built by different environment than gcc, this probably will not work because of the naming conventions. If this the case, read here.