<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marco Agüero </title>
    <description>The latest articles on DEV Community by Marco Agüero  (@nandev_16).</description>
    <link>https://dev.to/nandev_16</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F894790%2F13f99e21-d1b4-4508-8f7b-334c32777614.jpeg</url>
      <title>DEV Community: Marco Agüero </title>
      <link>https://dev.to/nandev_16</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nandev_16"/>
    <language>en</language>
    <item>
      <title>Introducción a React: Fundamentos para Principiantes</title>
      <dc:creator>Marco Agüero </dc:creator>
      <pubDate>Sun, 11 Aug 2024 00:24:13 +0000</pubDate>
      <link>https://dev.to/nandev_16/introduccion-a-react-fundamentos-para-principiantes-2kcm</link>
      <guid>https://dev.to/nandev_16/introduccion-a-react-fundamentos-para-principiantes-2kcm</guid>
      <description>&lt;p&gt;¡Hola a todos! 👋 Soy Marco, un estudiante de Ingeniería Informática, y quiero darles la bienvenida a este mini curso de React.&lt;/p&gt;

&lt;p&gt;Como estudiante de Ing. Informática, me doy cuenta de que los estudiantes finalizando la carrera y los egresados no tienen conocimiento de tecnologías modernas como React o Next para el desarrollo de páginas web o aplicaciones web. Mi mejor amiga, también estudiante de Ing. Informática, tiene problemas para comprender estas tecnologías. Por eso, decidí crear este pequeño curso, con la intención de ayudar a colegas que ya saben de programación, para que puedan aprender fácilmente tecnologías web tan importantes como estas. ¡Espero que les sea útil y sobre todo, que disfruten el proceso de aprendizaje tanto como yo disfruto compartirlo!&lt;/p&gt;

&lt;h2&gt;
  
  
  ¿Qué es React?
&lt;/h2&gt;

&lt;p&gt;Empecemos desde el principio: ¿Qué es React? 🤔&lt;/p&gt;

&lt;p&gt;React es una biblioteca de JavaScript creada por Facebook en 2013 para construir interfaces de usuario, especialmente para aplicaciones web de una sola página (SPA). Es decir, React nos permite construir componentes reutilizables que forman la base de nuestras aplicaciones web. Si alguna vez te has preguntado cómo es que las grandes aplicaciones como Facebook o Instagram son tan rápidas e interactivas, ¡React es parte de la magia detrás de eso!&lt;/p&gt;

&lt;h2&gt;
  
  
  Historia y evolución de React
&lt;/h2&gt;

&lt;p&gt;Aunque React nació en 2013, su historia comienza un poco antes, cuando los ingenieros de Facebook buscaban una solución para mejorar el rendimiento y la experiencia del usuario en su plataforma. React fue su respuesta a estos desafíos, y desde entonces ha evolucionado constantemente, ganando popularidad hasta convertirse en una de las tecnologías más utilizadas en el desarrollo web.&lt;/p&gt;

&lt;p&gt;Desde su lanzamiento, React ha crecido y se ha fortalecido con una comunidad vibrante y activa que contribuye constantemente a su mejora. ¡Y ahora, tú también formas parte de esta comunidad!&lt;/p&gt;

&lt;h2&gt;
  
  
  Ventajas de usar React
&lt;/h2&gt;

&lt;p&gt;¿Por qué React se ha vuelto tan popular? Bueno, hay varias razones que hacen de React una excelente opción para desarrollar aplicaciones web modernas:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Componentes Reutilizables:&lt;/strong&gt; En React, todo se basa en componentes. Esto significa que puedes crear pequeños bloques de código que se pueden reutilizar en diferentes partes de tu aplicación. ¡Menos trabajo, más eficiencia!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Virtual DOM:&lt;/strong&gt; React utiliza un concepto llamado Virtual DOM para actualizar solo las partes de la interfaz que han cambiado, en lugar de recargar toda la página. Esto hace que las aplicaciones React sean extremadamente rápidas.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gran Comunidad y Ecosistema:&lt;/strong&gt; React cuenta con una enorme comunidad de desarrolladores, lo que significa que hay montones de recursos, bibliotecas y herramientas disponibles para hacer tu trabajo más fácil.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fácil de Aprender:&lt;/strong&gt; Si ya conoces JavaScript, aprender React es relativamente sencillo. Además, una vez que aprendas React, tendrás una base sólida para aprender otras tecnologías relacionadas como Next.js.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Instalación y configuración del entorno
&lt;/h3&gt;

&lt;p&gt;¡Es hora de ensuciarnos las manos! 🛠️&lt;/p&gt;

&lt;p&gt;Antes de comenzar a escribir código en React, necesitamos preparar nuestro entorno de desarrollo. No te preocupes, es más fácil de lo que parece. Aquí te dejo una guía rápida:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Instala Node.js:&lt;/strong&gt; Primero, necesitas tener Node.js instalado en tu máquina. Node.js es un entorno de ejecución para JavaScript que nos permitirá utilizar herramientas como npm (Node Package Manager) o yarn para gestionar nuestras dependencias. Puedes descargar Node.js desde su sitio oficial.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Crea una nueva aplicación React:&lt;/strong&gt; Una vez que tengas Node.js instalado, abrirás tu terminal o línea de comandos y ejecutarás el siguiente comando:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app my-first-react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Esto creará una nueva carpeta llamada my-first-react-app con todos los archivos necesarios para empezar a trabajar en tu primera aplicación React.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inicia la aplicación:&lt;/strong&gt; Ahora, navega hasta la carpeta que acabas de crear e inicia la aplicación con estos comandos:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;my-first-react-app
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;¡Y listo! Se abrirá una ventana en tu navegador con tu primera aplicación React en funcionamiento. 🎉&lt;/p&gt;

&lt;h3&gt;
  
  
  Primer componente React
&lt;/h3&gt;

&lt;p&gt;Vamos a crear nuestro primer componente en React. ¿Estás listo? ¡Vamos allá!&lt;/p&gt;

&lt;p&gt;En React, los componentes son como bloques de construcción. Puedes pensar en ellos como pequeñas piezas de Lego que juntas forman una aplicación completa. Vamos a crear un componente súper básico que simplemente diga "¡Hola, Mundo!".&lt;/p&gt;

&lt;p&gt;Abre el archivo &lt;code&gt;src/App.js&lt;/code&gt; en tu editor de texto favorito.&lt;/p&gt;

&lt;p&gt;Borra el contenido que ya está allí y reemplázalo con este código:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;¡Hola, Mundo!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Guarda el archivo y mira cómo se actualiza automáticamente tu navegador para mostrar el mensaje "¡Hola, Mundo!".&lt;/p&gt;

&lt;p&gt;¡Felicidades! Acabas de crear tu primer componente React. 🎉&lt;/p&gt;

&lt;h3&gt;
  
  
  JSX: Qué es y cómo funciona
&lt;/h3&gt;

&lt;p&gt;Si miraste el código anterior y te preguntaste, "¿Qué es este HTML mezclado con JavaScript?", no te preocupes, eso es JSX.&lt;/p&gt;

&lt;p&gt;JSX es una extensión de JavaScript que nos permite escribir código que se parece a HTML, pero dentro de archivos JavaScript. Lo genial de JSX es que es mucho más fácil de leer y escribir que el código JavaScript puro para generar elementos HTML. Aunque parece HTML, en realidad, es JavaScript bajo el capó.&lt;/p&gt;

&lt;p&gt;Por ejemplo, en lugar de escribir:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;¡Hola, Mundo!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Podemos escribirlo como:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;¡Hola, Mundo!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mucho más simple, ¿verdad?&lt;/p&gt;

&lt;h3&gt;
  
  
  Props y State: Introducción
&lt;/h3&gt;

&lt;p&gt;Para cerrar esta introducción, es importante mencionar dos conceptos clave en React: Props y State.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Props (Propiedades):&lt;/strong&gt; Las Props son como los argumentos que pasamos a una función, pero en lugar de funciones, se los pasamos a los componentes. Las Props permiten que un componente reciba datos de su componente padre y los utilice dentro de sí mismo.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;State (Estado):&lt;/strong&gt; El State es como la "memoria" de un componente. Es un objeto que puede contener datos que pueden cambiar con el tiempo, y cada vez que el State cambia, React vuelve a renderizar el componente para reflejar los nuevos datos.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;En los próximos posts, vamos a profundizar más en estos conceptos y a ver cómo funcionan en la práctica.&lt;/p&gt;

&lt;p&gt;¡Y eso es todo por hoy! Espero que esta introducción a React te haya sido útil y que estés emocionado por lo que viene. En el próximo post, profundizaremos en cómo trabajar con componentes, Props y State en React. ¡Hasta la próxima! 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Comprendiendo la recursividad</title>
      <dc:creator>Marco Agüero </dc:creator>
      <pubDate>Wed, 24 Aug 2022 23:49:16 +0000</pubDate>
      <link>https://dev.to/nandev_16/comprendiendo-la-recursividad-3n1b</link>
      <guid>https://dev.to/nandev_16/comprendiendo-la-recursividad-3n1b</guid>
      <description>&lt;p&gt;Hey, que tal?&lt;br&gt;
Espero que tu querido lector que encontraste este post, estés pasando un excelente día! 😎&lt;/p&gt;



&lt;p&gt;Hoy quiero hablar sobre un tema sumamente interesante e importante para los desarrolladores, la &lt;code&gt;recursividad&lt;/code&gt; pues este es un tema con el que te vas a encontrar en algún momento de tu carrera y mientras mas temprano lo comprendas mejor será para ti.&lt;br&gt;
Antes de empezar debes entender que la recursividad no es algo complicado, simplemente debes comprender muy bien los conceptos básicos y con esto podrás resolver los problemas que se te presenten.&lt;/p&gt;


&lt;h2&gt;
  
  
  ¿Qué es la recursividad?
&lt;/h2&gt;

&lt;p&gt;La recursividad es un proceso mediante el cual una función se llama a si misma repetidas veces con la intención de resolver un problema.&lt;/p&gt;

&lt;p&gt;Entendamos esto con ejemplos muy sencillos; imagina que tienes un computador muy simple, únicamente puede resolver problemas mediante operaciones sencillas. &lt;br&gt;
Tienes una lista de números:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;li = [1, 2, 3, 4, 5, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ahora, por cada elemento de esa lista tienes que verificar cual de ellos es el valor de x de la función: &lt;code&gt;f(x): x-2 = 2&lt;/code&gt;, podríamos verificarlo fácilmente si utilizamos un bucle, por ejemplo "While" o "for", y te doy un ejemplo en pseudocódigo: &lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Por cada elemento de la lista &lt;code&gt;li&lt;/code&gt;:&lt;/li&gt;
&lt;li&gt;Si el resultado de restarle 2 al elemento es igual a 2:&lt;/li&gt;
&lt;li&gt;imprime verdadero&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Al no poder hacer esto, ya que tenemos un computador muy simple, entonces debemos idear una solución. Bueno una forma de hacerlo seria hacer una función sencilla, que verifique si el primer elemento de la lista cumple con lo especificado, y que de no ser así, lo elimine y vuelva a preguntarse a si mismo si el siguiente elemento es el que estamos buscando.&lt;/p&gt;

&lt;p&gt;¿Te perdiste? No te preocupes, vamos a ver un ejemplo:&lt;/p&gt;

&lt;p&gt;Primero en pseudocódigo y luego lo veremos en código, tenemos la lista &lt;code&gt;li&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tenemos una lista:
li = [1, 2, 3, 4, 5, 6]
-&amp;gt; Creamos una función que recibe esa lista.
-&amp;gt; Verifica si el primer elemento de la lista existe.
-&amp;gt; Si es correcto pregunta: ¿elemento - 2 = 2?
-&amp;gt; Si esto también fue correcto, entonces retorne verdadero.
-&amp;gt; En caso de que sea falso, entonces elimine el primer elemento de la lista y vuelva a llamar esta función con la nueva lista.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bien, eso es todo... ¿Sencillo no? Ok ok, vamos al ejemplo en código:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Para efectos de este tutorial utilizare Python para los ejemplos en código, si gustan otro lenguaje cono Java o JavaScript déjenlo en los comentarios :D&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;lista&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;miFuncion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;True&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;miFuncion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;miFuncion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lista&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bien, ahora espero hayas comprendido la función anterior, ahora veamos un ejemplo un poco mas avanzado, vamos a crear una función que nos retorne el factorial de un numero.&lt;br&gt;
Primero entendamos la teoría del factorial:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Se denota &lt;code&gt;n!&lt;/code&gt; y se lee "n factorial".&lt;/li&gt;
&lt;li&gt;Corresponde al producto de los números enteros positivos desde uno hasta 'n', incluso, es decir:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;n! = 1 * 2 * 3 * ... (n-2)*(n-1)*n
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Ejemplos:&lt;br&gt;
a) 3! = 3 * 2 * 1 = 6&lt;br&gt;
b) 5! = 5 * 4 * 3 * 2 * 1 = 120&lt;br&gt;
c) 6! = 6 * 5! = 6 * 120 = 720&lt;/p&gt;

&lt;p&gt;Muy bien, ahora que entendimos la función factorial, vamos a programarla:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;
   &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Y eso es todo, con eso ya tenemos la función factorial trabajando, luego simplemente es añadir validaciones como por ejemplo que si es un numero negativo retorne un mensaje, si el numero es cero, que retorne otro y con eso la función estaría mas que perfecta.&lt;/p&gt;

&lt;p&gt;Eso que acabamos de ver es recursividad, únicamente necesitas comprender que es lo que esta haciendo la función por dentro para poder comprenderla. &lt;/p&gt;

&lt;p&gt;Espero este tutorial te sea de ayuda, si tienes dudas déjalas en los comentarios y con gusto los leeré y tratare de continuar explicando o enseñando :D &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>programacion</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Build and deploy a Pocketbase project with Docker and Fly.io</title>
      <dc:creator>Marco Agüero </dc:creator>
      <pubDate>Wed, 20 Jul 2022 03:30:00 +0000</pubDate>
      <link>https://dev.to/nandev_16/build-and-deploy-a-pocketbase-project-oi4</link>
      <guid>https://dev.to/nandev_16/build-and-deploy-a-pocketbase-project-oi4</guid>
      <description>&lt;h2&gt;
  
  
  &lt;a href="https://github.com/pocketbase/pocketbase" rel="noopener noreferrer"&gt;PocketBase&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Today I will talk about pocketbase, and how to develop a backend with this tool.&lt;br&gt;
Pocketbase is an open source backend which is distributed in a single Go binary. This new tool is similar to Firebase.&lt;/p&gt;

&lt;p&gt;This project is created to use SQLite as a database with a REST api. Some of the functions that this tool integrates are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real time database (Powered by SQLite)&lt;/li&gt;
&lt;li&gt;File storage: integrates with S3, more object storage support is coming.&lt;/li&gt;
&lt;li&gt;Autenticación&lt;/li&gt;
&lt;li&gt;Full-featured admin UI - to manage users, collections and more&lt;/li&gt;
&lt;li&gt;Extensible via Go programming language to extend functionality&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This tool is perfect for making simple backends for small projects, hobbies, practice, and more.&lt;/p&gt;
&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;You must have knowledge of the following topics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;Web development&lt;/li&gt;
&lt;li&gt;Linux&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 1: Create an image with Docker
&lt;/h2&gt;

&lt;p&gt;If you want to save time you can use my Docker image, for that you can skip to step 2.&lt;/p&gt;

&lt;p&gt;The first thing will be to create an image with Docker, for this you must first have it installed, then we are going to open a terminal.&lt;/p&gt;

&lt;p&gt;First we create a folder where we will store our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;pocketbase-docker 
~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;pocketbase-docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we are going to create our &lt;code&gt;Dockerfile&lt;/code&gt; so for this we can open our preferred editor, in my case vscode and already in it we are going to create the file and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;alpine:3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;downloader&lt;/span&gt;

&lt;span class="k"&gt;ARG&lt;/span&gt;&lt;span class="s"&gt; TARGETOS&lt;/span&gt;
&lt;span class="k"&gt;ARG&lt;/span&gt;&lt;span class="s"&gt; TARGETARCH&lt;/span&gt;
&lt;span class="k"&gt;ARG&lt;/span&gt;&lt;span class="s"&gt; VERSION=0.2.8&lt;/span&gt;

&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; BUILDX_ARCH="${TARGETOS:-linux}_${TARGETARCH:-amd64}"&lt;/span&gt;

&lt;span class="c"&gt;# Install the dependencies&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;apk add &lt;span class="nt"&gt;--no-cache&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    ca-certificates &lt;span class="se"&gt;\
&lt;/span&gt;    unzip &lt;span class="se"&gt;\
&lt;/span&gt;    wget &lt;span class="se"&gt;\
&lt;/span&gt;    zip &lt;span class="se"&gt;\
&lt;/span&gt;    zlib-dev

&lt;span class="k"&gt;RUN &lt;/span&gt;wget https://github.com/pocketbase/pocketbase/releases/download/v&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/pocketbase_&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;_&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;BUILDX_ARCH&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.zip &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; unzip pocketbase_&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;_&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;BUILDX_ARCH&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.zip &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;chmod&lt;/span&gt; +x /pocketbase

&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; scratch&lt;/span&gt;

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 8090&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=downloader /pocketbase /usr/local/bin/pocketbase&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["/usr/local/bin/pocketbase", "serve", "--http=0.0.0.0:8090"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, once we have this, let's go back to the terminal to create our Docker image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# We must be in the terminal positioned in the folder where we have our Dockerfile&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; pocketbase &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this we can test the image to verify that it works, you can execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# You need to make sure you have the '-it' flag and expose the port&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 8090:8090 pocketbase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If this went well you can open your browser at &lt;code&gt;localhost:8090/_/&lt;/code&gt; and see the pocketbase admin panel.&lt;/p&gt;

&lt;p&gt;Now that we verify that it works we are going to publish our image in our docker account, if you do not have one I recommend you create it and log in from your terminal with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~&lt;span class="nv"&gt;$ &lt;/span&gt;docker login &lt;span class="nt"&gt;-u&lt;/span&gt; &amp;lt;your-username&amp;gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &amp;lt;your-password&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's deploy our image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# We must add a tag to our image before deploying, for simplicity I will leave it as 'latest'&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;docker tag pocketbase:latest &amp;lt;your-docker-user&amp;gt;/pocketbase:latest
&lt;span class="c"&gt;# Now let's roll out&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;docker push &amp;lt;your-docker-user&amp;gt;/pocketbase:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this you have your image uploaded in docker 😎&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Deploy our Docker image to fly.io
&lt;/h2&gt;

&lt;p&gt;For this, the first thing you need is to install fly.io in our operating system, then I leave you the commands for each operating system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Windows:&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;iwr https://fly.io/install.ps1 &lt;span class="nt"&gt;-useb&lt;/span&gt; | iex
&lt;span class="c"&gt;# Linux&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://fly.io/install.sh | sh
&lt;span class="c"&gt;# Mac&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;flyctl
&lt;span class="c"&gt;# or&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://fly.io/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later you will need to sign up, for this, you can execute the following command in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~&lt;span class="nv"&gt;$ &lt;/span&gt;flyctl auth signup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will open a window in the browser where you can register and then it will ask you to enter a payment method, don't worry, Fly will not charge you unless your application exceeds the established free limit, and for the purposes of this tutorial it will help you to perfection.&lt;/p&gt;

&lt;p&gt;Now you need to log in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~&lt;span class="nv"&gt;$ &lt;/span&gt;flyctl auth login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, once you have logged in we are going to proceed to deploy:&lt;/p&gt;

&lt;p&gt;For this we are going to need our Docker image that we deployed.&lt;br&gt;
First we must create a necessary file to deploy, but in my case I will let Fly create it for me, for this in the terminal we execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~&lt;span class="nv"&gt;$ &lt;/span&gt;flyctl launch &lt;span class="nt"&gt;--image&lt;/span&gt; &amp;lt;your-docker-user&amp;gt;/pocketbase:latest
&lt;span class="c"&gt;# if you decided to use my image you can copy the following command:&lt;/span&gt;
~&lt;span class="nv"&gt;$ &lt;/span&gt;flyctl launch &lt;span class="nt"&gt;--image&lt;/span&gt; marcoa16b/pocketbase:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point fly will ask us a couple of questions, we will give our project a name and select a region for our server.&lt;/p&gt;

&lt;p&gt;Very well, with this we will have our &lt;code&gt;fly.toml&lt;/code&gt; file, we must damage some modifications to this file, since we need to expose the port of the Docker container so that we can access it from the domain that fly creates for us, for this we modify the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
[experimental]
  allowed_public_ports = [8090]
  ...
...
[[services]]
  ...
  internal_port = 8090
  [[services.ports]]
    handlers = ["http"]
    port = 8090
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rest you can leave as is.&lt;/p&gt;

&lt;p&gt;Once you have modified these ports, you can run &lt;code&gt;flyctl deploy&lt;/code&gt; and if you get the following output, everything is fine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; 1 desired, 1 placed, 1 healthy, 0 unhealthy &lt;span class="o"&gt;[&lt;/span&gt;health checks: 1 total, 1 passing]
&lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; v0 deployed successfully
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can go to the fly.io page and verify that you have your project there, when you open it you have the link of your project and the first time you open it in the address &lt;code&gt;yourproject.fly.dev/_/&lt;/code&gt; you will be able to create your user administrator and login to start managing your backend.&lt;/p&gt;

&lt;p&gt;In the same pocketbase administrator panel you can find a simple but very complete documentation to be able to use this tool in your Javascript projects.&lt;/p&gt;

&lt;p&gt;If you see any errors in the code, or have any suggestions to improve the project, do not hesitate to leave your comment.&lt;/p&gt;

&lt;p&gt;If everything went well and you managed to create your backend with pocketbase and Docker, I congratulate you and thank you for reading this tutorial. 😁🎉 &lt;/p&gt;

&lt;p&gt;Do not forget to follow me on my social networks, soon I will begin to publish more content in most of them, also so you can find out about my new tutorials and projects.👍&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/marcoa16b" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/mars_elit" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>backend</category>
      <category>tutorial</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
