Cosas del pasado, con un poco de arte

En aquellos días… huy no, que la historia es otra. Probemos de nuevo. Érase una vez… mmmh, tampoco. No parece buen principio para la historia de hoy. A ver a la tercera:

Tiempo ha, servidor solía dejarse caer por el GPUL (el Grupo de Programadores y Usuarios de Linux de la facultad), y además de meterse en otros fregados diseñar algún que otro cartel, a decir verdad con algo más de gusto que los diseñadores de las portadas de ciertos álbumes. El caso es que hoy, mientras buscaba el disco compacto de uno de mis juegos viejos, encontré una copia de seguridad del portátil que utilizaba por aquel entonces (un iBook G3 que todavía funciona después de nueve años, eso si que es un récord de TCO para un portátil).

En dicha copia de seguridad me encontré con un par de perlitas. Nada menos que dos de los carteles que en su momento diseñé en mi época de máxima actividad en GPUL:

Como «bonus», me he topado también  con el que —hipotéticamente— iba a ser el fondo de pantalla de GNOME en la versión de GPUL LiveCD que nunca llegó a ver la luz del día:

Ya véis que uno nunca sabe lo que se encontrará en el futuro al hacer copias de seguridad 😉

How-to: Bazaar smart server on Nginx

This is a recipe which will teach you how to set-up a Bazaar smart server on top of the great Nginx HTTP server. I will not deal with optimization or fancy setups at all, the goal is just having your Bazaar branches published, feel free to comment if you feel like the proposed setup could be improved.

First of all, you will need the following:

  • An Un*x box. It does not matter which particular incarnation you prefer (*BSD, GNU/Linux, MacOS X…), just make sure the following components work with your operating system of choice.
  • Bazaar 1.0 or newer.
  • Nginx 0.6.x with the latest mod_wsgi builtin (Manlio did a great job bringing WSGI support o life!)
  • Your text editor of choice.

Now, the recipe for a read-only repository of Bazaar branches:

  1. Install Nginx with mod_wsgi. If you are a fortunate Gentoo user, you can use the Nginx ebuilds from my overlay the Connectical Overlay, just make sure you set python USE-flag when emerging www-servers/nginx.
  2. Create a directory where you will store your branches. I myself decided to place them under /home/bzr. Make sure that Nginx will be able of reading its contentse e.g. by making the directory and its contents world-readable.
  3. Write a small Python script which creates a WSGI application for the smart server and save it to /home/bzr/smartserver.wsgi. It should look like the following:
          from bzrlib.transport.http import wsgi
          application = wsgi.make_app(
  4. Edit /etc/nginx/nginx.conf and add the directives into a server section, be sure to use the same location as in the prefix variable above:
          location /bzr {
             wsgi_pass /home/bzr/smartserver.wsgi;
  5. Restart Nginx and enjoy: Now you can access a branch stored at /home/bzr/mybranch using the bzr+http://host/bzr/mybranch URL.

Final note: you must have include wsgi_vars somewhere in your Nginx configuration file, in a server section. That’s all for today. And remember… Bazaar and Nginx are a joy to work with! 😉

Get the women!

Excerpt from eutils.eclass, as included in the official Gentoo package tree:

  # Make a desktop file !
  # Great for making those icons in kde/gnome startmenu !
  # Amaze your friends !  Get the women !  Join today !
  # make_desktop_entry(, [name], [icon], [type], [path])

This is not the first joke I find while surfing Gentoo-related websites (their bugtracker has some funny tickets) or system-specific code. Humor is definetely good, especially when you are striving to improve some code and find hilarious comments like that. So please, please keep smiling, Gentoo folks!

C: Trick or Treat?

One of the things that amazes me about the C programming language is that you can always
find something new: it teaches you to be humble about your programming wizardry. Today I have found two new mind-melting techiques which can cause serious brain damage:

  • Duff’s Device: speeding-up tight loops by unrolling and using a switch statement in order to create a jump table for the leftover iterations of the unrolled loop. Cheesy.
  • Coroutines implemented in plain standard ANSI C. Contains heavy preprocessor abuse and some constructions derived from Duff’s Device.I definetely loved this one!

This was my christmas present for my readers, hope you found this enlightening 😉

C language explanations

Regarding this little quiz, here I will write down proper explanations for the snippet of code which does array access using the “2[p]” syntax instead of the usual “p[2]” form. In order to properly understand which is going under the roof, I will try to explain things from the ground up, starting with some basic language issues which may surprise the non-seasoned C programmer.

First of all, what is an array? I bet a coffee someone told you arrays are “containers” which can hold a fixed number of elements of a given type, and that the contained elements may be directly accessed by using their indexes. Conceptually thisis right, but remember this: in C things are how the compiler treats them, not how you think the compiler will treat them (this is axiom number zero of the C programmer). So you definetely want to look at things the way the compiler does… at least sometimes. So let’s rewrite the question: what the heck the compiler thinks an array is? From the language point of view, an array is no more than a memory area capable of holding a number of elements of the given type, so declaring size_t foo[10] will reserve sizeof(size_t) * 10 bytes somewhere. Period. So what is the array name “foo”? It is just a pointer to the first byte of allocated space. The array syntax is handy, but does not really add boilerplate to the core language.

Then, when on writes p[2] to access the third element of the “array”, as with the previous issue, it is no more than syntactic sugar for the *(p+2) syntax. The language already knows that p+2 increases the value of the “p” pointer in the same value os two times the size of the elements it holds. If you wondered why pointer arithmetic works like that now you have the answer: this behaviour allows for directly mapping array syntax into pointer arithmetic syntax.

When I was a lot younger I had to learn that “2+3” is exactly the same as “3+2”: sum is commutative. If we are dealing with pointers, which wouldn’t we maintain that property? The C language designers did, so you can write safely p+2 or 2+p, whatever makes you feel comfortable. This looks natural, so let’s follow a simple chain of transformations:

    p[2] = *(p + 2) = *(2 + p) = 2[p]

And we ended up with the bizarre-looking array syntax I presented in my quiz. I hope now you think it must be some quirk in the lexical analyzer of GCC, or some other captcha. You are dead wrong. If you take a look at a serious standard (read: ISO C99) you’ll find that array syntax is specified in a way that allows writing “2[p]”: you must have a pointer at the left and an arithmetic expression into the brackets. Using C’s type conversion rules, integer literals can be promoted to pointers and pointers can be treated as integers!

I hope you learned something and liked the explanation 😉