Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit f097340

Browse files
author
manuel.depaz
committed
Simple Samples
1 parent bbe18d9 commit f097340

7 files changed

Lines changed: 86 additions & 1 deletion

File tree

‎P00_CodeSamples/helloWorld_4.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ function serveBooks() {
88
var books = []; // Intentionally cleaned
99
}
1010

11-
// Only the first time echo the 3x books
11+
// Only the first time echo the 3x books

‎P00_CodeSamples/helloWorld_5.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
console.log('Hello');
2+
setTimeout(function() {
3+
console.log('World');
4+
}, 5000);
5+
6+
console.log('(I\m waiting here meanwhile... but not blocked)');

‎P00_CodeSamples/helloWorld_5.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
print('Hello');
3+
sleep(5);
4+
print('World');
5+
?>

‎P00_CodeSamples/helloWorld_6.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var start = Date.now();
2+
console.log('time at start? ' + start);
3+
4+
console.log('calling #1');
5+
setTimeout(function() {
6+
console.log('seconds elapsed at #1 function? '+ (Date.now()-start));
7+
for (var i=0;i<10000000000; i++) { /* do nothing, but blocks the execution */ }
8+
}, 1000);
9+
10+
console.log('calling #2');
11+
setTimeout(function() {
12+
console.log('seconds elapsed at #2 function? '+ (Date.now()-start));
13+
}, 2000);
14+
15+
console.log('EOF');

‎P00_CodeSamples/helloWorld_7.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// E/S Bloqueante
2+
var urls = db.query("select * from urls"); //esperar
3+
urls.each(function(url) {
4+
var page = http.get(url); //esperar
5+
save(page); //esperar
6+
});
7+
8+
// E/s No bloqueante, petición asincrona
9+
db.query("slect * from urls", function(urls) {
10+
url.each(function(url) {
11+
http.get(url, function(page) {
12+
save(page);
13+
});
14+
});
15+
});

‎P00_CodeSamples/helloWorld_8.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// http://blog.elfilo.net/charla_nodejs
2+
3+
var mail = require('mail');
4+
var addresses = [ 'jeff@mapbox.com', 'alex@mapbox.com', 'eric@mapbox.com' ];
5+
var message = 'I am writing to inform you of a...';
6+
7+
var count = 0;
8+
9+
addresses.forEach(function(sucker, i) {
10+
// Attempt to send email.
11+
mail(sucker, 'New opportunity', message, function(err) {
12+
if (!err) {
13+
count++;
14+
}
15+
16+
// Don't wait, get the next address NOW.
17+
if (i == addresses.length - 1) {
18+
console.log(count + " messages sent");
19+
}
20+
});
21+
});

‎P00_CodeSamples/helloWorld_8.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/* http://blog.elfilo.net/charla_nodejs */
4+
5+
$addresses = array(
6+
'jeff@mapbox.com',
7+
'alex@mapbox.com',
8+
'eric@mapbox.com'
9+
);
10+
$message = 'I am writing to inform you of a...';
11+
$count = 0;
12+
13+
foreach($addresses as $sucker) {
14+
// Attempt to send email.
15+
if (mail($sucker, 'New opportunity', $message)) {
16+
$count++;
17+
}
18+
}
19+
20+
// Once email is sent, get the next address.
21+
echo $count . "messages sent";
22+
23+
?>

0 commit comments

Comments
 (0)