"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)

Home » Page 21

Installed CVS

Thursday, November 13th, 2008

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

Posted by musante at 7:21:00 | permalink | Comments Off

Generating random people with PostgreSQL

Wednesday, November 5th, 2008

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=#
Posted by musante at 4:03:00 | permalink | Comments Off

Populating a table with random people

Friday, October 31st, 2008

 

It happened I had  to  fill a table with realistic but not real people data.Here how did I managed it (ported to MySQL sintax).

First lets create a people table like this :

CREATE TABLE PEOPLE(NAME VARCHAR(20),

                                     SURNAME VARCHAR(20),

                                     SEX VARCHAR(1),

                                     DOB DATE);

Then create tables with sample names and surnames:

CREATE TABLE NAMES(NAME VARCHAR(20), SEX VARCHAR(1));

CREATE TABLE SURNAMES(SURNAME VARCHAR(20));

And fill them with some values:

INSERT INTO NAMES(NAME,SEX) VALUES(‘Jhon’,‘M’);

INSERT INTO NAMES(NAME,SEX) VALUES(‘Jack’,‘M’);

INSERT INTO NAMES(NAME,SEX) VALUES(‘Jeff’,‘M’);

INSERT INTO NAMES(NAME,SEX) VALUES(‘Judy’,‘F’);

INSERT INTO NAMES(NAME,SEX) VALUES(‘Jade’,‘F’);

INSERT INTO NAMES(NAME,SEX) VALUES(‘Jane’,‘F’);

INSERT INTO SURNAMES(SURNAME) VALUES(‘Red’);

INSERT INTO SURNAMES(SURNAME) VALUES(‘White’);

INSERT INTO SURNAMES(SURNAME) VALUES(‘Green’);

Now we’ll be able to get a single random person with a query like this:

SELECT NAME, SEX,

           CURDATE() - INTERVAL RAND()*365.25*100 DAY AS DOB,

                 (SELECT SURNAME FROM SURNAMES ORDER BY RAND() LIMIT 1) AS SURNAME

FROM NAMES ORDER BY RAND() LIMIT 1;

We can write a simple procedure to populate the table with the desired number of rows:

CREATE PROCEDURE FILL(IN NUM INT)

   BEGIN

       WHILE NUM > 0 DO

          INSERT INTO PEOPLE(NAME,SEX,DOB,SURNAME)

          SELECT NAME, SEX,

                            CURDATE() - INTERVAL RAND()*365.25*100 DAY AS DOB,

                         (SELECT SURNAME FROM SURNAMES ORDER BY RAND() LIMIT 1) AS SURNAME

         FROM NAMES ORDER BY RAND() LIMIT 1;

         SET NUM = NUM-1;

      END WHILE;

END;

We can call this procedure like this:

mysql> call FILL(10000);

Query OK, 1 row affected (40.73 sec)

A ten thousand people population in forty seconds (on PIII at 550Mz) is not bad.

Of course many improvements can be done like adding a random place of birth (based on a table of places) or making date of birth distribution more realistic.

Posted by musante at 23:48:00 | permalink | Comments Off

More about me …

Friday, October 24th, 2008

  My name is Massimo, I live in Italy but my heart reside in the Philippines since 1997.(1)

  I bought my first computer when I was 15, since then I tasted the many flavors of computer programming from Basic to Pascal, C, C++, Matlab, Assembler, Java and many others.

  I actually work in Genoa where I design and develop public administration software for a local software house. I write software mainly using Java, Visual Basic and Oracle.

(1)
I owe my readers a little explanation about this phrase:  my wife is from Philippines, we married in 1997 and we went in the Philippines for our honeymoon. So I fell in love with my wife’s country too.

Posted by musante at 19:49:00 | permalink | Comments Off

My Machines …

Thursday, October 23rd, 2008

Sempron2400

(Windows, Ubuntu 9.04)

It’s actually my main desktop computer, I mainly use it for editing home videos and burning them on DVD.

 

 

PIII550

(Linux Ubuntu 8.04)

I bought this little old computer on a computer surplus fair at only 25€. I use it mostly for my “server side” linux experiments.

 

 

EEEPC900

(Linux EEEBuntu)

I bought it only recently, It’s the first really portable laptop I have. I use it for reading e-books, scratch-pad programming, watching videos and a little of gaming too.

Posted by musante at 19:52:00 | permalink | Comments Off