Setting up a shared bazaar repository

17 January 2010

Bazaar logoI found a lack of articles on the matter, so I put together this small guide that has the goal to show you – in few easy steps – how to set up a machine that acts as a central bazaar repository using bzr+ssh://. This allows a team of people to use it à la Subversion.

By the way: Bazaar is wonderful! Kudos to the devs!

Read the rest of this entry »

Advertisements

My thesis: Gallows

19 December 2009

This week I finally managed to get my Bachelor’s degree in Computer Science with a final mark of 101/110. Here you’ll find my thesis about the project I implemented during my final internship: Gallows.

Gallows is a scaffold generator that uses ExtJS 3.0 to achieve CRUD actions on a editable grid, as well as on some associated controller views. The Gallows generator produces a grid view of records starting from a pre-existing model. The capability of modifying, creating and deleting items is achieved via AJAX, by setting up ExtJS 3.0 to use a JSON renderer.

It is necessary to run the generator two times: the first round it creates a stub of configuration file, which you can alter to achieve the wanted result in views. The second time, it generates a controller and the right JSON-based views.

The advantage of this approach is to allow you to get automatically some join capabilities across different tables/models, and to associate the right widget to the right field when more than one may apply. (Hopefully) sensible defaults will be auto-generated. The controller name (which can be namespaced) must match the model name.

Feel free to download and share my thesis: Gallows: a scaffold generator for Ruby on Rails employing ExtJS 3.0.


ExtJS 3.0, XTemplate and fields with square brackets

21 August 2009

I’m working a lot with Ruby on Rails and ExtJS 3.0 in this period, and one of the problem I faced was with the management of the standard Rails field names when outputted for a form.

As you may know, Rails generates fields in the form with names like this:

artist[lastname]

…so that when in the controller you call @artist.update_attributes!(params) all the right magic works, since params is a hash in the form:

{ offset => 0, _method => 'put', artist => { 
    firstname => 'James', lastname => 'Hetfield' } 
}

However, ExtJS doesn’t like these kind of parameter names inside Ext.form.Combobox and Ext.DataView, to name two, since they use an XTemplate to render a list of items. The standard regular expression which is used to catch parameters inside a template allows only for digits, letters, ‘-‘ and ‘#’ (plus a little bit of other magic you really don’t want to read).

It turns out that you can override the ‘tpl’ configuration parameter to use XTemplate syntax for inline evaluation. For example, for a Combobox, you could move from the default to:

'<tpl for="."><div>{[values["' + this.displayField + '"]]}</div></tpl>'.

And there you go, problem solved – hopefully.

Cheers,
Matteo


stricmp, comparing two strings in C case-insensitively

12 August 2009

For some reason, I found that the stricmp() function isn’t implemented in standard C. So I implemented mine, which works for ASCII strings only.

Maybe it’s not that all interesting, but I’ll post it here, if someone needs it:

#include <string.h>
#include <stdio.h>

int
stricmp (const char *s1, const char *s2)
{
   if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
   if (s2 == NULL) return *s1;

   char c1, c2;
   while ((c1 = tolower (*s1)) == (c2 = tolower (*s2)))
   {
     if (*s1 == '\0') break;
     ++s1; ++s2;
   }

   return c1 - c2;
}

int
main ()
{
   const char *a = NULL;
   const char *b = NULL;
   const char *c = "piPpO";
   const char *d = "pIpPa";
   const char *e = "";
   const char *f = "pippOdue";

   printf ("%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
      stricmp (a, c),  // <0
      stricmp (c, a),  // >0
      stricmp (c, d),  // >0
      stricmp (c, c),  // =0
      stricmp (d, c),  // <0
      stricmp (e, e),  // =0
      stricmp (c, f)); // <0

   return 0;
}

Calcolo pagamento periodico con interesse cumulativo a tasso costante

7 July 2009

Oggi, al lavoro, ho dovuto risolvere un piccolo problema: ogni mese l’azienda deve pagare una cifra con un interesse a tasso costante sulla base di quanto pagato il mese precedente. In quanti mesi sarà estinto il debito?

Calcolo interesse mensile progressivo a tasso costante

Dimostrazione:

  1. Abbiamo: x0 + (1+k)·x0 + (1+k)((1+k)·x0) + … = σ
  2. Cioè: x0 · Σi = 0 → n (1+k)i = σ
  3. Da cui: σ/x0 = (1 – (1+k)n+1)/(1 – (1+k)) = (1 – (1+k)n+1)/-k
  4. Pertanto: n + 1 = log 1+k (k·σ/x0 + 1)
  5. Applicando il cambiamento di base con il logaritmo naturale, e sottraendo uno ad ambo i membri, si ottiene la formula voluta.

Fa piacere dover usare qualche sporadica nozione matematica, ogni tanto.

Speriamo serva a qualcosa (e, soprattutto, che i conti siano giusti!),
Matteo


Configuring Ubuntu Jaunty 9.10 to work with VirtualBox OSE 2.1

16 April 2009

Update: the non-opensource edition of VirtualBox 2.2, still not included in Jaunty, will enable you to skip all of this hassle; it’ll set up a bridged connection for you automatically. However, for 2.1, this still applies.

Many of you may know the OpenSource alternative to the proprietary VMWare solution. Sun’s VirtualBox is very fast and feature-complete enough to substitute most of VMWare’s functionalities. I use it at work since more than a year with wonderful results, both to virtualize Windows under GNU/Linux, or GNU/Linux under Windows.

However, network configuration isn’t as obvious as it should, since NetworkManager doesn’t support bridge-ing interfaces by default. Herein, you’ll find a short tutorial on how to enable your virtual machine to access the Internet when hosted inside a GNU/Linux OS using NetworkManager.

Read the rest of this entry »


Firefox 3 sluggish?

23 January 2009

Reported in many other places, but may be of interest also here.

If your Firefox 3 installation is becoming sluggish and/or unresponsive, especially when typing in the address bar or using other autocompletion features, make sure you’ve the sqlite3 binary installed, and try:

find ~/.mozilla/firefox -name "*.sqlite" -exec sqlite3 -line '{}' 'vacuum;' \;

Worked like a charm here.