<?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"><channel><title><![CDATA[Dhruv's Blog]]></title><description><![CDATA[Dhruv Sood blogs are posted here]]></description><link>https://blogs.dhruvsood.in</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 21:38:22 GMT</lastBuildDate><atom:link href="https://blogs.dhruvsood.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to use python to download 100 cat pics in one go]]></title><description><![CDATA[Alright, so we all know cats are awesome, right? But this blog post isn’t just about cats—today, we're gonna whip up a Reddit scraper using Python that can snag images from any subreddit you want! Pretty epic, right? Imagine the look on your crush's ...]]></description><link>https://blogs.dhruvsood.in/how-to-use-python-to-download-100-cat-pics-in-one-go</link><guid isPermaLink="true">https://blogs.dhruvsood.in/how-to-use-python-to-download-100-cat-pics-in-one-go</guid><dc:creator><![CDATA[Dhruv Sood]]></dc:creator><pubDate>Tue, 20 Aug 2024 08:00:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1724134592189/a4eafefd-aeda-47f7-a07b-f08c3d1d745c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExNHd0bHpsN2Vpbndsamk1aHp5cHY1c2dvN2Q3MHR4dGRiM2tjdml4MiZlcD12MV9naWZzX3NlYXJjaCZjdD1n/MDJ9IbxxvDUQM/giphy.gif" alt class="image--center mx-auto" /></p>
<p>Alright, so we all know cats are awesome, right? But this blog post isn’t just about cats—today, we're gonna whip up a Reddit scraper using Python that can snag images from any subreddit you want! Pretty epic, right? Imagine the look on your crush's face when you show up with a whole bucket of cat pics😼. Just a heads-up, though: this is all in good fun and for educational purposes, so don’t go using your newfound powers for anything sketchy[By sketchy i mean illegal]. Let’s dive in!</p>
<h1 id="heading-setting-up-a-reddit-app">Setting up a reddit app</h1>
<p>For starters, let’s first set up a Reddit app, which will allow us to access Reddit’s API. This process is straightforward and will provide you with the necessary credentials to authenticate your requests.</p>
<h4 id="heading-step-1-log-in-to-reddit-developer-portal">Step 1: Log in to Reddit Developer Portal</h4>
<p>Start by logging into your Reddit account. Once you're logged in, open <a target="_blank" href="https://www.reddit.com/prefs/apps">https://www.reddit.com/prefs/apps</a></p>
<p>You will get this screen</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724128916642/069c3b57-d959-4136-b632-b81536a59aff.png" alt class="image--center mx-auto" /></p>
<h4 id="heading-step-2-create-a-new-reddit-app">Step 2: Create a New Reddit App</h4>
<p>On this page, locate and click the button labeled "Are you a developer? Create an app." or "Create another app" This will bring up a form where you can configure your new app.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724127928235/d20b89fd-8788-4b74-8571-f11bcb5267fe.png" alt class="image--center mx-auto" /></p>
<h4 id="heading-step-3-configure-your-app">Step 3: Configure Your App</h4>
<ol>
<li><p><strong>Select the Type of App</strong>: Choose the "Script" option. This is ideal for personal scripts and tools that interact with Reddit's API.</p>
</li>
<li><p><strong>Name and Describe Your App</strong>: Give your app a meaningful name and a brief description. This will help you identify the app later, especially if you create multiple apps.</p>
</li>
<li><p><strong>Redirect URL</strong>: For the redirect URL, enter <a target="_blank" href="http://localhost:3000/"><code>http://localhost:3000/</code></a>. This is commonly used during local development, but it can be changed later when you deploy your application.</p>
</li>
<li><p><strong>Submit the Form</strong>: Once you've filled out all the necessary fields, click the "Create App" button.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724128136931/1faa3613-e1a1-45eb-8462-7406945265f4.png" alt class="image--center mx-auto" /></p>
<h4 id="heading-step-4-secure-your-client-id-and-secret">Step 4: Secure Your Client ID and Secret</h4>
<p>After creating your app, you’ll be provided with a <strong>Client ID</strong> and <strong>Client Secret</strong>. These credentials are crucial as they will be used to authenticate your API requests. Make sure to store them securely, as you’ll need them in the next steps of your development process.</p>
<p>(Don’t even think about trying my credentials—I know how lazy some of you are! 😂 But no worries, I'll be changing them before I post this blog anyway!)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724128620991/f6194fe2-81c3-4d0b-97dc-d23704c94b5c.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-bringing-our-reddit-tool-to-life">Bringing Our Reddit Tool to Life</h1>
<p><img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbjQ2aTg4MmYydWg2Y2U0N2pmMjJlYjN2YWpwd3BxMWcxcWx6MmY0MCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/VbnUQpnihPSIgIXuZv/giphy.gif" alt class="image--center mx-auto" /></p>
<p>Wow, you made it this far—I'm impressed! 🎉</p>
<p>Now, let's get our hands dirty with some code. This section is going to be smooth sailing. You can either follow along step-by-step or, if you're more of a "just give me the tool" person, feel free to grab the complete code from my <a target="_blank" href="https://github.com/Dhruv-Sood/reddit-scraper">Github Repository</a> . But trust me, coding it yourself is half the fun!</p>
<h4 id="heading-install-the-dependencies">Install the Dependencies</h4>
<p>Before we dive into the code, we need to ensure your environment is ready. This tutorial is built with Python, so if you haven’t installed Python yet, now's the time! You can download it from python.org. Once Python is installed, you’ll need to install a couple of essential libraries.</p>
<p>Fire up your terminal and run:</p>
<pre><code class="lang-bash">pip install praw requests
</code></pre>
<p>or</p>
<pre><code class="lang-bash">pip3 install praw requests
</code></pre>
<p>A little overview of the libraries we just installed</p>
<ul>
<li><p><code>praw</code>: This is the Python Reddit API Wrapper, a simple yet powerful library that lets you interact with Reddit’s API.</p>
</li>
<li><p><code>requests</code>: A popular HTTP library in Python for making requests and handling responses easily.</p>
</li>
</ul>
<p>With these dependencies in place, you’re all set to start building!</p>
<h1 id="heading-lets-start-coding">Let’s Start Coding</h1>
<h2 id="heading-step-1-set-up-your-project"><strong>Step 1: Set Up Your Project</strong></h2>
<p>First things first, let’s create a folder to keep everything organized. Name it <code>reddit-script</code> (or whatever you like). Inside this folder, create a new file called <a target="_blank" href="http://main.py"><code>main.py</code></a>. This is where we’ll write all our code.</p>
<h2 id="heading-step-2-setup-reddit-api-credentials"><strong>Step 2: Setup Reddit API Credentials</strong></h2>
<p>Before we can start downloading images, we need to connect to Reddit’s API. This requires setting up credentials using the PRAW library. We’ll need a <code>client_id</code>, <code>client_secret</code>, and a <code>user_agent</code>, which we already got in the previous section<br />For <code>user_agent</code> we can write any value, but we will write "postdownloader"</p>
<p>At the beginning of your <a target="_blank" href="http://main.py"><code>main.py</code></a> file, you need to import the required libraries.</p>
<p>In your <a target="_blank" href="http://main.py"><code>main.py</code></a> file, set up the connection like this:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> praw
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> os

reddit = praw.Reddit(client_id=<span class="hljs-string">"your_client_id"</span>,
                     client_secret=<span class="hljs-string">"your_client_secret"</span>,
                     user_agent=<span class="hljs-string">"postdownloader"</span>)
</code></pre>
<p>This code initializes the connection, allowing your script to interact with Reddit.</p>
<h2 id="heading-step-3-download-image-function"><strong>Step 3: Download Image Function</strong></h2>
<p>Now, let's create a function that handles the actual downloading of images. This function, named <code>download_image</code>, will take two parameters: the URL of the image and the path where you want to save it.</p>
<p>Here’s the code for the <code>download_image</code> function:</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">download_image</span>(<span class="hljs-params">url, path</span>):</span>
    response = requests.get(url)
    <span class="hljs-keyword">if</span> response.status_code == <span class="hljs-number">200</span>:
        <span class="hljs-keyword">with</span> open(path, <span class="hljs-string">'wb'</span>) <span class="hljs-keyword">as</span> f:
            f.write(response.content)
        print(<span class="hljs-string">f"Downloaded <span class="hljs-subst">{path}</span>"</span>)
    <span class="hljs-keyword">else</span>:
        print(<span class="hljs-string">f"Failed to download <span class="hljs-subst">{url}</span>"</span>)
</code></pre>
<h3 id="heading-understanding-whats-happening">Understanding what's happening:</h3>
<p>Let’s break down the function step by step:</p>
<ol>
<li><p><strong>Sending the HTTP Request</strong>:</p>
<pre><code class="lang-python"> response = requests.get(url)
</code></pre>
<ul>
<li>This line sends an HTTP GET request to the URL provided as an argument. The <code>requests.get(url)</code>function fetches the content from the specified URL, which in this case is an image file. The result of this request is stored in the <code>response</code> variable.</li>
</ul>
</li>
<li><p><strong>Checking the Response Status</strong>:</p>
<pre><code class="lang-python"> <span class="hljs-keyword">if</span> response.status_code == <span class="hljs-number">200</span>:
</code></pre>
<ul>
<li>Here, the function checks if the request was successful by examining the status code of the response. A status code of <code>200</code> means the request was successful, and the server returned the image data correctly. If the status code is anything other than <code>200</code>, it means there was an issue with fetching the image.</li>
</ul>
</li>
<li><p><strong>Saving the Image</strong>:</p>
<pre><code class="lang-python"> <span class="hljs-keyword">with</span> open(path, <span class="hljs-string">'wb'</span>) <span class="hljs-keyword">as</span> f:
     f.write(response.content)
</code></pre>
<ul>
<li><p>If the response is successful, the function proceeds to save the image.</p>
<ul>
<li><p>The <code>open(path, 'wb')</code> command opens a file in write-binary mode (<code>'wb'</code>), which is necessary for writing binary data like images.</p>
</li>
<li><p><code>f.write(response.content)</code> writes the content of the response (the image data) to the file specified by <code>path</code>.</p>
</li>
<li><p>The <code>with</code> statement ensures that the file is properly closed after writing the data.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Providing Feedback</strong>:</p>
<pre><code class="lang-python"> print(<span class="hljs-string">f"Downloaded <span class="hljs-subst">{path}</span>"</span>)
</code></pre>
<ul>
<li>After successfully saving the image, the function prints a confirmation message indicating the image has been downloaded and shows the path where it was saved.</li>
</ul>
</li>
<li><p><strong>Handling Errors</strong>:</p>
<pre><code class="lang-python"> <span class="hljs-keyword">else</span>:
     print(<span class="hljs-string">f"Failed to download <span class="hljs-subst">{url}</span>"</span>)
</code></pre>
<ul>
<li>If the response status code is not <code>200</code>, the function enters the <code>else</code> block and prints an error message, indicating that the image could not be downloaded from the provided URL.</li>
</ul>
</li>
</ol>
<p>This function is the core of your script, enabling it to download images from Reddit and save them to your local machine with just a URL and a specified file path.</p>
<h2 id="heading-step-4-main-function">Step 4: Main Function</h2>
<p>The <code>main</code> function is where everything comes together. It’s responsible for taking user input, setting up directories, fetching posts, and calling the <code>download_image</code> function to save the images.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span>():</span>
    subreddit_name = input(<span class="hljs-string">"Enter the subreddit: "</span>)
    num_photos = int(input(<span class="hljs-string">"Enter the number of photos to download: "</span>))

    directory = <span class="hljs-string">f"image/<span class="hljs-subst">{subreddit_name}</span>"</span>
    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(directory):
        os.makedirs(directory)

    subreddit = reddit.subreddit(subreddit_name)

    count = <span class="hljs-number">0</span>
    <span class="hljs-keyword">for</span> post <span class="hljs-keyword">in</span> subreddit.top(limit=<span class="hljs-number">1000</span>):  <span class="hljs-comment"># Fetch a large number of posts to increase chances of finding enough images</span>
        <span class="hljs-keyword">if</span> post.url.endswith((<span class="hljs-string">'jpg'</span>, <span class="hljs-string">'jpeg'</span>, <span class="hljs-string">'png'</span>)):
            count += <span class="hljs-number">1</span>
            image_name = <span class="hljs-string">f"<span class="hljs-subst">{directory}</span>/<span class="hljs-subst">{subreddit_name}</span>_<span class="hljs-subst">{count}</span>.jpg"</span>
            download_image(post.url, image_name)
        <span class="hljs-keyword">if</span> count &gt;= num_photos:
            <span class="hljs-keyword">break</span>

    print(<span class="hljs-string">f"Downloaded <span class="hljs-subst">{count}</span> images from r/<span class="hljs-subst">{subreddit_name}</span>"</span>)
</code></pre>
<p>Here’s the breakdown:</p>
<ul>
<li><p><strong>User Input</strong>: The script first asks for the subreddit name and the number of images to download.</p>
</li>
<li><p><strong>Create Directory</strong>: A directory named <code>image/[subreddit_name]</code> is created to store the images.</p>
</li>
<li><p><strong>Fetch and Download Images</strong>: The script fetches posts from the specified subreddit, checks if the post contains an image, and then downloads it.</p>
</li>
</ul>
<h2 id="heading-step-5-running-the-script">Step 5: Running the Script</h2>
<p>End your code with the following lines to ensure the script runs when executed directly:</p>
<pre><code class="lang-python"><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
    main()
</code></pre>
<p>This ensures that the <code>main</code> function is called when you run the script, starting the process of downloading images based on your inputs.</p>
<h1 id="heading-the-grand-finale-let-the-fun-begin">The Grand Finale: Let the Fun Begin!</h1>
<p>You're all set! Now, it's time to fire up the app and start filling your folders with all the cat pics, memes, or whatever else your heart desires. Hit that run button, grab some snacks, and watch the magic happen as your image collection takes off. Happy downloading, and enjoy the meme hoard!</p>
<p>And hey, stay tuned—there’s more cool stuff coming your way!</p>
<p><img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExdXVqZ2pnZTIxNWt0aGc2amI5dXIzd290d2dteXF0eG9jNzhieWsyeCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/er19eYafoFxrq/giphy.gif" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Hacks for Keeping Your Computer Science Fire Burning]]></title><description><![CDATA[Well, as a first-year computer science student, I know I may be a bit of a newbie when it comes to tech. But, despite my lack of experience, I've already learned a ton in just the past three months. And one of the most interesting things I've discove...]]></description><link>https://blogs.dhruvsood.in/hacks-for-keeping-your-computer-science-fire-burning</link><guid isPermaLink="true">https://blogs.dhruvsood.in/hacks-for-keeping-your-computer-science-fire-burning</guid><dc:creator><![CDATA[Dhruv Sood]]></dc:creator><pubDate>Sun, 12 Feb 2023 04:05:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/W53FwtFtoM0/upload/3b7da357c8322330898b1d25c536438e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Well, as a first-year computer science student, I know I may be a bit of a newbie when it comes to tech. But, despite my lack of experience, I've already learned a ton in just the past three months. And one of the most interesting things I've discovered is the power of challenges to keep me motivated as a developer.</p>
<p><img src="https://media.giphy.com/media/Y4ENDBs7dCub2dCo6u/giphy.gif" alt class="image--center mx-auto" /></p>
<p>One challenge in particular that I've found to be super helpful is the #100DaysOfCode challenge. The idea is simple: commit to coding something every day for 100 days, and share your progress on social media, mostly on Twitter. Not only does this challenge help keep me accountable and motivated, but it also provides a great opportunity to connect with other developers and newbies in the tech community.</p>
<p><img src="https://media.giphy.com/media/Wsju5zAb5kcOfxJV9i/giphy.gif" alt class="image--center mx-auto" /></p>
<p>And let me tell you, there's nothing quite like the feeling of accomplishment when you see your tweets getting more and more views and engagement. Learning in public is a great way to push yourself to improve and the encouragement and advice you get from the community are invaluable.</p>
<p>So, if you're a computer science student or developer looking for a way to stay motivated and connected to the tech community, I highly recommend giving the #100DaysOfCode challenge a try. It's a fun and rewarding way to grow as a developer and keep your computer science mojo going strong.</p>
<p><img src="https://media.giphy.com/media/Od0QRnzwRBYmDU3eEO/giphy.gif" alt class="image--center mx-auto" /></p>
<p>Another way that you can keep your computer science burning is to start making blogs. Writing blogs is a great way to do it! Sharing your learnings and experiences in words can really bring your learning to the next level. Just like I mentioned the #100daysofcode challenge in this article, writing a blog is the perfect follow-up to that. Not only will you be taking your "learning in public" to new heights, but you'll also get some well-deserved exposure. And here's the best part - even if you're still a beginner or a seasoned pro, there's always someone who could learn from your experiences. In other words, you're not only levelling up your own skills, but you're also giving back to the community!</p>
<p><img src="https://media.giphy.com/media/yNs2a0jRkYxy6191B2/giphy.gif" alt class="image--center mx-auto" /></p>
<p>Wrapping up, being a computer science student or developer is awesome, but it can be tough to keep the motivation and connection to the tech community going strong. That's why challenges like the #100DaysOfCode and writing blogs are the bomb! They're a chance to get better, connect with others, and give back all at the same time. So, if you haven't tried either one of these yet, do yourself a favour and give 'em a shot. Trust me, you won't regret it. The more effort you put in, the more awesome rewards you'll get. Happy coding, friends!</p>
]]></content:encoded></item><item><title><![CDATA[Why Computer Science is Like a Box of Chocolates: You Never Know What You're Gonna Get]]></title><description><![CDATA[So, this blog is all about how computer science in our heads is like a fantasy, but in the real world, it's a whole different story. Buckle up, folks, it's gonna be a wild ride.
Yo, so when I was a kid, I was all about technology. I mean, I still am ...]]></description><link>https://blogs.dhruvsood.in/why-computer-science-is-like-a-box-of-chocolates-you-never-know-what-youre-gonna-get</link><guid isPermaLink="true">https://blogs.dhruvsood.in/why-computer-science-is-like-a-box-of-chocolates-you-never-know-what-youre-gonna-get</guid><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Computer Science]]></category><category><![CDATA[Game Development]]></category><category><![CDATA[newbie]]></category><dc:creator><![CDATA[Dhruv Sood]]></dc:creator><pubDate>Fri, 27 Jan 2023 18:59:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/g3B53PbBfwU/upload/0801555e9f26a73f374582ddb1ebbf77.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So, this blog is all about how computer science in our heads is like a fantasy, but in the real world, it's a whole different story. Buckle up, folks, it's gonna be a wild ride.</p>
<p>Yo, so when I was a kid, I was all about technology. I mean, I still am today. I used to wonder how all these games and stuff were made, like how do windows work and where does the sound come from on speakers? As I got older, I started looking for answers to all my childhood questions.</p>
<p>When I was young, I used to search for fun things like how to make a game and stuff, and then I'd come across videos talking about the tech stack used to develop it. But I'd get bored and move on to the next thing. But deep down, I always thought learning how to make games and websites would be super easy. I was naive, but we all are at some point, right?</p>
<p><img src="https://media.giphy.com/media/Y4WDXbagwPoepikUdJ/giphy.gif" alt class="image--center mx-auto" /></p>
<p>But as I grew up and delved deeper into the tech world, I realized that things were not as simple as I thought. I mean, just to make a basic game, you gotta learn a ton of different coding languages and it can take forever to make something as simple as a website or a game. Plus, the bugs you gotta deal with, the complex algorithms, math and physics, it's insane! But all this made me realize that the developers are the real MVPs. My respect for them grew a million times more than before.</p>
<p>Nowadays, we got games like Fortnite and all that, and there are so many tools like Wix, WordPress, and Hashnode that make it easy to create personal blogs. Not to mention, the new AI tools like ChatGPT that are all over the internet. But just think about all the work and resources that went into developing all that stuff. It's crazy, right?</p>
<p><img src="https://media.giphy.com/media/MaJ7An3EUgLCCh4lXS/giphy.gif?cid=ecf05e47sqmpkdtpleeop9cmn1kmfnhb0zhxonej8f2sikol&amp;rid=giphy.gif&amp;ct=g" alt class="image--center mx-auto" /></p>
<p>Alright, listen up all you tech-curious folks out there! If you're thinking about diving into the world of computer science and technology, let me tell you, it's not all fun and games (although, it is pretty fun and you can make some cool games). But let's get real, it's not as easy as it seems. When we were kids, we probably thought making a game or website was just a matter of clicking a few buttons and boom, done. But in reality, it's a whole different story.</p>
<p>First of all, there are a ton of different programming languages to learn. It's like learning a new language, except you're not trying to impress a cute Italian girl, you're trying to impress your computer. And trust me, your computer is a tough critic(It doesn't care how much time you spend to look good).</p>
<p>And let's not forget about the bugs. Oh boy, the bugs. It's like trying to find a needle in a haystack, except the needle is a tiny little typo and the haystack is a million lines of code. And when you finally find that little bugger, you'll feel like a detective solving a mystery.</p>
<p>But the worst part, in my opinion, is math and physics. I mean, I thought I was done with math and physics after high school but no, they just keep coming back. But, it's not all bad, I promise. It makes you feel smart and it's kind of satisfying when you finally understand how it all works.</p>
<p>And let's not forget that there's a lot of time, effort and resources that goes into creating something as simple as a game or website. It's like building a house, but instead of bricks, you're using code and instead of a hammer, you're using a keyboard.</p>
<p>But don't let all that discourage you, because even though it's a challenging field, it's also one of the most exciting and interesting fields out there. There's always something new to learn and explore and with the constant evolution of technology, the possibilities are endless. Plus, the sense of accomplishment when you finally solve a problem or create something that works, it's like finding a pot of gold at the end of the rainbow.</p>
<p>So if you're thinking about diving into the world of computer science and technology, just remember that it's not easy, but it's definitely worth it. Embrace the challenges, make jokes and have fun with it.</p>
<p><em><mark>It's not just a subject, it's an adventure.</mark></em></p>
]]></content:encoded></item><item><title><![CDATA[How to create an AI discord bot]]></title><description><![CDATA[Introduction
Building a Discord bot is an exciting and fun way for beginners to put their coding skills to the test! Imagine having your very own robot that can help you and your community out with all sorts of tasks. But what exactly is a Discord bo...]]></description><link>https://blogs.dhruvsood.in/how-to-create-an-ai-discord-bot</link><guid isPermaLink="true">https://blogs.dhruvsood.in/how-to-create-an-ai-discord-bot</guid><category><![CDATA[openai]]></category><category><![CDATA[chatgpt]]></category><category><![CDATA[Discord bot]]></category><category><![CDATA[discord]]></category><category><![CDATA[WeMakeDevs]]></category><dc:creator><![CDATA[Dhruv Sood]]></dc:creator><pubDate>Thu, 26 Jan 2023 06:20:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674489917595/230fb9b8-1c26-4cee-8002-c8ffefdb4bd1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-introduction">Introduction</h3>
<p>Building a Discord bot is an exciting and fun way for beginners to put their coding skills to the test! Imagine having your very own robot that can help you and your community out with all sorts of tasks. But what exactly is a Discord bot? To understand that, you first need to know what a Discord server is.</p>
<p>A Discord server is like a virtual hangout spot where people with similar interests can come together, chat and have a good time. And to make things, even more, fun and exciting, we use bots! These bots act as your party planner, helping you manage the chat, play games, and perform all sorts of cool tasks. With a Discord bot, you'll have your own personal assistant that makes managing your Discord server a blast! So, in short, building a Discord bot is an awesome way to take your coding skills to the next level and make your Discord server the life of the party!</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li><p>Should have advanced knowledge of python (Should be familiar with OOPS, and have a basic idea of APIs)</p>
</li>
<li><p>A Discord Server</p>
</li>
<li><p>In this tutorial, I am working with pycharm and Recommend you guys use that only</p>
</li>
</ul>
<h3 id="heading-getting-started">Getting started</h3>
<p>In order to make a Discord bot, we need to use the Discord API. Now, don't worry if you're not familiar with APIs just yet. I'll be providing you with all the code we'll be using, and I'll do my best to explain everything in a way that's easy to understand. And if you have any questions, feel free to ask!</p>
<p>First thing first, Let's install some libraries</p>
<ul>
<li><p>Open pycharm and create a project</p>
</li>
<li><p>In the terminal type</p>
</li>
</ul>
<pre><code class="lang-plaintext">pip install discord
</code></pre>
<pre><code class="lang-plaintext">pip3 install openai
</code></pre>
<p>Now let's open our browser and get the discord API token</p>
<ul>
<li><p>Open the discord developer portal</p>
</li>
<li><p>Click on applications</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674584141417/9fbf33ff-0a4a-48f6-97d9-7dea57fcac66.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on new appication and give your application a name</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674584322247/09fc19b0-5379-49b4-9350-3ae17b520d71.png" alt class="image--center mx-auto" /></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674584373853/28db48c8-4b2f-4461-972e-b2ee7706f085.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>In the general information give the name and app icon</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674584791294/23237ddc-3287-4e3a-981b-9ba29477fee4.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now on the left click on bot and then add the bot</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674619105747/5c1b53ac-9ed1-4bad-b8c1-c497cf129a7f.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now click on reset token to get your API's token and then copy it and save it somewhere. This will be the key to your bot so don't ever share it with anyone or else your bot can get hacked</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674619247800/940147a2-e543-4885-8fbb-cd607ca946b8.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now scroll down and you will see <strong>MESSAGE CONTENT INTENT</strong> turn it on and save the changes</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674619460508/964d7975-7c4b-4819-9355-96d6eded4eb8.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now click on <strong>OAuth2 &gt; URL Generator</strong> and in the <strong>SCOPES</strong> section select bot</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674619688569/d56deb56-4f96-4688-a8cc-3e290c5ef641.png" alt class="image--center mx-auto" /></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674619721072/320f8c9f-b59c-4930-86bf-719547f83c0b.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now give the bot all necessary permissions according to your needs</p>
<p>  <mark>Note that if you are just starting to make a bot avoid giving it administrator permission as it can mess with your channel or even delete it</mark></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674619915837/9c0c9290-eeb5-4c8b-b782-5ba2430a3324.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now below this, you will get a URL, Go paste it into your browser and invite the bot to your server.</p>
</li>
</ul>
<p>Okay cool, so here's the deal. To make our Discord bot super smart and AI-powered, we're gonna use OpenAI's API key. Now, I know what you're thinking, "That sounds expensive", but the good news is that OpenAI is hooking new developers up with $18 of free credit. So, we can totally make this bot for free and show it off to everyone. Just keep in mind, if you're using the bot for something specific, you might end up using all the $18 credit and then you'll have to pay for more.</p>
<p>To check the pricing go to this <a target="_blank" href="https://openai.com/api/pricing/">link</a></p>
<p><strong>Process to obtain OpenAI's API token</strong></p>
<ul>
<li><p>First things first, we gotta head on over to the <a target="_blank" href="https://beta.openai.com/overview">OpenAI porta</a>l and sign up.</p>
<p>  Once you're all registered and good to go, you can then move on to the next steps of getting that API token. Keep in mind that the process might change depending on what type of API you're trying to use, and you might need to verify your account and agree to some terms and conditions before getting the token. But don't worry, it's not too hard, I promise!</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674661852246/6c6b4615-9097-4244-a1be-a6a100dedfea.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now, Click on personal and then View API Keys</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674662004008/89e89399-31de-42e0-8ddf-5f3ca32df1d5.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now click on usage to check if you have received $18 in your account.</p>
<p>  If yes, then we are good to go!!</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674662232984/7630f9a8-f3f6-460f-8d98-10e1c5e67517.png" alt class="image--center mx-auto" /></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674662244498/07e84b6f-199c-4bef-b8b7-9b35058a16eb.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now, back to API keys, Click on create new API key</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674662390447/f0a02dd9-1575-4f62-af2b-0f4eda83cb1e.png" alt class="image--center mx-auto" /></p>
<p>  Once you've obtained your secret key from OpenAI, it's important to store it in a secure location. This is because the key is highly confidential and should be protected to ensure the security of your bot and your account.</p>
<p>  It's also recommended to not share it with anyone</p>
<p>  It's also recommended to get new API keys regularly deleting the previous one, to keep your account secure.</p>
<p>  <mark>(The same goes for the discord bot's API token)</mark></p>
</li>
</ul>
<p>Now it's time to code!!</p>
<h3 id="heading-code-time-folks">Code time folks!!</h3>
<p>Now in the python project that we Have create we need to add 3 files</p>
<p>One is the main(must be there already), other ones are "responses.py" and "bot.py"</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674663146494/906b2a4d-f59a-4cdb-a556-5afa321c5f73.png" alt class="image--center mx-auto" /></p>
<p>Alright, here's the deal. We're gonna write the code for our bot in a file called "<a target="_blank" href="http://bot.py">bot.py</a>" and we'll put all the responses in a separate file called "<a target="_blank" href="http://responses.py">responses.py</a>". This way, our code will be super organized and easy to understand. We'll connect the bot file with the responses file so the bot can grab the right response and send it to our discord server's text channel. Sound good, right?</p>
<p><strong>Writing code for "bot.py":</strong></p>
<ul>
<li><p>First, the import statements</p>
<pre><code class="lang-python">  <span class="hljs-keyword">import</span> discord
  <span class="hljs-keyword">import</span> responses
</code></pre>
</li>
<li><p>Let's create an async function that gets a response from responses file and sends it to the text channel</p>
<pre><code class="lang-python">  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">send_message</span>(<span class="hljs-params">message , user_message</span>):</span>
      <span class="hljs-keyword">try</span>:
          response = responses.get_response(user_message)

          <span class="hljs-keyword">await</span> message.channel.send(response)
      <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
          print(e)
</code></pre>
<p>  Note that we have not written anything in the "responses.py" file so you will be getting an error but don't worry we will write code in it soon</p>
<p>  Explanation of this function:</p>
<p>  This is a function called "send_message" that takes in two arguments: "message" and "user_message".</p>
<p>  The function is "async" which means it runs in the background and does not hold up the rest of the code from running. Cool isn't it?</p>
<p>  It starts by trying to execute the code inside the "try" block. The first thing it does is call a function called "get_response" from a module called "responses" and pass in the "user_message" argument. The function returns a response, which is then assigned to a variable called "response".</p>
<p>  Then the function sends the "response" to the channel the original message came from by using the "await <a target="_blank" href="http://message.channel">message.channel</a>.send(response)".</p>
<p>  If an exception occurs while trying to execute the code inside the "try" block, it will be caught in the "except" block. The exception is saved in a variable called "e" and "print(e)" will print the exception message, which can be helpful for debugging.</p>
</li>
</ul>
<p>Alright, so now we're gonna make a new function called 'run_discord_bot()'. This function will be in charge of starting up our bot and making it work properly.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">run_discord_bot</span>():</span>
    TOKEN = <span class="hljs-string">"Your DISCORD TOKEN HERE"</span>

    intents = discord.Intents.default()
    intents.message_content = <span class="hljs-literal">True</span>
    client = discord.Client(intents=intents)
<span class="hljs-meta">    @client.event</span>
    <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">on_ready</span>():</span>
        print(<span class="hljs-string">f"<span class="hljs-subst">{client.user}</span> is now running"</span>)
<span class="hljs-meta">    @client.event</span>
    <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">on_message</span>(<span class="hljs-params">message</span>):</span>
        <span class="hljs-keyword">if</span> message.author == client.user:
            <span class="hljs-keyword">return</span>
        username = str(message.author)
        channel = str(message.channel)
        usrmsg = str(message.content)
        print(<span class="hljs-string">f"User <span class="hljs-subst">{username}</span> said: '<span class="hljs-subst">{usrmsg}</span>' in channel '<span class="hljs-subst">{channel}</span>'"</span>)
        <span class="hljs-keyword">await</span> send_message(message , usrmsg)
    client.run(TOKEN)
</code></pre>
<p>Explanation of this function:</p>
<ul>
<li><p>The first thing it does is create a variable called "TOKEN", which is where you would put your personal Discord API token(In double quotes). This token is used to authenticate your bot with the Discord servers.</p>
</li>
<li><p>Next, it sets up a variable called "intents" which is used to specify which types of events the bot should listen for. In this case, it's set to listen for new messages.</p>
</li>
<li><p>Then, it creates a new instance of the Discord "Client" class, and sets the "intents" variable as an argument. This creates the main connection to the Discord servers.</p>
</li>
<li><p>The following two lines define two events, the first one is when the bot is ready and the second one is when the bot receives a message.</p>
</li>
<li><p>The first event is "on_ready" which is triggered when the bot successfully connects to the Discord servers. It prints a message to the console letting you know that the bot is running.</p>
</li>
<li><p>The second event is "on_message", which is triggered every time a new message is sent in any of the channels the bot is a member of. It checks if the message was sent by the bot itself, if it was it skips it. It then prints a message to the console with the username of the person who sent the message, the content of the message, and the channel it was sent in.</p>
</li>
<li><p>Finally, it runs the bot using the "<a target="_blank" href="http://client.run">client.run</a>(TOKEN)" method, which starts the main event loop and keeps the bot running until it's manually stopped.</p>
</li>
</ul>
<p><mark>So the complete code of "bot.py" :</mark></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> discord
<span class="hljs-keyword">import</span> responses

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">send_message</span>(<span class="hljs-params">message , user_message</span>):</span>
    <span class="hljs-keyword">try</span>:
        response = responses.get_response(user_message)

        <span class="hljs-keyword">await</span> message.channel.send(response)
    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
        print(e)



<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">run_discord_bot</span>():</span>
    TOKEN = <span class="hljs-string">"Your Discord API token here"</span>

    intents = discord.Intents.default()
    intents.message_content = <span class="hljs-literal">True</span>
    client = discord.Client(intents=intents)

<span class="hljs-meta">    @client.event</span>
    <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">on_ready</span>():</span>
        print(<span class="hljs-string">f"<span class="hljs-subst">{client.user}</span> is now running"</span>)

<span class="hljs-meta">    @client.event</span>
    <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">on_message</span>(<span class="hljs-params">message</span>):</span>
        <span class="hljs-keyword">if</span> message.author == client.user:
            <span class="hljs-keyword">return</span>

        username = str(message.author)
        channel = str(message.channel)
        userMessage = str(message.content)

        print(<span class="hljs-string">f"User <span class="hljs-subst">{username}</span> said: '<span class="hljs-subst">{userMessage}</span>' in channel '<span class="hljs-subst">{channel}</span>'"</span>)


        <span class="hljs-keyword">await</span> send_message(message , userMessage)

    client.run(TOKEN)
</code></pre>
<p>Now let's move on to the second file we made "responses.py"</p>
<ul>
<li><p>First thing first let us deal with the import statement</p>
<pre><code class="lang-python">  <span class="hljs-keyword">import</span> openai
</code></pre>
</li>
</ul>
<p>Now let's create a function get_response() which takes an argument as string and returns a string</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_response</span>(<span class="hljs-params">message : str</span>) -&gt; str:</span>
    openai.api_key = <span class="hljs-string">"Your OpenAI API key here"</span>
    response = openai.Completion.create(
        engine = <span class="hljs-string">"text-davinci-003"</span>,
        prompt = message,
        temperature=<span class="hljs-number">0.6</span>,
        max_tokens=<span class="hljs-number">150</span>
    )
    <span class="hljs-keyword">return</span> (response.choices[<span class="hljs-number">0</span>].text)
</code></pre>
<p>Explanation of this function:</p>
<ul>
<li><p>The function starts by setting the OpenAI API key, which is used to authenticate with the OpenAI servers. You need to provide your own API key here in order for the code to work.</p>
</li>
<li><p>Then it creates a variable called "response" which is used to hold the response generated by the OpenAI API.</p>
</li>
<li><p>It uses the OpenAI API method "openai.Completion.create" which is used to generate text completions, given a prompt. It uses the "text-davinci-003" engine which is a text generation engine and the prompt is the message that is passed to the function.</p>
</li>
<li><p>The temperature parameter controls the level of randomness in the generated text. A temperature of 0.6 is usually a good balance of randomness and relevance to the prompt.</p>
</li>
<li><p>The max_tokens parameter limits the maximum number of tokens (words) in the generated text.</p>
</li>
<li><p>Finally, the function returns the first option generated by the API, which is stored in the "response.choices[0].text" attribute.</p>
</li>
</ul>
<p>So, the complete code of "responses.py" file is:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> openai
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_response</span>(<span class="hljs-params">message : str</span>) -&gt; str:</span>
    openai.api_key = <span class="hljs-string">"Your OpenAI API key here"</span>
    response = openai.Completion.create(
        engine = <span class="hljs-string">"text-davinci-003"</span>,
        prompt = message,
        temperature=<span class="hljs-number">0.6</span>,
        max_tokens=<span class="hljs-number">150</span>
    )
    <span class="hljs-keyword">return</span> (response.choices[<span class="hljs-number">0</span>].text)
</code></pre>
<p>Now let's move on to "main.py" and write this simple code to run our bot:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> bot

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
    bot.run_discord_bot()
</code></pre>
<p>Now before showing you how the bot works, I want to share something, I am using macbook air m1 and I encountered an error which my friend too has faced</p>
<p>The error is something like:</p>
<p>"Cannot connect to host <a target="_blank" href="http://discord.com:443">discord.com:443</a> ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)')]"</p>
<p>In order to fix it open the folder where python is installed</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674713250104/f1c98a77-90eb-4c8c-9922-281e1353857e.png" alt class="image--center mx-auto" /></p>
<p>And then open "Install Certificates.command"</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674713323316/749dfbe2-6cd8-48ee-b681-1df2c763816e.png" alt class="image--center mx-auto" /></p>
<p>Now we are good to go!!</p>
<h3 id="heading-run-time-folks">Run time folks!!</h3>
<p>After running you will see that your bot is now online in your server, Let's talk with him!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674713517478/eed3b196-7c1f-4df1-b9c3-650af7506741.png" alt class="image--center mx-auto" /></p>
<p>See, this is how our bot works.</p>
<p>Congrats on making it to the end of the tutorial! Building an AI Discord bot might seem like a big task, but trust me, it's not that bad. Plus, it's a great way to add some cool new features to your Discord server. And hey, you get to learn about AI and natural language processing too. Thanks for taking the time to read the tutorial. I hope you found it helpful and informative. Now go forth and build that bot! Don't be afraid to experiment and have fun with it.</p>
]]></content:encoded></item><item><title><![CDATA[2022: A Year of Coding Challenges and Triumphs - My Developer Recap]]></title><description><![CDATA[Hey there, my name is Dhruv Sood and I'm a first-year engineering student just trying to navigate the world of college. As a recent high school grad, I've got a lot to reflect on from the past year, and what better way to do that than through a blog?...]]></description><link>https://blogs.dhruvsood.in/2022-a-year-of-coding-challenges-and-triumphs-my-developer-recap</link><guid isPermaLink="true">https://blogs.dhruvsood.in/2022-a-year-of-coding-challenges-and-triumphs-my-developer-recap</guid><category><![CDATA[WeMakeDevs]]></category><category><![CDATA[hashnodebootcamp]]></category><category><![CDATA[#2022wrapup]]></category><category><![CDATA[#DevRetro2022]]></category><dc:creator><![CDATA[Dhruv Sood]]></dc:creator><pubDate>Thu, 26 Jan 2023 05:05:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/Yg4j2yw1kJk/upload/7fb5d2b832dd847c7e2524a2fe90ebdf.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey there, my name is Dhruv Sood and I'm a first-year engineering student just trying to navigate the world of college. As a recent high school grad, I've got a lot to reflect on from the past year, and what better way to do that than through a blog? Now, I know you might be thinking "just another boring tech blog," but hold on tight, because I'm not just going to be talking about computer science - I'm throwing some science in there too.</p>
<p>So, a little background on me - I chose non-medical in 11th grade and ended up topping my school with a whopping 96% in 12th grade. Now, I know some of you might be thinking "Wow, that's impressive," but let's be real, I had a bit of a secret weapon - Python.</p>
<p>But, here's the thing, I'll admit, I didn't put in as much effort as I should have in 11th and 12th grade, I just watched a quick overview of the theories before my exams and had very less knowledge of python. But, I'm excited to say that I'm making up for lost time now and diving deep into the world of coding. So, if you want to join me on my coding journey, stay tuned to this blog, and I'll keep you updated on my progress and all the cool stuff I'm learning.</p>
<p>Okay, so let's talk about what I did after 12th. I know, I know, it's a thrilling topic. So, as soon as my high school days were behind me, I started thinking about what's next? I had my JEE mains (which we'll talk about another time), but let's just say it didn't go as well as I hoped. I didn't make it into an IIT or NIT, but I knew that was a long shot since I only prepared for my boards. But instead of taking a gap year, I decided to dive right into engineering.</p>
<p>After my mains, I started exploring different programming languages and I decided to give Java a shot. But, after a few basic lectures, I didn't get the vibe. So, I switched gears and decided to try my hand at C.</p>
<p>So, after I got comfortable with C, I decided to explore C++ and I was loving it. But, as with anything in life, there were some bumps in the road. One of those bumps was when we were introduced to recursion. As a developer, you know the struggle of understanding recursion, so I won't bore you with the details. But, I know, you all can feel me.</p>
<p>I overcame my boredom with recursion by practising more and more questions until I finally got the hang of it. Fast forward to November, and my university classes were starting. I was excited to dive in and, let me tell you, the first month was full of enjoyment (although, I did get a little too excited and ended up with a short attendance). But, here's the funny part, in our university, I was expecting them to start with C or C++, but nope, they reintroduced me to Python. I was like "Really? Python again? okay, Let's do this!"</p>
<p>Alright, so let me tell you about my experience with Python. As I had already learned C++ and had less knowledge of Python, I found that all I really needed was to brush up on the syntax. And let me tell you, switching to Python again from C++ was surprisingly easy.</p>
<p>So, that's pretty much my story for 2022. To summarize,</p>
<ul>
<li><p>I topped in my school,</p>
</li>
<li><p>learned C,</p>
</li>
<li><p>then C++ and</p>
</li>
<li><p>Python again.</p>
</li>
</ul>
<p>And now, I'm excited to keep learning new things and share my journey with all of you. I hope I didn't bore you too much and if you're an experienced developer, maybe I even got you feeling a bit nostalgic? I mean, who doesn't love a good throwback to the days of coding struggles and breakthroughs? Anyway, tell me in the comments, if you're feeling it too, and send me a virtual high five (or a wink, whichever you prefer) for all the progress I've made this year.</p>
]]></content:encoded></item><item><title><![CDATA[What is git for beginners]]></title><description><![CDATA[Hey there! So, if you're just starting on your programming journey, you might have heard of something called version control systems (VCS) and thought "what the heck are those?" Trust me, I totally get it. They might sound super complicated and out o...]]></description><link>https://blogs.dhruvsood.in/what-is-git-for-beginners</link><guid isPermaLink="true">https://blogs.dhruvsood.in/what-is-git-for-beginners</guid><category><![CDATA[Git]]></category><category><![CDATA[WeMakeDevs]]></category><category><![CDATA[version control]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Productivity]]></category><dc:creator><![CDATA[Dhruv Sood]]></dc:creator><pubDate>Tue, 24 Jan 2023 16:39:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674578204513/ecd466b0-cfd7-4c01-8392-8ef7ac785aad.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey there! So, if you're just starting on your programming journey, you might have heard of something called version control systems (VCS) and thought "what the heck are those?" Trust me, I totally get it. They might sound super complicated and out of this world, but the truth is, once you dive in, they're not so bad. In fact, I think a lot of people overhype how difficult they are.</p>
<h3 id="heading-so-what-exactly-are-vcss">So, what exactly are VCSs?</h3>
<p>Simply put, they're systems that store the history of all the different versions of a project. Think of it like a history book for your code. It keeps track of every change that's made, who made it, and when. This way, you can see how your project has evolved over time, and also collaborate with other people on the same project. And if you ever mess up and break something, no worries! VCSs also have this cool feature called <strong>rollback</strong>, which lets you go back to an earlier version and fix it.</p>
<h3 id="heading-understanding-with-an-example">Understanding with an example</h3>
<p>Let me give you an example to make it more clear. Let's say you're building a calculator app.</p>
<ul>
<li><p>On day one, you add the basic addition and subtraction functionality (Version 1).</p>
</li>
<li><p>On day two, you add multiplication (Version 2).</p>
</li>
<li><p>On day three, you accidentally break it (Version 3).</p>
</li>
</ul>
<p>With a VCS like Git, you can easily go back to the working version (Version 2) and fix the problem.</p>
<p><strong>Now imagine working on this project with friends.</strong></p>
<ul>
<li><p>On day four, your friends John and Jacob join in. Every time they make a change to the project, it's recorded in Git.</p>
</li>
<li><p>On day five, when John adds a factorial function</p>
</li>
<li><p>On day six, the code poops out again</p>
</li>
</ul>
<p>Now with Git you can figure out who broke the code and fix it.</p>
<p>In short, VCSs like Git are super important for any programmer. They make it easy to track changes, collaborate with others, and fix bugs. And the best part is, once you get the hang of it, it's actually pretty simple to use. So don't be intimidated, give it a try and see how it can make your life easier!</p>
<h3 id="heading-some-resources-you-can-follow">Some resources you can follow!!</h3>
<p>Here are some links through which you can understand Git and trust me they are wonderful</p>
<p>1.) <a target="_blank" href="https://www.youtube.com/watch?v=8JJ101D3knE&amp;t=626s"><strong>Git Tutorial for Beginners: Learn Git in 1 Hour</strong></a> <em>by Programming with Mosh(English)</em></p>
<p>2.) <a target="_blank" href="https://www.youtube.com/playlist?list=PLu0W_9lII9agwhy658ZPA0MTStKUJTWPi"><strong>Complete Git Tutorials For Beginners</strong></a> <em>by code with harry(Hindi)</em></p>
<h3 id="heading-all-the-best">All the best!!</h3>
<p>Get ready to Git-r-done! Buckle up and hold onto your code, because you're about to embark on an epic journey through the wild world of version control. Sure, you might run into a few roadblocks and bugs along the way, but don't worry - that's all part of the fun! Just remember to take it one commit at a time, and don't be afraid to ask for help when you need it. And most importantly, don't forget to have a little fun and enjoy the ride! Good luck, and happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[Navigating the Challenges of College-Level Computer Science]]></title><description><![CDATA[Prologue
Starting college as a computer science student is a whole new ball game. Sure, it's exciting to dive into new technology and have more freedom, but let's face it, college classes are way more intense than high school. It can be hard to keep ...]]></description><link>https://blogs.dhruvsood.in/navigating-the-challenges-of-college-level-computer-science</link><guid isPermaLink="true">https://blogs.dhruvsood.in/navigating-the-challenges-of-college-level-computer-science</guid><category><![CDATA[General Programming]]></category><category><![CDATA[College]]></category><category><![CDATA[engineering]]></category><category><![CDATA[motivation]]></category><category><![CDATA[WeMakeDevs]]></category><dc:creator><![CDATA[Dhruv Sood]]></dc:creator><pubDate>Sun, 22 Jan 2023 11:41:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674392907646/5e33b2b2-20f7-4371-9040-cd84cd46951c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-prologue">Prologue</h3>
<p>Starting college as a computer science student is a whole new ball game. Sure, it's exciting to dive into new technology and have more freedom, but let's face it, college classes are way more intense than high school. It can be hard to keep up with the workload and the expectations, but don't freak out! With the right attitude and tools, you can totally crush it.</p>
<h3 id="heading-adjusting-to-the-increased-workload">Adjusting to the Increased Workload</h3>
<p>Hey there computer science students in India, It can be tough when you're in college and you have to study all these other subjects that have nothing to do with computer science. But trust me, it's not all bad. These other subjects are there to give you a well-rounded education and open up more opportunities for you in the future. But I know, it can still be stressful. Here are some tips to help you get through it:</p>
<ul>
<li><p>Make a plan: Set clear goals and priorities for what you need to get done. This way you know what's most important and can focus on that first.</p>
</li>
<li><p>Balance your schedule: Make sure you're giving equal attention to all your subjects, not just computer science. This way you don't fall behind in the other subjects.</p>
</li>
<li><p>Get help: Don't be afraid to ask for help. Form a study group with your classmates, or if you're struggling, find a tutor or a really nice Youtube channel.</p>
</li>
<li><p>Keep the big picture in mind: Remember why you're in college in the first place. All this work will pay off in the long run.</p>
</li>
</ul>
<p>So don't stress too much, you got this! And remember, a well-rounded education is key to unlocking more opportunities for you in the future.</p>
<h3 id="heading-dealing-with-the-higher-difficulty-level-of-the-material">Dealing with the Higher Difficulty Level of the Material</h3>
<p>Alright computer science peeps, let's talk about those tough classes. Yeah, they can be a real challenge, but don't let that stop you from pushing forward. Exams are just a test of what you've learned and how hard you've worked. If you're struggling with a particular subject, don't be afraid to ask for notes from your classmates or your prof. And don't be shy to use ChatGPT for short summaries to help you study, but remember, always double-check with your professor for accuracy. But most importantly, don't stop coding! The more you practice and get your hands dirty, the more comfortable you'll become with the material. So, don't give up, stay motivated, and keep pushing through the challenges. You got this!</p>
<h3 id="heading-dont-fear-the-code">Don't Fear the Code</h3>
<p>One thing I want to tell you guys is don't be afraid of coding and logic building! I know it can be intimidating at first, but trust me, it's not as hard as it seems. Coding is just like solving a puzzle, and the logic building is like putting together a lego set. And the best part is, the more you practice, the better you'll get at it. Don't be afraid to experiment and make mistakes, that's how you learn and improve. And remember, there's no such thing as a stupid question, so don't hesitate to ask for help when you need it. And also, don't be afraid to learn new languages and tools as they help you to broaden your skillset, and make you more versatile in the field. So don't be afraid, just keep coding and building your logic, and you'll be a pro in no time!</p>
<h3 id="heading-epilogue">Epilogue</h3>
<p>In short, college computer science can be tough but it's all worth it! Keep pushing through the workload and difficulty by setting goals, balancing your schedule and seeking help. Don't be shy to ask questions, participate in class and experiment with coding and logic building. Embrace the challenge and the mistakes, you'll come out as a pro. Keep going, you got this!</p>
]]></content:encoded></item><item><title><![CDATA[Consistency is Key: My Personal Story of Learning C and C++ and the Power of Sticking With It]]></title><description><![CDATA[As a first-year computer science student, learning C and C++ programming can be a challenging but rewarding experience. In this blog post, I will be sharing my personal journey of learning C and C++ programming, including the resources I used, the ch...]]></description><link>https://blogs.dhruvsood.in/consistency-is-key-my-personal-story-of-learning-c-and-c-and-the-power-of-sticking-with-it</link><guid isPermaLink="true">https://blogs.dhruvsood.in/consistency-is-key-my-personal-story-of-learning-c-and-c-and-the-power-of-sticking-with-it</guid><category><![CDATA[C++]]></category><category><![CDATA[C]]></category><category><![CDATA[coding]]></category><category><![CDATA[newbie]]></category><category><![CDATA[First Blog]]></category><dc:creator><![CDATA[Dhruv Sood]]></dc:creator><pubDate>Sun, 22 Jan 2023 05:54:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674393187823/c6dacf43-dda4-482e-9cca-4fcf83ed5eca.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As a first-year computer science student, learning C and C++ programming can be a challenging but rewarding experience. In this blog post, I will be sharing my personal journey of learning C and C++ programming, including the resources I used, the challenges I faced, and the tips and advice I have for others who are just starting to learn these languages.</p>
<p>I began my journey of learning C and C++ programming by taking a course from Internshala trainings. The course was well-structured and beginner-friendly, providing a solid foundation in the basics of these languages. I found the course to be of high quality, and at the time I purchased it, it was only around 1k INR. One of the best part of the course was that it was available in English and now Hindi. I would rate the course 4.5 out of 5.</p>
<p>Before I started learning C and C++, I had some prior programming experience, having learned basic Python in my class 11th and 12th as it was included in CBSE’s syllabus. If you are a beginner, I highly recommend starting with Python. It is a beginner-friendly language with a relatively simple syntax, which makes it a great starting point for those who are new to programming. Python also has a wide range of libraries and frameworks that make it easy to build powerful applications and automate tasks, which is perfect for those who are looking to explore different areas of computer science.</p>
<p>However, learning C and C++ was still a bit of a challenge for me, particularly when it came to understanding recursion. Recursion is a programming technique where a function calls itself, and it can be quite tricky to grasp. I found that the key to understanding recursion was to practice as much as I could. I took up multiple coding questions and exercises related to recursion and attempted them regularly. This helped me to build my understanding of recursion step by step and by the time I was done I was confident in solving recursion problems.</p>
<p>There were times when I lost my interest in learning C and C++, but I knew that consistency was key. I made sure to solve at least one question or exercise related to C and C++ every day, even when I wasn't feeling motivated. This helped me to keep my skills sharp and maintain my interest in the language.</p>
<p>My tip for anyone learning C and C++ is to be consistent, even when you're feeling stuck. Consistency is the key to success in any endeavour, and learning C and C++ is no exception. It may seem difficult at first, but with practice and persistence, you'll be able to master these languages and become a proficient computer scientist.</p>
<p>One of the projects I completed while learning C and C++ programming was a simple hand cricket game. It was a fun and engaging project that helped me to solidify my understanding of the concepts I had learned.</p>
<p>In conclusion, I believe that C is an important language to learn, not just because it is a prerequisite for learning C++, but also because it has a rich history and is still widely used today. Learning C and C++ can be challenging, but with the right resources and a consistent approach, it is possible to master these languages and become a proficient computer scientist</p>
<p>Learning C and C++ can be challenging, but with the right resources, it's definitely achievable. YouTube is a great place to start, as there are many tutorials and lectures available for free. However, a structured course can provide a clear roadmap and help you avoid distractions, which is why I invested in a course and I found it worth my time and investment. While free resources are available, a course can help you make the most of your time and effort.If you're interested, you can check out the course I took by using my referral link <a target="_blank" href="https://trainings.internshala.com/refer/copy_link/ISRP20311867">https://trainings.internshala.com/refer/copy_link/ISRP20311867</a></p>
]]></content:encoded></item></channel></rss>