Gentoo Portage: libxcb and broken libraries

November 14th, 2009

When using the Gentoο distribution, updating all your installed packages should be as easy as:
# emerge -avDuN world

But, when I tried it yesterday, It wouldn’t work: It could not emerge media-libs/xine-lib.

I tried running revdep-rebuild to find any broken libraries and it found a lot of them, all missing files from libxcb. I tried to emerge it, but I realized it was part of the packages “emerge world” had already emerged.

After doing some googling, I found Gentoo libxcb 1.4 Upgrade Guide. It says you have to manually run a bash script, then revdep-rebuild and finally remove an outdated shared library file.

So, be careful when you upgrade libxcb, world or any package that depends on libxcb (I think the new Xorg >= 1.6 is one of them).

However, when things like this happen, I always wonder: Why do I have to read upgrade guides and run things manually? Isn’t emerge supposed to do this for me? I’m sure there is some kind of explanation, but isn’t there some way to get around this? Maybe an option on emerge?

Even the annoying “eselect news” doesn’t inform you about this important guide. Instead, it keeps popping up every time it finds an article that you will surely not be interested to read (an exception was the new article about KDE 3.5 and the sunset overlay).

Bring functional programming to IEEExtreme!

September 1st, 2009

IEEExtreme 2009 competition registration opens today, 1st of September.

This competition seems very interesting, and some kamibu members are thinking about participating!

Languages supported are: Microsoft Visual C++/C#, C/C++, C# and some “surprises”.

I would really like to see some functional programming language getting on to that list, like Common Lisp, Haskell or my favourite: Scheme!

Functional programming may be very handy some times, and a lot of fun!

For example, I tried solving last year’s “Merging IP’s” problem (see IEEEXtreme 2008 Competition booklet, pdf) using Scheme.

The goal is to merge a list of IP intervals (e.g. 192.168.1.1 – 192.168.1.60), so that you only keep a list of the minimum required intervals.

Example Input:
3.0.0.0 – 3.100.0.0
3.99.0.0 – 3.255.0.0
10.1.0.0 – 10.200.0.0
10.2.0.1 – 10.5.99.99
10.200.0.1 – 10.225.225.0

Example Output:
3.0.0.0 – 3.255.0.0
10.1.0.0 – 10.225.225.0

Let’s build the main loop for the program (without input and output functions).

Suppose we have 2 functions ready: (should-merge int1 int2) that is true only if intervals int1 and int2 should be merged (one of them starts in the middle of the other and ends after it), and (precedes int1 int2) only if both addresses of interval1 “precede” interval2 (e.g. 5.0.0.0 – 6.0.0.0 precedes 6.0.0.5-7.0.0.0).

Now, we can write a function (merge-intervals intervals merged) that will recursively merge all intervals. Intervals parameter should be a list of intervals that have to be merged, sorted by their first address.
Merged should be a list of intervals that are always totally merged. In the beginning it should be an empty list, and in the end the solution of the problem.

(define (merge-intervals intervals merged)
  ; important! intervals must be sorted
  (cond ((null? intervals) merged) ; all intervals are merged. return merged list
          ((null? merged)
            ; just started, merged is empty
            ; remove first of intervals and add it to the merged list
            merge-intervals (cdr intervals) (list (car intervals)))
          ((should-merge (car intervals) (car merged)) 
            ; the two intervals should be merged
            (merge-intervals (cdr intervals) 
              (cons 
                (merge (car intervals) (car merged)) 
                (cdr merged))))
          ((precedes (car merged) (car intervals))
            ; add the first of intervals to the top of merged
            (merge-intervals (cdr intervals) (cons (car intervals) merged)))
          (else
            ; the first of intervals starts after the last merged
            ; and ends before the last merged ends
            ; ignore it
            (merge-intervals (cdr intervals) merged))))
 
; We also used the merge function, that has a pretty straightforward definition
; returns an interval that starts at the start of int1 and ends at the end of int2
(define (merge int1 int2)
  (interval-create
    (interval-start int1)
    (interval-end int2)))

Of course, there are no built-in functions to handle intervals in Scheme, you have to write them (interval-create etc) on your own. A pair is perfect for representing an interval.

Notice that an iterative implementation would not (or at least it shouldn’t) be faster than the recursive impementation used here, as Scheme implements tail-recursion.

For those not familiar with Scheme or Lisp,
(car l) can be interpreted as returning the first item of list l
(cdr l) as returning all the items but the first of list l, and
(cons item l) as pushing item to the beginning of the list l,
although that’s not exactly what they do.

Implementing should-merge and precedes function is a piece of cake if you represent the IP addresses as an integer (like ip2long of PHP or python iptools).

Bring Scheme to IEEExtreme 2009!
Bring functional programming to IEEExtreme 2009!

P.S.: Thanks to Ted for pointing out IEEExtreme to the team :)

Change default permission modes on Linux servers

March 28th, 2009

For our Kamibu projects we use Subversion for versioning of our code. As we aren’t only one person each other user on our server has to be able to modify files created by the svn command. Thus files need to get created with 0660 as their permission modes. The default permission modes on a debian system seem to be 0644. To change this behavior you’ve to edit /etc/profile. Search for the umask line.

On our fresh installed server it looked like this:

umask 022

This means 777 – 022 = 755. For directorys this is correct, to get the permission modes of a file you’ve to subtract 111. So after editing this line and saving the file you should logout and with your next login you will benefit from your new default permission modes.

Some critique by GreekWebWatch

December 3rd, 2008

We recently received some press coverage on Zino by the popular Greek blog GreekWebWatch, a blog concerning news on the Greek Internet. Here’s our official response.

The Vilundo Chat Protocol

October 8th, 2008

A while ago, we developed a simple chat protocol to-be-used for Zino. It’s still not in use, but we decided it would be a good idea to publish the specification so that other people could use it. It’s available under Creative Commons.

The Vilundo Chat Protocol Specification

RabbitEdit

October 4th, 2008

RabbitEdit is a nifty tool that allows easier Rabbit development and saves you quite some time and effort.
Its purpose is to automatically do particular common things for you, like writing pieces of code, creating parent directories for your new source files, and add the newly created files (and directories) into the SVN repository.
It can be found in rabbit/etc/rabbitedit/ and its installation is as simple as:

# make install 

You can uninstall it similarly, running:

# make uninstall 

Its configuration file can be found at /etc/rabbitedit/rabbitedit.conf and follows the common configuration rules used by the most programs.
You can see how it works, by issuing:

$ rabbitedit --help

A simple example of its usage, could be the following:

$ rabbitedit --parents --svn libs/customer/settings.php

Let’s assume you are in the root directory of your rabbit project. By running the above, RabbitEdit creates libs/customer/ if it does not exist (this is indicated by the “–parents” option), adds that directory into the SVN repository (indicated by “–svn”) as well as libs/customer/settings.php, and if settings.php did not exist before, it creates it and writes a standard piece of code in it (having the information that the file is a lib, and is about the settings of customers). If the file existed before, it leaves it as it was. Then, it opens the file with the source code editor of your choice.

RabbitEdit is written in Python, and is designed with the hope it fastens up the development of Rabbit projects and gives developers the chance to avoid drudgery, and focus on really important things, like actually coding.

“echo” and “md5sum”

October 4th, 2008

A problem I faced when I attempted to manually set a password for my user in Water, was that I could not login. I created the md5 sum of my password, running:

$ echo mypassword|md5sum

and pasted it into the MySQL field of phpMyAdmin. After many login failures and enough searching about what is to blame, Kostis90gr found out that “echo”, is outputting a newline at the end of the string, so the md5 sum produced from the command above, was different than the one produced from PHP’s md5() function, simply because they were given different input. So, the right thing to do, is to pass “echo” the “-n” option, like:

$ echo -n mypassword|md5sum

which prevents “echo” from outputting a newline at the end of the string.
I hope this post is helpful, because my unawareness of this “echo”’s little “particularity”, caused me quite enough frustration.

A Brief History of Comments

October 1st, 2008

A quick first try to draw the commenting system of http://www.zino.gr

Commenting

Commenting

vim regexp magic

September 23rd, 2008

Input, this one big liner:

function UnitUserSettingsSave( tInteger $dobd, tInteger $dobm, tInteger $doby, tText $gender, tInteger $place, tInteger $education, tInteger $school, tInteger $mood, tText $sex, tText $religion, tText $politics, tText $slogan, tText $aboutme, tText $favquote, tText $haircolor, tText $eyecolor, tInteger $height, tInteger $weight, tText $smoker, tText $drinker, tText $email, tText $msn, tText $gtalk, tText $skype, tText $yahoo, tText $web, tText $oldpassword, tText $newpassword, tText $emailprofilecomment, tText $notifyprofilecomment, tText $emailphotocomment, tText $notifyphotocomment, tText $emailpollcomment, tText $notifypollcomment, tText $emailjournalcomment, tText $notifyjournalcomment, tText $emailreply, tText $notifyreply, tText $emailfriendaddition, tText $notifyfriendaddition, tText $emailtagcreation, tText $notifytagcreation, tText $emailfavourite, tText $notifyfavourite ) {

Output, this beautifully spaced multiliner:

function UnitUserSettingsSave( tInteger $dobd, tInteger $dobm,
          tInteger $doby, tText $gender,
          tInteger $place, tInteger $education,
          tInteger $school, tInteger $mood,
          tText $sex, tText $religion,
          tText $politics, tText $slogan,
          tText $aboutme, tText $favquote,
          tText $haircolor, tText $eyecolor,
          tInteger $height, tInteger $weight,
          tText $smoker, tText $drinker,
          tText $email, tText $msn,
          tText $gtalk, tText $skype,
          tText $yahoo, tText $web,
          tText $oldpassword, tText $newpassword,
          tText $emailprofilecomment, tText $notifyprofilecomment,
          tText $emailphotocomment, tText $notifyphotocomment,
          tText $emailpollcomment, tText $notifypollcomment,
          tText $emailjournalcomment, tText $notifyjournalcomment,
          tText $emailreply, tText $notifyreply,
          tText $emailfriendaddition, tText $notifyfriendaddition,
          tText $emailtagcreation, tText $notifytagcreation,
          tText $emailfavourite, tText $notifyfavourite ) {

How? With one command, in vim:

:s/\(.\{-1,}\),\(.\{-1,}\),/\1,\2,\r        /ig

What does it do?

First off, :s/needle/replacement/g searches the current line for regular expression needle and replaces it with expression replacement. The current line is being searched because we didn’t specify a range before the “s”. “s” is the extended command that we’re running, which stands for “search and replace”. The “g” modifier after the final slash stands for “global”, meaning it should feel free to replace several occurrences in the same line, not just the first.

Now, for the needle expression. It can be essentially split into two parts:
1) \(.\{-1,}\),
2) \(.\{-1,}\),

These two expressions match exactly the same thing. They match anything they want, denoted with a dot, followed by a comma (the one that you see at the end of each expression). The “anything they want part” denoted with a single dot is just one character, so we’re modifying it to be able to match more than just one character (as many as it needs to satisfy the comma at the end) by adding the lazy quantifier \{-1,} after the dot.

The expression .\{-1,} means: match as many of any characters as you need to match the whole expression. In reality, because this is a lazy quantifier, it matches as less characters as possible providing it can find a comma right afterwards (but not the comma itself).

So both expressions tied together match anything followed by a comma followed by anything followed by a comma. Translation? They match two of the arguments of those provided in the function argument list.

The parentheses around each of them denoted \( and \) capture what is within, to be used in the replacement string. Our replacement string is simply “\1,\2,\r “. It will replace \1 with the first parenthesized match, then add a comma, then replace the \2 with the second parenthesized match, then add yet another comma. Finally it will add a new line (\r) and some whitespace.

Repeating this pattern with the “global” modifier applies the regular expression several times on the line, yielding to new lines being added after every second argument.

Kamibu Workroom

September 17th, 2008

Kamibu Workroom