"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Tuesday, 25 November 2008

New toy: Ubiquity

There are so many toys in the 'net and so little time to play with!  I first read about this tool from here almost a month ago.
Ubiquity is a Firefox plugin that let you perform a great variety of operations, simply by typing a command. You can , for example, search on the most famous search engines, send a mail or translate a word.You simply have to activate it with it's hot-key (ctrl-space) and type what you need.
This alone would make of Ubiquity an handy tool, if you do not like put your hands off the keyboard to search what you need in menus and bookmarks using the mouse,  what makes of Ubiquity a really enjoyable toy is how easily you can write your own commands.
Just type "command-editor" to get a simple but effective web based editor where you can write your Ubiquity commands with Javascript. No compiling or deploy is needed you can run your command in Ubiquity as soon as you have written it.
Here is my own ubiquity command to reverse a stringselected or passed as parameter. It's only a step beyond a 'hello world' program but it shows quite well how Ubiquity works.
    /* This is a template command */     
CmdUtils.CreateCommand({               
      name: 
"reverse",           
      icon: 
"http://example.com/example.png",       
      homepage: 
"http://example.com/",       author: name: "MM", email: "MM@mm.com"},       license: "LGPL",
      description: "reverse example",
      help: "just reverse a string",
      takes: {"input": noun_arb_text},
      preview: functionpblock, input ) {
        var template = "result will be: ${result}";
        pblock.innerHTML = CmdUtils.renderTemplate(template, {"result": reverse(input)});
      },
      execute: function(input) {
        CmdUtils.setSelection("You selected: " + input.html);
      }

      function reverse(in){
         var res = "";
         for(var i=in.length;i>0;i++){
              res = res + in(i);
          }
         return res;
      }
    });
More details about programming with Ubiquity on its wiki.

Thursday, 13 November 2008

Installed CVS

I've just installed CVS on PIII 550. I don't really write so much code to need a versioning system at home, but it's still an interesting experiment and also an easy way to share sources between laptop and desktop computer. I did it mainly following instructions from this howto.
first I installed CVS and XINETD with apt-get command:
sudo apt-get install cvs
sudo apt-get install xinetd
 then I added to xinetd the cvs configuration file
vim /etc/xinetd.d/cvspserver
here is the file content
service cvspserver
{
     port = 2401     
     socket_type = stream
     protocol = tcp
     user = root
     wait = no
     type = UNLISTED
     server = /usr/bin/cvs
     server_args = -f --allow-root /var/lib/cvs pserver
     disable = no
}
after restarting xinetd:
sudo /etc/init.d/xinetd start 
I added two users to the machine (for the two computers that are going to use CVS) and added them to the src group.
(adding only CVS users would be safer but this is only a home network server so why worry about it?)
sudo adduser --no-create-home eeepc900
sudo adduser --no-create-home sempron2400 
sudo addgroup eeepc900 src
sudo addgroup sempron2400 src
and, at last, I configured Eclipse to use the CVS server

Wednesday, 5 November 2008

Generating random people with PostgreSQL

I just installed PostgreSQL on my PIII550 linux 'server' and I used the SQL example from my last post to do some test. Only the random select query and the procedure needed some little rework due to the different syntax:
Here is the random selection query
SELECT NAME, SEX,
                   CURRENT_DATE - CAST(RANDOM()*365.25*100 AS INTEGER) AS DOB,
                  (SELECT SURNAME FROM SURNAMES ORDER BY RANDOM() LIMIT 1) AS SURNAME
FROM NAMES ORDER BY RANDOM() LIMIT 1;
 Here is the procedure:
CREATE OR REPLACE FUNCTION FILL(IN NUM INT) RETURNS VARCHAR(1) AS $$
    DECLARE
          N INTEGER;
       BEGIN
              N:=NUM;
             WHILE N > 0 LOOP
                  INSERT INTO PEOPLE(NAME,SEX,DOB,SURNAME)
                  SELECT NAME, SEX,
                                     CURRENT_DATE - CAST(RANDOM()*365.25*100 AS INTEGER) AS DOB,
                                   (SELECT SURNAME FROM SURNAMES ORDER BY RANDOM() LIMIT 1) AS SURNAME
                 FROM NAMES ORDER BY RANDOM() LIMIT 1;
                N := N - 1;
       END LOOP;
       RETURN 'T';
END; $$
LANGUAGE PLPGSQL;
(Update)
Forgot to say it takes about seven seconds to insert ten thousands rows ... quite faster than MySQL.

test=# SELECT NOW();SELECT FILL(10000);SELECT NOW();
now
——————————-
2008-11-09 17:32:53.985751+01 (1 row)
fill
——
T
(1 row)
now
——————————-
2008-11-09 17:32:59.359207+01
(1 row)
test=#