<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sriram on Medium]]></title>
        <description><![CDATA[Stories by Sriram on Medium]]></description>
        <link>https://medium.com/@sriram_61106?source=rss-9fb0fee2aecd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OgavRNDyQ5KNgYD9BdrJDA.jpeg</url>
            <title>Stories by Sriram on Medium</title>
            <link>https://medium.com/@sriram_61106?source=rss-9fb0fee2aecd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:55:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sriram_61106/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Customizable LeetCode Daily Challenge System: Part 2]]></title>
            <link>https://blog.devops.dev/customizable-leetcode-daily-challenge-system-part-2-f9a840719fe1?source=rss-9fb0fee2aecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9a840719fe1</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Sriram]]></dc:creator>
            <pubDate>Tue, 05 Mar 2024 10:18:30 GMT</pubDate>
            <atom:updated>2024-03-07T22:05:20.199Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome back to those of y’all who stayed with me through this two-part series or hello for the first time to those of you who stumbled on this blog post randomly. If you belong to the latter, here’s <a href="https://medium.com/@sriram_61106/customizable-leetcode-daily-challenge-system-part-1-03c54b8f413f">Part 1: Building the App</a> for more context so you are not completely confused by this article.</p><p>Alright, so we have a working application that&#39;s running locally, but how do we package it so that it’s easy to set up anywhere?</p><h3>Docker and Hosting</h3><p>Now, for those who may not be aware, here’s a high-level overview of Docker. Docker is an amazing piece of software that has done wonders for the “Hey it’s working in my system why is it not working in yours” conundrum that all of us inevitably would have had at some point in our lives.</p><p>Here’s a snippet from IBM’s article on Docker that I thought was a really good explanation for what it does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*dgbSWArpy5QB1NLZmyrn6g.png" /><figcaption>Docker overview</figcaption></figure><p>Now for creating our container, we need a node environment with the required npm packages. We also need the setup script that seeds the database to start up once the application is up.</p><p>For this application, there are two services, one is the mailer service and the other is the database that the mailer service is dependent on. Thus, a multi-container application makes the deployment a lot easier. For managing multiple services like this, another tool called <em>docker-compose</em> is used to define these multi-container applications, and we can configure YAML files to spin up or tear down the services. Let’s see how we can get these set up.</p><h4>Docker Setup</h4><p>We need to create a file called <em>Dockerfile</em> that looks something like this.</p><pre>FROM node:14<br>WORKDIR ./<br>COPY package*.json ./<br>RUN npm install<br>RUN mkdir logs \<br> &amp;&amp; touch logs/out.log \<br> &amp;&amp; chmod 777 logs/out.log \<br> &amp;&amp; printf &quot;npm run setup\nnpm start\n&quot; &gt; entrypoint.sh<br>COPY . .<br>CMD [&quot;/bin/sh&quot;, &quot;entrypoint.sh&quot;]</pre><p>Let’s quickly dive into what this file does.</p><p>The first line pulls from a node image, which essentially means a template that someone defined already that executes instructions to spin a container with Node installed.</p><p>Next, we copy all our current content onto this container along with the dependencies of our application that are present in the <em>package.json</em> files. Next, we set up our log files.</p><p>Then, we create an entry script to be executed once the container environment is up and running. This script executes “npm run setup” and “npm start” to seed the database and start our application.</p><p>That’s the docker file for our mailer service and we can spin up an environment-agnostic container by simply running the command “<strong>docker build .</strong>” However, we are going to define a <em>docker-compose</em> file that manages both this container and our database.</p><h4>Docker-compose</h4><p>In our compose file, we need to define two services. One for our app and one for the MySQL DB. Let’s see how this works.</p><pre>version: &#39;3.8&#39;<br>services:<br>  mysqldb:<br>    image: mysql:5.7<br>    restart: unless-stopped<br>    env_file: ./.env<br>    environment:<br>      - MYSQL_ROOT_PASSWORD=$DB_ROOT_PASSWORD<br>      - MYSQL_DATABASE=$DATABASE<br>    ports:<br>      - $DB_LOCAL_PORT:$DB_DOCKER_PORT<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;mysql&quot;, &quot;-uroot&quot;, &quot;-p$DB_ROOT_PASSWORD&quot;, &quot;-e&quot;, &quot;USE $DATABASE;&quot;]<br>      timeout: 30s<br>      retries: 5<br>      start_period: 30s<br>    volumes:<br>      - db:/var/lib/mysql<br>  <br>  app:<br>    depends_on:<br>      mysqldb:<br>        condition: service_healthy<br>    build: ./<br>    restart: unless-stopped<br>    env_file: ./.env<br>    ports:<br>      - $NODE_LOCAL_PORT:$NODE_DOCKER_PORT<br>    environment:<br>      - DB_HOST=mysqldb<br>      - DB_USER=$DB_USER<br>      - DB_PASSWORD=$DB_ROOT_PASSWORD<br>      - DB_NAME=$DATABASE<br>      - DB_PORT=$DB_DOCKER_PORT<br>    stdin_open: true<br>    tty: true<br>volumes: <br>  db:</pre><p>I know this seems like a lot, but it can be easily boiled down. We first inform the tool that there are two services, which are “mysqldb” and “app”. Then in the “mysqldb” service, we pull from a MySQL image, define our env file path, and provide env information such as the ports, credentials, etc…</p><p>There’s a field called “healthcheck” which I will explain in a bit. We also define the volume for our database.</p><p>That’s it. We have set up our database container. Next, on to our app.</p><p>For our app, we need to tell the compose tool that the app should be started only after the database has been set up. To do this, we use the “depends_on” field to specify a condition that should be satisfied before the app container is started. Since the LeetCode problem seeding process takes a while to finish, if we fail to include the “depends_on” condition, the app will start but crash instantly since there is no data to fetch from.</p><p>So, what condition do we specify to ensure that the app container always starts once the database is ready?</p><p>We specify a “service_healthy” condition, which tells the compose tool that only when the MySQL service is in a healthy condition the app container should be started.</p><p>Now how does the tool decide how to call the mysqldb service as healthy?</p><p>That’s where the “healthcheck” field in the mysqldb service comes into the picture. Here, we define a “test” to check if the service is healthy or not, and all this test does, is to connect to the DB. I have defined the <em>start_period</em>, <em>timeout</em>, and <em>number of retries</em> according to how long it took for my database to be seeded, but this can be configured as per requirement.</p><p>Thus, once the healthcheck for the mysqldb service returns a healthy status, the compose tool starts the app container and everything is up and ready to receive our custom daily challenge dropped straight to our inbox.</p><p>Alright, that was a lot, but we are almost at the end of setting up the mailer service. Thank you for staying with me this long. There’s just one more small step to see the app in action.</p><h4>Hosting</h4><p>For hosting the service, there are several options, such as servers in Digital Ocean or Heroku or it can also be deployed on the cloud using platforms such as AWS or GCP. For this application, I used my AWS free tier to spin up an EC2 and deploy my service.</p><p>Launching an EC2 instance in AWS is pretty simple, we first need to navigate to the EC2 service, and click on “Launch an instance”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pIL4DtewjJVnqw_1mxAypg.png" /><figcaption>Launching an EC2 instance</figcaption></figure><p>Here, the Ubuntu image can be chosen for our server in the quick start section. Next, we need to create a key pair for our EC2 that allows us to SSH into our instance to spin up our containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*v3dp-R1M-3pwHRRbtctFDg.png" /><figcaption>Key-Pair creation</figcaption></figure><p>Once this is done, the EC2 should be up and running in a little while, and we can connect to the instance using either the “EC2 instance connect” option in the AWS console which opens a session in the browser, or we can SSH into the instance from our terminal with the local “.pem” file (which has the key pair we created).</p><pre>ssh -i &quot;LCMailer-key-pair.pem&quot; ubuntu@ec2-3-19-217-150.us-east-2.compute.amazonaws.com</pre><p>We can use the above command to SSH into our server.</p><p>Once, we are in, we can clone our project into our server (this needs an SSH key of our new server to be set in GitHub but I’m assuming that’s a given and skipping that part) and execute the docker-compose command to spin up our containers.</p><pre>docker-compose up -d</pre><p>The above command sets up both the App and the DB.</p><h3>Conclusion</h3><p>That’s pretty much it. I have this service running in my EC2 that is delivering me a LeetCode problem every day. Now, whether I solve every question that I get is something that I am not willing to answer at the moment, I will pass on that, but I just had fun building this small app.</p><p>Feel free to check out the <a href="https://github.com/sriram1998/LCMAILER">Github Repo</a> for this project and suggest any improvements. For instance, one thing I think I could do to improve this service would be to build a discord bot that drops a DM to my server instead of using Gmail, which would be pretty cool I think. I could also have a UI for updating the config instead of having to hardcode it in the server every time.</p><p>I hope at least some part of this huge blog was insightful to whoever made it this far.</p><p>Follow for more blogs like this which I may or may not publish. Thank you and happy LeetCoding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9a840719fe1" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/customizable-leetcode-daily-challenge-system-part-2-f9a840719fe1">Customizable LeetCode Daily Challenge System: Part 2</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Customizable LeetCode Daily Challenge System: Part 1]]></title>
            <link>https://blog.devops.dev/customizable-leetcode-daily-challenge-system-part-1-03c54b8f413f?source=rss-9fb0fee2aecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/03c54b8f413f</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Sriram]]></dc:creator>
            <pubDate>Tue, 05 Mar 2024 10:16:56 GMT</pubDate>
            <atom:updated>2024-03-07T22:05:27.664Z</atom:updated>
            <content:encoded><![CDATA[<h3>Context</h3><p>Imagine this.</p><p>You are someone who loves solving the LeetCode (LC) daily challenge. You see a medium-difficulty problem one day. The LeetCode gods have blessed you and the problem does not make you lose your sanity. You get that glorious green tick after running your solution. You would think, “Hey things are looking up for me” so you log back in the next day, and bummer, it is a hard graph problem. That’s okay, you’ll just try again. You log back in the next day, and it’s just not your week for it’s another hard implementation problem. The next day, again, it’s a medium problem which is essentially just a hard problem that’s been tagged wrong.</p><p>At this point, it’s just cruel and you finally understand how Sisyphus felt. Well, I certainly did when I got back into my LeetCode grind. So much so that I even made a meme out of it. Honestly, I was tired of how unfairly random the daily challenge was being to me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*do1hYvnBbF4_xQ85quq23A.jpeg" /><figcaption>The suffering is enough to fill a man’s heart.</figcaption></figure><p>So, I set out to fix this problem.</p><p>My solution was simple but quite effective. I scraped all the URLs of all the unlocked LeetCode problems, stored them in an SQL database, and hosted a Node backend with a mailer service that emails me questions every day tailored to my liking based on my custom configuration.</p><p>For instance, if I want only easy and medium problems and I particularly do not want anything from Bit Manipulation, Linked Lists, and Math (let’s be honest, no one really likes those), I can configure exactly that!</p><p>This is the blog on how I built this service using Node and MySQL, packaged it into a one-command deployable app using Docker, Docker-Compose, and hosted it on AWS EC2 to get customized LC daily challenges delivered directly to my email. Although this was a rather small project, I learned a lot in building the services, packaging, and deploying them on the cloud and more importantly I had a lot of fun developing it. I wanted to share my thoughts on this and hopefully, it might help someone who wants to set up a similar service or use the tech I have used in this project.</p><p>The article is divided into two parts. In the first part, I will delve into the app itself, its services, DB structure, and logic. In the <a href="https://medium.com/@sriram_61106/customizable-leetcode-daily-challenge-system-part-2-f9a840719fe1">second part</a>, I will talk about using docker and docker-compose to package the application and about the deployment to AWS.</p><h3>Setup</h3><h4>Data Collection</h4><p>The first step I had to do was write a scraper in Python to get all the free problems that LC has. There are a lot of tools and resources available online on how to use Beautiful Soup to do this. I’ve linked a resource that helped me out below, but I&#39;m skipping the details of this part for now since it&#39;s pretty boring work. (I promise it gets better.)</p><p><a href="https://realpython.com/beautiful-soup-web-scraper-python/">Beautiful Soup: Build a Web Scraper With Python - Real Python</a></p><p>I have also included my GitHub repo towards the end of this post where the Python script named “questions.py” can be found under the “resources” directory in case anyone needs to take a look at that. I used this script to create a CSV file with the <em>problem name</em>, the <em>URL</em>, the <em>difficulty</em>, and the <em>tagged concept</em>.</p><p>The resulting problem set was used to seed my database.</p><h4>Project Structure</h4><p>I decided to structure the project into three main folders. <em>DB</em>, <em>Services</em>, and <em>Config</em>. Let&#39;s look at these one by one.</p><p>On to the fun part now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*wY_41tWKG3mB96DuZA95MQ.png" /><figcaption>Project Structure</figcaption></figure><h3>The Fun Part</h3><h4>Database Structure</h4><p>For the database structure, I had to have fields for the <em>problem name</em>, <em>URL</em>, <em>difficulty</em>, and <em>concept</em>. Another field I added was the “status” field which is updated as “SOLVED” if that problem has been mailed out. If a problem is marked as “SOLVED” then it will not be picked for mailing again.</p><h4>Database Creation</h4><p>Once the structure is decided, I used the MySQL npm package to create the DB schema:</p><pre>async function createDB(){<br>    var conn = mysql.createConnection({<br>        host: sqlConfig.HOST,<br>        user: sqlConfig.USER,<br>        password: sqlConfig.PASSWORD,<br>        port: sqlConfig.PORT,<br>        multipleStatements: true<br>    });<br>    <br>    var sqlCommand = `<br>    CREATE DATABASE IF NOT EXISTS lcproblemset;<br>    <br>    USE lcproblemset;<br>    <br>    CREATE TABLE IF NOT EXISTS problems (<br>        id int(11) NOT NULL auto_increment,<br>        title varchar(500) NOT NULL,<br>        difficulty varchar(20) NOT NULL,<br>        link varchar(500) NOT NULL,<br>        status varchar(20) NOT NULL,<br>        concept varchar(50) NOT NULL,<br>        PRIMARY KEY (id)<br>    );<br>    `<br>    return new Promise((resolve, reject) =&gt; {<br>        try {<br>            conn.query(sqlCommand, (err, response) =&gt; {<br>                if (err) {<br>                    logger.info(&quot;Database and table creation failed &quot;, err);<br>                    reject(err);<br>                }<br>                else {<br>                    logger.info(&quot;Connection to DB successful and table created&quot;, response);<br>                    resolve(response);<br>                }<br>            });<br>        }<br>        finally {<br>            conn.end()<br>        }<br>    })<br>    <br>}</pre><p>It is a fairly straightforward module that uses Promise (since it&#39;s an async operation), to create the DB and return the response.</p><p>Now, because this is a relatively small-scale application, opening and closing a connection to the DB will not be that frequent. But I decided to create a connection pool anyway just to make things scalable and easier. A connection pool is generally preferred because it prevents an overflow of connections to the database and it will reduce the load on the database server.</p><pre>async function getConnection(pool){<br>  return new Promise((resolve, reject) =&gt; {<br>      pool.getConnection((err, conn) =&gt; {<br>          if(err){<br>              console.log(&quot;Connection to Database failed &quot;, err);<br>              return reject(err);<br>          }<br>          else{<br>              resolve(conn);<br>          }<br>      })<br>  })<br>}<br><br>module.exports = {pool, getConnection}</pre><p>This module exports a connection pool that my service can use whenever it wants to establish a connection.</p><h4>Database Seeding</h4><p>For seeding the database from the CSV file, I used Node’s <em>readXlsxFile</em> package to parse the CSV and load the database.</p><pre>async function insertDataIntoDB() {<br><br>    var sql = await mysqlUtil.getConnection(pool);<br><br>    return new Promise((resolve, reject) =&gt; {<br>        readXlsxFile(filePath).then((rows) =&gt; {<br>            let query = `INSERT INTO problems (title, difficulty, link, concept, status) VALUES ?`;<br><br>            let flag = false;<br><br>            try {<br>                sql.query(query, [rows], (error, response) =&gt; {<br>                    if (error) {<br>                        logger.info(&quot;Insertion of records failed &quot;, error);<br>                        reject(error);<br>                    }<br>                    else {<br>                        logger.info(&quot;Data loaded successfully&quot;);<br>                        flag = true;<br>                        resolve(flag);<br>                    }<br>                })<br>            }<br>            finally {<br>                sql.release();<br>                pool.end();<br>            }<br><br>        });<br>    })<br><br>}</pre><p>We can call this seed module on setup of the service by configuring a <em>setup.js</em> file to be called on running npm setup.</p><pre>require(&quot;dotenv&quot;).config();<br><br>const { logger } = require(&quot;../utils/logger&quot;);<br>const seedService = require(&quot;./seedDB&quot;);<br>const createSchema = require(&quot;./createDB&quot;);<br><br><br>async function setup(){<br>    var setupStatus = await createSchema.createDB();<br><br>    logger.info(&quot;Status of schema setup is &quot;, setupStatus);<br>    <br>    var seedStatus = await seedService.checkSeed();<br><br>    if(!seedStatus){<br>        var loadResult = await seedService.insertDataIntoDB();<br>        logger.info(&quot;status of data loading is &quot;, loadResult);<br>    }<br>}<br><br>setup();</pre><p>Now that we have seeded the database with all the problems, we can go ahead and develop the service that fetches the problem based on our config.</p><h4>Application Config</h4><p>The essence of this application is the <em>config</em> file where we, well, configure the application to our liking.</p><pre>module.exports = {<br>    &quot;concepts&quot;: [&quot;array&quot;,&quot;string&quot;,&quot;hash-table&quot;,&quot;dynamic-programming&quot;,&quot;math&quot;,&quot;depth-first-search&quot;,&quot;sorting&quot;,&quot;greedy&quot;,&quot;breadth-first-search&quot;,&quot;tree&quot;,&quot;binary-search&quot;,&quot;matrix&quot;,&quot;binary-tree&quot;,&quot;two-pointers&quot;,&quot;bit-manipulation&quot;,&quot;stack&quot;,&quot;heap-priority-queue&quot;,&quot;graph&quot;],<br>    &quot;difficulty&quot;: [&quot;Easy&quot;, &quot;Medium&quot;, &quot;Hard&quot;], //Include only the difficulties needed.<br>    &quot;gmailAuth&quot;: {&quot;address&quot;: process.env.GMAIL_AUTH_EMAIL, &quot;password&quot;: process.env.GMAIL_AUTH_PASSWORD}, //setup app password in gmail and provide the creds here.<br>    &quot;DL&quot;: &quot;example1@gmail.com, example2@gmail.com, example3@gmail.com&quot;, //enter list of comma separated mail ids<br>    &quot;cron&quot;: &quot;0 10 * * *&quot; //set scheduled time to mail question (currently set to 10AM everyday).<br>}</pre><p>1. <strong>Concepts</strong>: This array lists all the currently existing concepts in LeetCode which we can edit to include only the concepts that we want. For example, I can set this config to only “array” and “hash-table” if I want my daily challenge to send me only problems of that category.</p><p>2. <strong>Difficulty</strong>: I can set the range of difficulties (easy, medium, or hard) I want by editing the “difficulty” array.</p><p>3. <strong>DL</strong>: The “DL” field, takes a list of email addresses that the service sends the email out to.</p><p>4. <strong>cron</strong>: The “cron” field represents the frequency with which I want the daily challenges. For example, I can set it to “<strong>0 10,22 * * *</strong>” which runs the service every day at 10:00 am and 10:00 pm.</p><p>Now that we have set the config to our liking, we can go ahead and develop the service that fetches the problems from our database.</p><h4>SQL Service</h4><p>This service takes the difficulty and the list of concepts as parameters and fetches the problems from the database accordingly.</p><pre>async function getProblems(difficultyRange, concepts) {<br>    let query = `SELECT * from problems ORDER BY RAND() LIMIT 1 WHERE difficulty in (?) AND concept in (?) and status = &quot;UNSOLVED&quot;`;<br><br>    var conn = await mysqlUtil.getConnection(pool);<br><br>    return new Promise((resolve, reject) =&gt; {<br>        try {<br>            conn.query(query, [difficultyRange, concepts], (error, response) =&gt; {<br>                if (error) {<br>                    console.log(&quot;querying table failed &quot;, error);<br>                    reject(error);<br>                }<br>                else {<br>                    resolve(response);<br>                }<br>            })<br>        }<br><br>        finally {<br>            conn.release();<br>        }<br>    })<br>};</pre><p>This module queries our database and selects a random row that has the difficulty and concept present in our configuration. It also searches for only “UNSOLVED” problems to fetch unique problems every time.</p><p>Now, we also need another module that updates the problem as “SOLVED” so it won&#39;t get picked again. This module takes the ID of the problem as a parameter and updates its status to SOLVED.</p><pre>async function updateStatus(id){<br>    let query = `UPDATE problems SET status = &quot;SOLVED&quot; where id = ?`;<br><br>    var conn = await mysqlUtil.getConnection(pool);<br><br>    return new Promise((resolve, reject) =&gt; {<br>        try{<br>            conn.query(query, id, (err, response) =&gt; {<br>                if(err){<br>                    console.log(&quot;Update Failed &quot;, err);<br>                    reject(err);<br>                }<br>                else{<br>                    resolve(response);<br>                }<br>            })<br>        }<br>        finally{<br>            conn.release();<br>        }<br>    })<br><br>};</pre><h4>Mailer Service</h4><p>Right, that covers all the major implementations for this service.</p><p>All we need now is to email the problem. For this, I used a npm package called <em>nodemailer</em>.</p><pre>const nodemailer = require(&quot;nodemailer&quot;); <br>const config = require(&quot;../../config/app.config&quot;);<br><br>async function sendMail(title, link, difficulty){<br>    let transporter = nodemailer.createTransport({<br>        service: &quot;gmail&quot;,<br>        auth: {<br>            user: config.gmailAuth.address,<br>            pass: config.gmailAuth.password<br>        }<br><br>    });<br><br>    var subject = &quot;Today&#39;s LC question: &quot; + title + &quot; (&quot; + difficulty + &quot;)&quot;;<br><br><br>    var html = &quot;&lt;p&gt;&quot; + link + &quot;&lt;/p&gt;&lt;br/&gt;&lt;b&gt;Next question tomorrow at 10 AM&lt;/b&gt;&quot;<br><br>    let info = await transporter.sendMail({<br>        from: config.gmailAuth.address, <br>        to: config.DL,<br>        subject: subject,<br>        html: html<br>    });<br><br>    console.log(&quot;Message sent &quot;, info.messageId);<br><br>    return info.messageId;<br>}<br><br>module.exports = {sendMail}</pre><h3>Bringing It All Together</h3><p>Now that we have all the individual components ready, we can integrate all of them to create a working service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*xqpVcZg8m8LTQEZbB3iz2A.jpeg" /><figcaption>Know your meme.</figcaption></figure><p>The main function performs these three things:</p><ol><li>Retrieves the problem from the database based on our configuration.</li><li>Schedules emails based on the cron set in the config and send them to the specified list of emails.</li><li>Updates the problem’s status in the database.</li></ol><pre>const SQLservice = require(&quot;./services/SQLService.js&quot;);<br><br>const mailer = require(&quot;./services/mailer.js&quot;);<br><br>const config = require(&quot;../config/app.config&quot;);<br><br>var cron = require(&#39;node-cron&#39;)<br><br>async function retrieveAndMail(){<br><br>    var problem = await SQLservice.getProblems(config.difficulty, config.concepts);<br><br>    var id = problem[0].id;<br>    var title = problem[0].title;<br>    var link = problem[0].link;<br>    var difficulty = problem[0].difficulty;<br><br>    var mailStatus = await mailer.sendMail(title, link, difficulty);<br><br>    if(mailStatus){<br>        console.log(mailStatus);<br>    }<br><br>    SQLservice.updateStatus(id).then((response) =&gt; {<br>        console.log(response);<br>        return response;<br>    });<br><br>    <br>}<br><br>cron.schedule(config.cron, () =&gt; {<br>    retrieveAndMail();<br>});</pre><p>And that’s pretty much the entire application. This command should set up the DB locally with all the LC problems and start the mailer service.</p><pre>npm run setup &amp;&amp; npm start</pre><p>Now, it’s ideal for me to run this application on a server that will stay up 24*7 to send me the LC problems that I may or may not solve. For that, I need to get a server, install node and npm, install the app’s dependencies run the setup script, and start the application.</p><p>These are a lot of steps and can quickly become cumbersome in large-scale applications. This is where Docker comes into the picture.</p><p>So let&#39;s dive into the part that neatly wraps this entire thing up in a package to be easily deployable anywhere.</p><p><a href="https://medium.com/@sriram_61106/customizable-leetcode-daily-challenge-system-part-2-f9a840719fe1">Click here for Part 2: “Docker and Hosting”</a></p><p>Feel free to check out the <a href="https://github.com/sriram1998/LCMAILER">Github Repo</a> for this project and suggest any improvements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03c54b8f413f" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/customizable-leetcode-daily-challenge-system-part-1-03c54b8f413f">Customizable LeetCode Daily Challenge System: Part 1</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>