Skip to content

Instantly share code, notes, and snippets.

View carboleda's full-sized avatar
👨‍💻

Carlos Fernando Arboleda carboleda

👨‍💻
View GitHub Profile
@carboleda
carboleda / constants.js
Last active February 9, 2019 17:07
nodejs-tictactoe-server
module.exports = {
//Tamaño del tablero, este caso es de 3x3
GAME_SIZE: 3,
//Una posición sin marcar
UNSELECTED_POSITION: ' ',
//Identificador del jugador 1
PLAYER_INDEX_1: 1,
//Identificador del jugador 2
PLAYER_INDEX_2: 2,
//Caracteres de los jugadores:
@carboleda
carboleda / db.js
Last active February 9, 2019 15:43
Bookshelf
const bookshelf = require('bookshelf');
const db = require('../knex/db');
module.exports = bookshelf(db.getPoolConnection());
@carboleda
carboleda / db.js
Last active February 8, 2019 14:15
Conexión a MySQL utilizando knex
const knex = require('knex');
let pool;
module.exports = {
getPoolConnection
}
function getPoolConnection() {
if(!pool) {
pool = knex({
@carboleda
carboleda / db.js
Last active February 8, 2019 14:09
Conexión a base de datos usando mysql2
const mysql = require('mysql2');
let pool;
module.exports = {
getPoolConnection
}
function getPoolConnection() {
if(!pool) {
pool = mysql.createPool({
docker pull mysql/mysql-server
docker images
docker run --name=mysql1 -p 3306:3306 -d mysql/mysql-server
docker start mysql1
docker logs mysql1
@carboleda
carboleda / events-keyboard.js
Last active February 9, 2019 17:20
nodejs-tictactoe-client
const readline = require('readline');
const Constants = require('../helpers/constants');
module.exports = function(GameBoardScreen) {
function initKeypressEvents() {
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
console.log('key', key);
if(key.ctrl && key.name === 'c') {