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
/** | |
* We should config the replica after start the 3 servers | |
* run this with a command like: | |
* mongo --port 27017 < mongodb_init_replica.js | |
*/ | |
config = { _id: "m101", members:[ | |
{ _id : 0, host : "localhost:27017"}, | |
{ _id : 1, host : "localhost:27018"}, | |
{ _id : 2, host : "localhost:27019"} ] |
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
; | |
; Archivo helloEEPROM.asm | |
; FUNCIONA CON UN PIC16F84A | |
; | |
; @author: DiganmeGiovanni | |
; | |
; Lee un número binario de 4 bits del PORTA, escribe ese número a la | |
; memoria EEPROM interna del microcontrolador, hace una pequeña pausa, | |
; lee el número de la memoria EEPROM y escribe el número leido al | |
; PORTB |
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
/** | |
* Agrega un mensaje a la lista de mensajes | |
* pertenecientes a la conversacióñ | |
*/ | |
function appendMessage(msg) { | |
var humanDate = moment(new Date(msg.date)).calendar(); | |
var html = '<div class="small-11">' + | |
'<blockquote><h6>' + msg.username + ':</h6>' + | |
msg.message + | |
'<cite>' + humanDate + '</cite></blockquote>' + |
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
/** | |
* Data Access Object (DAO) para 'messages' | |
* Debe ser construido con un objeto conectado a la | |
* base de datos | |
* | |
* @Created on: 29 March, 2015 | |
*/ | |
function MessageDAO(db) { | |
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
/** | |
* Server.js | |
* @author : DiganmeGiovanni | https://twitter.com/DiganmeGiovanni | |
* @Created on: 25 Oct, 2014 | |
* Updated on: 29 March, 2015 | |
*/ | |
/* Librerias necesarias para la aplicación */ | |
var express = require('express'); |
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
var messageDAO = require('./dao/MessageDAO').MessageDAO; | |
... | |
... | |
MongoClient.connect('mongodb://'+mdbconf.host+':'+mdbconf.port+'/'+mdbconf.db, function (err, db) { | |
var usersDAO = new userDAO(db); // Initialize userDAO | |
var messagesDAO = new messageDAO(db); | |
... |
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
socket.on('chat message', function(msg) { | |
messagesDAO.addMessage(msg.username, Date.now(), msg.message, function (err, nmsg) { | |
io.emit('chat message', msg); | |
}); | |
}); |
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
socket.on('latest messages', function () { | |
messagesDAO.getLatest(50, function (err, messages) { | |
if (err) console.log('Error getting messages from history'); | |
socket.emit('latest messages', messages); | |
}); | |
}); |
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
/** | |
* Solicitamos al servidor los ultimos mensajes | |
* del historial registrado. | |
*/ | |
socket.emit('latest messages'); |
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
/** | |
* Cuando el servidor envia los ultimos mensajes registrados | |
* se reciben a través de este evento. | |
* Cada mensaje se agrega a la lista de mensajes en la vista | |
* de la conversación. | |
*/ | |
socket.on('latest messages', function (messages) { | |
for (var i = messages.length - 1; i >= 0; i--) { | |
appendMessage(messages[i]); | |
}; |