<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kibe🔌💻</title>
    <description>The latest articles on DEV Community by Kibe🔌💻 (@labank_).</description>
    <link>https://dev.to/labank_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F922580%2Ff698ede8-027c-4965-bdc7-420ced723b50.jpeg</url>
      <title>DEV Community: Kibe🔌💻</title>
      <link>https://dev.to/labank_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/labank_"/>
    <language>en</language>
    <item>
      <title>The Ultimate Guide to Backend and Frontend Testing: Breaking Down the Essentials for a Flawless Application</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Wed, 12 Feb 2025 07:06:19 +0000</pubDate>
      <link>https://dev.to/labank_/the-ultimate-guide-to-backend-and-frontend-testing-breaking-down-the-essentials-for-a-flawless-3i4g</link>
      <guid>https://dev.to/labank_/the-ultimate-guide-to-backend-and-frontend-testing-breaking-down-the-essentials-for-a-flawless-3i4g</guid>
      <description>&lt;p&gt;In today’s fast-paced digital world, the quality of your application can make or break your success. Whether you're a developer, QA engineer, or a tech enthusiast, understanding the intricacies of backend and frontend testing is crucial. This blog will dive deep into the world of testing, breaking down the essentials to help you build robust, secure, and user-friendly applications. Let’s break the internet with knowledge!&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Why Testing Matters&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Testing is the backbone of any successful application. It ensures that your software works as intended, delivers a seamless user experience, and remains secure against vulnerabilities. Without proper testing, even the most beautifully designed app can crumble under real-world usage. Let’s explore the key types of backend and frontend testing that every developer should master.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Backend Testing: The Hidden Hero of Your Application&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The backend is the engine that powers your application. It handles data processing, business logic, and integrations with other services. Here’s how to ensure it runs smoothly:&lt;/p&gt;

&lt;h4&gt;
  
  
  1.  &lt;strong&gt;Functionality Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Ensures that API endpoints, business logic, and workflows function as expected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  A single bug in the backend can disrupt the entire application. Functionality testing validates that every feature works correctly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Use tools like Postman or Swagger to automate API testing and ensure consistent results.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2.  &lt;strong&gt;Performance Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Measures response time, load handling, and scalability under various conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  Slow or unresponsive backends can frustrate users and lead to lost revenue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Tools like JMeter or LoadRunner can simulate heavy traffic and help you identify bottlenecks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3.  &lt;strong&gt;Unit Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Tests individual functions, methods, or classes in isolation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  Unit testing catches bugs early in the development cycle, saving time and resources.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Frameworks like JUnit (Java) or pytest (Python) make unit testing efficient and scalable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4.  &lt;strong&gt;Security Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Checks authentication, authorization, data protection, and vulnerability resistance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  A secure backend protects user data and prevents breaches.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Use tools like OWASP ZAP or Burp Suite to identify and fix security vulnerabilities.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5.  &lt;strong&gt;Integration Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Ensures different modules (e.g., database, third-party services) work together seamlessly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  Even if individual components work, they might fail when integrated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Mock external services to test integrations without relying on live systems.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  6.  &lt;strong&gt;Database Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Verifies data integrity, schema validation, indexing, and query performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  A faulty database can lead to data loss, corruption, or poor performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Use SQL queries and tools like SQLMap to test database functionality and security.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Frontend Testing: The Face of Your Application&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The frontend is what users interact with, and it’s critical to ensure it’s intuitive, responsive, and bug-free. Here’s how to test it effectively:&lt;/p&gt;

&lt;h4&gt;
  
  
  1.  &lt;strong&gt;User Interface (UI) Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Ensures elements like buttons, forms, and layouts function properly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  A broken UI can frustrate users and lead to high bounce rates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Use tools like Selenium or Cypress to automate UI testing across different browsers and devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2.  &lt;strong&gt;Usability Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Evaluates user experience, navigation ease, and design clarity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  A user-friendly interface keeps users engaged and satisfied.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Conduct usability tests with real users to gather actionable feedback.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3.  &lt;strong&gt;User Acceptance Testing (UAT)&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Tests the frontend from an end-user perspective to ensure it meets requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  UAT ensures the application aligns with user expectations and business goals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Create detailed test cases and involve stakeholders in the UAT process.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4.  &lt;strong&gt;Regression Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Ensures new UI changes don’t break existing features.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  Frequent updates can introduce unintended bugs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Automate regression testing using tools like TestComplete or Katalon Studio.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5.  &lt;strong&gt;Performance Testing&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt;  Tests rendering speed, responsiveness, and UI load performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;  A slow frontend can drive users away.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt;  Use Lighthouse or WebPageTest to analyze and optimize frontend performance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Best Practices for Effective Testing&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automate Where Possible:&lt;/strong&gt;  Automation saves time and ensures consistency, especially for repetitive tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test Early and Often:&lt;/strong&gt;  Integrate testing into your development process to catch issues early.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaborate Across Teams:&lt;/strong&gt;  Developers, QA engineers, and designers should work together to ensure comprehensive testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prioritize Security:&lt;/strong&gt;  Regularly test for vulnerabilities to protect user data and maintain trust.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gather User Feedback:&lt;/strong&gt;  Real-world usage can reveal issues that automated tests might miss.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion: Testing is Not Optional&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Backend and frontend testing are not just technical necessities—they are critical to delivering a high-quality application that users love. By mastering these testing techniques, you can build software that is reliable, secure, and user-friendly. So, whether you're a seasoned developer or just starting out, make testing a priority. Your users (and your reputation) will thank you.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Additional Resources&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="https://testsigma.com/guides/what-is-test-case/" rel="noopener noreferrer"&gt;What is a Test Case?&lt;/a&gt;&lt;/strong&gt;: A beginner-friendly guide to understanding test cases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="https://testsigma.com/guides/test-cases-for-manual-testing/" rel="noopener noreferrer"&gt;Test Cases for Manual Testing&lt;/a&gt;&lt;/strong&gt;: Learn how to write effective test cases for manual testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.testrail.com/blog/effective-test-cases-templates/" rel="noopener noreferrer"&gt;Effective Test Case Templates&lt;/a&gt;&lt;/strong&gt;: Explore templates and ex&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s break the internet—not with bugs, but with flawless, high-performing applications!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Exploratory Testing - Cars.ng User Journey Analysis</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Tue, 04 Feb 2025 08:23:24 +0000</pubDate>
      <link>https://dev.to/labank_/-exploratory-testing-carsng-user-journey-analysis-543h</link>
      <guid>https://dev.to/labank_/-exploratory-testing-carsng-user-journey-analysis-543h</guid>
      <description>&lt;p&gt;Cars.ng is a platform designed to simplify the car-buying experience. In this post, I’ll walk you through my exploratory testing journey, where I evaluated Cars.ng’s core user flows to identify bugs, usability issues, and potential improvements. By sharing these findings, I aim to provide actionable feedback to enhance the platform’s overall functionality and user experience.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;User experience is critical for any online platform, especially in the automotive marketplace. As part of this analysis, I focused on Cars.ng’s main functionalities, including navigation, filtering, and user actions like viewing car details, submitting forms, and interacting with dashboards. Testing involved both desktop and mobile views, ensuring insights are relevant for diverse user needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Methodology&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;My exploratory testing process was divided into three phases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Environment Setup&lt;/strong&gt;&lt;br&gt;
Tested on both &lt;strong&gt;desktop&lt;/strong&gt; (Windows 10, Chrome v120) and &lt;strong&gt;mobile&lt;/strong&gt; (Android 13, Chrome v120).&lt;/p&gt;

&lt;p&gt;Used the latest versions of browsers (Chrome and Firefox).&lt;/p&gt;

&lt;p&gt;Documented all findings using a structured bug report template.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Core User Flows Tested&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigating and filtering car listings.&lt;/p&gt;

&lt;p&gt;Interacting with the dashboard functionalities.&lt;/p&gt;

&lt;p&gt;Testing the footer links and other essential interactions like “Pricing” and “Submit” buttons.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reporting &amp;amp; Categorizing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Identified and documented issues using categories: &lt;strong&gt;High&lt;/strong&gt;, &lt;strong&gt;Medium&lt;/strong&gt;, and &lt;strong&gt;Low&lt;/strong&gt; severity.&lt;br&gt;
   Provided visual proof (screenshots) and actionable steps to reproduce the issues.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Findings&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;During the testing phase, I documented &lt;strong&gt;six key issues&lt;/strong&gt;, which highlight usability gaps and potential bottlenecks in user interactions. Below are a few notable findings:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Broken Links in the Footer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Links for "Most Researched Car" in the footer section either do not work or redirect to a 404 page.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Unresponsive Dashboard Actions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The "View Request" button does not respond when clicked, leaving users unable to view request details.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Non-Responsive Dashboard Design&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The dashboard layout breaks on smaller screens, making it nearly impossible to navigate on mobile devices.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Filtering and Pricing Failures&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Clicking on “Pricing” for similar models does not display any information.&lt;br&gt;
  Filtering by “Similar Models” redirects users to a 404 page.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;404 Error on Form Submission&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Submitting an email in the “Do you want to be notified” section redirects to a 404 page instead of confirming the subscription.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each issue was categorized by severity and detailed in my bug report, which you can access &lt;a href="https://docs.google.com/spreadsheets/d/1jSISMv1PFs7ytBTJe0pZEAf0Adxx1qEg/edit?usp=sharing&amp;amp;ouid=112887571493628957655&amp;amp;rtpof=true&amp;amp;sd=true" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Suggested Improvements&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Based on the findings, here are &lt;strong&gt;six actionable recommendations&lt;/strong&gt; to improve the platform:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Fix Broken Links in the Footer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ensure all footer links redirect to the correct pages. This enhances user trust and usability.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add Logout Functionality&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implement a logout option to improve security and allow users to manage their sessions effectively.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Introduce Pagination on the Dashboard&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Adding pagination to the dashboard improves performance and user navigation for accounts with many requests.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Optimize Dashboard Responsiveness&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Redesign the dashboard to ensure it adapts seamlessly to various screen sizes for a better mobile experience.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add a Chat Feature&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Introduce a chat option to allow users to contact sellers easily, improving engagement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Save User Filters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Save user-applied filters for the session to reduce frustration and repetitive actions.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Exploratory testing provided valuable insights into Cars.ng’s strengths and weaknesses. While the platform offers promising features, addressing the issues and implementing the suggested improvements will greatly enhance user satisfaction and engagement.&lt;/p&gt;

&lt;p&gt;To explore the platform and see the current state, visit &lt;a href="https://cars.ng" rel="noopener noreferrer"&gt;Cars.ng&lt;/a&gt;. For a detailed bug report and actionable feedback, view the complete report &lt;a href="https://docs.google.com/spreadsheets/d/1jSISMv1PFs7ytBTJe0pZEAf0Adxx1qEg/edit?usp=sharing&amp;amp;ouid=112887571493628957655&amp;amp;rtpof=true&amp;amp;sd=true" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Testing is an ongoing process, and iterative improvements are key to creating a seamless user experience.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating Users and Groups with a Bash Script: An Automated Approach</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Mon, 01 Jul 2024 16:35:31 +0000</pubDate>
      <link>https://dev.to/labank_/creating-users-and-groups-with-a-bash-script-an-automated-approach-2399</link>
      <guid>https://dev.to/labank_/creating-users-and-groups-with-a-bash-script-an-automated-approach-2399</guid>
      <description>&lt;p&gt;As a SysOps engineer, efficiently managing user accounts and groups is crucial for maintaining a secure and organized system environment. Automating the user creation process not only saves significant time but also reduces human errors. This article introduces a Bash script, &lt;code&gt;create_users.sh&lt;/code&gt;, designed to read a text file with user information, create users and groups, set up home directories, generate random passwords, log actions for auditing purposes, and securely store passwords.&lt;/p&gt;

&lt;p&gt;Script file is located in  &lt;a href="https://github.com/Laban254/user-management-automation-script/blob/main/create_users.sh" rel="noopener noreferrer"&gt;this link&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Overview of the Script Functionality
&lt;/h4&gt;

&lt;p&gt;The Bash script automates the following tasks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reading User Data&lt;/strong&gt;: Reads a text file (&lt;code&gt;users.txt&lt;/code&gt;) containing usernames and associated groups. Each line in the file is formatted as &lt;code&gt;username;groups&lt;/code&gt;, where groups are comma-separated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Creating Users and Groups&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-   Each user gets a personal group with the same name as the username.
-   Additional groups specified in the file are created if they do not exist.
-   Users are added to their personal group and any additional groups.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setting Up Home Directories&lt;/strong&gt;: Creates home directories for each user with appropriate permissions and ownership.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Generating Random Passwords&lt;/strong&gt;: Utilizes &lt;code&gt;openssl&lt;/code&gt; to generate random passwords for each user and securely sets them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Logging Actions&lt;/strong&gt;: Logs all script actions to &lt;code&gt;/var/log/user_management.log&lt;/code&gt; for audit and troubleshooting purposes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Storing Passwords Securely&lt;/strong&gt;: Stores generated passwords securely in &lt;code&gt;/var/secure/user_passwords.csv&lt;/code&gt; with strict file permissions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Error Handling&lt;/strong&gt;: Includes robust error handling for scenarios such as existing users or groups.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Key Features
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Verbose Mode&lt;/strong&gt;: Enables detailed output during execution with the &lt;code&gt;-v&lt;/code&gt; option.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Dry Run Option&lt;/strong&gt;: Simulates user creation without making changes using the &lt;code&gt;-d&lt;/code&gt; option.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Backup Existing Password File&lt;/strong&gt;: Safeguards the existing password file by creating a backup before modifications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Usage
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;sudo ./create_users.sh users.txt&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;For verbose output:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ./create_users.sh -v users.txt&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;For a dry run (simulation):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ./create_users.sh -d users.txt&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Ensure your &lt;code&gt;users.txt&lt;/code&gt; file is formatted correctly:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;light;sudo,dev,www-data&lt;br&gt;
idimma;sudo&lt;br&gt;
mayowa;dev,www-data&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Benefits of Automation&lt;br&gt;
&lt;/h4&gt;

&lt;p&gt;Automating user creation offers numerous benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Efficiency&lt;/strong&gt;: Saves time by automating repetitive tasks.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Consistency&lt;/strong&gt;: Ensures uniform user setup across systems.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Security&lt;/strong&gt;: Generates strong, random passwords and stores them securely.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Auditing&lt;/strong&gt;: Logs all actions for accountability and auditing purposes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;create_users.sh&lt;/code&gt; script provides a reliable solution for automating user management tasks, enhancing system security, and maintaining consistency. By securely storing passwords and logging all operations, it supports accountability and facilitates efficient system administration.&lt;/p&gt;

&lt;p&gt;For internship opportunities, explore the &lt;a href="https://hng.tech/internship" rel="noopener noreferrer"&gt;HNG Internship&lt;/a&gt; program and discover top tech talent through &lt;a href="https://hng.tech/hire" rel="noopener noreferrer"&gt;HNG Hire&lt;/a&gt;. These platforms offer valuable resources for skill development and career advancement in the tech industry.&lt;/p&gt;

&lt;p&gt;For the complete script and detailed implementation, visit the &lt;a href="https://github.com/Laban254/user-management-automation-script" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By leveraging automation tools like Bash scripting, you can streamline system administration tasks, bolster security, and improve overall operational efficiency in managing your infrastructure.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Tackling Inadequate Monitoring: My Journey as a Backend Developer</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Sat, 29 Jun 2024 18:24:40 +0000</pubDate>
      <link>https://dev.to/labank_/tackling-inadequate-monitoring-my-journey-as-a-backend-developer-3g2k</link>
      <guid>https://dev.to/labank_/tackling-inadequate-monitoring-my-journey-as-a-backend-developer-3g2k</guid>
      <description>&lt;h2&gt;
  
  
  Tackling Inadequate Monitoring: My Journey as a Backend Developer
&lt;/h2&gt;

&lt;p&gt;As I embark on my journey with the &lt;a href="https://hng.tech/internship" rel="noopener noreferrer"&gt;HNG Internship&lt;/a&gt;, I reflect on a recent challenge I faced in backend development. This experience not only tested my technical skills but also reinforced the importance of effective monitoring in creating robust applications. Here’s a detailed account of how I resolved the issue of inadequate monitoring using Nginx, Gunicorn, and Django.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Challenge: Inadequate Monitoring
&lt;/h3&gt;

&lt;p&gt;In one of my recent projects, I encountered a significant issue with inadequate monitoring. This problem manifested in various ways: missed alerts for critical issues, lack of insight into application performance, and difficulty in diagnosing problems. I knew that resolving this issue would be critical in improving the overall stability and reliability of the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps i followed to tackle the Challenge
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Step 1: Identifying the Problem
&lt;/h4&gt;

&lt;p&gt;The first step in solving any problem is recognizing it. During the testing phase, I noticed that critical issues were going undetected because there was no monitoring in place. This meant that any downtime or performance issues were only discovered after users reported them, which was far from ideal.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Analyzing the Existing Setup
&lt;/h4&gt;

&lt;p&gt;I started by reviewing the existing infrastructure. The application was running on a Django framework, served by Gunicorn as the WSGI HTTP server, and Nginx as the reverse proxy. Despite this robust stack, there was no centralized logging, performance metrics, or alerting system in place.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: Implementing Centralized Logging
&lt;/h4&gt;

&lt;p&gt;To address this, I decided to implement centralized logging using Nginx and Gunicorn's logging capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nginx Logging Configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the Nginx configuration file, I enabled access and error logs to capture detailed information about incoming requests and server errors.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http {
    ...
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;
    error_log /var/log/nginx/error.log warn;
    ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Gunicorn Logging Configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For Gunicorn, I configured the logging settings to ensure all application-level logs were captured.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gunicorn --log-level debug --access-logfile /var/log/gunicorn/access.log --error-logfile /var/log/gunicorn/error.log myproject.wsgi:application&lt;/code&gt; &lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4: Setting Up Monitoring Tools
&lt;/h4&gt;

&lt;p&gt;With centralized logging in place, the next step was to set up monitoring tools to visualize performance metrics and send alerts for critical issues. I chose Prometheus for monitoring and Grafana for visualization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prometheus Configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I configured Prometheus to scrape metrics from both Nginx and Gunicorn. This involved exposing metrics endpoints and setting up Prometheus to collect data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nginx Metrics Exporter:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I used the Nginx Exporter to expose metrics to Prometheus.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nginx-prometheus-exporter -nginx.scrape-uri=http://localhost:8080/stub_status&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gunicorn Metrics Exporter:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For Gunicorn, I used the &lt;code&gt;gunicorn-prometheus-metrics&lt;/code&gt; library to expose metrics.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install gunicorn-prometheus-metrics
gunicorn --config gunicorn_conf.py --prometheus-dir /metrics myproject.wsgi:application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Prometheus Scrape Configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the Prometheus configuration file, I added scrape jobs for Nginx and Gunicorn metrics.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scrape_configs:

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;job_name: 'nginx'&lt;br&gt;
static_configs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;targets: ['localhost:9113']&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;job_name: 'gunicorn'&lt;br&gt;
static_configs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;targets: ['localhost:8000']
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;


Step 5: Visualizing Metrics with Grafana
&lt;/h4&gt;



&lt;p&gt;I set up Grafana to visualize the collected metrics. By creating dashboards for Nginx and Gunicorn, I could monitor the application's health, response times, error rates, and more in real-time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 6: Setting Up Alerts
&lt;/h4&gt;

&lt;p&gt;To ensure critical issues were promptly addressed, I configured alerts in Prometheus. Alerts were set up for high error rates, slow response times, and server downtime. These alerts were sent to Slack for immediate notification.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alerting:&lt;br&gt;
  alertmanagers:&lt;br&gt;
    - static_configs:&lt;br&gt;
        - targets: ['localhost:9093']

&lt;p&gt;alert_rules:&lt;br&gt;
  groups:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;name: alert.rules
rules:

&lt;ul&gt;
&lt;li&gt;alert: HighErrorRate
expr: rate(http_requests_total{status=~"5.."}[5m]) &amp;gt; 0.05
for: 1m
labels:
severity: critical
annotations:
summary: "High error rate detected"
description: "More than 5% of requests are failing with server errors." 
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;


The Outcome
&lt;/h3&gt;



&lt;p&gt;By implementing centralized logging and setting up robust monitoring and alerting, I significantly improved the stability and reliability of the application. I could now detect and resolve issues promptly, ensuring a smoother user experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Looking Forward: The HNG Internship
&lt;/h3&gt;

&lt;p&gt;As I prepare to start the &lt;a href="https://hng.tech/internship" rel="noopener noreferrer"&gt;HNG Internship&lt;/a&gt;, I am excited about the opportunities to further develop my skills and tackle more challenging problems. This internship represents a significant step in my journey as a backend developer. It offers a platform to work on real-world projects, collaborate with experienced professionals, and learn from their expertise.&lt;/p&gt;

&lt;p&gt;I am particularly motivated to join the HNG Internship because of its focus on hands-on learning and mentorship. I believe that this experience will not only enhance my technical skills but also help me grow as a professional. I am eager to contribute to impactful projects, learn from industry experts, and take my backend development skills to the next level.&lt;/p&gt;

&lt;h3&gt;
  
  
  conclusion
&lt;/h3&gt;

&lt;p&gt;Solving the issue of inadequate monitoring was a valuable learning experience. It reinforced the importance of robust monitoring in building reliable applications. As I embark on this new journey with the HNG Internship, I am excited about the challenges ahead and look forward to the growth and learning opportunities that lie ahead.&lt;/p&gt;

&lt;p&gt;Connect with me  &lt;a href="https://www.linkedin.com/in/laban-rotich/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for more insights on backend development and technology trends.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building RESTful APIs with Express.js</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Wed, 12 Jun 2024 20:29:18 +0000</pubDate>
      <link>https://dev.to/labank_/building-restful-apis-with-expressjs-he1</link>
      <guid>https://dev.to/labank_/building-restful-apis-with-expressjs-he1</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9ip46yymmiluj8aqskw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9ip46yymmiluj8aqskw.jpg" alt="Express.js" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Welcome to a journey into the world of web architecture! Whether you're a seasoned developer or just dipping your toes into the vast sea of software development, understanding the core concepts and tools that power the web is essential. In this article, we'll embark on an exploration of two fundamental components that underpin modern web services: REST and Express.js.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What is REST?
&lt;/h2&gt;

&lt;p&gt;In the realm of web interactions, there exists a crucial architectural style known as REST, which stands for Representational State Transfer. REST is like the conductor of a symphony, bringing harmony and structure to the chaos of web communication between computer systems.&lt;/p&gt;

&lt;p&gt;This article is your ticket to exploring the world of RESTful systems, where concepts like statelessness and the segregation of client and server responsibilities reign supreme. But before we dive in, let's demystify REST and understand why it plays such a vital role in the web's infrastructure.&lt;/p&gt;

&lt;p&gt;RESTful systems adhere to six fundamental constraints, as initially articulated by Roy Fielding in his doctoral dissertation. These constraints serve as the building blocks of the RESTful style:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Uniform Interface:&lt;/strong&gt; Creating a common language for both clients and servers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stateless:&lt;/strong&gt; No storage of session information on the server between requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cacheable:&lt;/strong&gt; Explicitly stating whether responses can be cached.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client-Server:&lt;/strong&gt; Keeping client and server concerns separate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Layered System:&lt;/strong&gt; Composing systems with multiple layers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code on Demand:&lt;/strong&gt; Providing the option to extend a client's functionality by transferring logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;REST's appeal lies in its use of HTTP requests for CRUD operations (Create, Read, Update, Delete), making it a straightforward and standardized approach to interact with web services.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is Express.js?
&lt;/h2&gt;

&lt;p&gt;Express is a fast, assertive, essential and moderate web framework of Node.js. You can assume express as a layer built on the top of the Node.js that helps manage a server and routes. It provides a robust set of features to develop web and mobile applications.&lt;/p&gt;

&lt;p&gt;Let’s see some of the core features of Express framework:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can be used to design single-page, multi-page and hybrid web applications.&lt;/li&gt;
&lt;li&gt;It allows to setup middleware to respond to HTTP Requests.&lt;/li&gt;
&lt;li&gt;It defines a routing table which is used to perform different actions based on HTTP method and URL.&lt;/li&gt;
&lt;li&gt;It allows to dynamically render HTML Pages based on passing arguments to templates.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Express.js Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6t16e7bill66720yczxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6t16e7bill66720yczxc.png" alt="Image description" width="800" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3 Why Choose Express.js?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Speedy I/O Operations: It handles data quickly.&lt;/li&gt;
&lt;li&gt;Works Smoothly with Asynchronous Tasks: It handles multiple tasks without getting stuck.&lt;/li&gt;
&lt;li&gt;Organized Like MVC: Makes your code neat and organized.&lt;/li&gt;
&lt;li&gt;Easy Routing with a Strong API: Helps you guide your web traffic effortlessly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4 Tools and Tech You Need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Node.js&lt;/li&gt;
&lt;li&gt;MongoDB&lt;/li&gt;
&lt;li&gt;A Text Editor (like Notepad++, Sublime, Atom, or VSCode)&lt;/li&gt;
&lt;li&gt;Postman (for testing your work)
## What You Need Before We Start
Before we dive in, make sure you have these two essentials installed:
&lt;a href="https://nodejs.org/en/download/package-manager" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt;
&lt;a href="https://www.mongodb.com/docs/manual/installation/" rel="noopener noreferrer"&gt;MongoDB&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Form Handling in Flask: Unleashing the Power of Flask-WTF</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Thu, 30 Nov 2023 07:59:58 +0000</pubDate>
      <link>https://dev.to/labank_/form-handling-in-flask-unleashing-the-power-of-flask-wtf-3024</link>
      <guid>https://dev.to/labank_/form-handling-in-flask-unleashing-the-power-of-flask-wtf-3024</guid>
      <description>&lt;p&gt;Handling forms is a crucial aspect of web development, and Flask, a lightweight and powerful web framework for Python, offers an excellent extension called Flask-WTF that simplifies form handling. Flask-WTF seamlessly integrates with WTForms, a flexible form handling library, providing features like form validation, CSRF protection, and form rendering. In this guide, I will  walk you through the process of handling forms in Flask using Flask-WTF, empowering you to effortlessly create and process forms in your Flask applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Flask-WTF?&lt;/strong&gt;&lt;br&gt;
Flask-WTF is a built-in module of Flask that provides an alternative way of designing forms in Flask. It seamlessly integrates with WTForms, a flexible form handling library for Python.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features of Flask-WTF:&lt;/strong&gt;&lt;br&gt;
Flask-WTF offers several features that simplify form handling in Flask, including:&lt;/p&gt;

&lt;p&gt;Global CSRF protection: Flask-WTF provides built-in protection against cross-site request forgery (CSRF) attacks, ensuring the security of your forms.&lt;/p&gt;

&lt;p&gt;Integration with web forms: Flask-WTF allows you to define form classes using WTForms, making it easy to create and manage form fields, validation rules, and rendering.&lt;/p&gt;

&lt;p&gt;reCAPTCHA support: Flask-WTF supports the integration of reCAPTCHA, a popular anti-bot service, into your forms, enhancing security and preventing spam.&lt;/p&gt;

&lt;p&gt;File upload support: Flask-WTF works seamlessly with Flask Uploads, enabling easy handling of file uploads in your forms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Simple Contact Form using Flask-WTF&lt;/strong&gt;&lt;br&gt;
To illustrate how to use Flask-WTF, let's create a simple contact form. Here are the steps involved:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Environment set up&lt;br&gt;
Install virtual environment (virtualenv)&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Virtualenv is a highly useful tool that allows Python developers to create isolated environments for their projects. By isolating the environment, it ensures that the project dependencies are separate from the global Python installation, preventing conflicts between different projects.&lt;br&gt;
To install Virtualenv, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install virtualenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing Virtualenv, you can proceed to create a new virtual environment within a specific folder. For example, let's create a folder called "flaskforms" and navigate into it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir flaskforms
$ cd flaskforms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create the virtual environment by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ virtualenv venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that the above command creates a virtual environment named "venv" in the current directory.&lt;/p&gt;

&lt;p&gt;In case you are using Windows, you can activate the virtual environment with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ venv\Scripts\activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On other operating systems like macOS or Linux, the activation command will be slightly different:&lt;br&gt;
&lt;code&gt;shell&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ source venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the virtual environment is activated, you can proceed to install Flask, a popular web framework for Python, by using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install flask
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To leverage the power of WTForms, a library for form handling in Flask, you need to install the flask-wtf library. You can install it by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install flask-wtf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With these steps completed, you are now equipped with a virtual environment containing Flask and Flask-WTF installed, allowing you to handle forms seamlessly in your Flask application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Step 1: Import necessary modules&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from wtforms import StringField, TextAreaField, SubmitField
from wtforms.validators import DataRequired, Email

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you import the required modules for your Flask application. The &lt;code&gt;Flask&lt;/code&gt; module handles the web application, &lt;code&gt;render_template&lt;/code&gt; is used to render HTML templates, and &lt;code&gt;request&lt;/code&gt; is used to handle HTTP requests. The &lt;code&gt;FlaskForm&lt;/code&gt; class from flask_wtf is imported to create the form, while the field types &lt;code&gt;(StringField, TextAreaField, SubmitField)&lt;/code&gt; and validators &lt;code&gt;(DataRequired, Email)&lt;/code&gt; from &lt;code&gt;wtforms&lt;/code&gt; are imported to define form fields and validation rules.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Step 2: Create Flask application and set secret key&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app = Flask(__name__)
app.secret_key = 'secret_key'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You create a Flask application instance and set the secret key. The secret key is used to protect against security vulnerabilities like Cross-Site Request Forgery (CSRF).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 3: Define the ContactForm class&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class UserContactForm(FlaskForm):
    Firstname = StringField('firstname', validators=[DataRequired()])
    Lastname = StringField('lastname', validators=[DataRequired()])
    email = StringField('Password', validators=[DataRequired(), Email()])
    text_message = TextAreaField('message', validators=[DataRequired()])
    send = SubmitField('Send')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you define the &lt;code&gt;ContactForm&lt;/code&gt;class that inherits from &lt;code&gt;FlaskForm&lt;/code&gt;. Each field (Firstname, Lastname, email, text_message) is assigned a field type and associated validators. The field types &lt;code&gt;(StringField, TextAreaField, SubmitField)&lt;/code&gt; define the input type, while validators &lt;code&gt;(DataRequired, Email)&lt;/code&gt; specify the validation rules for each field.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 4: Define the contact route&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/user-contact', methods=['GET', 'POST'])
def user_contact():
    form = UserContactForm()

    if form.validate_on_submit():
        return 'Form  has been succesfully submitted'

    return render_template('user_contact.html', form=form)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines the &lt;code&gt;/user-contact&lt;/code&gt; route for your Flask application, which can handle both GET and POST requests. Inside the &lt;code&gt;user_contact&lt;/code&gt; function, an instance of the &lt;code&gt;UserContactForm&lt;/code&gt; class is created. If the form is submitted and passes the validation &lt;code&gt;(form.validate_on_submit())&lt;/code&gt;, the string &lt;code&gt;'Form submitted'&lt;/code&gt;is returned. Otherwise, the &lt;code&gt;user_contact.html&lt;/code&gt; template is rendered with the &lt;code&gt;form&lt;/code&gt; object passed to it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 4: Create the HTML template&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Certainly! Here's an example of how you can render the UserContactForm in an HTML template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;lt;!-- contact.html --&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;User Contact Form&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="static/css/style.css"&amp;gt;
    &amp;lt;style&amp;gt;
        body {
            background-color: #f2f2f2;
            font-family: Arial, sans-serif;
        }

        .container {
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        .form-control {
            margin-bottom: 20px;
        }

        .form-control label {
            font-weight: bold;
            display: block;
        }

        .form-control input, .form-control textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        .form-control input[type="submit"] {
            background-color: #4CAF50;
            color: #fff;
            border: none;
            cursor: pointer;
        }

        .form-control input[type="submit"]:hover {
            background-color: #45a049;
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;h1&amp;gt;Contact Us&amp;lt;/h1&amp;gt;
        &amp;lt;form method="POST" action="{{ url_for('user_contact') }}" class="form-control"&amp;gt;

            {{ form.csrf_token }}

            &amp;lt;label&amp;gt;{{ form.Firstname.label }}&amp;lt;/label&amp;gt;
            {{ form.Firstname }}
            &amp;lt;br&amp;gt;
            &amp;lt;label&amp;gt;{{ form.Lastname.label }}&amp;lt;/label&amp;gt;
            {{ form.Lastname }}
            &amp;lt;br&amp;gt;
            &amp;lt;label&amp;gt;{{ form.email.label }}&amp;lt;/label&amp;gt;
            {{ form.email }}
            &amp;lt;br&amp;gt;
            &amp;lt;label&amp;gt;{{ form.text_message.label }}&amp;lt;/label&amp;gt;
            {{ form.text_message }}
            &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
            {{ form.send }}

        &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above HTML template, we define a form that uses the POST method to submit the data to the &lt;code&gt;/user-contact route&lt;/code&gt;. We include the CSRF token &lt;code&gt;{{ form.csrf_token }}&lt;/code&gt; for security purposes.&lt;/p&gt;

&lt;p&gt;Each field of the form is rendered using the &lt;code&gt;{{ form.field_name }}&lt;/code&gt; syntax, where &lt;code&gt;field_name&lt;/code&gt; corresponds to the fields defined in the &lt;code&gt;UserContactForm&lt;/code&gt; class &lt;code&gt;(Firstname, Lastname, email, text_message, send)&lt;/code&gt;. The labels for each field are accessed using &lt;code&gt;{{ form.field_name.label }}&lt;/code&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Exceptions and Errors in Python</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Mon, 19 Dec 2022 09:15:55 +0000</pubDate>
      <link>https://dev.to/labank_/exceptions-and-errors-in-python-47ln</link>
      <guid>https://dev.to/labank_/exceptions-and-errors-in-python-47ln</guid>
      <description>&lt;p&gt;In Python, an error indicates a problem that occurs while the program is executing, while an exception is a signal that indicates an exceptional condition that has occurred.&lt;/p&gt;

&lt;p&gt;Errors are typically caused by problems with the code itself, such as syntax errors, name errors, or type errors. These are usually detected by the interpreter before the program starts running, and the interpreter will display an error message indicating what went wrong.&lt;/p&gt;

&lt;p&gt;Here's an example of a syntax error in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def foo():
    print('Hello')
    return

foo()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to run this code, you'll see an error message like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;File "example.py", line 6
    foo()
    ^
IndentationError: expected an indented block
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exceptions, on the other hand, are events that occur during the execution of the program and can be handled by the code. Exceptions are used to signal a variety of conditions, such as division by zero, file not found, or invalid input. When an exception occurs, the interpreter raises (or "throws") an exception object.&lt;/p&gt;

&lt;p&gt;Here's an example of how you can catch and handle an exception in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try:
    x = int(input('Enter a number: '))
    print(1 / x)
except ZeroDivisionError:
    print('You cannot divide by zero!')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the user enters a number other than zero, the code will execute without any problems. If the user enters zero, however, the interpreter will raise a ZeroDivisionError exception, which will be caught by the except clause and the appropriate message will be printed.&lt;/p&gt;

&lt;p&gt;In summary, errors are problems that occur when the code is incorrect and cannot be executed, while exceptions are events that occur during execution and can be handled by the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  When do we need to use exceptions?
&lt;/h2&gt;

&lt;p&gt;Exceptions are used in Python to signal a variety of exceptional conditions that can occur during the execution of a program. Some common examples of when exceptions might be used include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handling runtime errors: Exceptions can be used to handle runtime errors, such as division by zero or out-of-bounds array access, which would otherwise cause the program to crash.&lt;/li&gt;
&lt;li&gt;Validating user input: Exceptions can be used to validate user input and ensure that it meets certain criteria. For example, you might use an exception to ensure that a user has entered a valid email address or phone number.&lt;/li&gt;
&lt;li&gt;Dealing with external resources: Exceptions can be used to handle errors that occur when interacting with external resources, such as reading from or writing to a file, or connecting to a network server.&lt;/li&gt;
&lt;li&gt;Handling unexpected conditions: Exceptions can be used to handle unexpected conditions that may arise during the execution of a program. For example, you might use an exception to handle the case where a user attempts to access a resource that does not exist.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, exceptions are a useful tool for handling errors and exceptional conditions in a clean and robust way. They allow you to write code that is more resilient to failure and can gracefully&lt;br&gt;
handle a variety of error scenarios.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to correctly handle an exception
&lt;/h2&gt;

&lt;p&gt;To handle an exception in a program, you can use a try-except block. The try block contains the code that may throw an exception, and the except block contains the code that will handle the exception if it occurs. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try:
   # code that may throw an exception
except ExceptionType:
   # code to handle the exception

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can specify a particular type of exception to handle by replacing ExceptionType with the name of the exception class. For example, to handle a ZeroDivisionError, you can use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try:
   # code that may throw a ZeroDivisionError
except ZeroDivisionError:
   # code to handle the ZeroDivisionError

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also handle multiple exception types by using multiple except blocks. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try:
   # code that may throw an exception
except ZeroDivisionError:
   # code to handle a ZeroDivisionError
except ValueError:
   # code to handle a ValueError

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to handle all exception types, you can use the Exception class as the exception type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try:
   # code that may throw an exception
except Exception:
   # code to handle any exception

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's generally a good idea to be specific about which exception types you want to handle, rather than catching all exceptions, because this can help you identify and fix errors in your code.&lt;/p&gt;

&lt;p&gt;Finally, you can use the finally block to include code that should always be executed, whether or not an exception occurs. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try:
   # code that may throw an exception
except ExceptionType:
   # code to handle the exception
finally:

   # code that should always be executed

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What’s the purpose of catching exceptions
&lt;/h2&gt;

&lt;p&gt;The purpose of catching exceptions is to handle errors that may occur during the execution of a program. When an error, or exception, occurs in a program, it can cause the program to crash or produce incorrect results. By catching exceptions, you can prevent these issues and gracefully handle the errors in your program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There are several benefits to catching exceptions:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Improved stability: Catching exceptions can help prevent your program from crashing or producing incorrect results when an error occurs. This can improve the stability of your program and make it more reliable.&lt;/li&gt;
&lt;li&gt;Improved user experience: If your program crashes or produces incorrect results, it can be frustrating for the user. By catching exceptions, you can provide a better user experience by handling errors in a way that is more user-friendly.&lt;/li&gt;
&lt;li&gt;Debugging: Catching exceptions can also help you identify and fix errors in your program. When you catch an exception, you can print out a message or log the error to help you understand what went wrong and how to fix it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In summary, the purpose of catching exceptions is to handle errors that may occur during the execution of a program, improve the stability and reliability of the program, and provide a better user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  When do we need to implement a clean-up action after an exception
&lt;/h2&gt;

&lt;p&gt;You may need to implement a clean-up action after an exception if your program has performed some action that needs to be undone or resources that need to be released.&lt;/p&gt;

&lt;p&gt;For example, consider a program that opens a file, reads from it, and then closes the file. If an exception occurs while reading from the file, the file may not be closed properly. In this case, you would want to include a clean-up action in the except block to ensure that the file is closed properly.&lt;/p&gt;

&lt;p&gt;You can use the finally block to include code that should always be executed, whether or not an exception occurs. The finally block is useful for performing clean-up actions, such as releasing resources or closing open files.&lt;/p&gt;

&lt;p&gt;Here's an example of how you can use the finally block to perform a clean-up action after an exception:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try:
   # code that may throw an exception
except ExceptionType:
   # code to handle the exception
finally:
   # clean-up action

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the clean-up action will be executed whether or not an exception occurs. This ensures that the clean-up action is always performed, even if an exception occurs.&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>Creating and Using Dynamic Libraries ( C )</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Tue, 13 Dec 2022 12:54:38 +0000</pubDate>
      <link>https://dev.to/labank_/creating-and-using-dynamic-libraries-c--1g2h</link>
      <guid>https://dev.to/labank_/creating-and-using-dynamic-libraries-c--1g2h</guid>
      <description>&lt;p&gt;I provided a thorough description of how to make and use static libraries in the post linked to below. Please take a look at it if you need a refresher. I'll concentrate on detailing how to develop and use dynamic libraries in the C programming language in this article.&lt;/p&gt;

&lt;p&gt;I'll need to establish a few words before I can explain why using dynamic libraries is important. A function is first and foremost a piece of a program that is named and performs a certain task. By using the previously mentioned function to complete a task instead of having to rewrite that particular block of code later on in the program, functions may be used throughout the program to save time.&lt;/p&gt;

&lt;p&gt;Despite the fact that static libraries can be used by numerous programs, once a program has been compiled, it becomes impossible to change the various pieces of object code in an executable file because all the code is contained in a single file that was statically linked during the program's compilation.&lt;/p&gt;

&lt;p&gt;The topic of dynamic or shared libraries is now finally brought up. Dynamic libraries, in contrast to static libraries, are made up of independent files that each contain a unique piece of object code. A single object code file is created by dynamically linking these files together. Dynamic libraries also provide additional data that the operating system will need in order to link the library to other programs.&lt;/p&gt;

&lt;p&gt;Because each application or program can access the dynamic library without needing a separate copy, as would be the case if we were using static libraries, the inference is that memory is conserved while utilizing dynamic libraries. Static libraries execute more quickly at run-time since the object code for the library's functions is already present in the executable file, even if dynamic libraries allow for source code changes without requiring a complete program recompilation. Multiple function calls are therefore dealt with more effectively than when using dynamic libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Create a Dynamic Library (Linux)
&lt;/h2&gt;

&lt;p&gt;Simply type the following command on Linux to build a dynamic library: Press return after typing &lt;code&gt;gcc *.c -c -fPIC&lt;/code&gt;. Essentially, this operation generates one object file  &lt;code&gt;.o&lt;/code&gt;for  each source file. The &lt;code&gt;-fPIC&lt;/code&gt; flag guarantees position independence for the code.&lt;/p&gt;

&lt;p&gt;This implies that the location of where the computer loads the code into memory is irrelevant. Some processors and operating systems must create libraries from position-independent code so that they can choose where to load them into memory during runtime. The &lt;code&gt;-c&lt;/code&gt; options just ensures that each &lt;code&gt;.o&lt;/code&gt; file isn’t linked yet.&lt;/p&gt;

&lt;p&gt;Next, type in the following command: &lt;code&gt;gcc *.o -shared -o liball.so&lt;/code&gt;(substitute your desired library name with all) and hit return. The wildcard * tells the compiler to compile all the &lt;code&gt;.o&lt;/code&gt; files into a dynamic library which is specified by the &lt;code&gt;-shared&lt;/code&gt; flag. The naming convention for dynamic libraries is such that each shared library name must start with lib and end with &lt;code&gt;.so&lt;/code&gt; . Other than that though, let your imagination run free when considering names for your dynamic libraries.&lt;/p&gt;

&lt;p&gt;Finally, we’ll need to export the path for libraries so that programs know where to look for them by executing the following command: &lt;code&gt;export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How Do we use it?
&lt;/h2&gt;

&lt;p&gt;First of all, we need to create a test file that uses our functions described in the library. convert that file into object code (in this case is not important to convert it into PIC because it won’t be requested from another directory).&lt;br&gt;
&lt;code&gt;gcc test.c -c&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When we have already compiled it, we need to specify that we are linking it to a dynamic library. This could be done by running the command with the file that we are going to link followed by the flag -L. Telling the compiler to look for libraries in the current directory. After that we need to specify the name of the library, in this case, is “l_test”. Note that the name of the library passed is now shorten on the word lib. In this step, we can use that shortcut because the compiler is assuming that all the words beginning with l will be libraries. And as usual, we give a name to our executable program.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gcc test.o -L. l_test -o testlib&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If we try to run our executable file that calls the functions that we have described. It will give us an error because by default the system will be searching for libraries in the native libraries directory of the system and our library is in the current directory. We can get away with this error in two ways. The first one is to copy our library to the default searching directory, /lib, /usr/lib, usr/local/lib. By doing that at the run time our library will be in the place that the system would search.&lt;/p&gt;

&lt;p&gt;The second one is by giving the program the specific path of where is located the library we want to use before executing the file. In order to get the specific paths, we can run the command “pwd”. Copy and paste it after the following variable LD_LIBRARY_PATH . By doing this we are giving the address of our library for the file to link it at runtime.&lt;br&gt;
&lt;code&gt;LD_LIBRARY_PATH=”:/home/ubuntu/programs/libtest;$LD_LIBRARY_PATH” ./testlib&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;That is pretty much all, I hope you enjoyed this article and learned something new&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>codenewbie</category>
      <category>linux</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Compiling C File With gcc</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Fri, 16 Sep 2022 07:02:36 +0000</pubDate>
      <link>https://dev.to/labank_/compiling-c-file-with-gcc-1kof</link>
      <guid>https://dev.to/labank_/compiling-c-file-with-gcc-1kof</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is c programming&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system. The main features of the C language include low-level memory access, a simple set of keywords, and a clean style, these features make C language suitable for system programmings like an operating system or compiler development. &lt;br&gt;
For C to be executable it must first be compiled&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction to gcc&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The original author of the GNU C Compiler (GCC) is Richard Stallman,the founder of the GNU Project.&lt;br&gt;
gcc stands for GNU compiler collections which is used to compile mainly c and c++&lt;br&gt;
To check gcc version present in you system use the following command&lt;br&gt;
&lt;code&gt;gcc -v&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;syntax&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;gcc [-C | -S | -E |] [-std = standard]&lt;/code&gt; &lt;br&gt;
&lt;strong&gt;Compilation&lt;/strong&gt;&lt;br&gt;
Compilation refers to the process of converting a program from the textual source code, in a programming language such as C or C++, into machine code, the sequence of 1’s and 0’s used to control the central processing unit (CPU) of the computer. This machine code is then stored in a file known as an executable file, sometimes referred to as a binary&lt;br&gt;
file.&lt;/p&gt;

&lt;p&gt;A compiler is a computer program that translates the source code written in a high-level programming language(i.e C) to a low-level language such as machine code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The compilation process&lt;/strong&gt;&lt;br&gt;
There are four main steps involved in the compilation process as mentioned below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Preprocessing&lt;/li&gt;
&lt;li&gt;Compiling&lt;/li&gt;
&lt;li&gt;Assembling&lt;/li&gt;
&lt;li&gt;Linking&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jk1uxd2gcq9qyly0yrj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jk1uxd2gcq9qyly0yrj.PNG" alt="Image description" width="307" height="382"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Preprocessing&lt;/strong&gt;&lt;br&gt;
This is the first phase through which the source code is passed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This phase includes:&lt;/li&gt;
&lt;li&gt;Removal of comments&lt;/li&gt;
&lt;li&gt;Expansion of included files&lt;/li&gt;
&lt;li&gt;Conditional combination&lt;/li&gt;
&lt;li&gt;inclusion of  the code from the header files
Its output is stored with a file extesion of &lt;code&gt;.i&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To view the output of the pre-processing stage, we can use the command &lt;code&gt;gcc -E filename.c&lt;/code&gt; option as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@DESKTOP-TI71NAL:~# gcc -E helloworld.c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Compiler&lt;/strong&gt;&lt;br&gt;
In this phase compilation of the &lt;code&gt;filename.i&lt;/code&gt; happens in order to compile an output file of filename which is in an assembly level&lt;br&gt;
&lt;code&gt;username@hostname:~$ gcc -S filename.c&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Assembler&lt;/strong&gt;&lt;br&gt;
Here is where &lt;code&gt;filename.s&lt;/code&gt; is taken as input and turned into &lt;code&gt;filename.o&lt;/code&gt; by the assembler.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcc -c filename.c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Linker&lt;/strong&gt;&lt;br&gt;
This the final phase in which all the linking  of function call with their definitions are done.&lt;br&gt;
&lt;code&gt;gcc&lt;/code&gt; by default does dynamic linking and so &lt;code&gt;printf()&lt;/code&gt; is dynamically linked.&lt;br&gt;
The tasks performed by the linker include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linking together all the object files from the different source files.&lt;/li&gt;
&lt;li&gt;Linking function calls with their definitions. The linker knows the locations of the function definitions in the static or dynamic libraries.
&lt;strong&gt;Option 1&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;username@hostname:~$ gcc helloworld.c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run this command, the compiler generates an executable program called a.out. To run the executable program type the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;username@hostname:~$ ./a.out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Option 2&lt;/strong&gt;&lt;br&gt;
To give the executable program a different name, we can add the "-o" option to the gcc command after the name of the file we are compiling, as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;username@hostname:~$ gcc helloworld.c -o helloworld
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run the executable program, use the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;username@hostname:~$ ./helloworld
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;## gcc options&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-o&lt;/code&gt; this option is used for output&lt;br&gt;
      this will compile the filename.c , but instead of giving the default name it is executed using ./filename&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcc filename.c -o filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-werror&lt;/code&gt; This compiles the source and show the warning if any error is present in the program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcc filename.c -werror -o filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-wall&lt;/code&gt; this not only checks the errors but any other kind of warning&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcc filename.c -wall -o filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thanks for reading
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Shell I/O Redirection, The Shell Filters and Shell Expansion</title>
      <dc:creator>Kibe🔌💻</dc:creator>
      <pubDate>Wed, 07 Sep 2022 23:22:58 +0000</pubDate>
      <link>https://dev.to/labank_/shell-io-redirection-the-shell-filters-and-shell-expansion-3a9p</link>
      <guid>https://dev.to/labank_/shell-io-redirection-the-shell-filters-and-shell-expansion-3a9p</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;INTRODUCTION&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are many reasons why you should learn about I/O redirection, shell filters, and shell expansion. These concepts are essential for anyone who wants to use the command line effectively. Without an understanding of how these features work, it will be difficult to fully utilize the potential of the command line. Additionally, learning about these topics will give you a better understanding of how Linux works under the hood. Finally, being knowledgeable about I/O redirection, shell filters, and shell expansion will make it easier for you to troubleshoot any issues that might arise when using the command line.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;I/O Redirections&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Redirection is a feature in Linux that allows you to change the standard input/output devices when executing a command. The basic workflow of any Linux command is that it takes input and produces output.&lt;/p&gt;

&lt;p&gt;Each command performs all terminal-related activities with three files that the shell makes available to every command:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Standard input (stdin)&lt;/strong&gt;: Represented by &lt;strong&gt;&amp;lt;&lt;/strong&gt;, it is the information inputted into the terminal through the keyboard or input device.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Standard output (stdout)&lt;/strong&gt;: Represented by &lt;strong&gt;&amp;gt;&lt;/strong&gt;, it is the information outputted after a process is run.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Standard error (stderr)&lt;/strong&gt;: It is an error message outputted by a failed process.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Output Redirection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;"&amp;gt;"&lt;/strong&gt; symbol is used for output redirection.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# ls -l &amp;gt; listings 
root@537302f1e700:~/fruits# cat listings 
total 0                                                    
-rw-r--r-- 1 root root 0 Sep  7 13:46 apple                
-rw-r--r-- 1 root root 0 Sep  7 13:46 Apple                
-rw-r--r-- 1 root root 0 Sep  7 13:49 banana               
-rw-r--r-- 1 root root 0 Sep  7 13:48 Banana               
-rw-r--r-- 1 root root 0 Sep  7 13:47 cherry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The output of &lt;strong&gt;ls&lt;/strong&gt; when redirected will be stored in the &lt;code&gt;listings&lt;/code&gt; file. This is how you can redirect a command.&lt;/p&gt;

&lt;p&gt;When you use the &lt;strong&gt;"&amp;gt;"&lt;/strong&gt; operator to redirect to a file with the same name, the information in the file is overwritten.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# echo " welcome " &amp;gt; listings 
root@537302f1e700:~/fruits# cat listings 
 welcome 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, &lt;code&gt;echo "welcome" &amp;gt; listings&lt;/code&gt; has overwritten the existing file.&lt;/p&gt;

&lt;p&gt;To prevent overwriting a file, you can append to it using the output append operator &lt;strong&gt;&amp;gt;&amp;gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# echo " welcome " &amp;gt; listings 
root@537302f1e700:~/fruits# cat listings 
 welcome                                                     
root@537302f1e700:~/fruits# echo "welcome again" &amp;gt;&amp;gt; listings 
root@537302f1e700:~/fruits# cat listings 
 welcome                                                     
welcome again
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Input Redirection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;"&amp;lt;"&lt;/strong&gt; symbol is used for stdin redirection.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ wc -l users
2 users
$


$ wc -l &amp;lt; users
2
$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note that there is a difference in the output produced by the two forms of the &lt;code&gt;wc&lt;/code&gt; command. In the first case, the name of the file &lt;code&gt;users&lt;/code&gt; is listed with the line count; in the second case, it is not.&lt;/p&gt;

&lt;p&gt;In the first case, &lt;code&gt;wc&lt;/code&gt; knows that it is reading its input from the file &lt;code&gt;users&lt;/code&gt;. In the second case, it only knows that it is reading its input from standard input, so it does not display the filename.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Filters in Linux&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Filters are programs that take in plain text as standard input, transform it into a meaningful format, and then return it as standard output. These include:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. &lt;code&gt;cat&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;cat&lt;/code&gt; command displays the text of the file line by line.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat [path]

root@537302f1e700:~/fruits# cat list 
apple                                                      
mango                                                      
banana                                                     
oranges
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;2. &lt;code&gt;head&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;head&lt;/code&gt; command displays the first &lt;code&gt;n&lt;/code&gt; lines of a file. If the number of lines is not specified, it prints the first 10 lines by default.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;head [lines-to-print] [path]

root@537302f1e700:~/fruits# head list 
apple                                                      
mango                                                      
banana                                                     
oranges                                                    
Melon                                                      
mandarin                                                   
Avocado                                                    
coconut                                                    
Cherry                                                     
lime                                                       
root@537302f1e700:~/fruits# head -3 list 
apple                                                      
mango                                                      
banana                                                     
root@537302f1e700:~/fruits#
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;3. &lt;code&gt;tail&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;tail&lt;/code&gt; command is the reverse of &lt;code&gt;head&lt;/code&gt;, returning the lines from bottom to top.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# tail list 
mango                                                      
banana                                                     
oranges                                                    
Melon                                                      
mandarin                                                   
Avocado                                                    
coconut                                                    
Cherry                                                     
lime                                                       
Longan                                                     
root@537302f1e700:~/fruits# tail -3 list 
Cherry                                                     
lime                                                       
Longan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;4. &lt;code&gt;sort&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;sort&lt;/code&gt; command is used to sort a file, arranging the records in a particular order.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sort [options] path

root@537302f1e700:~/fruits# sort list 
1mango                                                     
20melon                                                    
3lime                                                      
apple                                                      
Avocado                                                    
banana                                                     
Cherry                                                     
coconut
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Options with &lt;code&gt;sort&lt;/code&gt; command:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;-r&lt;/strong&gt;: Sorts in reverse order.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-n&lt;/strong&gt;: Sorts the file numerically.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-nr&lt;/strong&gt;: Sorts a file with numeric data in reverse order.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-k&lt;/strong&gt;: Sorts the table based on any column.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-c&lt;/strong&gt;: Checks if a given file is already sorted.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-u&lt;/strong&gt;: Sorts and removes duplicates.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-M&lt;/strong&gt;: Sorts a file on a monthly basis.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5. &lt;code&gt;uniq&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;uniq&lt;/code&gt; command is used to remove duplicate lines. For example, in this case, &lt;code&gt;banana&lt;/code&gt; was duplicated, and the &lt;code&gt;uniq&lt;/code&gt; command removed the duplicate item.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# cat list 
apple                                                      
mango                                                      
banana                                                     
banana                                                     
oranges                                                    
Melon                                                      
mandarin                                                   
Avocado                                                    
coconut                                                    
Cherry                                                     
lime                                                       
Longan                                                     
1mango                                                     
3lime                                                      
20melo                                                     
apple                                                      
root@537302f1e700:~/fruits# uniq list 
apple                                                      
mango                                                      
banana                                                     
oranges
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;6. &lt;code&gt;wc&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;wc&lt;/code&gt; command gives the number of lines, words, and characters in the data. By default, it displays four columnar outputs.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# wc list 
 17  17 112 list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;wc [options] [path]&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;code&gt;wc&lt;/code&gt; stands for word count.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;wc&lt;/code&gt;, you can pass more than one file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; When more than one file is placed in the argument, it adds one more line that counts the total.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# wc list melon orange 
 17  17 112 list                                           
  0   0   0 melon                                          
  0   0   0 orange                                         
 17  17 112 total
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;wc&lt;/code&gt; options:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;-l&lt;/strong&gt;: Prints the number of lines in a file.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-w&lt;/strong&gt;: Prints the number of words in a file.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-m&lt;/strong&gt;: Displays the count of characters in a file.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-v&lt;/strong&gt;: Displays the version of &lt;code&gt;wc&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Some applications of the &lt;code&gt;wc&lt;/code&gt; command:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  To count all the files and folders present in a directory: &lt;code&gt;ls list | wc -l&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;root@537302f1e700:~/fruits# ls list | wc -l &lt;br&gt;
1&lt;/code&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  To display the number of word count only of a file: &lt;code&gt;wc -w list&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;root@537302f1e700:~/fruits# wc -w list &lt;br&gt;
17 list&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;7. &lt;code&gt;grep&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;grep&lt;/code&gt; command is used to search for particular information in a text file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grep [options] pattern [path]

root@537302f1e700:~/fruits# grep banana list 
banana
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# cat list | grep banana 
banana
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;grep&lt;/code&gt; options:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;-v&lt;/strong&gt;: Displays names not matching the specified word.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-i&lt;/strong&gt;: Filters output in a case-insensitive way.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-A&lt;/strong&gt;: Displays a line after the result.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-B&lt;/strong&gt;: Displays a line before the result.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-C&lt;/strong&gt;: Displays a line before and after the result.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;8. &lt;code&gt;nl&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;nl&lt;/code&gt; command is used to print line numbers of the text file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nl [file-path]

root@537302f1e700:~/fruits# nl list 
     1  apple                                               
     2  mango                                               
     3  banana                                              
     4  oranges                                             
     5  Melon                                               
     6  mandarin



root@537302f1e700:~/fruits# cat -n list 
     1  apple                                               
     2  mango                                               
     3  banana                                              
     4  oranges                                             
     5  Melon                                               
     6  mandarin                                            
     7  Avocado                                             
     8  coconut                                             
     9  Cherry                                              
    10  lime                                                
    11  Longan                                              
    12  1mango                                              
    13  3lime                                               
    14  20melon                                             
    15  apple                                               
    16  mango                                               
    17  apple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;nl&lt;/code&gt; options:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;-n&lt;/strong&gt;: To display the number and file.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-s&lt;/strong&gt;: To display number padding with space.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;-b&lt;/strong&gt;: To display line numbers when the pattern matches.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Some applications of &lt;code&gt;nl&lt;/code&gt; command:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To print a certain section of a file:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@537302f1e700:~/fruits# head -5 list | nl -b a 
     1  apple                                               
     2  mango                                               
     3  banana                                              
     4  oranges                                             
     5  Melon                                               
root@537302f1e700:~/fruits# head -n 3 list | nl -b a 
     1  apple                                               
     2  mango                                               
     3  banana
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Shell Expansions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Shell expansion is the process of simplifying commands in order to get a return value from a shell prompt. The shell reads the command line and analyzes it to make it easier to understand.&lt;/p&gt;

&lt;p&gt;The types of shell expansion include:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Pathname Expansion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is also known as "globbing." Pathname expansion is performed by the shell when it encounters a wildcard pattern (e.g., &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt;). These wildcards are replaced with a list of matching files and directories.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;ls *.txt&lt;/code&gt; would list all &lt;code&gt;.txt&lt;/code&gt; files in the current directory.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls *.txt&lt;br&gt;
file1.txt file2.txt file3.txt&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;2. Tilde Expansion&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;When the shell encounters a tilde (&lt;code&gt;~&lt;/code&gt;), it expands it to the current user's home directory.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;cd ~&lt;/code&gt; would change the directory to the user's home directory.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo ~&lt;br&gt;
/home/username&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;3. Arithmetic Expansion&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Arithmetic expansion allows the evaluation of an arithmetic expression and its substitution into the command.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;echo $((2 + 2))&lt;/code&gt; would output &lt;code&gt;4&lt;/code&gt;.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo $((2 + 2))&lt;br&gt;
4&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;4. Command Substitution&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Command substitution allows the output of a command to replace the command itself. This is done using backticks (&lt;code&gt;) or&lt;/code&gt;$(...)`.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;echo "Today is $(date)"&lt;/code&gt; would output the current date.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo "Today is $(date)"&lt;br&gt;
Today is Mon Aug 28 10:37:26 UTC 2024&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;5. Brace Expansion&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Brace expansion is used to generate arbitrary strings. It is typically used for creating multiple similar files or directories at once.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;echo file{1..3}.txt&lt;/code&gt; would output &lt;code&gt;file1.txt file2.txt file3.txt&lt;/code&gt;.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo file{1..3}.txt&lt;br&gt;
file1.txt file2.txt file3.txt&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;6. Variable Expansion&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Variable expansion allows the value of a variable to replace the variable name.&lt;/p&gt;

&lt;p&gt;For example, if &lt;code&gt;NAME="John"&lt;/code&gt;, then &lt;code&gt;echo "Hello, $NAME"&lt;/code&gt; would output &lt;code&gt;Hello, John&lt;/code&gt;.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ NAME="John"&lt;br&gt;
$ echo "Hello, $NAME"&lt;br&gt;
Hello, John &lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Learning about I/O redirection, shell filters, and shell expansion is essential for effective command-line usage. These features allow for powerful text manipulation and automation, enabling users to work more efficiently with files, processes, and data in a Linux environment. By mastering these concepts, you will be better equipped to harness the full potential of the command line and streamline your workflow.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>ubuntu</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
