Say Perl

Worldwide Perl Blogging

Totally
311 feeds,
9627 posts.

IPS: MPS AnyEvent:: HTTPD, AnyEvent:: HTTP and DBI

1 December, 09:04, by Nick, machine translated from Portuguese

Игрался на perl связкой IPS: MPS , AnyEvent:: HTTPD, AnyEvent:: HTTP и DBI.
Сделал четыре процесса: главный (управляющий), HTTP сервер, HTTP клиент, DBI клиент.
Хотя блокируемый процесс тут один: DBI, но с этого поиграться межпроцессным взаимодействием сообщений в стиле передачи хватит:

use IPC:: MPS:: Event;
use AnyEvent:: HTTPD;
use AnyEvent:: HTTP;
use DBI;

my $ port = 9090;

print "Please contact me at: http://127.0.0.1: $ port / q = foo \ n";

my $ spawn = {vpid_server

my% url2req; # $ url => [$ req, ...]

my $ httpd = AnyEvent:: HTTPD-> new (port => $ port);

$ Httpd-> reg_cb (
''=> Sub {
my ($ httpd, $ req) = @ _;
my $ q = $ req-> parm ('q');
if ($ q) {
my $ url = "http://www.google.com/search?q = $ q";
snd (0, "req", $ url);
push @ {$ url2req {$ url}}, $ req;
Else {}
$ Req-> respond ([404, 'NOT FOUND']);
}
}
);

receive {
msg res => sub {
my ($ from, $ url, $ data, $ headers) = @ _;
for my $ req (@ {$ url2req {$ url}}) {
$ Req-> respond ([200, 'OK', {'Content-Type' => 'text / html'}, $ date]);
}
url2req delete $ {$ url};
};
};

};


my $ spawn = {vpid_client
receive {
msg req => sub {
my ($ from, $ url) = @ _;
HTTP_GET $ url, sub {
my ($ data, $ headers) = @ _;
snd ($ from, "res", $ url, $ data, $ headers);
};
};
}
};


my $ spawn = {vpid_dbi

# CREATE DATABASE OWNER nick nick ENCODING 'UTF8';
# CREATE TABLE urls (id_url SERIAL, datetime TIMESTAMP DEFAULT now (), url text, PRIMARY KEY (id_url));
DROP TABLE # urls;
my $ data_sourse = "DBI: Pg: dbname = nick, host = localhost";
my $ dbh = DBI-> connect ($ data_sourse, "nick", "") or die $ DBI:: errstr;
my $ sth = $ dbh-> prepare ("INSERT INTO urls (url) VALUES (?)") or die $ dbh-> errstr ();

receive {
msg res => sub {
my ($ from, $ url) = @ _;
$ Sth-> execute ($ url) or die $ dbh-> errstr ();
};
}
};


receive {
msg req => sub {
my ($ from, $ url) = @ _;
snd ($ vpid_client, "req", $ url);
warn "Q, $ url";
};
msg res => sub {
my ($ from, $ url, $ data, $ headers) = @ _;
snd ($ vpid_server, "res", $ url, $ data, $ headers);
snd ($ vpid_dbi, "res", $ url);
warn "R, $ url";
};
};

Забавно получается.

Plack in Portuguese

14 June, 04:27, by miyagawa, machine translated from Portuguese

via www.slideshare.net

Speaking of the slides in non-Español, here's the slide from Portuguese Perl Workshop by Pedro Melo.

Creativity, hackers and other stuff

31 January, 12:15, machine translated from Portuguese

Below you'll find an article That I wrote to my local Mac users group. I have not HAD the time to translate it into English, so Unless you are willing to learn Portuguese, you'll Have to wait a bit.

But For Those That share my mother tongue, here it is.


(For those who read the version in the mailing-list, has only minor changes in style, and a "short," there by the way)

The discussion is happening on the IPAD, the effect of the closed model and controlled by Apple, and he brings creativity and spirit hacker (in the tickling, funny, and not towards cracker) is really interesting.

I think the question of creativity, I realized that by starting with the post from Tim Bray that ends with the phrase "For creative people, this device is nothing" is a false issue.

Frankly, the natural bias of Tim Bray for the Android platform shuffled her ideas temporarily. Just point the work of our Jorge Colombo with the covers of the New Yorker as a counter example of his argument.

But even though he was creative to say as a programmer / developer, it would be false. No one program for Android in the actual device. These devices are not computers that may exist in a vacuum, are appendages to the computers we have at home or at work.

The only context in which they can see the iPhone / IPAD as limiting creativity and policies for approval of the AppStore. Everything else is available.


The part of discussion about hackers is much closer to my heart. As far as I can see starts with this sentence Alex Payne :

The Thing That bothers me most about the ipad is this: if I Had An ipad rather than the actual computer as a kid, I'd never be a programmer today.

You can only agree with that if you think that IPAD is our only computer, and clearly it was not designed for that. Mark Pilgrim seems to agree with this vision of the future of black hackers:

Once upon a time, Apple made the Machines That Made Me Who I Am. Who I Became I am by Tinkering. Now it "seems they're doing everything in Their power to stop my kids from finding That sense of wonder. Apple Has Declared war on the tinkerers of the world.

My journey (as well as others in this list, I'm sure) is similar to the Mark: first computer at 11, start programming at 12, 13 in BASIC and Assembler then, begin to assemble their own PCs, using Pascal, C ; use minix, because Linux gave us control of our machine, wanting to know how it works, disassemble, open, change. In my case when I ran a little to the electronics of the thing, I do not get with electronics, and more focused on the low-level software.

But answering the question: does IPAD will limit the next generation of hackers? I could say no and explain my reasons, but I think Gina Trapani has a response better than qq thing I could write:

Because while we're all ranting about how the closed ipad Will be, the jailbreak community is planning competitions to see Who Can crack it first. The setting sun isn't on tinkerers; Their desire to crack things open intensifies When faced with something that's closed by design. The challenge is part of The Appeal.

...

I'm of the mind That if someone wants to tinker, They Will tinker, period. Because it's In Their DNA, not because it's easy, and because by nature, tinkerers do not play by the rules.

The part that I can add to the discussion is this: in 1991, the University of Minho, the vast majority of students did not have internet access. They had no mail, had not or Web browsers, began to appear usenet. At that time, who walked through the computer centers, or was there the shortest possible time to do their jobs and go, or else belonged to that group of people who wanted to see everything how it worked, how to use (and abuse) system. Was a "war" against the system administrators, because it was fun. What if