Skip to content

Instantly share code, notes, and snippets.

View dcortesnet's full-sized avatar
🏀
quick to answer

Diego Esteban dcortesnet

🏀
quick to answer
View GitHub Profile
@dcortesnet
dcortesnet / javascript_array_2D.js
Last active February 14, 2023 12:56
Javascript estructura de datos array 2D
const array2D = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
for (let cols = 0; cols < array2D.length; cols++) {
for (let rows = 0; rows < array2D[cols].length; rows++) {
const element = array2D[cols][rows];
console.log(element);
@dcortesnet
dcortesnet / nodejs_google_sheets_api_basic.js
Last active February 14, 2023 12:51
Nodejs interacción básica con api de google sheets
const { google } = require("googleapis");
const auth = new google.auth.GoogleAuth({
keyFile: "credentials.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
const main = async () => {
const client = await auth.getClient();
const googleSheets = google.sheets({ version: "v4", auth: client });
@dcortesnet
dcortesnet / nodejs_read_excel_file.js
Last active February 14, 2023 12:52
Nodejs lectura de archivo excel
// npm install xlsx
const xlsx = require("xlsx");
const file = xlsx.readFile("./data.xlsx");
let data = [];
let sheets = file.SheetNames; // ["Hoja1", "Hoja2"];
for (let index = 0; index < sheets.length; index++) {
const jsonSheet = xlsx.utils.sheet_to_json(file.Sheets[sheets[index]]);
data.push(jsonSheet);
@dcortesnet
dcortesnet / nodejs_read_txt_async_file.js
Last active February 14, 2023 12:42
Nodejs lectura de archivo asíncono txt
const fs = require("fs");
fs.readFile("./text.txt", "utf8", (err, data) => {
if (err) throw err;
const arr = data.toString().replace(/\r\n/g, "\n").split("\n");
arr.forEach((item, index) => {
console.log(`Line ${index + 1} - Item: ${item}`);
});
@dcortesnet
dcortesnet / nodejs_read_txt_sync_file.js
Last active February 14, 2023 12:49
Nodejs lectura de archivo síncrono txt
const fs = require("fs");
const data = fs.readFileSync("./text.txt", { encoding: "utf-8", flag: "r" });
const arr = data.toString().replace(/\r\n/g, "\n").split("\n");
console.log(arr);
@dcortesnet
dcortesnet / nodejs_write_txt_file.js
Last active February 14, 2023 12:57
Nodejs escritura de archivo síncrono txt
const fs = require("fs");
const arr = ["JBKR23", "TN9728"];
fs.writeFileSync("./text_copy.txt", arr.join("\n"));
//JBKR23
//TN9728
@dcortesnet
dcortesnet / javascript_cal_factorial_recursive_num.js
Last active February 14, 2023 12:48
Javascript calcular el factorial de un número con recursividad
const factorial = (num) => {
if (num <= 1) {
return 1;
}
return num * factorial(num - 1);
}
console.log(factorial(5)); // 120
@dcortesnet
dcortesnet / javascript_return_random_number.js
Last active February 14, 2023 12:50
Javascript retornar número random
const randomNumber = (until) => {
return Math.floor(Math.random() * until);
};
console.log(randomNumber(20));
@dcortesnet
dcortesnet / javascript_generate_array_countdown_recursive.js
Last active February 14, 2023 12:56
Javascript generar array cuenta regresiva con recursividad
function countdown(n){
if(n < 1){
return []
}
const countArray = countdown(n - 1);
countArray.unshift(n)
return countArray;
}
console.log(countdown(5));
@dcortesnet
dcortesnet / swagger_microadaptador.yml
Created May 23, 2022 15:07
Swagger estructura base open api microservicio
openapi: "3.0.2"
info:
title: API docs
version: "1.0"
servers:
- url: https:ma-autored
paths:
/v1.0/paises/CL/vehiculo/{patente}:
get:
tags: