Unsigned long long and gmplib

September 23, 2011 on 6:19 pm | In geeky | No Comments

While doing some projecteuler's, I wanted to convert an unsigned long long (64-bit unsigned integer on an 32-bit machine) to mpz_t (and possible vice versa). The API does not have a convenient method for this, but it is possible using the mpz_import and mpz_export; it goes something like this:

mpz_t mp;
unsigned long long ull = 42;


/* mp = ull */
mpz_import(mp, 1, 1, sizeof(ull), 0, 0, &ull);

/* ull = mp; note: this needs bondary checking */
if (mpz_sizeinbase(mp, 256) <= sizeof(ull))
        mpz_export(&ull, NULL, 1, sizeof(ull), 0, 0, mp);

For signed integers you'll need some additional tricks, as mpz_import and mpz_export do not support negatives; just negate before and after conversion (hint: mpz_neg()). The boundary checking in export case is slightly more problematic then, and is likely easier to do after export.

Git branch in prompt

March 7, 2011 on 12:48 pm | In geeky | No Comments

While creating set of bash_completion rules for mc-tool, I read some other rule files to see how things are done. I happened to spot some useful functions from git's completion, mainly __git_ps1, which prints the name of the current branch.

Having the name of the current branch can save some mistakes every now and then, and with environment variable GIT_PS1_SHOWDIRTYSTATE you can even make it show if there are non-staged and/or non-committed changes in your tree.

This is how I used it:

PS1='\u@\h \w$(GIT_PS1_SHOWDIRTYSTATE=1 __git_ps1)\$ '

By default the output of __git_ps1 is " (name-of-branch)", or "" if current directory does not belong to a git tree. The format string can be given on command line, like " (%s)".

The current version seems to have a small glitch that causes it to print give (unknown) for home directory, if you use git global settings.

Context aware bash environment

March 4, 2011 on 2:03 pm | In geeky | No Comments

While mixing hobby and work development on the same machine, I've every now and then longed for a way to set environment variables depending on the current directory. Up to now had I been too lazy to do anything about it, but finally did it.

What the snippet does, it finds all current user owned .env files from current directory and it's parent directories, checks if the topmost has changed and if it has, reads them all in reverse order. If home directory was not a parent of current directory, the ~/.env is read before others.

If you want this too, look at the code. Include these in your .bashrc, and you should be good to go.

Examples of environment variables I've found useful are DEB_EMAIL and DEB_FULLNAME used by dpkg tools and the equivalents in git world, GIT_COMMITTER_EMAIL, GIT_COMMITTER_NAME.

Future of MeeGo

February 24, 2011 on 2:15 pm | In maemo, meego | No Comments

My interest in the future of MeeGo is quite intense, both professionally and personally. Today the CEO of my employer wrote his thoughts into his blog. It was quite interesting read, and hopefully gives new hope for those in doubt.

qmake and D-Bus

February 18, 2011 on 9:58 pm | In geeky | 5 Comments

Something I did not find documented anywhere: a sensible way to generate QtDBus adaptor and interface classes from introspection data with qdbusxml2cpp. I only found hacks using system() and custom targets to accomplish the feat.

I though to myself that there must be a saner, better way, and while looking at the qmake generated Makefile, I noticed some interesting includes. After some investigation, I found "magic" variables DBUS_INTERFACES and DBUS_ADAPTORS. The introspect files should be named servicename.xml and listed in the variables, and qmake will do all the magic for you.

With these variables, it is really easy to generate the helper classes on-demand. Just remember to include the generated header in some code file, otherwise compilation will choke.

QT = core dbus
TARGET = qtdbus
DBUS_ADAPTORS = fi.inz.hello.xml
SOURCES = hello.cpp main.cpp
HEADERS = hello.h

With this simple .pro file qmake autogenerates the adaptor on build.

To see other files from the example, see fi.inz.hello.xml hello.cpp hello.h main.cpp qtdbus.pro

LinkedIn test

March 11, 2009 on 1:45 pm | In LinkedIn | No Comments


More scratchbox x86_64 goodness

March 6, 2009 on 2:49 pm | In maemo | 2 Comments

On 64-bit platform and willing to try the new fremantle SDK? Look no further, following the previous release, now here are the debs for scratchbox as needed by fremantle.

As last time, the debs are, again, available with apt, just add:

deb http://www.ipi.fi/~pablo/maemo5-sdk_amd64 /

to your sources.list and apt-get yourself out!

Scratchbox on AMD64

February 27, 2009 on 12:07 pm | In maemo | 2 Comments

Following yesterday's vdso32 hack. The same colleague now built amd64 packages for maemo4 scratchbox.

Also with debian repo; just add

deb http://www.ipi.fi/~pablo/sbox_amd64 /

to your apt sources.

VDSO32 disabler kernel module

February 26, 2009 on 1:16 pm | In maemo | 4 Comments

Scratchbox needs vdso disabled, which can be done run-time with 32-bit kernels. With 64-bit kernels, however, this is not possible... until now. A colleague of mine wrote a (hacky) kernel module to do exactly that, it seeks the vdso-flag and writes 0 to it. I helped him with dkms/deb packaging, and now it's available for download.

Note that this does not help with any other annoyances with sbox on 64-bit system, but at least it is something.

Blobby Volley 2 extra AI package

October 14, 2008 on 11:56 am | In maemo | 1 Comment

Blobby Volley 2 is a nice volley ball game in the spirit of clbuttic arcade volleyball. However, the default AIs are beatable by jumping in certain point, definitely too easy. Found some AIs over at esnips, and for convenience packaged them for maemo. .install file available as usual. Just install the package, start the game, go to options and select some AI.

Warning: these AIs aren't easy to beat.

« Previous PageNext Page »

Powered by WordPress.
Entries and comments feeds. Valid XHTML and CSS. ^Top^