forked from redradix-school/curso-node-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var Reloj = require("./reloj").Reloj; | ||
var reloj = new Reloj(); | ||
|
||
reloj.on("segundo", function(fecha) { | ||
console.log("Un segundo! son las:", fecha); | ||
reloj.removeAllListeners("segundo"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var fs = require("fs"); | ||
|
||
var origen = process.argv[2], | ||
dest = process.argv[3]; | ||
|
||
var readStream = fs.createReadStream(origen, { flags: "r", autoClose: true}); | ||
var writeStream = fs.createWriteStream(dest, { flags: "w"}); | ||
|
||
// readStream.on("data", writeStream.write.bind(writeStream)); | ||
// readStream.on("end", writeStream.end.bind(writeStream)); | ||
|
||
readStream.on("data", function(chunk) { | ||
writeStream.write(chunk); | ||
}); | ||
|
||
readStream.on("end", function() { | ||
writeStream.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var fs = require("fs"); | ||
|
||
var readStream = fs.createReadStream(process.argv[2], | ||
{ flags: "r", | ||
autoClose: true }); | ||
|
||
var contenido = ""; | ||
|
||
readStream.on("data", function(chunk) { | ||
contenido += chunk; | ||
}); | ||
|
||
readStream.on("end", function() { | ||
console.log(contenido.split("\n").length - 1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var EventEmitter = require("events").EventEmitter, | ||
inherits = require("util").inherits; | ||
|
||
function Tambor() { | ||
var self = this; | ||
setInterval(function() { | ||
self.emit("pom!"); | ||
}, 1000); | ||
}; | ||
inherits(Tambor, EventEmitter); | ||
|
||
var tambor1 = new Tambor(); | ||
|
||
tambor1.on("pom!", function() { | ||
console.log("El tambor suena!"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var start = Date.now(); | ||
|
||
setTimeout(function() { | ||
for (var i=Number.MAX_VALUE; i--;) { | ||
Math.pow(12345, 123455); | ||
} | ||
}, 100); | ||
|
||
setInterval(function() { | ||
var now = Date.now(); | ||
console.log("Han pasado", now - start, "ms"); | ||
start = now; | ||
console.log("Hola otra vez, Mundo del futuro!"); | ||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var EventEmitter = require("events").EventEmitter, | ||
inherits = require("util").inherits; | ||
|
||
function Reloj() { | ||
this.emit("segundo", new Date()); | ||
} | ||
inherits(Reloj, EventEmitter); | ||
|
||
exports.Reloj = Reloj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
$(function() { | ||
|
||
/* Tu código aquí! */ | ||
var socket = io.connect("http://localhost:3000/"), | ||
me = $.get("/me"); | ||
|
||
Chat.registerHandler(function(msg) { | ||
var msgData = {text: msg, date: new Date()} | ||
me.then(function(me) { | ||
socket.emit("send:message", me, msgData); | ||
Chat.showMyMsg(me, msgData); | ||
}) | ||
}) | ||
|
||
socket.on("posted:message", function(user, msgData) { | ||
Chat.postMsg(user, msgData); | ||
}) | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters