<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Problem Solving - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Problem Solving - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 18 Jun 2026 23:24:06 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/problem-solving/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Use Chrome DevTools – Simple Strategies for Smarter Web Development ]]>
                </title>
                <description>
                    <![CDATA[ As a web developer, there are many tools out there – in addition to your code editor – that can make you more efficient.  It doesn't matter if you're just starting out or have been coding for years. Knowing how to effectively use Developer Tools (Dev... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/chrome-devtools/</link>
                <guid isPermaLink="false">66c5a334215f782a032b1cb7</guid>
                
                    <category>
                        <![CDATA[ Google Chrome ]]>
                    </category>
                
                    <category>
                        <![CDATA[ clean code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ debugging ]]>
                    </category>
                
                    <category>
                        <![CDATA[ devtools ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ophy Boamah ]]>
                </dc:creator>
                <pubDate>Thu, 15 Feb 2024 16:12:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/02/ChromeDevTools-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As a web developer, there are many tools out there – in addition to your code editor – that can make you more efficient. </p>
<p>It doesn't matter if you're just starting out or have been coding for years. Knowing how to effectively use Developer Tools (DevTools for short) can significantly boost your development process. You can edit pages on the fly, quickly spot issues, and deeply understand your site's performance. </p>
<p>All major browsers have their own DevTools that let you examine the code of a webpage, evaluate its metrics, and run some tests alongside. This article will discuss Chrome's DevTools, as it's the industry standard.</p>
<h2 id="heading-table-of-contents">Table of contents:</h2>
<ul>
<li><a class="post-section-overview" href="#heading-what-is-chrome-devtools">What is Chrome DevTools?</a></li>
<li><a class="post-section-overview" href="#heading-how-to-open-chrome-devtools">How to Open Chrome DevTools</a></li>
<li><a class="post-section-overview" href="#heading-keyboard-shortcuts-for-easy-navigation">Keyboard shortcuts for Easy Navigation</a></li>
<li><a class="post-section-overview" href="#heading-key-chrome-devtools-features">Key Chrome DevTools Features</a></li>
<li><a class="post-section-overview" href="#heading-practical-devtools-use-cases">Practical DevTools Use Cases</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h1 id="heading-what-is-chrome-devtools">What is Chrome DevTools?</h1>
<p>Chrome DevTools is a set of tools that are essential for diagnosing and solving web development challenges, directly within the Google Chrome browser. </p>
<p>It gives you direct access to a website's inner workings - to inspect HTML and CSS, debug JavaScript, analyze performance, and see the immediate impact of your code, all in realtime. </p>
<p>This direct access to a website's inner workings is crucial for diagnosing issues quickly and efficiently, ensuring your web applications are both performant and bug-free.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/DevToolsScreenshots-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>A grid of elements, console, performance and network panels screenshots</em></p>
<h1 id="heading-how-to-open-chrome-devtools">How to Open Chrome DevTools</h1>
<p>To open DevTools in your Chrome browser, you can either:</p>
<ol>
<li>Right-click on any webpage and select inspect from the list of options.</li>
<li>Use the shortcut (command + option + I on Mac or control + shift + I on Windows). </li>
<li>Click the three dot icon next to your profile picture on your Chrome browser, choose 'More Tools' and 'Developer Tools' from the second option box.</li>
</ol>
<p>It usually opens in a split screen interface, either below your current webpage or beside it. Once open, its features line up as tabs at the top of the DevTools window. These tabs include: Elements, Console, Source, Network, Application, Security, Memory, Performance, Audits.</p>
<h2 id="heading-keyboard-shortcuts-for-easy-navigation">Keyboard Shortcuts for Easy Navigation</h2>
<ol>
<li>Use Cmd or Ctrl + Shift + C to open the Elements panel</li>
<li>Use Cmd or Ctrl + Shift + J to open the Console panel</li>
<li>Use Cmd or Ctrl + ] to move forward to the next panel </li>
<li>Use Cmd or Ctrl + [ to move back to the previous panel </li>
</ol>
<h1 id="heading-key-chrome-devtools-features">Key Chrome DevTools Features</h1>
<p>DevTools is packed with features essential for web developers to streamline various aspects of their workflow. Let's look at a few of them in some detail now.</p>
<h2 id="heading-elements-panel">Elements Panel</h2>
<p>This panel is used for inspecting and modifying the HTML and CSS of a webpage in real-time, which is great for debugging layout issues or experimenting with new styles before applying them in your actual code. You also get to see how the DOM (Document Object Model) is structured. </p>
<p>Imagine fine-tuning your website's footer appearance (background color, font size) directly in your browser and seeing the results instantly. </p>
<p>With DevTools open, click on the Elements tab to access it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/elpanel-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>A screenshot of Chrome DevTools' Elements panel</em></p>
<h2 id="heading-console-panel">Console Panel</h2>
<p>This panel serves as your interactive playground for JavaScript within the browser. Whether you're tracking down an elusive bug with a quick <code>console.log()</code> or experimenting with DOM elements, in the Console panel you can test snippets of JavaScript and view any logs or errors in the currently loaded webpage. </p>
<p>To use it, simply open DevTools and select the "Console" tab or use the shortcut (option + command + J on Mac or contrl + shift + J on Windows).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/clpanel-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>A screenshot of Chrome DevTools' Console panel</em></p>
<h2 id="heading-network-panel">Network Panel</h2>
<p>This panel gives you an overview of all network activity on your webpage – from tracking every resource that is loaded to how your site communicates with servers. </p>
<p>If you've wondered why your website takes forever to load or why some API requests seem to vanish into thin air, the Network panel is your go-to as it provides insights into the success or failure of API calls. </p>
<p>To access it, open DevTools and navigate to the "Network" tab.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/netpanel-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>A screenshot of Chrome DevTools' Network panel</em></p>
<h2 id="heading-performance-panel">Performance Panel</h2>
<p>This panel is used for capturing and analyzing a website's performance metrics. It shows all the activities happening when interacting with a page. </p>
<p>When your web app starts to crawl under heavy usage, the Performance panel can pinpoint where the performance bottlenecks lie so that you can resolve these issues, ensuring your app runs smoothly. </p>
<p>With DevTools open, click on the "Performance" tab to use it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/perfpanel-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>A screenshot of Chrome DevTools' Performance panel</em></p>
<p>The above are only a handful of the panels available, but they're by far the most popular and must-knows. Using them properly will make your development processes more intuitive and rewarding.</p>
<h1 id="heading-practical-devtools-use-cases">Practical DevTools Use Cases</h1>
<p>In the following interactive examples, I intentionally created the mini project in Codepen <strong>with issues</strong> to simulate real-world debugging scenarios using Chrome DevTools. </p>
<p>I figured it'd be a great way to highlight the practical uses of certain DevTools panels and features in identifying bugs and troubleshooting right in the browser. </p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li>Chrome browser (<a target="_blank" href="https://support.google.com/chrome/answer/95346?hl=en&amp;co=GENIE.Platform%3DDesktop">Click this link to download</a>)</li>
<li>A basic understanding of HTML, CSS, and JavaScript</li>
<li><a target="_blank" href="https://codepen.io/ophyboamah/full/rNpZZwo">Codepen</a></li>
</ul>
<p></p><p>
  <span>See the Pen <a href="https://codepen.io/ophyboamah/pen/rNpZZwo">
  Modal Window</a> by Ophy Boamah (<a href="https://codepen.io/ophyboamah">@ophyboamah</a>)
  on <a href="https://codepen.io">CodePen</a>.</span>
</p><p></p>


<h2 id="heading-how-to-debug-html-and-css-with-the-elements-panel">How to Debug HTML and CSS with the Elements Panel</h2>
<p>Our mini project contains a modal that, upon clicking, should display a modal window with some important information. But there's a bug preventing this from happening. </p>
<p>This situation sets the stage for a practical demonstration of how you can use the Elements Panel to troubleshoot and resolve styling and structural issues.</p>
<pre><code>&lt;body&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"show-modal"</span>&gt;</span>Click me to learn a secret 🤫<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>

  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"modal hidden"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"close-modal"</span>&gt;</span><span class="hljs-symbol">&amp;times;</span><span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hey Ophy here 👋🏾<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
      I lead Women Who Code Frontend, a global remote community of 3,000+ women frontend devs and enthusiasts. Find us on beacons.ai/wwcodefrontend
    <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"overlay hidden"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>

  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"script.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
&lt;/body&gt;
</code></pre><pre><code class="lang-css"><span class="hljs-selector-class">.hidden</span> {
  <span class="hljs-attribute">display</span>: none;
}

<span class="hljs-selector-class">.modal</span> {
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate</span>(-<span class="hljs-number">50%</span>);
  <span class="hljs-attribute">width</span>: <span class="hljs-number">70%</span>;

  <span class="hljs-attribute">background-color</span>: white;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">6rem</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">3rem</span> <span class="hljs-number">5rem</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.3</span>);
  <span class="hljs-attribute">z-index</span>: <span class="hljs-number">10</span>;
}
</code></pre>
<p>In our modal's HTML code above, we've added the class name 'modal hidden' which has a corresponding styling with the CSS property of <code>display:none</code> that is set to hide the modal when the page is loaded initially and only display it when the button is clicked.</p>
<h3 id="heading-step-1-initial-inspection">✅ Step 1 - Initial inspection:</h3>
<p>Attempt to trigger the modal by clicking on the 'Click me to learn a secret' button. Since we've set that up not to work, right-click on the area where the modal should appear and choose "Inspect" to open DevTools' Elements Panel.</p>
<h3 id="heading-step-2-diagnose-visibility-issues">✅ Step 2 - Diagnose visibility issues:</h3>
<p>In the Elements Panel, locate the modal in the DOM to see that the modal is present but not visible. This confirms that the bug is caused within our CSS code <code>display: hidden</code>. </p>
<p>As soon as you click on the modal in the DOM, any corresponding CSS classes will be pulled up within Styles at the bottom section of the Elements panel. You can toggle some properties on and off or type others to see the effects in real-time.</p>
<p>Manually change the class name from <code>modal hidden</code> to <code>modal block</code> to trigger the right properties that'll cause the modal to show.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/modalblock.png" alt="Image" width="600" height="400" loading="lazy">
<em>A screenshot of debugging the modal's HTML, CSS in Elements panel</em></p>
<h3 id="heading-step-3-center-the-modal">✅ Step 3 - Center the modal:</h3>
<p>Now the modal is visible, but it's displayed at the top – which is different from where we'd like it to be (that is, in the center of the page).</p>
<p>To change this, modify the <code>transform</code> property to <code>translate(-50%, -50%)</code> by adding the second <code>-50%</code> and ensure that <code>top: 50%</code>, and <code>left: 50%</code> are correctly set to center the modal on the screen.</p>
<h3 id="heading-step-4-enhance-the-appearance">✅ Step 4 - Enhance the appearance:</h3>
<p>You can go further to refine the modal's appearance by tweaking its <code>background-color</code>, <code>padding</code>, or other stylistic properties directly within the Styles to achieve the desired look and feel.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/ChromeDevTools.gif" alt="Image" width="600" height="400" loading="lazy">
<em>A GIF fixing the modal in Chrome DevTools' Elements panel</em></p>
<h2 id="heading-debug-javascript-with-the-sources-panel">Debug JavaScript with the Sources Panel</h2>
<p>I added a bug in the JavaScript code of our modal mini project to prevent it from opening when the button is clicked. </p>
<p>In the real world, this would cause neither the open nor close commands to trigger any action, which would leave users unable to interact with the content and frustrated as a result. Let's troubleshoot and debug this issue in the Sources Panel.</p>
<p>In the code below, the openModal function is set to remove the indicated classes. However, this doesn't work because we deliberately misspelled <code>hidden</code>. </p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Introducing a bug: Incorrectly spelling 'hidden' as 'hiddn'</span>
<span class="hljs-keyword">const</span> openModal = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  modal.classList.remove(<span class="hljs-string">"hiddn"</span>); <span class="hljs-comment">// Intentional bug</span>
  overlay.classList.remove(<span class="hljs-string">"hidden"</span>);

  <span class="hljs-comment">// Fetch data from a real API and display in the modal</span>
};
</code></pre>
<h3 id="heading-step-1-set-up-breakpoints">✅ Step 1 - Set up breakpoints:</h3>
<p>Open Chrome DevTools and navigate to the Sources Panel. Here, find the JavaScript file that includes the modal functionality (in our example its pen.js). </p>
<p>The openModal function contains the logic for displaying the modal on the screen. This function will include a line where the modal element's class is manipulated to remove a "hidden" class. </p>
<p>Click on the number next to this code line in DevTools. A blue (or sometimes red, depending on the theme) icon appears next to the line number, indicating that a breakpoint has been set. This breakpoint will pause the execution of our JavaScript code as soon as it reaches this line.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/soscreenshot.png" alt="Image" width="600" height="400" loading="lazy">
<em>A screenshot of setting breakpoints the modal's JS in Sources panel</em></p>
<p>Breakpoints pause code execution at critical points, allowing you to inspect the current state of variables and understand the flow of execution. This step is crucial for identifying where the code deviates from expected behaviour.</p>
<h3 id="heading-step-2-examine-the-code-execution-flow">✅ Step 2 - Examine the code execution flow:</h3>
<p>With our breakpoint in place, try to open the modal by clicking on its button. Execution of our JavaScript code now pauses at our breakpoint, which enables us to step through the code line by line. </p>
<p>This is an opportunity to observe variables, function calls, look for anomalies such as misnamed functions, incorrect logic, or uncaught exceptions that could explain why the modal isn't working. </p>
<p>In our case it's because we intentionally misspelled the class name <code>hidden</code> as <code>hiddn</code>. Fix that in the code to get the modal working again.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/ChromeDevTools--2-.gif" alt="Image" width="600" height="400" loading="lazy">
<em>A GIF troubleshooting the modal bug in Chrome DevTools' Elements panel</em></p>
<h2 id="heading-optimize-performance-with-the-network-panel">Optimize Performance with the Network Panel</h2>
<p>Here I've added a fetch function that makes an API call to a live endpoint (<a target="_blank" href="https://jsonplaceholder.typicode.com/posts/1"><code>https://jsonplaceholder.typicode.com/posts/1</code></a>). This is an excellent opportunity to explore the Network Panel's capabilities in diagnosing and understanding network-related problems.</p>
<p>From the code below, you can see that the openModal function doesn't only open the modal but also makes an API call to the <code>jsonplaceholder</code> endpoint to fetch some data. </p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> openModal = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>)
    .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
    .then(<span class="hljs-function"><span class="hljs-params">json</span> =&gt;</span> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'modal-content'</span>).innerText = json.title)
    .catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.error(<span class="hljs-string">'Error loading the content:'</span>, error));
};
</code></pre>
<h3 id="heading-step-1-initiate-the-api-call">✅ Step 1 - Initiate the API call:</h3>
<p> On the modal project UI, click on the 'Click me to learn a secret' button. Though the modal does not visibly activate, because of the fetch logic within the openModal function, an API call will be made.</p>
<h3 id="heading-step-2-network-panel-inspection">✅ Step 2 - Network Panel Inspection:</h3>
<p>Ideally, your Network Panel should be open before clicking the button, but you can also reverse the steps. Detailed insights on your API request such as the request's method, status code, response and the time it took to complete, will be available under headers, preview, response, initiator and timing tabs respectively. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/netscreenshot.png" alt="Image" width="600" height="400" loading="lazy">
<em>A screenshot overview of API request in Network panel</em></p>
<h3 id="heading-step-3-simulating-network-conditions">✅ Step 3 - Simulating Network Conditions:</h3>
<p>Use the Network Panel's throttling feature to mimic various network speeds like offline or slow 3G to see how the API request behaves under constrained conditions. </p>
<p>From this you can compare how different network speeds can affect application performance. This will teach you the importance of optimizing data loading strategies to enhance user experience, especially on slower connections.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/ChromeDevTools--1-.gif" alt="Image" width="600" height="400" loading="lazy">
<em>A GIF observing API requests and responses in Chrome DevTools' Network panel</em></p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Bringing Chrome DevTools into your web development routine is not just about fixing bugs. It's about streamlining your workflow, making your sites more accessible, and boosting their performance. </p>
<p>Through our modal window mini-project, we've seen firsthand how DevTools can address a wide array of development challenges, but that’s merely scratching the surface of what it can do. </p>
<p>As you continue to explore its capabilities and familiarize yourself with its features, you'll find it's an invaluable companion on your web development journey – designed to make your development process not just faster, but also more rewarding.</p>
<ul>
<li><a target="_blank" href="https://developer.chrome.com/docs/devtools">The Official Chrome DevTools documentation</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/learn-how-to-use-the-chrome-devtools-to-troubleshoot-websites/">How to use the Chrome DevTools to troubleshoot websites</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Print Array Elements in a Given Order with or without a Function ]]>
                </title>
                <description>
                    <![CDATA[ If you are learning to solve problems using a programming language, you've likely faced the problem of printing array elements in a given order or in reverse order. You might have also needed to do this by either using a user-defined function or not ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-print-array-elements-in-given-order-with-and-without-function/</link>
                <guid isPermaLink="false">66b902f7380c84d101de5dac</guid>
                
                    <category>
                        <![CDATA[ arrays ]]>
                    </category>
                
                    <category>
                        <![CDATA[ C++ ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Md. Fahim Bin Amin ]]>
                </dc:creator>
                <pubDate>Thu, 16 Feb 2023 21:58:53 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/02/func.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you are learning to solve problems using a programming language, you've likely faced the problem of printing array elements in a given order or in reverse order.</p>
<p>You might have also needed to do this by either using a user-defined function or not using any function at all.</p>
<p>If this problem seems kind of complicated to you, then don't worry! I have come to help you. So, let's dive into the question real quick and see how it works.</p>
<p>🎥 If you are the kind of person that loves to follow along with a video too, I have also created a video for you:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/pACJ2_bGaZ0" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-understand-the-question-then-start-solving">Understand The Question – Then Start Solving</h2>
<p>For solving any kind of problem, the first thing you have to do is to understand the question first. Not only that, you also need to pay close attention to all the instructions including the required criteria for solving that problem.</p>
<p>If your question asks you to use recursion, that's the technique you'll employ. If your question asks you not to use any built-in special functions, you'll avoid those.</p>
<p>For this article, I will be using only one question but with two different criteria. I will go through the process to help you understand what you would need to do from the beginning for solving the problem.</p>
<h3 id="heading-heres-the-question-with-its-criteria">Here's the question with its criteria:</h3>
<p>Create an integer array. Take the array elements as input from the user and print all the array elements in the given order and later in reverse order. You can't use any user-defined function.</p>
<p>Alright, now that we have our question, make sure you've read it fully. If reading it through one time does not make it clear in your mind, then read it two or three – or even more – times.</p>
<p>Then also look into the given criteria carefully. The question tells you that you can not use any user defined function. That means you can not add any kind of manually user-defined function in your code like <code>myFunction()</code>, and so on.</p>
<p>For this article, I will be using the <strong>C++</strong> programming language. But if you can understand the core concept then you can use any other programming language to solve this problem. After solving the problem, make sure to add your solution <a target="_blank" href="https://github.com/FahimFBA/problem-solving-made-easy">to this GitHub repository</a>. </p>
<p>Also, if you like to solve problems using programming languages, then make sure to check <a target="_blank" href="https://www.youtube.com/playlist?list=PL7ZCWbO2Dbl5p3wf0IOHeIZ6PHxTI3ADD">my ongoing YouTube playlist where I solve problems using the programming language</a>.</p>
<h3 id="heading-how-to-solve-the-problem">How to Solve the Problem</h3>
<p>In C/C++, if you declare an array without initializing the value, then you need to specify the array size as well. </p>
<p>When you declare the array with the array size, it automatically takes the necessary space in the memory for the entire array. So, if you take a larger array than you actually need, you will waste memory, as it takes the full space in memory for the full array whether you use all the indexes or not. </p>
<p>So first, we want the user to input the array size (how many numbers they want us to process). Then we will create the array with the given array size. In that way, we can save unnecessary memory wastage. </p>
<p>Well, as today's computers are more powerful, you would likely not notice any differences in memory wastage, as it would be pretty negligible. But trust me, you do need to understand how to save memory as that is one of the biggest concerns in today's world. Also, you never know when this knowledge will help you later, right?</p>
<pre><code class="lang-cpp">    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Enter the array size: "</span>;
    <span class="hljs-keyword">int</span> arraySize;
    <span class="hljs-built_in">cin</span> &gt;&gt; arraySize;
    <span class="hljs-keyword">int</span> arr[arraySize];
</code></pre>
<p>Well then, after declaring our array, we will take the array elements from the user. We can simply use a <code>for()</code> loop for that. </p>
<pre><code class="lang-cpp">    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Enter the array elements "</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; arraySize; i++)
    {
        <span class="hljs-built_in">cin</span> &gt;&gt; arr[i];
    }
</code></pre>
<p>In this way, we can take each value from the user and store it in our array in a sequential way. Keep in mind that the array always starts from the <code>0</code> index (the first element is at index <code>0</code>, the second is at index <code>1</code>, and so on).</p>
<p>Now it is time to print all the array elements (the value that each index of the array has) in the given order. That means we have to print the entire array in the same order we received from the user.</p>
<pre><code class="lang-cpp">    <span class="hljs-comment">// printing the array in the correct order</span>
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Printing the array in the original order"</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; arraySize; i++)
    {
        <span class="hljs-built_in">cout</span> &lt;&lt; arr[i] &lt;&lt; <span class="hljs-string">" "</span>;
    }
</code></pre>
<p>For printing the array in reverse order, we can simply print the array in a backwards direction. In this way, the last indexed value from the array will get printed first. Then the second to last indexed value (from the right side of the array) would get printed in the second position, and so on.</p>
<pre><code class="lang-cpp">    <span class="hljs-comment">// printing the array in the reverse order</span>
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"\nPrinting the array in the reversed order"</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = arraySize - <span class="hljs-number">1</span>; i &gt;= <span class="hljs-number">0</span>; i--)
    {
        <span class="hljs-built_in">cout</span> &lt;&lt; arr[i] &lt;&lt; <span class="hljs-string">" "</span>;
    }
</code></pre>
<p>That's it! Through this, you can solve the problem easily. Notice that we did not use any kind of user-defined function in our entire code. Thus, we also made sure that we successfully met all of the criteria.</p>
<p>The entire code now looks like this:</p>
<pre><code class="lang-cpp"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;bits/stdc++.h&gt;</span></span>
<span class="hljs-keyword">using</span> <span class="hljs-keyword">namespace</span> <span class="hljs-built_in">std</span>;

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>
</span>{
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Enter the array size: "</span>;
    <span class="hljs-keyword">int</span> arraySize;
    <span class="hljs-built_in">cin</span> &gt;&gt; arraySize;
    <span class="hljs-keyword">int</span> arr[arraySize];
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Enter the array elements "</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; arraySize; i++)
    {
        <span class="hljs-built_in">cin</span> &gt;&gt; arr[i];
    }
    <span class="hljs-comment">// printing the array in the correct order</span>
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Printing the array in the original order"</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; arraySize; i++)
    {
        <span class="hljs-built_in">cout</span> &lt;&lt; arr[i] &lt;&lt; <span class="hljs-string">" "</span>;
    }
    <span class="hljs-comment">// printing the array in the reverse order</span>
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"\nPrinting the array in the reversed order"</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = arraySize - <span class="hljs-number">1</span>; i &gt;= <span class="hljs-number">0</span>; i--)
    {
        <span class="hljs-built_in">cout</span> &lt;&lt; arr[i] &lt;&lt; <span class="hljs-string">" "</span>;
    }    
}
</code></pre>
<h3 id="heading-heres-another-example-question-and-criteria">Here's another example question and criteria:</h3>
<p>Create an integer array. Take the array elements as input from the user and print all the array elements in the given order and later in the reverse order. You have to use a user-defined function for printing the array in reverse order.</p>
<p>Now, this time the criteria has been changed. The only difference is that we need to use a user defined function right now.</p>
<p>If you can understand the previous technique and the code, then most probably you have already guessed how to solve this problem. We have to shift the part of the code that prints the array in the reverse order to a new user-defined function. Simply doing that will solve our problem. </p>
<p>For example, I am going to name the new user-defined function <code>printReversely(int arr[], int arraySize)</code>. You can name it however you want by following the naming conventions of C++ (or whatever programming language you're using).</p>
<p>I am simply giving you the entire code for now:</p>
<pre><code class="lang-cpp"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;bits/stdc++.h&gt;</span></span>
<span class="hljs-keyword">using</span> <span class="hljs-keyword">namespace</span> <span class="hljs-built_in">std</span>;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">printReversely</span><span class="hljs-params">(<span class="hljs-keyword">int</span> arr[], <span class="hljs-keyword">int</span> arraySize)</span></span>;
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>
</span>{
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Enter the array size: "</span>;
    <span class="hljs-keyword">int</span> arraySize;
    <span class="hljs-built_in">cin</span> &gt;&gt; arraySize;
    <span class="hljs-keyword">int</span> arr[arraySize];
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Enter the array elements "</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; arraySize; i++)
    {
        <span class="hljs-built_in">cin</span> &gt;&gt; arr[i];
    }
    <span class="hljs-comment">// printing the array in the correct order</span>
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Printing the array in the original order"</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; arraySize; i++)
    {
        <span class="hljs-built_in">cout</span> &lt;&lt; arr[i] &lt;&lt; <span class="hljs-string">" "</span>;
    }
    <span class="hljs-comment">// printing the array in the reverse order</span>
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"\nPrinting the array in the reversed order"</span> &lt;&lt; <span class="hljs-built_in">endl</span>;
    printReversely(arr, arraySize);
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">printReversely</span><span class="hljs-params">(<span class="hljs-keyword">int</span> arr[], <span class="hljs-keyword">int</span> arraySize)</span>
</span>{
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = arraySize - <span class="hljs-number">1</span>; i &gt;= <span class="hljs-number">0</span>; i--)
    {
        <span class="hljs-built_in">cout</span> &lt;&lt; arr[i] &lt;&lt; <span class="hljs-string">" "</span>;
    }
}
</code></pre>
<p>In C/C++, the code execution always starts from the upper left corner.</p>
<p>As I wrote my <code>printReversely(int arr[], int arraySize)</code> function after the main function, I added the declaration part of it before the <strong>main()</strong> function. This will help the compiler determine whether it has access to the function or not. If you do not do that, then you'll get an error.</p>
<p>But if you write the entire <code>printReversely(int arr[], int arraySize)</code> function before the <strong>main()</strong> function then you do not necessarily need to add the declaration again before that. </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Thanks for reading the entire article. If it helps you then you can also check out other articles of mine at <a target="_blank" href="https://www.freecodecamp.org/news/author/fahimbinamin/">freeCodeCamp</a>.</p>
<p>If you want to get in touch with me, then you can do so using <a target="_blank" href="https://twitter.com/Fahim_FBA">Twitter</a>, <a target="_blank" href="https://www.linkedin.com/in/fahimfba/">LinkedIn</a>, and <a target="_blank" href="https://github.com/FahimFBA">GitHub</a>. </p>
<p>You can also <a target="_blank" href="https://www.youtube.com/@FahimAmin?sub_confirmation=1">SUBSCRIBE to my YouTube channel</a> (Code With FahimFBA) if you want to learn various kinds of programming languages with a lot of practical examples regularly.</p>
<p>If you want to check out my highlights, then you can do so at my <a target="_blank" href="https://www.polywork.com/fahimbinamin">Polywork timeline</a>.</p>
<p>You can also <a target="_blank" href="https://fahimbinamin.com/">visit my website</a> to learn more about me and what I'm working on.</p>
<p>Thanks a bunch!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Understand Complex Coding Concepts Using the Feynman Technique ]]>
                </title>
                <description>
                    <![CDATA[ The Feynman approach is an excellent way to gain a deeper understanding of a complex topic. It's one of the quickest ways to turn a complex topic into one that you can explain in simple terms to others. This article will teach you how to break comple... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-understand-complex-coding-concepts-better-using-the-feynman-technique/</link>
                <guid isPermaLink="false">66bb89f17a6500a14ba5b76e</guid>
                
                    <category>
                        <![CDATA[ beginners guide ]]>
                    </category>
                
                    <category>
                        <![CDATA[ coding ]]>
                    </category>
                
                    <category>
                        <![CDATA[ learning to code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Cess ]]>
                </dc:creator>
                <pubDate>Tue, 28 Jun 2022 19:26:19 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/HTML-Best-Practices---How-to-Build-a-Better-HTML-Based-Website.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The Feynman approach is an excellent way to gain a deeper understanding of a complex topic. It's one of the quickest ways to turn a complex topic into one that you can explain in simple terms to others.</p>
<p>This article will teach you how to break complex coding concepts into the simplest terms.</p>
<p>Let's get started 💃</p>
<h2 id="heading-the-feynman-technique-of-learning">The Feynman Technique Of Learning</h2>
<p>Richard Feynman, a Nobel Prize-winning physicist, created the Feynman method for learning. He enjoyed explaining complex topics in simpler terms. </p>
<p>In Feynman's view, the best way to study an idea was to ask hard questions and fully understand it.</p>
<p>For more information about Richard Feynman, see this <a target="_blank" href="https://www.nobelprize.org/prizes/physics/1965/feynman/biographical/">article.</a></p>
<blockquote>
<p>"If you want to learn something, read about it. If you want to understand something, write about it. If you want to master something, teach it." -  Yogi Bhajan.</p>
</blockquote>
<p>Feynman's technique, in a nutshell, revolves around the belief that you can't explain something well if you do not know it well yourself. </p>
<p>When you try to explain what you know to someone who doesn't know anything about it, you'll notice the flaws in your understanding. The goal is to communicate what you've learned in a simple way that a child can understand.</p>
<h2 id="heading-what-are-the-benefits-of-using-the-feynman-technique">What Are the Benefits of Using the Feynman Technique?</h2>
<p>Here are a few of the benefits of using Feynman's learning techniques:</p>
<ul>
<li>It helps you gain a thorough understanding of what you're learning. If you're having trouble understanding JavaScript loops, for example, try this learning method.</li>
<li>It helps you <strong>learn new ideas.</strong> This technique allows you to learn new things fast, recall what you have learned, and be more productive.</li>
<li>It helps you become a better teacher. You get better at teaching when you keep sharing your knowledge with others.</li>
<li>It improves your critical thinking ability. You will be able to reason in an organized manner to explain complex stuff in simpler terms.</li>
</ul>
<h2 id="heading-the-four-steps-of-the-feynman-technique">The Four Steps of the Feynman Technique</h2>
<p>The Feynman Technique is made up of four significant steps:</p>
<ul>
<li>Choose a topic you want to learn about.</li>
<li>Explain it to a 12-year-old.</li>
<li>Review your explanation.</li>
<li>Simplify.</li>
</ul>
<h3 id="heading-step-1-choose-a-topic-you-want-to-learn-about">Step 1 - Choose a topic you want to learn about</h3>
<p>First, you should come up with a subject or topic you would like to learn and then write it at the top of a piece of paper.</p>
<p>For example, if you want to study JavaScript loops, write it as a heading on a blank piece of paper. As you keep learning about JavaScript loops, write whatever you know on that piece of paper. Write it so that someone who knows nothing about JavaScript loops will understand it.</p>
<h3 id="heading-notes-on-javascript-loops">Notes on JavaScript Loops</h3>
<p>Loops allow us to repeatedly run a code block until we meet a specific condition.  We call this condition the stop condition.</p>
<h3 id="heading-types-of-loops">Types of  loops</h3>
<ul>
<li>for loop</li>
<li>for-of loop</li>
<li>for-in loop</li>
<li>While loop</li>
<li>Do-while loop</li>
</ul>
<h4 id="heading-for-loop">For loop</h4>
<p>For loop allows us to repeat a series of actions until a specific condition is false. When a stop condition is true, the for loop runs, and when it is false, it stops running.</p>
<p>For loop syntax:</p>
<pre><code><span class="hljs-keyword">for</span> (initialExpression; stopCondition; incrementExpression) {
  <span class="hljs-comment">// code block to be executed</span>
}
</code></pre><p>Example of a for loop:</p>
<pre><code><span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">1</span>; i&lt;=<span class="hljs-number">10</span>; i++) {
   <span class="hljs-built_in">console</span>.log(i);
}  <span class="hljs-comment">// 1,2,3,4,5,6,7,8,9,10</span>
</code></pre><h4 id="heading-while-loop">While loop</h4>
<p>The while loop continues to run as long as the stop condition is true. It will stop running if the condition resolves to false.</p>
<p>We use a while loop when we are unsure of the number of times the loop will run before it starts running.</p>
<p>While loop syntax:</p>
<pre><code><span class="hljs-keyword">while</span> (stop condition) {
   <span class="hljs-comment">// code block to be executed</span>
}
</code></pre><p>Example of a While loop:</p>
<pre><code><span class="hljs-keyword">let</span> i = <span class="hljs-number">1</span>;

<span class="hljs-keyword">while</span>(i &lt;=<span class="hljs-number">10</span>) {
   <span class="hljs-built_in">console</span>.log(i);
   i++
}  <span class="hljs-comment">// 1,2,3,4,5,6,7,8,9,10</span>
</code></pre><h4 id="heading-do-while-loop">Do-while loop</h4>
<p>Do-while loops run a block of code (loop's body) at least once before rerunning if the stop condition is true or false.</p>
<p>Do-while loop syntax:</p>
<pre><code><span class="hljs-keyword">do</span> {   
  <span class="hljs-comment">// code to be executed </span>
} <span class="hljs-keyword">while</span>(stop condition)
</code></pre><p>Example of a Do-while loop:</p>
<pre><code><span class="hljs-keyword">let</span> i = <span class="hljs-number">1</span>;
<span class="hljs-keyword">do</span> {
  <span class="hljs-built_in">console</span>.log(i);
  i++;
} <span class="hljs-keyword">while</span>(i &lt;= <span class="hljs-number">10</span>) <span class="hljs-comment">// 1,2,3,4,5,6,7,8,9,10</span>
</code></pre><p>Check out this article for a detailed explanation of <a target="_blank" href="https://cesscode.hashnode.dev/what-are-the-different-javascript-loops">JavaScript Loops</a>.</p>
<p>Before moving on to step 2, do more research on JavaScript loops or take a practice test to see how good you are.</p>
<p>Check out this article for resources to help you practice <a target="_blank" href="https://cesscode.hashnode.dev/resources-to-help-you-practice-web-development">web development</a>.</p>
<p>Once you have a firm understanding of the topic (JavaScript loops), proceed to step 2.</p>
<p>Also, just a note – paper can be anything you use for writing, such as your phone's notebook app to any other app you use every day.</p>
<h3 id="heading-step-2-explain-it-to-a-12-year-old">Step 2 - Explain it to a 12-year-old</h3>
<p>Now that you have a clear understanding of JavaScript loops, it's time to explain it to a 12-year-old.</p>
<p>You don't have to look for an actual 12-year-old to teach. All you have to do is explain loops in the most basic terms possible, such that even a child can understand.</p>
<h3 id="heading-explanation-of-loops-to-a-12year-old">Explanation of loops to a 12year old</h3>
<p>Imagine you have a box of 20 candies and want to give them to your schoolmates. Each time there is still candy in the candy box, someone gets one until there is none left.</p>
<p>A classmate gets candy as long as there's candy in your box. If there's no candy left in the box, no one gets candy. To keep sharing sweets with more of your friends, you'll need to go out and buy more.</p>
<p><a target="_blank" href="https://cesscode.hashnode.dev/what-are-the-different-javascript-loops">JavaScript loops</a> help to make a series of activities repeat themselves. It allows you to run a code block repeatedly until we meet a specific condition and it stops running.</p>
<p>Loops operate similarly to your candy box. The code block must meet a specific condition to run or stop running.</p>
<ul>
<li><p>If the condition is true, your code runs</p>
</li>
<li><p>If the condition is false, your code stops running</p>
</li>
</ul>
<pre><code><span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> candyBox = <span class="hljs-number">1</span>; candyBox &lt;=<span class="hljs-number">20</span>; candyBox++) {
   <span class="hljs-built_in">console</span>.log(candyBox);
}  <span class="hljs-comment">// 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20</span>
</code></pre><ul>
<li><p><code>let candyBox = 1</code> means that your code should start counting at 1</p>
</li>
<li><p><code>candyBox &lt;= 20</code> is the condition that must be met for your code to run. It means that your code should stop counting when it gets to 20.</p>
</li>
<li><p><code>candyBox++</code> means that your code should increase by 1 for every time it runs</p>
</li>
</ul>
<p>There's a saying that using complex terms to explain a topic masks your lack of understanding. So your ability to explain loops in the simplest terms possible means you know what you are saying through and through.</p>
<h3 id="heading-how-to-explain-your-code-when-you-dont-have-a-12-year-old-to-talk-to">How to explain your code – when you don't have a 12 year old to talk to</h3>
<p>I know some of you reading this article are thinking, but what if I don't have somebody to explain what I'm learning?</p>
<p>That's not a problem. You can use a variety of methods to explain what you've learned, including:</p>
<p><strong>Technical writing:</strong> You don't have to be a great writer to start writing. All you have to do is start getting knowledge down on paper, so to speak. </p>
<p>Open platforms like dev.to, Hashnode, and Medium make it easy to share what you learn. So sign up for one of the platforms and begin writing. Also, you can check out Google's free technical writing <a target="_blank" href="https://developers.google.com/tech-writing">course</a>.</p>
<p><strong>Join online communities:</strong> Join online communities to share what you have learned. When you join online developer groups, you'll meet people who share your interests. This can help you become comfortable sharing and answering questions. </p>
<p>A fantastic developer community to join is the freeCodeCamp online <a target="_blank" href="https://forum.freecodecamp.org">forum</a>. You can also use social media platforms like YouTube, TikTok, Twitter, and so on.</p>
<p><a target="_blank" href="https://twitter.com/i/communities/1532313139810906114">You can also join my community for developers</a> on Twitter to ask questions, share ideas, and more.</p>
<p>Another way you can explain what you've learned is by doing it in front of an imaginary audience. Pretend you're teaching a group of 12-year-olds about JavaScript loops.</p>
<p>Teaching to an imaginary audience might be fun, but they cannot ask questions. This learning method works best when you use a real audience because they can ask questions.</p>
<p>When your audience asks you questions, you get to identify areas in which you need to improve.</p>
<p><strong>Fun tip:</strong> you can also try out the <a target="_blank" href="https://www.freecodecamp.org/news/rubber-duck-debugging/">rubber duck technique</a>, where you explain your code to a rubber duck (or another inanimate object) to make sure you've thought it through clearly.</p>
<h3 id="heading-step-3-review-your-explanation">Step 3 - Review Your Explanation</h3>
<p>Step 2 will help you identify specific areas where you need to improve. And then in step 3, you can review how you explained the topic to see what you could do better.</p>
<p>Review your loop explanation and identify areas where you think it fell short. Now that you know where you fell short, go back over your learning material to understand better. </p>
<p>Consider using other learning resources if possible. Study until everything you couldn't explain before is clearer to you.</p>
<p>Step 3's goal is to change your areas of weakness into your areas of strength.</p>
<h3 id="heading-step-4-simplify-your-explanation">Step 4 - Simplify Your Explanation</h3>
<p>As a result of step 3, you now have a better knowledge of JavaScript loops. Step 4 requires you to practice step 2 again with your new understanding of loops.</p>
<p>Take up your notes and simplify every area of loops you couldn't explain before. Rewrite your loops article or give someone else a better explanation.</p>
<p>You can also pretend you're teaching a group of 12-year-olds again about JavaScript loops. If you cannot explain a particular part of the topic, go back to step 3 to understand it better.</p>
<p>This method of learning works best for topics that are tough to understand. It is not an effective learning method if you already understand a concept.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>This learning style is all about understanding a topic to the point where you can explain it in your own words. When you describe it, act as though you're educating a child to see how well you know the subject.</p>
<p>Also, keep in mind that you can use this learning method to study any concepts that you find difficult.</p>
<p>Thank you for reading. I hope you enjoyed the article! If you have any questions or a learning strategy you would love to share? Send a message on <a target="_blank" href="https://twitter.com/Cessss_">Twitter</a> or <a target="_blank" href="https://www.linkedin.com/in/success-eriamiantoe">LinkedIn</a>.</p>
<h2 id="heading-resources">Resources</h2>
<p>Here are some resources that may be useful to you:</p>
<ul>
<li><a target="_blank" href="https://cesscode.hashnode.dev/what-are-the-different-javascript-loops">What are the different JavaScript Loops?</a></li>
<li><a target="_blank" href="https://twitter.com/i/communities/1532313139810906114">Twitter Community for Developers</a></li>
<li><a target="_blank" href="https://medium.com/taking-note/learning-from-the-feynman-technique-5373014ad230">Learning From the Feynman Technique</a></li>
<li><a target="_blank" href="https://cesscode.hashnode.dev/getting-work-done-with-the-pomodoro-technique">Getting work done with the Pomodoro Technique</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Prepare for Technical Interviews – Problem-Solving Tips + Mindset Tricks to Get You Ready ]]>
                </title>
                <description>
                    <![CDATA[ Hi everyone! In this article we're going to talk a bit about technical interviews. I'll share a few tips that, based on my experience, might help you go through these interviews successfully. I originally wrote this article more than a year ago, befo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/problem-solving-and-technical-interview-prep/</link>
                <guid isPermaLink="false">66d45f1ad1ffc3d3eb89ddf7</guid>
                
                    <category>
                        <![CDATA[ Interview tips ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Interviewing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mindset ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ German Cocca ]]>
                </dc:creator>
                <pubDate>Mon, 06 Jun 2022 22:50:19 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/06/pexels-christina-morillo-1181345.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hi everyone! In this article we're going to talk a bit about technical interviews. I'll share a few tips that, based on my experience, might help you go through these interviews successfully.</p>
<p>I originally wrote this article more than a year ago, before getting my first job offer as a developer.</p>
<p>I'm sharing this with you now because I recently went through another interview process. And I found that the same concepts and thoughts that helped me get my first job offer allowed me to pass all the interviews successfully again. 🙂</p>
<h2 id="heading-my-background">My Background</h2>
<p>I took up coding more or less a year ago. I started learning out of pure curiosity, and as I learned more about it and was able to build personal projects, I just fell in love with it.</p>
<p>I got so obsessed and passionate about it that I dedicated all the free time I had to coding, reading about code, watching videos about code, and just learning as much as I possible could, because for me it was fun and interesting!</p>
<p>Time passed and at a point I started imagining myself working as a developer. First it was like a blurry thought, and then I started thinking about it seriously and learning about what I needed to do to get to that point.</p>
<p>My learning journey and the approach I took towards becoming a dev will probably be the subject of another article, but my point is that I made it! I recently got an offer for my first job as a full time developer and I couldn’t be happier about it.</p>
<p>And there were many things and learning experiences I had to go through to get to this point, but I’d say the toughest one – and the one I was less prepared for – was technical interviews.</p>
<h3 id="heading-what-are-technical-interviews-like">What are Technical Interviews Like?</h3>
<p>I come from a social sciences background, and most of the time, within that field, there’s nothing too “technical” to talk about during interviews. Employers normally hire you based on your experience and behavior during interviews.</p>
<p>But in the coding field it’s really different. Experience is valuable, of course, but employers also value projects you can show to them, theoretical knowledge about different programming topics, and, most of all, the problem solving skills you can show off during technical interviews.</p>
<p>In almost all selection processes I went through, there was a technical interview in which an interviewer tossed me a problem and I had to solve it live with them looking at me the whole time.</p>
<p>This is a standard practice for coding jobs, but I wasn’t prepared at all. I failed miserably more than once, and these experiences were some of the most embarrassing and frustrating moments in my professional life so far.</p>
<p>At times I felt stupid for even thinking I’d be capable of switching careers at almost 30. I thought I just wasn’t smart enough. But luckily I kept going, researched about technical interviews, learned, practiced, and kept failing until I didn’t fail anymore.</p>
<p>Technical interviews are tough and can be really stressful if you’re not prepared correctly. Also, even though I successfully passed a selection process, I know I still have a lot to learn about this and that I’ll need to perfect this skill to further grow my career in the future. So here are my main tips for nailing your technical interviews.</p>
<h2 id="heading-1-prepare-for-the-interview"><strong>1. Prepare for the Interview</strong></h2>
<p>This is important for all kind of interviews, but for technical interviews I think it’s crucial. Your chances of passing these evaluations are way lower if you don’t prepare correctly for them.</p>
<p>Here are some ideas that allowed me to better prepare for these interviews.</p>
<h3 id="heading-do-your-research">Do Your Research</h3>
<p>Find out about technical interviews in general, how are they normally organized, what interviewers ask and what do they intend to measure, what kind of problems do companies toss at you, and what are the best approaches towards interviews.</p>
<p>The internet is an infinite resource of knowledge, so don’t waste it! Google about everything you can and take advantage of the experience of the thousands of people who have gone through similar situations and share their experiences.</p>
<h3 id="heading-practice-solving-problems">Practice Solving Problems</h3>
<p>Problem solving is a skill just like any other. There is specific knowledge you’ll need to get good at it, but most of it is practice and getting your brain to be comfortable in that situation.</p>
<p>There are tons of websites that contain the types of problems you’ll see during interviews. <a target="_blank" href="https://www.freecodecamp.org/learn/coding-interview-prep/">freeCodeCamp has an amazing course designed for this.</a> Some other cool resources are <a target="_blank" href="https://www.hackerrank.com/">hackerrank.com</a>, <a target="_blank" href="https://leetcode.com/">leetcode.com</a>, <a target="_blank" href="https://www.codewars.com/">codewars.com</a>, <a target="_blank" href="https://exercism.io/">exercism.io</a>, <a target="_blank" href="https://app.codesignal.com/">app.codesignal.com</a>, and <a target="_blank" href="https://www.algoexpert.io/">algoexpert.io</a>.</p>
<p>Solve as many problems as you can from any of these sites and you’ll start getting good at them.</p>
<p>And when you practice, at first it’s okay to just worry about solving the problem. But once you get comfortable enough, a great idea is to try to make your practice as similar as possible to an actual interview. And by this I mean setting a timer, explaining your solution out loud, analyzing your final algorithm and refactoring…just basically following all the steps you’d normally follow in an actual interview.</p>
<p>If your practice is similar to the actual situation, once you get to that situation you’ll feel more confident because in some way you’ve already been there.</p>
<h3 id="heading-build-a-theoretical-foundation">Build a Theoretical Foundation</h3>
<p>Besides actually practicing, learning theoretical concepts about algorithms and data structures is a great idea to get better at solving these problems.</p>
<p>Think about it as adding tools to your toolbox. The more tools and concepts you have in your mind, the more problems will sound familiar or ring a bell in your brain, and from that you'll be more able to arrive at a solution.</p>
<p>There are many resources on the internet, some free and some paid. A course about data structures and algorithms is pretty much a must for any programmer, so I encourage you to find a good one. Here are a couple you can start with:</p>
<ul>
<li><p><a target="_blank" href="https://www.freecodecamp.org/news/learn-all-about-data-structures-used-in-computer-science/">Data Structures Explained</a></p>
</li>
<li><p><a target="_blank" href="https://www.freecodecamp.org/news/learn-data-structures-from-a-google-engineer/">Learn Data Structures from a Google Engineer</a></p>
</li>
<li><p><a target="_blank" href="https://www.freecodecamp.org/news/learn-algorithms-and-data-structures-in-python/">Learn Algorithms and Data Structures in Python</a></p>
</li>
<li><p><a target="_blank" href="https://www.freecodecamp.org/news/algorithms-and-data-structures-free-treehouse-course/">Learn about Algorithms and Data Structures</a></p>
</li>
</ul>
<p>Of course also theoretical knowledge about your programming language of choice and any other tools in your stack (frameworks, libraries, databases, and so on) is also very important.</p>
<h3 id="heading-imitate-others">Imitate Others</h3>
<p>It’s ok to run into problems you don’t know how to solve or to come up with solutions that are not the best suited ones.</p>
<p>In these type of situations, or always actually, it’s a good idea to take a look at how other people solved that same problem and learn from them. What approach did they take? What ideas did they have? Did they get stuck? How did they move towards the solution?</p>
<p>Analyze their solution and their behavior, identify what works for them, think if that could work for you and if the answer is yes, copy them! It’s crucial that you deeply understand why their solution works and how their logic works. You want to internalize the logical approach, not the code, as that’s just an after effect.</p>
<p>Looking at problem solutions and videos of mock interviews is a good idea to get this kind of data.</p>
<h3 id="heading-understand-what-kind-of-interview-youll-have">Understand What Kind of Interview You'll Have</h3>
<p>I mentioned the most classic type of technical interview is the one based on algorithms and data structures, in which the interviewer will give you a problem to solve through an algorithm.</p>
<p>But I found that there're also interviews that are mostly theoretical, in the sense that the interviewer will ask questions to measure your knowledge about a given programming language, framework, library, design and architecture patterns, and so on.</p>
<p>Another kind of interview is where the interviewer shows you an actual project or asks you to build one. During the interview you discuss the decisions you made to build it or implement new features/modifications on it.</p>
<p>Each kind of interview is different and might require different preparation, so it's always a good idea to ask the company what will the interview be based on, and prepare accordingly.</p>
<h2 id="heading-2-breathe-and-think-things-through"><strong>2. Breathe and Think Things Through</strong></h2>
<p>Once you've seen and gone through a ton of examples and start feeling somewhat confident around coding problems, it’s time to get to the deeper stuff.</p>
<p>Here are some tips that helped me go through the interviews successfully.</p>
<h3 id="heading-dont-code">Don’t code</h3>
<p>This sounds crazy right? The best approach to solving most coding problems is actually not coding, or at least <strong>not right away</strong>.</p>
<p>No matter how anxious or secure you are about the idea you have in mind, I find it better to always take a step back and make sure you understand things deeply before going to the details and breaking out the code.</p>
<p>So how do you do that?</p>
<h3 id="heading-understand-the-problem">Understand the Problem</h3>
<p>The first step to solving a problem is actually understanding it. And to understand it, the best idea is to “make it yours”, and internalize it.</p>
<p>A good idea is to read the exercise twice, repeat it again in your own words, and go through multiple examples (simple ones, complex ones, examples with null or invalid inputs…).</p>
<p>No matter how silly, complex or simple the problem may seem, this helps you make sure you understand it properly and gives your brain data and time to come up with solution ideas.</p>
<h3 id="heading-make-sure-you-understood-it">Make Sure You Understood It</h3>
<p>Repetitive? Yeah, but effective. Check and make sure you understood what you need to do and how your function will work.</p>
<p>Ask yourself, what are the inputs going to be? What will be the output? Check for edge cases. Will you always receive the same input or could you expect different formats? Do you have to be prepared for strange cases or does the exercise restrict the kind of situation you’ll encounter?</p>
<p>It’s better to clear out all this things before even starting to think about a solution.</p>
<h3 id="heading-explore-your-toolbox">Explore Your Toolbox</h3>
<p>I said that learning theoretical concepts and practicing is like adding tools to your problem solving toolbox. When you see a new problem, it’s a good idea to explore that toolbox and see if any of the concepts or solutions you’ve used in the past could work here.</p>
<p>Could it help to use some sort of counter? What about implementing some sort of data structure to help you out? Could you use pointers or a sliding window? Would it be a good idea to take a divide and conquer approach? What about recursion? Could sorting the input help for anything?</p>
<p>You don’t necessarily have to know the exact path to take, but comparing the problem to previous patterns you’ve seen can help spark ideas in your mind.</p>
<p>Of course the more you practice solving problems and learning about possible solutions, the more patterns you’ll have to remember and compare.</p>
<h3 id="heading-break-down-the-problem">Break Down the Problem</h3>
<p>Once you’ve analyzed the problem deeply, hopefully you’ll have at least an idea of how to tackle it, or where to start.</p>
<p>A great idea here is to try to think about the different steps you need to take to get to your solution and write down those steps to analyze them, check if your logic is correct, and later use them as little memory helpers and “instructions” for you to translate into code.</p>
<p>Simplifying your solution through steps and specially writing them down will often help you identify flaws in your logic or cases you didn’t think about before.</p>
<p>This is great because you’re at a stage when it’s really easy to modify your approach or lean towards a different idea. You didn’t waste time coding or getting yourself into a maze of logic that doesn’t actually work.</p>
<h3 id="heading-simplify-the-problem">Simplify the Problem</h3>
<p>Specially when facing complex and difficult problems, a good idea is to first ignore the main difficulty of the problem and try to solve a similar, simpler version of it.</p>
<p>When you nail that solution, bring the main difficulty back and see if you can translate your solution to it.</p>
<h3 id="heading-visualize-the-problem">Visualize the Problem</h3>
<p>Complex problems are sometimes difficult to get your head around. Having a whiteboard, either a physical or a digital one, is always a great idea.</p>
<p>Visually stimulating your brain by drawing up the problem or an idea can be a good approach to buy yourself some time and see if that perspective shows you some data you didn’t notice.</p>
<h3 id="heading-start-to-write-your-code">Start to Write Your Code</h3>
<p>So once you have a clear idea of the steps you’ll need to cover to get to the solution, it’s time for translating that into code. This should be the simple part if you’re comfortable enough with the language.</p>
<p>A thought to keep in mind here is that if you can’t remember something very specific, don’t let that hold you down – pseudo code it and carry on with the rest of the solution.</p>
<p>Talk to your interviewer and see if they can help you with that part, or ask if they'll let you Google it. In most cases this will be ok and the important thing will be to show that you nailed the correct logic to solve the problem.</p>
<h3 id="heading-test-your-code">Test Your Code</h3>
<p>Test your solution at every step and at the end. There’s nothing more annoying than writing a ton of code and later seeing it fail without knowing the exact cause.</p>
<p>Test your code and your logic at every step of the solution, as this will allow you to catch bugs earlier and will save you from wasting time and effort.</p>
<p>Of course testing at the end is important to check if your solution actually works! So throw your function different inputs and edge cases to see if it behaves as expected.</p>
<h3 id="heading-analyze-the-solution">Analyze the Solution</h3>
<p>Once you've gotten to the solution, you’re not done yet. It’s a great idea to show your interviewer you can analyze what you did too.</p>
<p>Ask yourself and tell them, what’s the big O complexity of your solution? Can you think of a way to improve the performance or the memory usage of your algorithm? Is there a way to make your function easier to read and understand?</p>
<p>Even if you can’t think about how to code it exactly, it’s great to show them that you’re the kind of developer who is always going to look for improvements and not settle for something that just works.</p>
<h3 id="heading-improve-your-solution">Improve Your Solution</h3>
<p>Of course, if you can find ways to optimize your solution and know how to code it, do it!</p>
<p>And about this, in a coding interview situation you’ll rarely come up with the perfect solution for a problem. You’re under pressure and on the clock, so it’s perfectly ok to come up with a so-so solution and then refactor it until it reaches an acceptable level.</p>
<p>It’s often better to show you can solve the problem even if not in the perfect way than spend all your time just thinking about the perfect solution.</p>
<h3 id="heading-talk-to-your-interviewer">Talk to Your Interviewer</h3>
<p>Talk with your interviewer during the whole process. What your interviewer is trying to measure is your problem solving ability and your level of comfort with your programming language of choice.</p>
<p>That is a hard thing to measure if you don’t open your mouth and just code away.</p>
<p>It’s crucial that you talk to your interviewer and let them know what you’re thinking, what is your thought process, what ideas are you having, how are you understanding the problem, what logic are you going to follow with your solution and why are you making decisions.</p>
<p>Talk to them, ask questions, explain yourself, and if you get stuck or don’t know how to go on, explain to them exactly the thing that is giving you trouble. In most cases you’ll get some help and more importantly you’ll show them you’re actually trying to work towards a solution.</p>
<h3 id="heading-listen-to-your-interviewer">Listen to Your Interviewer</h3>
<p>When you’re being given the problem to solve – and specially if you get tips or feedback from your interviewers – pay attention! No matter if you think you already have the best idea or if there’s something that’s driving you crazy and need to solve right now, just drop it and listen to what you’re being told.</p>
<p>If you don’t listen to feedback, you’re giving a very negative signal to your possible future employers. Think about it: would you like to work with someone that doesn’t listen to feedback? Besides, feedback will certainly help you solve your problem, so listen!</p>
<h2 id="heading-3-control-your-emotions"><strong>3. Control Your Emotions</strong></h2>
<p>This for me was the toughest part of the interviewing process, and it's something I didn’t really find a lot of information about when researching technical interviews.</p>
<p>Dealing with the anxiety and frustration these situations can provoke is hard, but also a crucial step to improve your performance.</p>
<p>So here are some things that have helped me in this regard.</p>
<h3 id="heading-prepare-your-body-and-mind">Prepare Your Body and Mind</h3>
<p>Interviews are stressful situations in which you have to deal with expectations and perform to reach those expectations while being judged by other people.</p>
<p>I’ve always felt uncomfortable in these type of situations so I’m quite familiar with the type of anxiety you might feel.</p>
<p>Something that helps me is try to think about it like the moment of a game for a sports player or when actors get out on stage. You normally see these people trying to warm up and focus before they start to perform, right? There’s a reason for that – and it’s that this preparation actually enhances performance and gets you ready to give your best.</p>
<p>It may sound stupid at first, but stretching, warming up your voice, meditating, imagining the moment in your mind and picturing yourself being successful in the moment are all things that will push you towards doing nicely in this important moment.</p>
<h3 id="heading-be-confident">Be Confident</h3>
<p>Easier said than done, right? Absolutely. Confidence for most people isn’t something you can just turn off and on, but something you build along the way and comes with lots of practice, studying, and preparation behind it.</p>
<p>You'll build confidence with the work you do prior to the interview, but once you’re in the moment it’s important to remember that you want to show the interviewers you have confidence in yourself as a coder and that you trust yourself to solve any problem you face.</p>
<p>This doesn’t mean you have to know absolutely everything and be able to solve any complex problem absolutely by yourself. Rather, it means that you won’t panic when you face something you don’t know how to solve at first, and that you have the ability to slowly analyze the problem, break it down, and work towards a solution.</p>
<h3 id="heading-slow-down">Slow Down</h3>
<p>Stress, anxiety, and the wish to show that you can solve the problem can make you rush more than you need to. And rushing can lead to missing key information, flaws in your logic, bugs in your code, and errors in general.</p>
<p>So take your time, actually, take more time than you actually need. Analyze the heck out of the problem, talk slowly, code slowly, think slowly, and remember to breath. Things are easier to deal with when you take your time and <em>slow-mo</em> the process.</p>
<h3 id="heading-dont-take-it-personally-or-do">Don’t Take it Personally – or Do...</h3>
<p>You’ll mess up at some point, that’s a certainty. Especially in your first interviews, you’ll probably fail and feel miserable about it. It’s just the way it is, and it's a step that is needed for you to understand where you need to improve.</p>
<p>A key issue here is how you deal with that frustration. I could tell you to think about it as a process, to not get mad when you fail, to be patient… But if you’re an anxious and self demanding person as I am, you’ll be very frustrated when you fail, and there’s nothing you can do to avoid it.</p>
<p>But how do you deal with that? Do you get depressed and quit coding forever? Do you get scared of interviews and never apply for a job ever again?</p>
<p>Personally, I get very mad at myself when I fail at something or find out I don’t know something I "was supposed" to know. I get mad at myself for not preparing correctly or for missing things, and even though that anger feels bad at first, later on is something that pushes me forward.</p>
<p>I feel so bad about it that I make absolutely sure I won't fail at that again, and I practice as hard as I can to avoid being in that situation again.</p>
<p>Different approaches work for different people, but the thing is to handle your emotions in a way that pushes you forward and not backwards.</p>
<h3 id="heading-learn-from-your-mistakes">Learn from Your Mistakes</h3>
<p>As it’s a certainty you’ll mess up, the smart thing to do is to learn from the errors you made and try to not make them again.</p>
<p>Always try to take note of the problems you were presented and your solutions, analyze your mistakes, analyze other possible approaches you could have taken, what optimizations you didn’t see, and what key concepts you didn’t remember at that moment.</p>
<p>Also always ask your interviewers for feedback about what you could have done better. This information is gold if you get the best of it.</p>
<h3 id="heading-have-fun">Have Fun</h3>
<p>If you love coding, you probably have lots of fun doing it. Never forget that, no matter the context.</p>
<p>In interviews, try to approach each problem with curiosity rather than fear of failing. Try to show your interviewers you’re enthusiastic about problems, because you’re probably going to work with similar stuff on a daily basis.</p>
<p>Plus if you’re having fun and thinking in a positive way, you’ll be more relaxed and your mind will be clearer, which of course helps your problem solving skills.</p>
<h3 id="heading-keep-going">Keep Going</h3>
<p>If you pass or if you fail, at the end it doesn’t matter, in the sense that your approach and behavior should stay the same.</p>
<p>Just as code can always be improved, so can you as a programmer. You should always keep learning, keep getting better, keep practicing, keep facing stuff you didn’t know anything about and eventually overcoming it.</p>
<p>So don’t get too high if you pass or too low if you miss – just keep coding and keep learning.</p>
<h1 id="heading-roundup"><strong>Roundup</strong></h1>
<p>As always, I hope you enjoyed the article and learned something new. If you want, you can also follow me on <a target="_blank" href="https://www.linkedin.com/in/germancocca/">LinkedIn</a> or <a target="_blank" href="https://twitter.com/CoccaGerman">Twitter</a>.</p>
<p>See you later!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/see-you-soon-see-you.gif" alt="Image" width="600" height="400" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Fix Google Chrome Black Screen on Linux OS (Wayland) ]]>
                </title>
                <description>
                    <![CDATA[ If you are a Linux user, then you've likely used the GNOME Desktop Environment at least once. The latest GNOME DE (Desktop Environment) uses Wayland nowadays. And while it's possible to remove Wayland and select Xorg if you want, most users are start... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-fix-black-screen-on-google-chrome-on-linux-os/</link>
                <guid isPermaLink="false">66b902da5730a049b6bfea7a</guid>
                
                    <category>
                        <![CDATA[ Google Chrome ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Md. Fahim Bin Amin ]]>
                </dc:creator>
                <pubDate>Wed, 27 Apr 2022 19:33:58 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/Fix---1-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you are a Linux user, then you've likely used the GNOME Desktop Environment at least once.</p>
<p>The latest GNOME DE (Desktop Environment) uses Wayland nowadays. And while it's possible to remove Wayland and select Xorg if you want, most users are starting to use Wayland as their daily driver. </p>
<p>And if you still use the Chrome or Chromium browsers, you'll often face the black screen issue during screen sharing.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Untitled-design.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If you typically use Wayland on your desktop, you'll have these issues while screen sharing, especially in Google Meet. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Untitled-design--1-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In this article, I will show you a very simple trick that will help you solve the black screen issue during screen sharing on any kind of Chromium browser including the most popular browser, Google Chrome. </p>
<p>I have used Ubuntu for writing this article, but the same process is applicable to all other Linux OS distros running on Wayland.</p>
<h2 id="heading-the-black-screen-issue">The Black Screen Issue</h2>
<p>If you're having the black screen issue in Google Meet in a Chromium browser (Chrome, Brave, Vivaldi, etc), it probably looks like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-38-51.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Sometimes it might happen because screen sharing in Wayland gets broken or because of other issues. A lot of users also say it happens as developers are trying hard to increase the security level. </p>
<p>The issue of screen sharing might become common for many people in the usual way. A lot of users go back to X11 only for this issue or try the pipewire solution to fix this.</p>
<p>I will show you the solution using the pipewire technology so that you do not need to go back to X11 only for solving this issue. 😊</p>
<p>Go to <strong><code>chrome://flags/#enable-webrtc-pipewire-capturer</code></strong> using the address bar of your browser.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-39-23.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You will get a long list, but we are interested in <strong>WebRTC PipeWire Support</strong>. You will see that the option is on the Default mode right now.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-39-31.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We need to change it to <strong>Enabled</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-39-40.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Simply click the drop down menu, and click <strong>Enabled</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-39-54.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now you will see a prompt on the below right side to relaunch the browser so this can take effect.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-39-54-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Click on <strong>Relaunch</strong>. It will simply restart your browser.</p>
<p>The issue has been solved! ✌️</p>
<h2 id="heading-how-to-test-screen-sharing">How to Test Screen Sharing</h2>
<p>Now if you want to share your screen as usual, you can definitely do that. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-40-27.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Whenever you want to share the screen, a prompt will appear and will request you to select the monitor. You have to share the monitor. If you have only one monitor like I do, then you would get one monitor. Simply click on that and click <strong>Share</strong>. </p>
<p>You will also get to see the preview of the screen sharing.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-40-40.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You may need to select the monitor again in the prompt. Simply select the monitor and click Share as earlier.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-40-47.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>From now on, you can share your screen on Google Meet from Wayland.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-from-2022-04-25-19-41-07.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>If this article helps you resolve the black screen issue for your Linux DE, then I've been successful. 😊</p>
<p>Thanks for reading the entire article. If it helps you then you can also check out other articles of mine at <a target="_blank" href="https://www.freecodecamp.org/news/author/fahimbinamin/">freeCodeCamp</a>.</p>
<p>If you want to get in touch with me, then you can do so using <a target="_blank" href="https://twitter.com/Fahim_FBA">Twitter</a>, <a target="_blank" href="https://www.linkedin.com/in/fahimfba/">LinkedIn</a>, and <a target="_blank" href="https://github.com/FahimFBA">GitHub</a>. </p>
<p>You can also <a target="_blank" href="https://www.youtube.com/@FahimAmin?sub_confirmation=1">SUBSCRIBE to my YouTube channel</a> (Code With FahimFBA) if you want to learn various kinds of programming languages with a lot of practical examples regularly.</p>
<p>If you want to check out my highlights, then you can do so at my <a target="_blank" href="https://www.polywork.com/fahimbinamin">Polywork timeline</a>.</p>
<p>You can also <a target="_blank" href="https://fahimbinamin.com/">visit my website</a> to learn more about me and what I'm working on.</p>
<p>Thanks a bunch!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Debug Applications with Strace, Python, and Wireshark ]]>
                </title>
                <description>
                    <![CDATA[ In this article I will show you a few techniques you can use to troubleshoot a program when is not behaving. This list is not universal and, depending on what you are looking for, it may not be enough to solve your problem. But it should be a good st... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/debug-an-app-with-strace-python-wireshark/</link>
                <guid isPermaLink="false">66d85136f5638bdd06059a55</guid>
                
                    <category>
                        <![CDATA[ debugging ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jose Vicente Nunez ]]>
                </dc:creator>
                <pubDate>Tue, 26 Apr 2022 00:23:26 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/pexels-egor-kamelev-3819742.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this article I will show you a few techniques you can use to troubleshoot a program when is not behaving.</p>
<p>This list is not universal and, depending on what you are looking for, it may not be enough to solve your problem. But it should be a good start.</p>
<p>Before we start you should be familiar with a few things:</p>
<ul>
<li><p>How to run commands on Linux</p>
</li>
<li><p>Protocols like DNS, HTTP, and TLS</p>
</li>
<li><p>A scripting language like Python</p>
</li>
</ul>
<p>Don't worry too much. I will give you enough information so you can follow along with the tutorial.</p>
<p>And what will you learn?</p>
<ul>
<li><p>Basic usage of strace, nslookup, and RPM</p>
</li>
<li><p>How to use some interesting features of the Python debugger</p>
</li>
<li><p>How to analyze traffic with Wireshark</p>
</li>
</ul>
<h2 id="heading-the-problem-failing-to-upload-a-file-to-asciinema"><strong>The Problem: Failing to upload a file to asciinema</strong></h2>
<p>So I recorded an asciicast, using the cool Open Source project <a target="_blank" href="https://asciinema.org/docs/usage">asciinema</a>, for my small Open Source project <a target="_blank" href="https://pypi.org/project/SuricataLog">SuricataLog</a>. Then I decided to share it with the world.</p>
<p>But unlike the other recordings, this one refused to be uploaded:</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ asciinema upload demo-ascii.cast 
asciinema: upload failed: &lt;urlopen error [Errno <span class="hljs-number">32</span>] Broken pipe&gt;
asciinema: retry later by running: asciinema upload demo-ascii.cast
</code></pre>
<p>Asciinema doesn't tell us much about the error. For example:</p>
<ul>
<li><p>What server and port does the tool try to use to upload the file?</p>
</li>
<li><p>Which part of the protocol handshake is failing?</p>
</li>
<li><p>Is the destination a problem or is it an issue on my side?</p>
</li>
</ul>
<p>We will use a few tools to see what is going on here.</p>
<h2 id="heading-how-to-run-the-program-with-strace"><strong>How to run the program with strace</strong></h2>
<p>What is <a target="_blank" href="https://strace.io/">strace</a>?</p>
<blockquote>
<p>strace is a diagnostic, debugging, and instructional userspace utility for Linux. It is used to monitor and tamper with interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes of process state.</p>
<p>System administrators, diagnosticians, and troubleshooters will find it invaluable for solving problems with programs for which the source is not readily available since they do not need to be recompiled in order to trace them.</p>
</blockquote>
<p>strace is super useful when you don't have the source code of an application and yet you need to understand what is wrong when you call a program. Time to see it in action:</p>
<pre><code class="lang-python">josevnz@dmaf5 SuricataLog]$ strace asciinema upload demo-ascii.cast
xecve(<span class="hljs-string">"/usr/bin/asciinema"</span>, [<span class="hljs-string">"asciinema"</span>, <span class="hljs-string">"upload"</span>, <span class="hljs-string">"demo-ascii.cast"</span>], <span class="hljs-number">0x7ffdcddb1160</span> /* <span class="hljs-number">55</span> vars */) = <span class="hljs-number">0</span>
brk(NULL)                               = <span class="hljs-number">0x55e912d58000</span>
arch_prctl(<span class="hljs-number">0x3001</span> /* ARCH_??? */, <span class="hljs-number">0x7fff2f136480</span>) = <span class="hljs-number">-1</span> EINVAL (Invalid argument)
access(<span class="hljs-string">"/etc/ld.so.preload"</span>, R_OK)      = <span class="hljs-number">-1</span> ENOENT (No such file <span class="hljs-keyword">or</span> directory)
openat(AT_FDCWD, <span class="hljs-string">"/etc/ld.so.cache"</span>, O_RDONLY|O_CLOEXEC) = <span class="hljs-number">3</span>
fstat(<span class="hljs-number">3</span>, {st_mode=S_IFREG|<span class="hljs-number">0644</span>, st_size=<span class="hljs-number">92299</span>, ...}) = <span class="hljs-number">0</span>
mmap(NULL, <span class="hljs-number">92299</span>, PROT_READ, MAP_PRIVATE, <span class="hljs-number">3</span>, <span class="hljs-number">0</span>) = <span class="hljs-number">0x7f69dd26a000</span>
close(<span class="hljs-number">3</span>)                                = <span class="hljs-number">0</span>
<span class="hljs-comment"># </span>
<span class="hljs-comment"># Commented out LOTS output</span>
<span class="hljs-comment"># ...</span>
close(<span class="hljs-number">4</span>)                                = <span class="hljs-number">0</span>
socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_IP) = <span class="hljs-number">4</span>
connect(<span class="hljs-number">4</span>, {sa_family=AF_INET, sin_port=htons(<span class="hljs-number">443</span>), sin_addr=inet_addr(<span class="hljs-string">"109.107.38.233"</span>)}, <span class="hljs-number">16</span>) = <span class="hljs-number">0</span>
getsockname(<span class="hljs-number">4</span>, {sa_family=AF_INET, sin_port=htons(<span class="hljs-number">33771</span>), sin_addr=inet_addr(<span class="hljs-string">"192.168.1.22"</span>)}, [<span class="hljs-number">28</span> =&gt; <span class="hljs-number">16</span>]) = <span class="hljs-number">0</span>
connect(<span class="hljs-number">4</span>, {sa_family=AF_UNSPEC, sa_data=<span class="hljs-string">"\0\0\0\0\0\0\0\0\0\0\0\0\0\0"</span>}, <span class="hljs-number">16</span>) = <span class="hljs-number">0</span>
connect(<span class="hljs-number">4</span>, {sa_family=AF_INET, sin_port=htons(<span class="hljs-number">443</span>), sin_addr=inet_addr(<span class="hljs-string">"109.107.37.0"</span>)}, <span class="hljs-number">16</span>) = <span class="hljs-number">0</span>
getsockname(<span class="hljs-number">4</span>, {sa_family=AF_INET, sin_port=htons(<span class="hljs-number">35023</span>), sin_addr=inet_addr(<span class="hljs-string">"192.168.1.22"</span>)}, [<span class="hljs-number">28</span> =&gt; <span class="hljs-number">16</span>]) = <span class="hljs-number">0</span>
close(<span class="hljs-number">4</span>)                                = <span class="hljs-number">0</span>
socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = <span class="hljs-number">4</span>
connect(<span class="hljs-number">4</span>, {sa_family=AF_INET, sin_port=htons(<span class="hljs-number">443</span>), sin_addr=inet_addr(<span class="hljs-string">"109.107.38.233"</span>)}, <span class="hljs-number">16</span>) = <span class="hljs-number">0</span>
setsockopt(<span class="hljs-number">4</span>, SOL_TCP, TCP_NODELAY, [<span class="hljs-number">1</span>], <span class="hljs-number">4</span>) = <span class="hljs-number">0</span>
getsockopt(<span class="hljs-number">4</span>, SOL_SOCKET, SO_TYPE, [<span class="hljs-number">1</span>], [<span class="hljs-number">4</span>]) = <span class="hljs-number">0</span>
getsockname(<span class="hljs-number">4</span>, {sa_family=AF_INET, sin_port=htons(<span class="hljs-number">55682</span>), sin_addr=inet_addr(<span class="hljs-string">"192.168.1.22"</span>)}, [<span class="hljs-number">128</span> =&gt; <span class="hljs-number">16</span>]) = <span class="hljs-number">0</span>
ioctl(<span class="hljs-number">4</span>, FIONBIO, [<span class="hljs-number">0</span>])                  = <span class="hljs-number">0</span>
getpeername(<span class="hljs-number">4</span>, {sa_family=AF_INET, sin_port=htons(<span class="hljs-number">443</span>), sin_addr=inet_addr(<span class="hljs-string">"109.107.38.233"</span>)}, [<span class="hljs-number">16</span>]) = <span class="hljs-number">0</span>
getpid()                                = <span class="hljs-number">45070</span>
getpid()                                = <span class="hljs-number">45070</span>
getpid()                                = <span class="hljs-number">45070</span>
getpid()                                = <span class="hljs-number">45070</span>
getpid()                                = <span class="hljs-number">45070</span>
getpid()                                = <span class="hljs-number">45070</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\26\3\1\2\0\1\0\1\374\3\3\327\2*\v\316GT*\262\207\235\264\317\254\37$|,V\205\362"</span>..., <span class="hljs-number">517</span>) = <span class="hljs-number">517</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\26\3\3\0z"</span>, <span class="hljs-number">5</span>)                = <span class="hljs-number">5</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\2\0\0v\3\3E\217G?\335.;\212\237pn\16\257$\2\324J\324y\17\306\263\325i\264p"</span>..., <span class="hljs-number">122</span>) = <span class="hljs-number">122</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\24\3\3\0\1"</span>, <span class="hljs-number">5</span>)               = <span class="hljs-number">5</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\1"</span>, <span class="hljs-number">1</span>)                        = <span class="hljs-number">1</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3\0\27"</span>, <span class="hljs-number">5</span>)              = <span class="hljs-number">5</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"0{}\22t9\264\265\340j\362\30\342\360\234\205\1\370\33\246\1z'"</span>, <span class="hljs-number">23</span>) = <span class="hljs-number">23</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3\17\335"</span>, <span class="hljs-number">5</span>)            = <span class="hljs-number">5</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\17\5\310\261\355\271\227oUaI\366\361]\3\275q)\5{\367z\20\233\345\352k?\371\272\23\237"</span>..., <span class="hljs-number">4061</span>) = <span class="hljs-number">4061</span>
stat(<span class="hljs-string">"/etc/pki/tls/certs/8d33f237.0"</span>, <span class="hljs-number">0x7ffd20be3620</span>) = <span class="hljs-number">-1</span> ENOENT (No such file <span class="hljs-keyword">or</span> directory)
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3\1\31"</span>, <span class="hljs-number">5</span>)              = <span class="hljs-number">5</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"t\27\337\366G6\226Qs\273\327\314,\205\221\222Xu\233\21%\0s\340\270\224\330\t\2774\222h"</span>..., <span class="hljs-number">281</span>) = <span class="hljs-number">281</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3\0005"</span>, <span class="hljs-number">5</span>)              = <span class="hljs-number">5</span>
read(<span class="hljs-number">4</span>, <span class="hljs-string">"\204{\314\232\311\0P-*$\245\315\271\236c\210N\315\5\371\364\23\235\16\0350N0K\246\336\374"</span>..., <span class="hljs-number">53</span>) = <span class="hljs-number">53</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\24\3\3\0\1\1\27\3\3\0005\361\311\347\t\254m#\273\204\350\16\343\34P\320sS\211\30\232&lt;"</span>..., <span class="hljs-number">64</span>) = <span class="hljs-number">64</span>
ioctl(<span class="hljs-number">4</span>, FIONBIO, [<span class="hljs-number">0</span>])                  = <span class="hljs-number">0</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3\1\251\271\2673-\30\313\253\363\320H0\224\370Q\353(#?,\216\3\341\315|J\353\303"</span>..., <span class="hljs-number">430</span>) = <span class="hljs-number">430</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3@\21\20\221\240\331\2737\10\244pv\312B\n\rn\272\33\336T\216\f\303\374k\177c\25"</span>..., <span class="hljs-number">16406</span>) = <span class="hljs-number">16406</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3@\21\214\30\262\240s\216\240\354e\31\304Q\337Oy\21y\373\241g\311\224)\26\320\10{"</span>..., <span class="hljs-number">16406</span>) = <span class="hljs-number">16406</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3@\21\36\323\240\376\276\224\35\f\10!@\36D\347\33ay\2617Hpv\4d\267y7"</span>..., <span class="hljs-number">16406</span>) = <span class="hljs-number">16406</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3@\21\366x\264\242O2\7?\7\334\221W\24\2\f)\"@\20\375~\354\243W\32\0c"</span>..., <span class="hljs-number">16406</span>) = <span class="hljs-number">16406</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3@\21\354\32W\36\265g\304\314\376\205\315\20\22\10c\333\342\264\330\366SS\4\217\356:V"</span>..., <span class="hljs-number">16406</span>) = <span class="hljs-number">16406</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3@\21\1\274\35\335\271n\235e\202\202\207\221~\313\0y\210\344\312\32r\347\306x]\241C"</span>..., <span class="hljs-number">16406</span>) = <span class="hljs-number">16406</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\27\3\3@\21I\315\202\274\342\274\26\335qx\22-\226\322\320\203\231\274wLB\250\252\2\352\367\""</span>..., <span class="hljs-number">16406</span>) = <span class="hljs-number">8716</span>
write(<span class="hljs-number">4</span>, <span class="hljs-string">"\377\4m\341\317\376SUr\rQ\221\207\22#\262\314B7\33_v\310\271\fl\v\242\fK\v?"</span>..., <span class="hljs-number">7690</span>) = <span class="hljs-number">-1</span> EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=<span class="hljs-number">45070</span>, si_uid=<span class="hljs-number">1000</span>} ---
close(<span class="hljs-number">4</span>)                                = <span class="hljs-number">0</span>
close(<span class="hljs-number">3</span>)                                = <span class="hljs-number">0</span>
write(<span class="hljs-number">2</span>, <span class="hljs-string">"\33[0;31masciinema: upload failed:"</span>..., <span class="hljs-number">76</span>asciinema: upload failed: &lt;urlopen error [Errno <span class="hljs-number">32</span>] Broken pipe&gt;
) = <span class="hljs-number">76</span>
write(<span class="hljs-number">2</span>, <span class="hljs-string">"\33[0;31masciinema: retry later by"</span>..., <span class="hljs-number">79</span>asciinema: retry later by running: asciinema upload demo-ascii.cast
) = <span class="hljs-number">79</span>
munmap(<span class="hljs-number">0x7fa1aa089000</span>, <span class="hljs-number">12447744</span>)        = <span class="hljs-number">0</span>
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=<span class="hljs-number">0x7fa1bad0fa70</span>}, {sa_handler=<span class="hljs-number">0x7fa1baf551d0</span>, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=<span class="hljs-number">0x7fa1bad0fa70</span>}, <span class="hljs-number">8</span>) = <span class="hljs-number">0</span>
munmap(<span class="hljs-number">0x7fa1ac649000</span>, <span class="hljs-number">593920</span>)          = <span class="hljs-number">0</span>
exit_group(<span class="hljs-number">1</span>)                           = ?
+++ exited <span class="hljs-keyword">with</span> <span class="hljs-number">1</span> +++
</code></pre>
<p>Look at this socket call (<code>man 2 getpeername</code>):</p>
<pre><code class="lang-shell">getpeername(4, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("109.107.38.233")}, [16]) = 0
</code></pre>
<p>And below that, as you can see, we are actually writing data to the website and the connection breaks:</p>
<pre><code class="lang-shell">write(4, "\27\3\3@\21\366x\264\242O2\7?\7\334\221W\24\2\f)\"@\20\375~\354\243W\32\0c"..., 16406) = 16406
write(4, "\27\3\3@\21\354\32W\36\265g\304\314\376\205\315\20\22\10c\333\342\264\330\366SS\4\217\356:V"..., 16406) = 16406
write(4, "\27\3\3@\21\1\274\35\335\271n\235e\202\202\207\221~\313\0y\210\344\312\32r\347\306x]\241C"..., 16406) = 16406
write(4, "\27\3\3@\21I\315\202\274\342\274\26\335qx\22-\226\322\320\203\231\274wLB\250\252\2\352\367\""..., 16406) = 8716
write(4, "\377\4m\341\317\376SUr\rQ\221\207\22#\262\314B7\33_v\310\271\fl\v\242\fK\v?"..., 7690) = -1 EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=45070, si_uid=1000} ---
</code></pre>
<p>So who is '109.107.38.233'?:</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ nslookup <span class="hljs-number">109.107</span><span class="hljs-number">.38</span><span class="hljs-number">.233</span>
<span class="hljs-number">233.38</span><span class="hljs-number">.107</span><span class="hljs-number">.109</span>.<span class="hljs-keyword">in</span>-addr.arpa    name = cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-38</span><span class="hljs-number">-233.</span>gb1.brightbox.com.
</code></pre>
<p>You can see on the <a target="_blank" href="https://asciinema.org/about">about</a> webpage that brightbox.com provides the hosting for asciinema.</p>
<p>So what is wrong? It is not that the site is down or unreachable. Can we dig further?</p>
<h2 id="heading-if-i-only-had-the-source-code-deep-diving-with-the-python-debugger"><strong>If I only had the source code – deep diving with the Python debugger</strong></h2>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ file /usr/bin/asciinema
/usr/bin/asciinema: Python script, ASCII text executable
</code></pre>
<p>Oh, yes we do! Ever curious, you open the asciinema script:</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/python3</span>
<span class="hljs-comment"># EASY-INSTALL-ENTRY-SCRIPT: 'asciinema==2.0.2','console_scripts','asciinema'</span>
<span class="hljs-keyword">import</span> re
<span class="hljs-keyword">import</span> sys 

<span class="hljs-comment"># for compatibility with easy_install; see #2198</span>
__requires__ = <span class="hljs-string">'asciinema==2.0.2'</span>

<span class="hljs-keyword">try</span>:
    <span class="hljs-keyword">from</span> importlib.metadata <span class="hljs-keyword">import</span> distribution
<span class="hljs-keyword">except</span> ImportError:
    <span class="hljs-keyword">try</span>:
        <span class="hljs-keyword">from</span> importlib_metadata <span class="hljs-keyword">import</span> distribution
    <span class="hljs-keyword">except</span> ImportError:
        <span class="hljs-keyword">from</span> pkg_resources <span class="hljs-keyword">import</span> load_entry_point


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">importlib_load_entry_point</span>(<span class="hljs-params">spec, group, name</span>):</span>
    dist_name, _, _ = spec.partition(<span class="hljs-string">'=='</span>)
    matches = ( 
        entry_point
        <span class="hljs-keyword">for</span> entry_point <span class="hljs-keyword">in</span> distribution(dist_name).entry_points
        <span class="hljs-keyword">if</span> entry_point.group == group <span class="hljs-keyword">and</span> entry_point.name == name
    )   
    <span class="hljs-keyword">return</span> next(matches).load()


globals().setdefault(<span class="hljs-string">'load_entry_point'</span>, importlib_load_entry_point)


<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    sys.argv[<span class="hljs-number">0</span>] = re.sub(<span class="hljs-string">r'(-script\.pyw?|\.exe)?$'</span>, <span class="hljs-string">''</span>, sys.argv[<span class="hljs-number">0</span>])
    sys.exit(load_entry_point(<span class="hljs-string">'asciinema==2.0.2'</span>, <span class="hljs-string">'console_scripts'</span>, <span class="hljs-string">'asciinema'</span>)())
</code></pre>
<p>The main script was generated with <a target="_blank" href="https://setuptools.pypa.io/en/latest/deprecated/easy_install.html">easy install</a>, which means <code>asciinema.py</code> is just a wrapper around the interesting code. To find out where the interesting stuff is, let's run the script through the Python <a target="_blank" href="https://www.redhat.com/sysadmin/python-debugger-pdb">pdb debugger</a>:</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ python3 -m pdb /usr/bin/asciinema upload demo-ascii.cast 
&gt; /usr/bin/asciinema(<span class="hljs-number">3</span>)&lt;module&gt;()
-&gt; <span class="hljs-keyword">import</span> re
(Pdb) n
&gt; /usr/bin/asciinema(<span class="hljs-number">4</span>)&lt;module&gt;()
-&gt; <span class="hljs-keyword">import</span> sys
(Pdb) c
asciinema: upload failed: &lt;urlopen error [Errno <span class="hljs-number">32</span>] Broken pipe&gt;
asciinema: retry later by running: asciinema upload demo-ascii.cast
The program exited via sys.exit(). Exit status: <span class="hljs-number">1</span>
</code></pre>
<p>Not quite what we need. The program runs, hits the exception, and then it restarts at the beginning.</p>
<p>Let's cheat a little. Was asciinema installed with an RPM (I use Fedora Linux)?</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ rpm -qif /usr/bin/asciinema
Name        : asciinema
Version     : <span class="hljs-number">2.0</span><span class="hljs-number">.2</span>
Release     : <span class="hljs-number">6.</span>fc33
</code></pre>
<p>And we are trying to upload a file, anything that looks like an uploader?</p>
<pre><code class="lang-python">josevnz@dmaf5 SuricataLog]$ rpm -qil asciinema|grep -i uploa
/usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/commands/__pycache__/upload.cpython<span class="hljs-number">-39.</span>opt<span class="hljs-number">-1.</span>pyc
/usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/commands/__pycache__/upload.cpython<span class="hljs-number">-39.</span>pyc
/usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/commands/upload.py
</code></pre>
<p>Ah, getting interesting! Let's open 'upload.py':</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> asciinema.commands.command <span class="hljs-keyword">import</span> Command
<span class="hljs-keyword">from</span> asciinema.api <span class="hljs-keyword">import</span> APIError


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UploadCommand</span>(<span class="hljs-params">Command</span>):</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, api, filename</span>):</span>
        Command.__init__(self)
        self.api = api 
        self.filename = filename

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">execute</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">try</span>:
            result, warn = self.api.upload_asciicast(self.filename)

            <span class="hljs-keyword">if</span> warn:
                self.print_warning(warn)

            self.print(result.get(<span class="hljs-string">'message'</span>) <span class="hljs-keyword">or</span> result[<span class="hljs-string">'url'</span>])

        <span class="hljs-keyword">except</span> OSError <span class="hljs-keyword">as</span> e:
            self.print_error(<span class="hljs-string">"upload failed: %s"</span> % str(e))
            <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>

        <span class="hljs-keyword">except</span> APIError <span class="hljs-keyword">as</span> e:
            self.print_error(<span class="hljs-string">"upload failed: %s"</span> % str(e))
            self.print_error(<span class="hljs-string">"retry later by running: asciinema upload %s"</span> % self.filename)
            <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>

        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>
</code></pre>
<p>Let's put a few breakpoints inside the UploadCommand (Lines 14, 26 on my copy of the code):</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ python3 -m pdb /usr/bin/asciinema upload demo-ascii.cast 
&gt; /usr/bin/asciinema(<span class="hljs-number">3</span>)&lt;module&gt;()
-&gt; <span class="hljs-keyword">import</span> re
(Pdb) b /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/commands/upload.py:<span class="hljs-number">14</span>
Breakpoint <span class="hljs-number">1</span> at /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/commands/upload.py:<span class="hljs-number">14</span>
(Pdb) c
&gt; /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/commands/upload.py(<span class="hljs-number">14</span>)execute()
-&gt; result, warn = self.api.upload_asciicast(self.filename)
(Pdb) c
&gt; /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/commands/upload.py(<span class="hljs-number">26</span>)execute()
-&gt; self.print_error(<span class="hljs-string">"upload failed: %s"</span> % str(e))
(Pdb) n
asciinema: upload failed: &lt;urlopen error [Errno <span class="hljs-number">32</span>] Broken pipe&gt;
&gt; /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/commands/upload.py(<span class="hljs-number">27</span>)execute()
-&gt; self.print_error(<span class="hljs-string">"retry later by running: asciinema upload %s"</span> % self.filename)
(Pdb) ll
 <span class="hljs-number">12</span>          <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">execute</span>(<span class="hljs-params">self</span>):</span>
 <span class="hljs-number">13</span>              <span class="hljs-keyword">try</span>:
 <span class="hljs-number">14</span> B                result, warn = self.api.upload_asciicast(self.filename)
 <span class="hljs-number">15</span>      
 <span class="hljs-number">16</span>                  <span class="hljs-keyword">if</span> warn:
 <span class="hljs-number">17</span>                      self.print_warning(warn)
 <span class="hljs-number">18</span>      
 <span class="hljs-number">19</span>                  self.print(result.get(<span class="hljs-string">'message'</span>) <span class="hljs-keyword">or</span> result[<span class="hljs-string">'url'</span>])
 <span class="hljs-number">20</span>      
 <span class="hljs-number">21</span>              <span class="hljs-keyword">except</span> OSError <span class="hljs-keyword">as</span> e:
 <span class="hljs-number">22</span>                  self.print_error(<span class="hljs-string">"upload failed: %s"</span> % str(e))
 <span class="hljs-number">23</span>                  <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>
 <span class="hljs-number">24</span>      
 <span class="hljs-number">25</span>              <span class="hljs-keyword">except</span> APIError <span class="hljs-keyword">as</span> e:
 <span class="hljs-number">26</span> B                self.print_error(<span class="hljs-string">"upload failed: %s"</span> % str(e))
 <span class="hljs-number">27</span>  -&gt;                self.print_error(<span class="hljs-string">"retry later by running: asciinema upload %s"</span> % self.filename)
 <span class="hljs-number">28</span>                  <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>
 <span class="hljs-number">29</span>      
 <span class="hljs-number">30</span>              <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>
</code></pre>
<p>We got an APIError. Anything interesting with that type of exception?</p>
<pre><code class="lang-shell">(Pdb) source APIError
11      class APIError(Exception):
12          pass
(Pdb) e.args
('&lt;urlopen error [Errno 32] Broken pipe&gt;',)
</code></pre>
<p>So nothing special, derived directly from <code>Exception</code>. Also, the arguments to the exception are just the error message.</p>
<p>Of course the next step is to see if this error comes from a known library (Search on the Internet <a target="_blank" href="https://duckduckgo.com/?q=%3Curlopen+error+%5BErrno+32%5D+Broken+pipe%3E&amp;ia=web">for the error</a>).</p>
<p>I found this issue on <a target="_blank" href="https://github.com/asciinema/asciinema/issues/335">GitHub</a>. Reading <a target="_blank" href="https://github.com/asciinema/asciinema/issues/91">further</a> you can see than the generous author of Asciicast is paying the storage from his own pocket so all of us can enjoy the online storage for free:</p>
<blockquote>
<p>The max size was set 2MB which appears to be too low. I have upped it to 5MB. This isn't much, but I'm paying for the storage (S3) from my own pocket, so I can't offer GBs of storage for every user. Let me know if that works for you. I'm fine with increasing it even more, but now I want to figure out the good middle ground between user needs and hosting costs.</p>
</blockquote>
<p>So let's confirm that this is indeed the cause:</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ ls -lh demo-ascii.cast 
-rw-rw-r-- <span class="hljs-number">1</span> josevnz josevnz <span class="hljs-number">12</span>M Apr <span class="hljs-number">21</span> <span class="hljs-number">15</span>:<span class="hljs-number">44</span> demo-ascii.cast
</code></pre>
<p>So far the big size of the file seems to be the culprit.</p>
<p>I'm still running the debugger, and I would love to see what asciinema modules were loaded. For that switch to the '<em>interact</em>' mode and get that listing with a <a target="_blank" href="https://peps.python.org/pep-0202/">list comprehension</a> and a <a target="_blank" href="https://docs.python.org/3/howto/regex.html">regular expression</a>:</p>
<pre><code class="lang-python">(Pdb) interact
*interactive*
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> re
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> sys
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> pprint
<span class="hljs-meta">&gt;&gt;&gt; </span>pprint.pprint([name <span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> sys.modules.keys() <span class="hljs-keyword">if</span> re.search(<span class="hljs-string">'asciinema'</span>, name)], indent=<span class="hljs-literal">True</span>)
[<span class="hljs-string">'asciinema.asciicast.events'</span>,
 <span class="hljs-string">'asciinema.asciicast.v1'</span>,
 <span class="hljs-string">'asciinema.asciicast.v2'</span>,
 <span class="hljs-string">'asciinema.asciicast'</span>,
 <span class="hljs-string">'asciinema.term'</span>,
 <span class="hljs-string">'asciinema.pty'</span>,
 <span class="hljs-string">'asciinema'</span>,
 <span class="hljs-string">'asciinema.config'</span>,
 <span class="hljs-string">'asciinema.commands'</span>,
 <span class="hljs-string">'asciinema.commands.command'</span>,
 <span class="hljs-string">'asciinema.commands.auth'</span>,
 <span class="hljs-string">'asciinema.asciicast.raw'</span>,
 <span class="hljs-string">'asciinema.http_adapter'</span>,
 <span class="hljs-string">'asciinema.urllib_http_adapter'</span>,
 <span class="hljs-string">'asciinema.api'</span>,
 <span class="hljs-string">'asciinema.commands.record'</span>,
 <span class="hljs-string">'asciinema.player'</span>,
 <span class="hljs-string">'asciinema.commands.play'</span>,
 <span class="hljs-string">'asciinema.commands.cat'</span>,
 <span class="hljs-string">'asciinema.commands.upload'</span>,
 <span class="hljs-string">'asciinema.__main__'</span>]
&gt;&gt;&gt;
</code></pre>
<p>The following look like they could hold some clues:</p>
<ul>
<li><p>asciinema.urllib_http_adapter</p>
</li>
<li><p>asciinema.commands.upload</p>
</li>
<li><p>asciinema.http_adapter</p>
</li>
</ul>
<p>Exit the debugger (or go to another terminal) and search for the urllib_http_adapter:</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ find /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/ -name <span class="hljs-string">'urllib_http_adapter*'</span>
/usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/__pycache__/urllib_http_adapter.cpython<span class="hljs-number">-39.</span>opt<span class="hljs-number">-1.</span>pyc
/usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/__pycache__/urllib_http_adapter.cpython<span class="hljs-number">-39.</span>pyc
/usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py
</code></pre>
<p>If you open the file you will see that 'post' method is the one we want to troubleshoot:</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">URLLibHttpAdapter</span>:</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">post</span>(<span class="hljs-params">self, url, fields={}, files={}, headers={}, username=None, password=None</span>):</span>
        content_type, body = MultipartFormdataEncoder().encode(fields, files)

        headers = headers.copy()
        headers[<span class="hljs-string">"Content-Type"</span>] = content_type

        <span class="hljs-keyword">if</span> password:
            auth = <span class="hljs-string">"%s:%s"</span> % (username, password)
            encoded_auth = base64.encodebytes(auth.encode(<span class="hljs-string">'utf-8'</span>))[:<span class="hljs-number">-1</span>]
            headers[<span class="hljs-string">"Authorization"</span>] = <span class="hljs-string">b"Basic "</span> + encoded_auth

        request = Request(url, data=body, headers=headers, method=<span class="hljs-string">"POST"</span>)

        <span class="hljs-keyword">try</span>:
            response = urlopen(request)
            status = response.status
            headers = self._parse_headers(response)
            body = response.read().decode(<span class="hljs-string">'utf-8'</span>)
        <span class="hljs-keyword">except</span> HTTPError <span class="hljs-keyword">as</span> e:
            status = e.code
            headers = {}
            body = e.read().decode(<span class="hljs-string">'utf-8'</span>)
        <span class="hljs-keyword">except</span> (http.client.RemoteDisconnected, URLError) <span class="hljs-keyword">as</span> e:
            <span class="hljs-keyword">raise</span> HTTPConnectionError(str(e))

        <span class="hljs-keyword">return</span> (status, headers, body)
</code></pre>
<p>A breakpoint in line 65 will get us where we need to be:</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ python3 -m pdb /usr/bin/asciinema upload demo-ascii.cast 
&gt; /usr/bin/asciinema(<span class="hljs-number">3</span>)&lt;module&gt;()
-&gt; <span class="hljs-keyword">import</span> re
(Pdb) b /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py:<span class="hljs-number">65</span>
Breakpoint <span class="hljs-number">1</span> at /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py:<span class="hljs-number">65</span>
(Pdb) c
&gt; /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py(<span class="hljs-number">65</span>)post()
-&gt; headers = headers.copy()
(Pdb) ll
 <span class="hljs-number">62</span>          <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">post</span>(<span class="hljs-params">self, url, fields={}, files={}, headers={}, username=None, password=None</span>):</span>
 <span class="hljs-number">63</span>              content_type, body = MultipartFormdataEncoder().encode(fields, files)
 <span class="hljs-number">64</span>      
 <span class="hljs-number">65</span> B-&gt;            headers = headers.copy()
 <span class="hljs-number">66</span>              headers[<span class="hljs-string">"Content-Type"</span>] = content_type
 <span class="hljs-number">67</span>      
 <span class="hljs-number">68</span>              <span class="hljs-keyword">if</span> password:
 <span class="hljs-number">69</span>                  auth = <span class="hljs-string">"%s:%s"</span> % (username, password)
 <span class="hljs-number">70</span>                  encoded_auth = base64.encodebytes(auth.encode(<span class="hljs-string">'utf-8'</span>))[:<span class="hljs-number">-1</span>]
 <span class="hljs-number">71</span>                  headers[<span class="hljs-string">"Authorization"</span>] = <span class="hljs-string">b"Basic "</span> + encoded_auth
 <span class="hljs-number">72</span>      
 <span class="hljs-number">73</span>              request = Request(url, data=body, headers=headers, method=<span class="hljs-string">"POST"</span>)
 <span class="hljs-number">74</span>      
 <span class="hljs-number">75</span>              <span class="hljs-keyword">try</span>:
 <span class="hljs-number">76</span>                  response = urlopen(request)
 <span class="hljs-number">77</span>                  status = response.status
 <span class="hljs-number">78</span>                  headers = self._parse_headers(response)
 <span class="hljs-number">79</span>                  body = response.read().decode(<span class="hljs-string">'utf-8'</span>)
 <span class="hljs-number">80</span>              <span class="hljs-keyword">except</span> HTTPError <span class="hljs-keyword">as</span> e:
 <span class="hljs-number">81</span>                  status = e.code
 <span class="hljs-number">82</span>                  headers = {}
 <span class="hljs-number">83</span>                  body = e.read().decode(<span class="hljs-string">'utf-8'</span>)
 <span class="hljs-number">84</span>              <span class="hljs-keyword">except</span> (http.client.RemoteDisconnected, URLError) <span class="hljs-keyword">as</span> e:
 <span class="hljs-number">85</span>                  <span class="hljs-keyword">raise</span> HTTPConnectionError(str(e))
 <span class="hljs-number">86</span>      
 <span class="hljs-number">87</span>              <span class="hljs-keyword">return</span> (status, headers, body)
(Pdb) args
self = &lt;asciinema.urllib_http_adapter.URLLibHttpAdapter object at <span class="hljs-number">0x7f59ed3e4640</span>&gt;
url = <span class="hljs-string">'https://asciinema.org/api/asciicasts'</span>
fields = {}
files = {<span class="hljs-string">'asciicast'</span>: (<span class="hljs-string">'ascii.cast'</span>, &lt;_io.BufferedReader name=<span class="hljs-string">'demo-ascii.cast'</span>&gt;)}
headers = {<span class="hljs-string">'User-Agent'</span>: <span class="hljs-string">'asciinema/2.0.2 CPython/3.9.9 Linux/5.14.18-100.fc33.x86_64-x86_64-with-glibc2.32'</span>, <span class="hljs-string">'Accept'</span>: <span class="hljs-string">'application/json'</span>}
username = <span class="hljs-string">'XXXX'</span>
password = <span class="hljs-string">'XXXX0f1-1d73-43fc-XX36-c9d7ZZZAAAA'</span>
</code></pre>
<p>Very interesting – we could use definitely use the following fields to exercise the upload functionality without Python (obtained using <code>args</code> from the debugger):</p>
<ul>
<li><p>url = '<a target="_blank" href="https://asciinema.org/api/asciicasts">https://asciinema.org/api/asciicasts</a>'</p>
</li>
<li><p>headers = {'User-Agent': 'asciinema/2.0.2 CPython/3.9.9 Linux/5.14.18-100.fc33.x86_64-x86_64-with-glibc2.32', 'Accept': 'application/json'}</p>
</li>
<li><p>username = 'XXXX'</p>
</li>
<li><p>password = 'XXXX0f1-1d73-43fc-XX36-c9d7ZZZAAAA'</p>
</li>
</ul>
<p>What exception we will get? We set 2 more breakpoints and let the debugger run until it reaches them:</p>
<pre><code class="lang-python">(Pdb) b <span class="hljs-number">81</span>
Breakpoint <span class="hljs-number">2</span> at /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py:<span class="hljs-number">81</span>
(Pdb) b <span class="hljs-number">85</span>
Breakpoint <span class="hljs-number">3</span> at /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py:<span class="hljs-number">85</span>
(Pdb) c
&gt; /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py(<span class="hljs-number">85</span>)post()
-&gt; <span class="hljs-keyword">raise</span> HTTPConnectionError(str(e))
(Pdb) e
URLError(BrokenPipeError(<span class="hljs-number">32</span>, <span class="hljs-string">'Broken pipe'</span>))
</code></pre>
<p>The type of the error is <a target="_blank" href="https://docs.python.org/3/library/exceptions.html#BrokenPipeError">BrokenPipeError</a>:</p>
<blockquote>
<p>A subclass of ConnectionError, raised when trying to write on a pipe while the other end has been closed, or trying to write on a socket which has been shutdown for writing. Corresponds to errno EPIPE and ESHUTDOWN.</p>
</blockquote>
<p>One last thing – do we read the whole file in memory before sending it to the website?</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ python3 -m pdb /usr/bin/asciinema upload demo-ascii.cast 
&gt; /usr/bin/asciinema(<span class="hljs-number">3</span>)&lt;module&gt;()
-&gt; <span class="hljs-keyword">import</span> re
(Pdb) b /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py:<span class="hljs-number">49</span>
Breakpoint <span class="hljs-number">1</span> at /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py:<span class="hljs-number">49</span>
(Pdb) c
&gt; /usr/lib/python3<span class="hljs-number">.9</span>/site-packages/asciinema/urllib_http_adapter.py(<span class="hljs-number">49</span>)iter()
-&gt; <span class="hljs-keyword">yield</span> (data, len(data))
(Pdb) len(data)
<span class="hljs-number">12444283</span>
</code></pre>
<p>12MB, not huge for today's computer memory but also not small.</p>
<p>Do you remember the parameters we managed to capture before with the help of the debugger (URL, user, and so on)? We now know enough to use a different tool (<a target="_blank" href="https://curl.se/">curl</a>) to try to upload the file:</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ curl --fail --http1<span class="hljs-number">.1</span> --verbose --user $USER:$(cat ~/.config/asciinema/install-id) https://asciinema.org/api/asciicasts --form asciicast=@demo-ascii.cast
*   Trying <span class="hljs-number">109.107</span><span class="hljs-number">.37</span><span class="hljs-number">.0</span>:<span class="hljs-number">443.</span>..
* Connected to asciinema.org (<span class="hljs-number">109.107</span><span class="hljs-number">.37</span><span class="hljs-number">.0</span>) port <span class="hljs-number">443</span> (<span class="hljs-comment">#0)</span>
* ALPN, offering http/<span class="hljs-number">1.1</span>
* successfully set certificate verify locations:
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* TLSv1<span class="hljs-number">.3</span> (OUT), TLS handshake, Client hello (<span class="hljs-number">1</span>):
* TLSv1<span class="hljs-number">.3</span> (IN), TLS handshake, Server hello (<span class="hljs-number">2</span>):
* TLSv1<span class="hljs-number">.3</span> (IN), TLS handshake, Encrypted Extensions (<span class="hljs-number">8</span>):
* TLSv1<span class="hljs-number">.3</span> (IN), TLS handshake, Certificate (<span class="hljs-number">11</span>):
* TLSv1<span class="hljs-number">.3</span> (IN), TLS handshake, CERT verify (<span class="hljs-number">15</span>):
* TLSv1<span class="hljs-number">.3</span> (IN), TLS handshake, Finished (<span class="hljs-number">20</span>):
* TLSv1<span class="hljs-number">.3</span> (OUT), TLS change cipher, Change cipher spec (<span class="hljs-number">1</span>):
* TLSv1<span class="hljs-number">.3</span> (OUT), TLS handshake, Finished (<span class="hljs-number">20</span>):
* SSL connection using TLSv1<span class="hljs-number">.3</span> / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use http/<span class="hljs-number">1.1</span>
* Server certificate:
*  subject: CN=*.asciinema.org
*  start date: Mar  <span class="hljs-number">9</span> <span class="hljs-number">06</span>:<span class="hljs-number">02</span>:<span class="hljs-number">26</span> <span class="hljs-number">2022</span> GMT
*  expire date: Jun  <span class="hljs-number">7</span> <span class="hljs-number">06</span>:<span class="hljs-number">02</span>:<span class="hljs-number">25</span> <span class="hljs-number">2022</span> GMT
*  subjectAltName: host <span class="hljs-string">"asciinema.org"</span> matched cert<span class="hljs-string">'s "asciinema.org"
*  issuer: C=US; O=Let'</span>s Encrypt; CN=R3
*  SSL certificate verify ok.
* Server auth using Basic <span class="hljs-keyword">with</span> user <span class="hljs-string">'XXXX'</span>
&gt; POST /api/asciicasts HTTP/<span class="hljs-number">1.1</span>
&gt; Host: asciinema.org
&gt; Authorization: Basic XXXXX=
&gt; User-Agent: curl/<span class="hljs-number">7.71</span><span class="hljs-number">.1</span>
&gt; Accept: */*
&gt; Content-Length: <span class="hljs-number">12444495</span>
&gt; Content-Type: multipart/form-data; boundary=-----------------------<span class="hljs-number">-0</span>d76dac3e1f8aed4
&gt; Expect: <span class="hljs-number">100</span>-<span class="hljs-keyword">continue</span>
&gt; 
* TLSv1<span class="hljs-number">.3</span> (IN), TLS handshake, Newsession Ticket (<span class="hljs-number">4</span>):
* Mark bundle <span class="hljs-keyword">as</span> <span class="hljs-keyword">not</span> supporting multiuse
&lt; HTTP/<span class="hljs-number">1.1</span> <span class="hljs-number">100</span> Continue
* Mark bundle <span class="hljs-keyword">as</span> <span class="hljs-keyword">not</span> supporting multiuse
* The requested URL returned error: <span class="hljs-number">413</span> Request Entity Too Large
* Closing connection <span class="hljs-number">0</span>
* TLSv1<span class="hljs-number">.3</span> (OUT), TLS alert, close notify (<span class="hljs-number">256</span>):
curl: (<span class="hljs-number">22</span>) The requested URL returned error: <span class="hljs-number">413</span> Request Entity Too Large
</code></pre>
<p>The error <code>413 Request Entity Too Large</code> <a target="_blank" href="https://developer.mozilla.org/en-US/docs/web/http/status/413">means</a>:</p>
<blockquote>
<p>The HTTP 413 Payload Too Large response status code indicates that the request entity is larger than limits defined by server; the server might close the connection or return a Retry-After header field.</p>
</blockquote>
<p>So curl is much better than Python on telling us the truth about why our file was rejected.</p>
<p>How much data did we manage to transmit before our connection was cut off? Let's see if we can find that out using a packet sniffer.</p>
<h2 id="heading-how-to-use-wireshark-and-the-sslkeylogfile-to-inspect-the-http-traffic"><strong>How to use Wireshark and the SSLKEYLOGFILE to inspect the HTTP traffic</strong></h2>
<p>You can capture the traffic between your machine and the asciinema website using a network sniffer like <a target="_blank" href="https://wireshark.org/">Wireshark</a> or the well known <a target="_blank" href="https://www.tcpdump.org/">tcpdump</a>.</p>
<p>The traffic will be encrypted as we use HTTPS, but using a feature supported by many programs known as a '<a target="_blank" href="https://www.paolotagliaferri.com/overview-of-transport-layer-security-protocol-tls-1-3/">TLS master encryption secrets</a>' you can decrypt the session. For that let's enable the <a target="_blank" href="https://everything.curl.dev/usingcurl/tls/sslkeylogfile">feature</a> on the client:</p>
<pre><code class="lang-python">export SSLKEYLOGFILE=$HOME/keylogfile.txt
</code></pre>
<p>If is supported, the $SSLKEYLOGFILE file will be populated with the keys:</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ export SSLKEYLOGFILE=$HOME/keylogfile.txt
[josevnz@dmaf5 SuricataLog]$ /usr/bin/asciinema upload demo-ascii.cast 
asciinema: upload failed: &lt;urlopen error [Errno <span class="hljs-number">32</span>] Broken pipe&gt;
asciinema: retry later by running: asciinema upload demo-ascii.cast
[josevnz@dmaf5 SuricataLog]$ ls -l $SSLKEYLOGFILE
-rw-rw-r-- <span class="hljs-number">1</span> josevnz josevnz <span class="hljs-number">832</span> Apr <span class="hljs-number">21</span> <span class="hljs-number">21</span>:<span class="hljs-number">02</span> /home/josevnz/keylogfile.txt

[josevnz@dmaf5 SuricataLog]$ cat /home/josevnz/keylogfile.txt

<span class="hljs-comment"># TLS secrets log file, generated by OpenSSL / Python</span>
SERVER_HANDSHAKE_TRAFFIC_SECRET <span class="hljs-number">2987e32066</span>d608a3de0cdd896f62801290045c2616abfaef5fac1c6986131847 <span class="hljs-number">4</span>dd1a1bc1261a84886b28ee72798d89ba77d7de7051b3dcdafd548a621ed1124
EXPORTER_SECRET <span class="hljs-number">2987e32066</span>d608a3de0cdd896f62801290045c2616abfaef5fac1c6986131847 <span class="hljs-number">1</span>ec8d94b7ec373a984abed25fa0dfaa6346fe67feea0516d7e2e46a666a12614
SERVER_TRAFFIC_SECRET_0 <span class="hljs-number">2987e32066</span>d608a3de0cdd896f62801290045c2616abfaef5fac1c6986131847 e1d8fa6dba5eea00d4e52af0ce7e7007da0ade4c9dd9da3d9a060b55880531f1
CLIENT_HANDSHAKE_TRAFFIC_SECRET <span class="hljs-number">2987e32066</span>d608a3de0cdd896f62801290045c2616abfaef5fac1c6986131847 <span class="hljs-number">903</span>bf381f927d783e72846201e87203ff130d9cf21f84cf0b923834d69c3fe76
CLIENT_TRAFFIC_SECRET_0 <span class="hljs-number">2987e32066</span>d608a3de0cdd896f62801290045c2616abfaef5fac1c6986131847 <span class="hljs-number">495</span>b5acf783869d74a7521e3b9c3f7bfc6dbc25e24ba95f684e96f6b2a435206
SERVER_HANDSHAKE_TRAFFIC_SECRET <span class="hljs-number">82</span>cab66e906c3cd3c58b3aeeecd66b2a12e521704d3e19e2f008550705e78e00 <span class="hljs-number">5</span>a0d699640bd460530bd38148cf979e585b9a43c1bd545974561df18841fa5f4
EXPORTER_SECRET <span class="hljs-number">82</span>cab66e906c3cd3c58b3aeeecd66b2a12e521704d3e19e2f008550705e78e00 <span class="hljs-number">32</span>b69cb41b8db36371e7d207a45e20d401bb05e0cd8bf492e3ace009e2845d12
SERVER_TRAFFIC_SECRET_0 <span class="hljs-number">82</span>cab66e906c3cd3c58b3aeeecd66b2a12e521704d3e19e2f008550705e78e00 <span class="hljs-number">1</span>f42b4392b2cc14789c4eaec4dae275c6a040ae3b11fc6bba58c90c7b80caa96
CLIENT_HANDSHAKE_TRAFFIC_SECRET <span class="hljs-number">82</span>cab66e906c3cd3c58b3aeeecd66b2a12e521704d3e19e2f008550705e78e00 bd93073bda56e559743a1f1ffc48c062089addcfc007c7defe08c28ac0ee6287
CLIENT_TRAFFIC_SECRET_0 <span class="hljs-number">82</span>cab66e906c3cd3c58b3aeeecd66b2a12e521704d3e19e2f008550705e78e00 <span class="hljs-number">32</span>b615c0dd25cb7b430a0cff44871e3263bd67af973e4b2f7fb19aab4df468d8
SERVER_HANDSHAKE_TRAFFIC_SECRET <span class="hljs-number">68</span>dcc859bc4edb51354a9f583e036d0b2787a337ee894e253925e273a5cd3889 a52a20827ce04dfc4ee557608ed5a0bfb6794ace0c4a1b69a1d56e5f16d8570b
EXPORTER_SECRET <span class="hljs-number">68</span>dcc859bc4edb51354a9f583e036d0b2787a337ee894e253925e273a5cd3889 <span class="hljs-number">8179</span>afb8e7c7a77e35143c40a6bb62ccea2e644e48cc95b91b05f525bc59ada7
SERVER_TRAFFIC_SECRET_0 <span class="hljs-number">68</span>dcc859bc4edb51354a9f583e036d0b2787a337ee894e253925e273a5cd3889 <span class="hljs-number">3</span>d4abf6a9ea06395648a45428ca78c24962d8cc11440fe1d72f035ae35e61010
CLIENT_HANDSHAKE_TRAFFIC_SECRET <span class="hljs-number">68</span>dcc859bc4edb51354a9f583e036d0b2787a337ee894e253925e273a5cd3889 <span class="hljs-number">1</span>d812a6c3c012a8fa4a6017ee573b47a5b361d15b861938ebca9194ecbc2a250
CLIENT_TRAFFIC_SECRET_0 <span class="hljs-number">68</span>dcc859bc4edb51354a9f583e036d0b2787a337ee894e253925e273a5cd3889 <span class="hljs-number">6348</span>a88dc9b6a350d72a7154140b824db80ba4f48c9e1fabcee76da8d248b041
</code></pre>
<p>Good. Next step is to capture the traffic. We'll use <a target="_blank" href="https://www.tcpdump.org/">tcpdump</a> with a <a target="_blank" href="https://www.tcpdump.org/papers/ethereal-tcpdump.pdf">simple expression</a> to filter out the captured traffic:</p>
<pre><code class="lang-python">[josevnz@dmaf5 temp]$ sudo tcpdump -i eno1 -v -v -v <span class="hljs-string">'host asciinema.org'</span> -w ~/temp/asciinema.org.pcap
dropped privs to tcpdump
tcpdump: listening on eno1, link-type EN10MB (Ethernet), snapshot length <span class="hljs-number">262144</span> bytes
</code></pre>
<p>And in another window run the asciinema client (we'll do it twice to have more data):</p>
<pre><code class="lang-python">[josevnz@dmaf5 SuricataLog]$ /usr/bin/asciinema upload demo-ascii.cast 
asciinema: upload failed: &lt;urlopen error [Errno <span class="hljs-number">32</span>] Broken pipe&gt;
asciinema: retry later by running: asciinema upload demo-ascii.cast
[josevnz@dmaf5 SuricataLog]$ 
[josevnz@dmaf5 SuricataLog]$ /usr/bin/asciinema upload demo-ascii.cast 
asciinema: upload failed: &lt;urlopen error [Errno <span class="hljs-number">104</span>] Connection reset by peer&gt;
asciinema: retry later by running: asciinema upload demo-ascii.cast
</code></pre>
<p>Now kill the tcpdump capture on the other window:</p>
<pre><code class="lang-python">tcpdump: listening on eno1, link-type EN10MB (Ethernet), snapshot length <span class="hljs-number">262144</span> bytes
^C113 packets captured
<span class="hljs-number">118</span> packets received by filter
<span class="hljs-number">0</span> packets dropped by kernel
</code></pre>
<p>Let's replay the pcap file to see what got recorded:</p>
<pre><code class="lang-python">[josevnz@dmaf5 temp]$ tcpdump -r ~/temp/asciinema.org.pcap
reading <span class="hljs-keyword">from</span> file /home/josevnz/temp/asciinema.org.pcap, link-type EN10MB (Ethernet), snapshot length <span class="hljs-number">262144</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.244941</span> IP dmaf5.home<span class="hljs-number">.59896</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [S], seq <span class="hljs-number">1651239781</span>, win <span class="hljs-number">64240</span>, options [mss <span class="hljs-number">1460</span>,sackOK,TS val <span class="hljs-number">3293505858</span> ecr <span class="hljs-number">0</span>,nop,wscale <span class="hljs-number">7</span>], length <span class="hljs-number">0</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.337023</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59896</span>: Flags [S.], seq <span class="hljs-number">2395275599</span>, ack <span class="hljs-number">1651239782</span>, win <span class="hljs-number">65160</span>, options [mss <span class="hljs-number">1460</span>,sackOK,TS val <span class="hljs-number">3934370169</span> ecr <span class="hljs-number">3293505858</span>,nop,wscale <span class="hljs-number">7</span>], length <span class="hljs-number">0</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.337070</span> IP dmaf5.home<span class="hljs-number">.59896</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [.], ack <span class="hljs-number">1</span>, win <span class="hljs-number">502</span>, options [nop,nop,TS val <span class="hljs-number">3293505950</span> ecr <span class="hljs-number">3934370169</span>], length <span class="hljs-number">0</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.337643</span> IP dmaf5.home<span class="hljs-number">.59896</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [P.], seq <span class="hljs-number">1</span>:<span class="hljs-number">518</span>, ack <span class="hljs-number">1</span>, win <span class="hljs-number">502</span>, options [nop,nop,TS val <span class="hljs-number">3293505951</span> ecr <span class="hljs-number">3934370169</span>], length <span class="hljs-number">517</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.429273</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59896</span>: Flags [.], ack <span class="hljs-number">518</span>, win <span class="hljs-number">506</span>, options [nop,nop,TS val <span class="hljs-number">3934370263</span> ecr <span class="hljs-number">3293505951</span>], length <span class="hljs-number">0</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.433850</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59896</span>: Flags [.], seq <span class="hljs-number">1</span>:<span class="hljs-number">1449</span>, ack <span class="hljs-number">518</span>, win <span class="hljs-number">506</span>, options [nop,nop,TS val <span class="hljs-number">3934370267</span> ecr <span class="hljs-number">3293505951</span>], length <span class="hljs-number">1448</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.433863</span> IP dmaf5.home<span class="hljs-number">.59896</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [.], ack <span class="hljs-number">1449</span>, win <span class="hljs-number">501</span>, options [nop,nop,TS val <span class="hljs-number">3293506047</span> ecr <span class="hljs-number">3934370267</span>], length <span class="hljs-number">0</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.433966</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59896</span>: Flags [P.], seq <span class="hljs-number">1449</span>:<span class="hljs-number">2897</span>, ack <span class="hljs-number">518</span>, win <span class="hljs-number">506</span>, options [nop,nop,TS val <span class="hljs-number">3934370267</span> ecr <span class="hljs-number">3293505951</span>], length <span class="hljs-number">1448</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.433981</span> IP dmaf5.home<span class="hljs-number">.59896</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [.], ack <span class="hljs-number">2897</span>, win <span class="hljs-number">496</span>, options [nop,nop,TS val <span class="hljs-number">3293506047</span> ecr <span class="hljs-number">3934370267</span>], length <span class="hljs-number">0</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">18.434089</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59896</span>: Flags [.], seq <span class="hljs-number">2897</span>:<span class="hljs-number">4345</span>, ack <span class="hljs-number">518</span>, win <span class="hljs-number">506</span>, options [nop,nop,TS val <span class="hljs-number">3934370267</span> ecr <span class="hljs-number">3293505951</span>], length <span class="hljs-number">1448</span>
...
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.612523</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59898</span>: Flags [.], ack <span class="hljs-number">11148</span>, win <span class="hljs-number">501</span>, options [nop,nop,TS val <span class="hljs-number">3934382447</span> ecr <span class="hljs-number">3293518134</span>], length <span class="hljs-number">0</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.612524</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59898</span>: Flags [.], ack <span class="hljs-number">12596</span>, win <span class="hljs-number">501</span>, options [nop,nop,TS val <span class="hljs-number">3934382447</span> ecr <span class="hljs-number">3293518134</span>], length <span class="hljs-number">0</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.612558</span> IP dmaf5.home<span class="hljs-number">.59898</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [.], seq <span class="hljs-number">35764</span>:<span class="hljs-number">37212</span>, ack <span class="hljs-number">4724</span>, win <span class="hljs-number">499</span>, options [nop,nop,TS val <span class="hljs-number">3293518226</span> ecr <span class="hljs-number">3934382447</span>], length <span class="hljs-number">1448</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.612563</span> IP dmaf5.home<span class="hljs-number">.59898</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [P.], seq <span class="hljs-number">37212</span>:<span class="hljs-number">38660</span>, ack <span class="hljs-number">4724</span>, win <span class="hljs-number">499</span>, options [nop,nop,TS val <span class="hljs-number">3293518226</span> ecr <span class="hljs-number">3934382447</span>], length <span class="hljs-number">1448</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.612637</span> IP dmaf5.home<span class="hljs-number">.59898</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [.], seq <span class="hljs-number">38660</span>:<span class="hljs-number">40108</span>, ack <span class="hljs-number">4724</span>, win <span class="hljs-number">499</span>, options [nop,nop,TS val <span class="hljs-number">3293518226</span> ecr <span class="hljs-number">3934382447</span>], length <span class="hljs-number">1448</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.612643</span> IP dmaf5.home<span class="hljs-number">.59898</span> &gt; cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https: Flags [P.], seq <span class="hljs-number">40108</span>:<span class="hljs-number">41556</span>, ack <span class="hljs-number">4724</span>, win <span class="hljs-number">499</span>, options [nop,nop,TS val <span class="hljs-number">3293518226</span> ecr <span class="hljs-number">3934382447</span>], length <span class="hljs-number">1448</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.613064</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59898</span>: Flags [P.], seq <span class="hljs-number">4724</span>:<span class="hljs-number">5080</span>, ack <span class="hljs-number">12596</span>, win <span class="hljs-number">501</span>, options [nop,nop,TS val <span class="hljs-number">3934382448</span> ecr <span class="hljs-number">3293518134</span>], length <span class="hljs-number">356</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.613106</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59898</span>: Flags [P.], seq <span class="hljs-number">5080</span>:<span class="hljs-number">5104</span>, ack <span class="hljs-number">12596</span>, win <span class="hljs-number">501</span>, options [nop,nop,TS val <span class="hljs-number">3934382448</span> ecr <span class="hljs-number">3293518134</span>], length <span class="hljs-number">24</span>
<span class="hljs-number">07</span>:<span class="hljs-number">17</span>:<span class="hljs-number">30.614231</span> IP cip<span class="hljs-number">-109</span><span class="hljs-number">-107</span><span class="hljs-number">-37</span><span class="hljs-number">-0.</span>gb1.brightbox.com.https &gt; dmaf5.home<span class="hljs-number">.59898</span>: Flags [R.], seq <span class="hljs-number">5104</span>, ack <span class="hljs-number">12596</span>, win <span class="hljs-number">501</span>, options [nop,nop,TS val <span class="hljs-number">3934382448</span> ecr <span class="hljs-number">3293518134</span>], length <span class="hljs-number">0</span>
</code></pre>
<p>Time to fire up wireshark. I like to use a GUI for this as the filtering capabilities are nice, and you can explore the contents of the PCAP file much easier.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/wireshark-open-pcap-file.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The contents of the traffic capture:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/wireshark-traffic-dump.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>So we follow the first time we got a TLS hello message, right-click on the protocol preferences -&gt; Transport Layer Security and then "pre-Master-Secret log filename":</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/wireshark-tls-pre-master-key.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now time for the fun part. If you right-click the first hello message and say "follow TLS stream" a new window will open the whole conversation to the moment we got our connection reset, no encryption!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/wireshark-follow-tls.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>So we only managed to sent 33 KB before being cut-off by the asciinema server. How rude! :satisfied:</p>
<p>Because the data payload is not so big I will show it to you next, make sure you pay attention to the following:</p>
<ol>
<li><p>I changed the Authorization: Basic contents as I don't want to leak my user/password encoded in base64.</p>
</li>
<li><p>Content-Length: 12444474. That's how asciinema knows how big is the file we want to upload, so the server rejects it.</p>
</li>
<li><p>Asciinema uses Nginx.</p>
</li>
<li><p>You can see the close message at the end (entity too large).</p>
</li>
</ol>
<pre><code class="lang-python">POST /api/asciicasts HTTP/<span class="hljs-number">1.1</span>
Accept-Encoding: identity
Content-Length: <span class="hljs-number">12444474</span>
Host: asciinema.org
User-Agent: asciinema/<span class="hljs-number">2.0</span><span class="hljs-number">.2</span> CPython/<span class="hljs-number">3.9</span><span class="hljs-number">.9</span> Linux/<span class="hljs-number">5.14</span><span class="hljs-number">.18</span><span class="hljs-number">-100.</span>fc33.x86_64-x86_64-<span class="hljs-keyword">with</span>-glibc2<span class="hljs-number">.32</span>
Accept: application/json
Content-Type: multipart/form-data; boundary=d5c6b2543ee94511943126c6a3c5d33a
Authorization: Basic XXXXX=
Connection: close

--d5c6b2543ee94511943126c6a3c5d33a
Content-Disposition: form-data; name=<span class="hljs-string">"asciicast"</span>; filename=<span class="hljs-string">"ascii.cast"</span>
Content-Type: application/octet-stream

{<span class="hljs-string">"version"</span>: <span class="hljs-number">2</span>, <span class="hljs-string">"width"</span>: <span class="hljs-number">203</span>, <span class="hljs-string">"height"</span>: <span class="hljs-number">32</span>, <span class="hljs-string">"timestamp"</span>: <span class="hljs-number">1650568938</span>, <span class="hljs-string">"env"</span>: {<span class="hljs-string">"SHELL"</span>: <span class="hljs-string">"/bin/bash"</span>, <span class="hljs-string">"TERM"</span>: <span class="hljs-string">"xterm-256color"</span>}}
[<span class="hljs-number">0.191182</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b]777;notify;Command completed;eve_log.py --format table --timestamp '2022-02-23T18:22:24.405139+0000' test/eve.json\u001b\\\u001b]777;precmd\u001b\\\u001b]0;josevnz@dmaf5:~/SuricataLog-Logging-features-branch\u001b\\"</span>]
[<span class="hljs-number">0.19215</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b]7;file://dmaf5/home/josevnz/SuricataLog-Logging-features-branch\u001b\\"</span>]
[<span class="hljs-number">0.192399</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"[josevnz@dmaf5 SuricataLog-Logging-features-branch]$ "</span>]
[<span class="hljs-number">1.000538</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"Let me show you how you can filter your Suricata alerts, displaying the results in different formats"</span>]
[<span class="hljs-number">4.506902</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\r\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C"</span>]
[<span class="hljs-number">4.921813</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b[1@#"</span>]
[<span class="hljs-number">5.170393</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b[1@ "</span>]
[<span class="hljs-number">5.538486</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C"</span>]
[<span class="hljs-number">6.914337</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\r\n"</span>]
[<span class="hljs-number">6.918708</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b]777;notify;Command completed;# Let me show you how you can filter your Suricata alerts, displaying the results in different formats\u001b\\\u001b]777;precmd\u001b\\\u001b]0;josevnz@dmaf5:~/SuricataLog-Logging-features-branch\u001b\\"</span>]
[<span class="hljs-number">6.920219</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b]7;file://dmaf5/home/josevnz/SuricataLog-Logging-features-branch\u001b\\"</span>]
[<span class="hljs-number">6.920352</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"[josevnz@dmaf5 SuricataLog-Logging-features-branch]$ "</span>]
[<span class="hljs-number">8.202111</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"1"</span>]
[<span class="hljs-number">8.658197</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">")"</span>]
[<span class="hljs-number">8.962176</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">" "</span>]
[<span class="hljs-number">10.153862</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"A"</span>]
[<span class="hljs-number">10.409632</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">" "</span>]
[<span class="hljs-number">10.61679</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"n"</span>]
[<span class="hljs-number">10.777002</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"i"</span>]
[<span class="hljs-number">10.881112</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"c"</span>]
[<span class="hljs-number">10.952884</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"e"</span>]
[<span class="hljs-number">11.088641</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">" "</span>]
[<span class="hljs-number">11.201045</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"t"</span>]
[<span class="hljs-number">11.466022</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"a"</span>]
[<span class="hljs-number">11.553785</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"b"</span>]
[<span class="hljs-number">11.818412</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"l"</span>]
[<span class="hljs-number">11.961808</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"e"</span>]
[<span class="hljs-number">13.51443</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\r\n"</span>]
[<span class="hljs-number">13.514675</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"bash: syntax error near unexpected token `)'\r\n"</span>]
[<span class="hljs-number">13.518913</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b]777;notify;Command completed;1) A nice table\u001b\\\u001b]777;precmd\u001b\\\u001b]0;josevnz@dmaf5:~/SuricataLog-Logging-features-branch\u001b\\"</span>]
[<span class="hljs-number">13.520551</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b]7;file://dmaf5/home/josevnz/SuricataLog-Logging-features-branch\u001b\\"</span>]
[<span class="hljs-number">13.52072</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"[josevnz@dmaf5 SuricataLog-Logging-features-branch]$ "</span>]
[<span class="hljs-number">22.176716</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"eve_log.py --format table --timestamp '2022-02-23T18:22:24.405139+0000' test/eve.jso"</span>]
[<span class="hljs-number">24.202009</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"n"</span>]
[<span class="hljs-number">26.097822</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\r\n"</span>]
[<span class="hljs-number">26.098024</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b]777;preexec\u001b\\"</span>]
[<span class="hljs-number">26.312676</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b[?1049h\u001b[H\u001b[?1000h\u001b[?1003h\u001b[?1015h\u001b[?1006h\u001b[?25l\u001b[?1003h\r\n"</span>]
[<span class="hljs-number">26.314059</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001bP=1s\u001b\\\u001b[H\u001b[H                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                               "</span>]
[<span class="hljs-number">26.314299</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"            \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                              "</span>]
[<span class="hljs-number">26.314387</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"             \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                             "</span>]
[<span class="hljs-number">26.314455</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"              \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                            "</span>]
[<span class="hljs-number">26.314502</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"               \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                           "</span>]
[<span class="hljs-number">26.31456</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"                \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                          "</span>]
[<span class="hljs-number">26.314616</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"                 \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \u001bP=2s\u001b\\"</span>]
[<span class="hljs-number">26.31467</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001bP=1s\u001b\\\u001b[H\u001b[H                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                               "</span>]
[<span class="hljs-number">26.314714</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"            \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                              "</span>]
[<span class="hljs-number">26.314781</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"             \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                             "</span>]
[<span class="hljs-number">26.314843</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"              \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                            "</span>]
[<span class="hljs-number">26.314902</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"               \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                           "</span>]
[<span class="hljs-number">26.314957</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"                \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                          "</span>]
[<span class="hljs-number">26.315012</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"                 \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \u001bP=2s\u001b\\"</span>]
[<span class="hljs-number">26.316033</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001b[?25l"</span>]
[<span class="hljs-number">26.318086</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\r\u001b[2KParsing test/eve.json \u001b[38;5;237m........................................................................................................................\u001b[0m \u001b[35m  0%\u001b[0m \u001b[36m-:--:--\u001b[0m"</span>]
[<span class="hljs-number">26.378123</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\r\u001b[2KParsing test/eve.json \u001b[38;2;114;156;31m........................................................................................................................\u001b[0m \u001b[35m100%\u001b[0m \u001b[36m0:00:00\u001b[0m\r\n\u001b[?25h"</span>]
[<span class="hljs-number">26.390312</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001bP=1s\u001b\\\u001b[H\u001b[H                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                               "</span>]
[<span class="hljs-number">26.39044</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"            \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                              "</span>]
[<span class="hljs-number">26.390499</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"             \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                             "</span>]
[<span class="hljs-number">26.390559</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"              \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                            "</span>]
[<span class="hljs-number">26.390615</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"               \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                           "</span>]
[<span class="hljs-number">26.39064</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"                \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                          "</span>]
[<span class="hljs-number">26.390719</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"                 \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \u001bP=2s\u001b\\"</span>]
[<span class="hljs-number">26.390868</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001bP=1s\u001b\\\u001b[H\u001b[H                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                               "</span>]
[<span class="hljs-number">26.390893</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"            \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                              "</span>]
[<span class="hljs-number">26.390944</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"             \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                             "</span>]
[<span class="hljs-number">26.391027</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"              \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                            "</span>]
[<span class="hljs-number">26.391091</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"               \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                           "</span>]
[<span class="hljs-number">26.391116</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"                \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                          "</span>]
[<span class="hljs-number">26.391172</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"                 \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \u001bP=2s\u001b\\"</span>]
[<span class="hljs-number">26.431391</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"\u001bP=1s\u001b\\\u001b[H\u001b[3m                                                                                      Suricata alerts for 2022-02-23 18:22:24.405139, logs=test/eve.json                                                   \u001b[0m\r\n.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\r\n...\u001b[1;35m \u001b[0m\u001b[1;35mTimestamp                      \u001b[0m\u001b[1;35m \u001b[0m...\u001b[1;35m \u001b[0m\u001b[1;35mSeverity\u001b[0m\u001b[1;35m \u001b[0m...\u001b[1;35m \u001b[0m\u001b[1;35mSignature                                           \u001b"</span>]
[<span class="hljs-number">26.431543</span>, <span class="hljs-string">"o"</span>, <span class="hljs-string">"[0m\u001b[1;35m \u001b[0m...\u001b[1;35m \u001b[0m\u001b[1;35mProtocol\u001b[0m\u001b[1;35m \u00HTTP/1.1 413 Request Entity Too Large
Content-Length: 176
Content-Type: text/html
Date: Fri, 22 Apr 2022 11:17:19 GMT
Server: nginx
Connection: close

&lt;html&gt;
&lt;head&gt;&lt;title&gt;413 Request Entity Too Large&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;&lt;h1&gt;413 Request Entity Too Large&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;</span>
</code></pre>
<h1 id="heading-what-is-next-for-you"><strong>What is next for you?</strong></h1>
<p>So next time you have an issue with a program that is installed on your system you will know what to check.</p>
<p>We covered 3 ways to investigate an issue with an application that uploads a file to a remote website using HTTPS:</p>
<ol>
<li><p>Using <em>strace</em></p>
</li>
<li><p>If the program is a Python script, then there is a good chance you can read the code yourself and run the script through <em>the debugger</em>, step by step, to understand the issue. This is probably the most time-consuming way, but also it is the most rewarding as you learn how other good developers think!</p>
</li>
<li><p>And finally, we captured the encrypted traffic between us and the remote site and analyzed the upload. By enabling certain special features we were able to decrypt and replay the traffic, confirming our findings from the previous two interactions.</p>
</li>
</ol>
<p>This list of techniques is not exhaustive, but for some cases like this they will give you a good start.</p>
<p>As usual please share your feedback! Let's have a conversation so everybody learns a little.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Discord Won't Open on my PC [Solved in Windows 10] ]]>
                </title>
                <description>
                    <![CDATA[ Discord is an instant messaging app you can use to communicate through text messages, voice calls, and video calls. You can also use it to share files.  Discord was originally created for gamers, but many other people now use it these days. It has be... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/discord-wont-open-on-my-pc-solved-in-windows-10/</link>
                <guid isPermaLink="false">66adf0b6febac312b73075a8</guid>
                
                    <category>
                        <![CDATA[ Chat ]]>
                    </category>
                
                    <category>
                        <![CDATA[ discord ]]>
                    </category>
                
                    <category>
                        <![CDATA[ how-to ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Tue, 09 Nov 2021 14:57:04 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/Discord.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Discord is an instant messaging app you can use to communicate through text messages, voice calls, and video calls. You can also use it to share files. </p>
<p>Discord was originally created for gamers, but many other people now use it these days. It has become an alternative to Slack for many users – especially for those who want to have an online community.</p>
<p>But sometimes, Discord might not open when you launch it. This could be due to pending updates, running games, and other causes.</p>
<p>In this article, I will show you 5 quick ways you can make Discord open again on a Windows 10 computer.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-how-to-fix-discord-not-opening-in-the-command-line">How to Fix Discord Not Opening in the Command Line</a></li>
<li><a class="post-section-overview" href="#heading-how-to-fix-discord-not-opening-by-clearing-appdata">How to Fix Discord Not Opening by Clearing AppData</a></li>
<li><a class="post-section-overview" href="#heading-how-to-fix-discord-not-opening-by-clearing-localappdata">How to Fix Discord Not Opening by Clearing LocalAppData</a></li>
<li><a class="post-section-overview" href="#heading-how-to-fix-discord-not-opening-by-closing-background-applications">How to Fix Discord Not Opening by Closing Background Applications</a></li>
<li><a class="post-section-overview" href="#heading-how-to-fix-discord-not-opening-with-the-task-manager">How to Fix Discord Not Opening with the Task Manager</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-how-to-fix-discord-not-opening-in-the-command-line">How to Fix Discord Not Opening in the Command Line</h2>
<p>The number one fix I would recommend to make Discord open again is to kill the Discord task with the Command Prompt.</p>
<p>This is how to do it:</p>
<p><strong>Step 1</strong>: Click on Start or press <code>WIN</code> (Windows key) on your keyboard, then search for "cmd".</p>
<p><strong>Step 2</strong>: Hit <code>ENTER</code> or select the first search result to open the Command Prompt.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-1-5.jpg" alt="ss-1-5" width="600" height="400" loading="lazy"></p>
<p><strong>Step</strong>: Type in <code>taskkill /F /IM discord.exe</code> and hit <code>ENTER</code>.</p>
<p>You should get a message that the Discord process has been terminated.
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-2-1.png" alt="ss-2-1" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-fix-discord-not-opening-by-clearing-appdata">How to Fix Discord Not Opening by Clearing AppData</h2>
<p>When you clear an app's AppData, all cache files are cleared – which can fix some problems, including loading.</p>
<p>Go through the following steps to clear your Discord's AppData:</p>
<p><strong>Step 1</strong>: Press <code>WIN</code> (Windows key) + R to open the Run dialogue.</p>
<p><strong>Step 2</strong>: Type in "%appdata%" (without quotes) and press <code>ENTER</code> on your keyboard. This will open up the AppData folder.
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-3-1.png" alt="ss-3-1" width="600" height="400" loading="lazy"></p>
<p><strong>Step 3</strong>: Locate the Discord folder and delete it. Delete it from your Recycle Bin too.
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-4-6.jpg" alt="ss-4-6" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-fix-discord-not-opening-by-clearing-localappdata">How to Fix Discord Not Opening by Clearing LocalAppData</h2>
<p>Clearing the Discord's LocalAppData can make it open again. It can also fix the common JavaScript error associated with Discord as well. </p>
<p>To clear LocalAppData, follow these steps:</p>
<p><strong>Step 1</strong>: Press <code>WIN</code> (Windows key) + R to open the Run dialogue.</p>
<p><strong>Step 2</strong>: Type in "%localappdata%" (without quotes) and press <code>ENTER</code> on your keyboard. This will open up the LocalAppData folder.
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-5.png" alt="ss-5" width="600" height="400" loading="lazy"></p>
<p><strong>Step 3</strong>: Look for the Discord folder and delete it. Go to your Recycle Bin and delete it too.
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-6-5.jpg" alt="ss-6-5" width="600" height="400" loading="lazy"></p>
<p>Note that you might have to reinstall Discord to get it running again after clearing its LocalAppData. I can attest that this solves the issue as I recently had to do it.</p>
<h2 id="heading-how-to-fix-discord-not-opening-by-closing-background-applications">How to Fix Discord Not Opening by Closing Background Applications</h2>
<p>A lot of games run in the background and this could have a negative effect on your Discord app.</p>
<p>Use the steps below to fix the issue only if you don't have useful apps running in the background.</p>
<p><strong>Step 1</strong>: Click on Start or press <code>WIN</code> (Windows key) on your keyboard and select Settings.
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-7-1.jpg" alt="ss-7-1" width="600" height="400" loading="lazy"></p>
<p><strong>Step 2</strong>: Select "Privacy".
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-8-2.jpg" alt="ss-8-2" width="600" height="400" loading="lazy"></p>
<p><strong>Step 3</strong>: Click on Background apps on the left, then turn off the toggle under "Let apps run in the background".
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-9-1.jpg" alt="ss-9-1" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-fix-discord-not-opening-with-the-task-manager">How to Fix Discord Not Opening with the Task Manager</h2>
<p>Stopping the Discord process with the Task Manager can make Discord open again as this refreshes the app.</p>
<p><strong>Step 1</strong>: Press <code>CTRL</code> + <code>SHIFT</code> + <code>ESC</code> to open the Task Manager</p>
<p><strong>Step 2</strong>: Make sure you are under the <code>Processes</code>. Right-click on Discord and select "End Task". 
<img src="https://www.freecodecamp.org/news/content/images/2021/11/ss-10-2.jpg" alt="ss-10-2" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, you learned how to fix Discord when it won't open in a few different ways.</p>
<p>Apart from the methods discussed in this guide, you can also fix the issue by uninstalling and reinstalling Discord. </p>
<p>Note that you can also fix another popular issue with Discord – JavaScript error – by using one of the fixes suggested in this article – clearing LocalAppData. I've had to do this myself.</p>
<p>Thanks a lot for reading. If you find this article helpful, consider sharing it with your friends. That's very much appreciated.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Pseudocode? How to Use Pseudocode to Solve Coding Problems ]]>
                </title>
                <description>
                    <![CDATA[ You might be wondering what pseudocode is and why it's so useful for writing computer programs. But before we jump into pseudocode, let's refresh our memories about what programming and coding are, in the simplest sense. Programming is the manifestat... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-pseudocode-in-programming/</link>
                <guid isPermaLink="false">66d4619e38f2dc3808b79119</guid>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kingsley Ubah ]]>
                </dc:creator>
                <pubDate>Mon, 26 Jul 2021 19:23:37 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/07/Pseudocode.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>You might be wondering what pseudocode is and why it's so useful for writing computer programs.</p>
<p>But before we jump into pseudocode, let's refresh our memories about what programming and coding are, in the simplest sense.</p>
<p>Programming is the manifestation of logic. A program is a set of instructions that defines the behaviour of your software application. Writing code is how you implement it for the machine.</p>
<h2 id="heading-what-is-pseudocode">What is Pseudocode?</h2>
<p>Pseudocode literally means ‘fake code’. It is an <strong>informal</strong> and <strong>contrived</strong> way of writing programs in which you represent the sequence of actions and instructions (aka algorithms) in a form that humans can easily understand.</p>
<p>You see, computers and human beings are quite different, and therein lies the problem.</p>
<p>The language of a computer is very rigid: you are not allowed to make any mistakes or deviate from the rules. Even with the invention of high-level, human-readable languages like JavaScript and Python, it’s still pretty hard for an average human developer to reason and program in those coding languages.</p>
<p>With pseudocode, however, it’s the exact opposite. You make the rules. It doesn’t matter what language you use to write your pseudocode. All that matters is comprehension.</p>
<p>In pseudocode, you don't have to think about semi-colons, curly braces, the syntax for arrow functions, how to define promises, DOM methods and other core language principles. You just have to be able to explain what you're thinking and doing.</p>
<h2 id="heading-benefits-of-writing-pseudocode">Benefits of Writing Pseudocode</h2>
<p>When you're writing code in a programming language, you’ll have to battle with strict syntax and rigid coding patterns. But you write pseudocode in a language or form with which you're very familiar.</p>
<p>Since pseudocode is an informal method of program design, you don’t have to obey any set-out rules. <strong>You make the rules yourself.</strong></p>
<p>Pseudocode acts as the bridge between your brain and computer’s code executor. It allows you to plan instructions which follow a logical pattern, without including all of the technical details.</p>
<p>Pseudocode is a great way of getting started with software programming as a beginner. You won’t have to overwhelm your brain with coding syntax.</p>
<p>In fact, many companies organize programming tests for their interviewees in pseudocode. This is because the importance of problem solving supersedes the ability to ‘hack’ computer code.</p>
<p>You can get quality code from many platforms online, but you have to learn problem solving and practice it a lot.</p>
<p>Planning computer algorithms with pseudocode makes you meticulous. It helps you explain exactly what each line in a software program should do. This is possible because you are in full control of everything, which is one of the great features of pseudocode.</p>
<h2 id="heading-example-of-pseudocode">Example of Pseudocode</h2>
<p>Pseudocode is a very intuitive way to develop software programs. To illustrate this, I am going to refer back to a very simple program I wrote in my <a target="_blank" href="https://www.freecodecamp.org/news/programming-coding-developement-whats-the-difference/">last article</a>:</p>
<p>When a user fills in a form and clicks the submit button, execute a ValidateEmail function. What should the function do?</p>
<ol>
<li><p>Derive an email regular expression (regex) to test the user's email address against.</p>
</li>
<li><p>Access the user's email from the DOM and store it in a variable. Find and use the right DOM method for that task.</p>
</li>
<li><p>With the email value now accessed and stored, create a conditional statement:</p>
</li>
</ol>
<ul>
<li><p>If the email format doesn’t match the rule specified by the regex, access the element with the <code>myAlert</code> id attribute and pass in the “Invalid Email” message for the user to see.</p>
</li>
<li><p>Else, if the above condition isn’t true and the email address format actually matches with the regex, check to see if the database already has such an email address. If it already does, access the element with the <code>myAlert</code> id attribute and pass in the “Email exists!” message for the user to see.</p>
</li>
<li><p>Now, if both of these conditions aren’t met, (that is the email format matches the regex and the database doesn’t have such an email address stored yet), push the users email address into the database and pass in the “Successful!” message for the user to see.</p>
</li>
</ul>
<p>Once you are done outlining the various steps you want your code to take, everything becomes easier and clearer. Now, let’s turn that psedocode into real JavaScript code:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> database = [<span class="hljs-string">'test1@gmail.com'</span>, <span class="hljs-string">'test2@gmail.com'</span>, <span class="hljs-string">'test3@gmail.com'</span>];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">validateEmail</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">let</span> regexEmail = <span class="hljs-regexp">/^\w+([.-]?\w+)@\w+([.-]?\w+)(.\w{2,3})+$/</span>;
    <span class="hljs-keyword">let</span> emailAddress = <span class="hljs-built_in">document</span>.getElementbyID(<span class="hljs-string">'emailFld'</span>).value;
    <span class="hljs-keyword">if</span> (!emailAddress.match(regexEmail)) {
        <span class="hljs-built_in">document</span>.getElementbyID(<span class="hljs-string">'myAlert'</span>).innerHTML = <span class="hljs-string">"Invalid Email!"</span>;
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (database.includes(emailAddress)) {
        <span class="hljs-built_in">document</span>.getElementbyID(<span class="hljs-string">'myAlert'</span>).innerHTML = <span class="hljs-string">"Email exists!"</span>;
      <span class="hljs-keyword">else</span> {
        database.push(emailAddress);
        <span class="hljs-built_in">document</span>.getElementbyID(<span class="hljs-string">'myAlert'</span>).innerHTML = <span class="hljs-string">"Successful!"</span>;
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
      }
}

<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"myBtn"</span>).addEventListener(<span class="hljs-string">"click"</span>, validateEmail);
</code></pre>
<p>All you have to do at this stage is find the programming language constructs that will help you achieve each of your steps. Noticed how seamless the transition from pseudocode to actual code became? That’s how effective writing pseudocode can be for program design.</p>
<p>Pseudocode is also a great way to solve programming-related problems when you're struggling with them. For those practising programming in coding challenge platforms like <a target="_blank" href="https://www.codewars.com/dashboard">CodeWars</a>, pseudocode can be of immense help.</p>
<h2 id="heading-how-to-solve-programming-problems-with-pseudocode">How to Solve Programming Problems with Pseudocode</h2>
<p>Solving programming problems can be hard. Not only do you have the logical part to reckon with, but also the technical (code forming) part as well. I recently uncovered a brilliant and effective formula for solving tricky coding problems.</p>
<p>Here are the steps you can follow to solving programming problems with pseudocode:</p>
<h3 id="heading-step-1-understand-what-the-function-does">Step 1: Understand what the function does</h3>
<p>First, you need to understand that all a function does is (optionally) accept data as input, work on the data little by little, and finally return an output. The body of the function is what actually solves the problem and it does so line by line.</p>
<h3 id="heading-step-2-make-sure-you-understand-the-question">Step 2: Make sure you understand the question</h3>
<p>Next, you need to read and understand the question properly. This is arguably the most important step in the process.</p>
<p>If you fail to properly understand the question, you won’t be able to work through the problem and figure out the possible steps to take. Once you identify the main problem to be solved you'll be ready to tackle it.</p>
<h3 id="heading-step-3-break-the-problem-down">Step 3: Break the problem down.</h3>
<p>Now you need to break down the problem into smaller parts and sub-problems. With each smaller problem you solve, you'll get closer to solving the main problem.</p>
<p>It helps to represent these problem solving steps in the clearest and most easily understandable way you can – which is psedocode!</p>
<ul>
<li><p>Start solving: open and use tools like Google, Stack Overflow, MDN, and of course freeCodeCamp! :)</p>
</li>
<li><p>For every step of the problem that you solve, test the output to make sure you’re on the right path. Keep solving these small problems until you arrive at the final solution.</p>
</li>
</ul>
<p>I picked up this highly effective formula from Aaron Jack and I think you’ll benefit from it. Check out his video about how to solve coding problems:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/Dblfmk3ATeg" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p> </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>As you can see, pseudocode is a very useful strategy for planning computer programs.</p>
<p>Of course, you have to remember that pseudocode is <strong>not a true representation</strong> of a computer program. While using pseudocode to plan your algorithm is great, you will ultimately have to translate it into an actual computer-readable program. This means that you'll eventually need to learn how to program in a real programming language.</p>
<p>Taking up coding challenges online is a great way to learn how to program because, as they say, practice makes perfect. But when you try your next challenge, don’t forget to implement pseudocode in the process!</p>
<p>You can check out some of my other programming-related posts on my personal <a target="_blank" href="https://ubahthebuilder.tech/">blog</a>. I am also available on <a target="_blank" href="https://twitter.com/ubahthebuilder">Twitter</a>.</p>
<p>Thank you for reading and see you soon.</p>
<blockquote>
<p>P/S: If you are learning JavaScript, I created an eBook which teaches 50 topics in JavaScript with hand-drawn digital notes. <a target="_blank" href="https://ubahthebuilder.gumroad.com/l/js-50">Check it out here</a>.</p>
</blockquote>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Solve Leetcode Problems With Python One-Liners ]]>
                </title>
                <description>
                    <![CDATA[ By Ganesh Kumar Marimuthu Python is one of the most powerful programming languages. It gives us various unique features and functionalities that make it easy for us to write code.  In this article we'll solve Leetcode array problems in one line using... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/solve-leetcode-problems-using-python-list-comprehension/</link>
                <guid isPermaLink="false">66d45edbb3016bf139028d2f</guid>
                
                    <category>
                        <![CDATA[ leetcode ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 02 Apr 2021 15:13:35 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/60640fde9618b008528aa027.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ganesh Kumar Marimuthu</p>
<p>Python is one of the most powerful programming languages. It gives us various unique features and functionalities that make it easy for us to write code. </p>
<p>In this article we'll solve Leetcode array problems in one line using one of Python's most interesting features – <strong>List Comprehension</strong>.</p>
<h2 id="heading-what-is-list-comprehension">What is List Comprehension?</h2>
<p>Before going into the problems, let's make sure we understand what list comprehension is all about.</p>
<blockquote>
<p>A list comprehension is a syntactic construct available in some programming languages for creating a list based on existing lists  </p>
<ul>
<li>Wikipedia</li>
</ul>
</blockquote>
<p>Let's see how list comprehension works with an example.</p>
<p>Consider an array of numbers. Our task is to add 1 to the numbers at odd indices and to add 2 to the number at even indices.</p>
<p>Now we'll see how to solve the above problem using both a for-loop and list comprehension.</p>
<h3 id="heading-how-to-solve-the-problem-with-a-for-loop">How to solve the problem with a for-loop</h3>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">addOneAndTwo</span>(<span class="hljs-params">nums, n</span>):</span>
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(n):
        <span class="hljs-keyword">if</span> i % <span class="hljs-number">2</span> == <span class="hljs-number">1</span>:
            nums[i] += <span class="hljs-number">1</span> 
        <span class="hljs-keyword">else</span>:
            nums[i] += <span class="hljs-number">2</span> 
    <span class="hljs-keyword">return</span> nums
</code></pre>
<h3 id="heading-how-to-solve-it-with-list-comprehension">How to solve it with list comprehension</h3>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">addOneAndTwo</span>(<span class="hljs-params">nums, n</span>):</span>
    <span class="hljs-keyword">return</span> [nums[i] + <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> i % <span class="hljs-number">2</span> == <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> nums[i] + <span class="hljs-number">2</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(n)]
</code></pre>
<p>You can see how the solution using list comprehension is simplified from 6 lines to 1 line. This is the power of list comprehension.</p>
<h2 id="heading-how-to-solve-leetcode-problems-with-list-comprehension">How to Solve Leetcode Problems with List Comprehension</h2>
<p>Now let us solve the below Leetcode problems in 1 line using list comprehension.</p>
<h3 id="heading-1-shuffle-the-arrayhttpsleetcodecomproblemsshuffle-the-array">1. <a target="_blank" href="https://leetcode.com/problems/shuffle-the-array/">Shuffle The Array</a></h3>
<p>Here's the problem from Leetcode:</p>
<p>Given the array <code>nums</code> consisting of <code>2n</code> elements in the form <code>[x&lt;sub&gt;1&lt;/sub&gt;,x&lt;sub&gt;2&lt;/sub&gt;,...,x&lt;sub&gt;n&lt;/sub&gt;,y&lt;sub&gt;1&lt;/sub&gt;,y&lt;sub&gt;2&lt;/sub&gt;,...,y&lt;sub&gt;n&lt;/sub&gt;]</code>. <em>Return the array in the form</em> <code>[x&lt;sub&gt;1&lt;/sub&gt;,y&lt;sub&gt;1&lt;/sub&gt;,x&lt;sub&gt;2&lt;/sub&gt;,y&lt;sub&gt;2&lt;/sub&gt;,...,x&lt;sub&gt;n&lt;/sub&gt;,y&lt;sub&gt;n&lt;/sub&gt;]</code>.</p>
<h4 id="heading-example">Example</h4>
<p>Input: nums = [2,5,1,3,4,7], n = 3<br>Output: [2,3,5,4,1,7] </p>
<p>Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].</p>
<h4 id="heading-solution">Solution</h4>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">shuffle</span>(<span class="hljs-params">self, nums, n</span>):</span>
    <span class="hljs-keyword">return</span> reduce(<span class="hljs-keyword">lambda</span> a, b: a + b, [[nums[i], nums[j]] <span class="hljs-keyword">for</span> i, j <span class="hljs-keyword">in</span> zip(range(<span class="hljs-number">0</span>, n), range(n, <span class="hljs-number">2</span> * n))])
</code></pre>
<h3 id="heading-2-number-of-good-pairshttpsleetcodecomproblemsnumber-of-good-pairs">2. <a target="_blank" href="https://leetcode.com/problems/number-of-good-pairs/">Number of Good Pairs</a></h3>
<p>Given an array of integers <code>nums</code>. A pair <code>(i,j)</code> is called <em>good</em> if <code>nums[i]</code> == <code>nums[j]</code> and <code>i</code> &lt; <code>j</code>.Return the number of <em>good</em> pairs.</p>
<h4 id="heading-example-1">Example</h4>
<p>Input: nums = [1,2,3,1,1,3]<br>Output: 4 </p>
<p>Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.</p>
<h4 id="heading-solution-1">Solution</h4>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">numIdenticalPairs</span>(<span class="hljs-params">self, nums</span>):</span>
    <span class="hljs-keyword">return</span> sum([int(i != j <span class="hljs-keyword">and</span> nums[i] == nums[j]) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">0</span>, len(nums)) <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> range(i + <span class="hljs-number">1</span>, len(nums))])
</code></pre>
<h3 id="heading-3-kids-with-the-greatest-number-of-candieshttpsleetcodecomproblemskids-with-the-greatest-number-of-candies">3. <a target="_blank" href="https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/">Kids With the Greatest Number of Candies</a></h3>
<p>Given the array <code>candies</code> and the integer <code>extraCandies</code>, where <code>candies[i]</code> represents the number of candies that the <strong><em>ith</em></strong> kid has.</p>
<p>For each kid check if there is a way to distribute <code>extraCandies</code> among the kids such that they can have the <strong>greatest</strong> number of candies among them. Notice that multiple kids can have the <strong>greatest</strong> number of candies.</p>
<h4 id="heading-example-2">Example</h4>
<p>Input: candies = [2,3,5,1,3], extraCandies = 3<br>Output: [true,true,true,false,true]</p>
<p>Explanation: Kid 1 has 2 candies, and if they receive all extra candies (3) they will have 5 candies – the greatest number of candies among the kids. </p>
<p>Kid 2 has 3 candies, and if they receive at least 2 extra candies then they will have the greatest number of candies among the kids. </p>
<p>Kid 3 has 5 candies, and this is already the greatest number of candies among the kids. </p>
<p>Kid 4 has 1 candy, and even if they receive all extra candies they will only have 4 candies. </p>
<p>Kid 5 has 3 candies, and if they receive at least 2 extra candies then they will have the greatest number of candies among the kids.</p>
<h4 id="heading-solution-2">Solution</h4>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">kidsWithCandies</span>(<span class="hljs-params">self, candies, extraCandies</span>):</span>
    <span class="hljs-keyword">return</span> [candy + extraCandies &gt;= max(candies) <span class="hljs-keyword">for</span> candy <span class="hljs-keyword">in</span> candies]
</code></pre>
<h3 id="heading-4-decompress-run-length-encoded-listhttpsleetcodecomproblemsdecompress-run-length-encoded-list">4. <a target="_blank" href="https://leetcode.com/problems/decompress-run-length-encoded-list/">Decompress Run-Length Encoded List</a></h3>
<p>We are given a list <code>nums</code> of integers representing a list compressed with run-length encoding.</p>
<p>Consider each adjacent pair of elements <code>[freq, val] = [nums[2*i], nums[2*i+1]]</code> (with <code>i &gt;= 0</code>).  For each such pair, there are <code>freq</code> elements with value <code>val</code> concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.</p>
<p>Return the decompressed list.</p>
<h4 id="heading-example-3">Example</h4>
<p>Input: nums = [1,2,3,4]<br>Output: [2,4,4,4] </p>
<p>Explanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2]. </p>
<p>The second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4]. At the end the concatenation [2] + [4,4,4] is [2,4,4,4].</p>
<h4 id="heading-solution-3">Solution</h4>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">decompressRLElist</span>(<span class="hljs-params">self, nums</span>):</span>
    <span class="hljs-keyword">return</span> reduce(<span class="hljs-keyword">lambda</span> a, b: a + b, [[nums[i + <span class="hljs-number">1</span>]] * nums[i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">0</span>, len(nums), <span class="hljs-number">2</span>)])
</code></pre>
<h3 id="heading-5-richest-customers-wealthhttpsleetcodecomproblemsrichest-customer-wealth">5. <a target="_blank" href="https://leetcode.com/problems/richest-customer-wealth/">Richest Customer's Wealth</a></h3>
<p>You are given an <code>m x n</code> integer grid <code>accounts</code> where <code>accounts[i][j]</code> is the amount of money the <code>i​​​​​&lt;sup&gt;​​​​​​th&lt;/sup&gt;​​​​</code> customer has in the <code>j​​​​​&lt;sup&gt;​​​​​​th&lt;/sup&gt;</code>​​​​ bank. Return <em>the <strong>wealth</strong> that the richest customer has.</em></p>
<p>A customer's <strong>wealth</strong> is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum <strong>wealth</strong>.</p>
<h4 id="heading-example-4">Example</h4>
<p>Input: accounts = [[1,2,3],[3,2,1]]<br>Output: 6 </p>
<p>Explanation: <code>1st customer has wealth = 1 + 2 + 3 = 6 2nd customer has wealth = 3 + 2 + 1 = 6</code>  Both customers are considered the richest with a wealth of 6 each, so return 6.</p>
<h4 id="heading-solution-4">Solution</h4>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">maximumWealth</span>(<span class="hljs-params">self, accounts</span>):</span>
    <span class="hljs-keyword">return</span> max([sum(row) <span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> accounts])
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I hope the above solutions were useful. You can combine <a target="_blank" href="https://data-flair.training/blogs/python-list-comprehension/"><strong>list comprehension</strong></a> with other functions like <a target="_blank" href="https://www.freecodecamp.org/news/15-useful-javascript-examples-of-map-reduce-and-filter-74cbbb5e0a1f/"><strong>map</strong>, <strong>filter</strong> and <strong>reduce</strong></a> to make the solutions more simple and effective.</p>
<h2 id="heading-thank-you">Thank You 🤘</h2>
<p><a target="_blank" href="https://www.linkedin.com/in/ganeshkumarm1">Linkedin</a> | <a target="_blank" href="https://github.com/ganeshkumarm1">Github</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Programming Project Step by Step ]]>
                </title>
                <description>
                    <![CDATA[ By Ogundiran Ayobami This tweet about building projects really resonated with me:  It says a lot about how programmers build the projects we all admire. It pin-points the less glamorous parts of our activities which beginners don't always pay attent... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-programming-projects/</link>
                <guid isPermaLink="false">66d84e6f5a0b456f4d32144c</guid>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ projects ]]>
                    </category>
                
                    <category>
                        <![CDATA[ self-improvement  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 30 Mar 2021 22:08:44 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/6040a754a7946308b7681492.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ogundiran Ayobami</p>
<p>This tweet about building projects really resonated with me: </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/03/projects-tweet.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>It says a lot about how programmers build the projects we all admire. It pin-points the less glamorous parts of our activities which beginners don't always pay attention to, probably because of their lack of experience.</p>
<p>And that reminds me of my recent experience building a VSCode extension. The extension is meant to make me look like a genius in video tutorials and reduce my recording challenges. (But hey – I am really not a genius 😜).</p>
<p>The extension displays the content of a file per character whenever any key is pressed. It simulates a real-coding experience while I only pay attention to the voice recording. Wow! How did I build that? Well, let's see how it went.</p>
<p>It might go without saying, but you don't know how to build a new project until you've actually built it. Before I started, I didn't feel like I knew what to do and what to bring together. But I was sure of one thing – I knew how to find what I needed. Boom! The research began.</p>
<p>So let me tell you how I did it, so you can get better at building your own projects, too.</p>
<h2 id="heading-break-the-project-down-into-smaller-units">Break the Project Down into Smaller Units</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-310.png" alt="Image" width="600" height="400" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@markusspiske?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Markus Spiske / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
<p>I knew it would be hard to find a complete tutorial about what I wanted to build. But it was relatively easy to find tutorial related to each unit of the project. So, I broke the project down into these parts:</p>
<ol>
<li>Installing the VSCode extension.</li>
<li>Getting the content of an active file.</li>
<li>Breaking down the content of the file into characters. (Word =&gt; w, o, r, d).</li>
<li>Listening to key-presses.</li>
<li>Displaying the character one by one whenever any key was pressed.</li>
</ol>
<p>Those are the basic things I expected the extension to be able to handle.</p>
<p>But wait! What if I am building a whole website? Don't worry – it's still the same process. This is what I would have done if I wanted to build a website, too.</p>
<h3 id="heading-step-1-break-everything-up-into-sections">Step 1: Break everything up into sections</h3>
<p>For a website, your manageable sections might look like this:</p>
<ol>
<li>Header</li>
<li>Main</li>
<li>SideBars</li>
<li>Footer</li>
</ol>
<h3 id="heading-step-2-break-the-sections-down-into-components">Step 2: Break the sections down into components</h3>
<p>To do this, I would ask myself what I wanted in each section. And then I would list those elements out one by one.</p>
<p>✅ Header: I want a logo, search-box, signup/login button (or other navigation buttons) and settings in the header.</p>
<p>✅ Main: How many column(s) do I need? Does it have to include a left or right sidebar or a list?</p>
<p>✅ Footer: Do I want copyright information and navigation in the footer? Anything else?</p>
<p>Then I'd ask myself what other things I wanted and note them down as I thought of them.</p>
<p>In short, you have to list out everything you want in each section and component. But don't waste too much time on planning, because execution is key. Do it as quickly as possible because once you have a job, you'll probably hardly have any spare time to plan out your projects. </p>
<p>But you might be thinking, Oh, no! I am confused. How do I know all the sections and components I need as a beginner? </p>
<p>That is a good observation because I am not a beginner and I have had experience with of all of these components. That is why I can list them easily. </p>
<p>But it's ok. You will learn all these things along the line. You just need to pay attention to my VSCode extension story. :)</p>
<h2 id="heading-write-your-first-line-of-code-and-get-stuck">Write Your First Line of Code and Get Stuck‌</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-311.png" alt="Image" width="600" height="400" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@fx24?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Fernando Jorge / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
<p>After having a clear picture of what to build, I believe the most important thing to kick-start a project is to write you first line of code and get stuck. It is pessimistic, but it helps you to become solution driven. </p>
<p>Instead of being worried unnecessarily because you're not sure of how to start, open you code editor of choice and write your first line of code – even if you get stuck right after that.</p>
<p>You first line of code will probably get deleted or improved upon several times, and that is fine. It is meant to help you overcome procrastination. </p>
<p>In reality, you will always be confused about how to start and what to do. Don't procrastinate because of such feelings, especially after you understand how the project should work in your head or on paper.</p>
<p>Don't try to understand everything before writing your first line of code. You will never understand everything. At least, no one has ever understood everything yet.</p>
<h2 id="heading-no-project-is-perfect-including-google">No Project is Perfect – Including Google‌</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-312.png" alt="Image" width="600" height="400" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@brett_jordan?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Brett Jordan / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
<p>It is easy to want your project to be the best ever built, especially when you are a beginner. I have been there, so I know how it feels. </p>
<p>I was just an art student trying to solve a problem by using web technology. After I failed to hire a web developer to build the project for me because I couldn't afford the price they quoted, I decided to learn how to build it by myself.</p>
<p>Silly me tried to build almost every feature on the internet to make sure my project had all the features others didn't have. Anyway, I killed the project eventually.</p>
<p>The point I am making is don't try to build a project that can't be criticized – there is nothing like that. You need to focus on core features, not extra features that might make the project unusable. </p>
<p>Don't try to make a perfect project or feature – make usable and lovable projects and features instead.</p>
<h2 id="heading-every-project-is-built-on-other-projects">Every Project is Built on Other Projects</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-313.png" alt="Image" width="600" height="400" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@lidyanada?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Lidya Nada / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
<p>After I had a clear picture of what I needed to build the VSCode extension, I had to look into related projects. I opened the source code of vscode-hacker-typer to study how the project handles some of the things I wanted to implement. By doing that, I learnt a bit about VSCode extension APIs.</p>
<p>As I was totally inexperienced in making VSCode extensions, looking into vscode-hacker-typer helped me move from being totally clueless to knowing what to research. </p>
<p>Knowing the name of what you want to deal with is the greatest first step to solving any problem in programming. </p>
<p>For instance, say that there is a feature you like on a related website but you don't know what it is called. How will you research the feature? Well, it is not rocket science.</p>
<p>You can take a picture of the feature and ask for its name in programming groups or ask someone. Or you can discover it name or API by diving into a related project's source code like I did. So check out projects that are similar to your project, learn from them, and copy their features.</p>
<h2 id="heading-dont-be-afraid-to-google">Don't Be Afraid to Google</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-314.png" alt="Image" width="600" height="400" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@mitchel3uo?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Mitchell Luo / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
<p>Before I dove into creating the VSCode extension, I didn't even know where to start – but I was sure I would be able to research my way to something reasonable. I started googling different questions:</p>
<p>✅ How to get the content of a VSCode active editor?</p>
<p>✅ How to use VSCode activeTextEditor?</p>
<p>✅ How to use VSCode onDidTextDocumentChange?</p>
<p>And so on.</p>
<p>Understanding what you want to build is the first step to having relevant search results especially when building a project you have never built. You need to conceptualize the idea or features you want to implement so that you can find solutions you need.</p>
<h3 id="heading-basic-googling-tips-that-can-help-you-get-better-results">Basic googling tips that can help you get better results</h3>
<h4 id="heading-know-the-keywords-you-care-about">Know the keywords you care about.</h4>
<p>For example, if I want to built a landing page with HTML and CSS only, I won't search for something like "How to build a landing page". That will be bring a lot of things I don't want. It has to include the keywords I care about. </p>
<p>Below are examples to study:</p>
<ul>
<li>How to build a landing page with HTML and CSS?</li>
<li>How to make a VSCode extension with Typescript (If I want Typescript)?</li>
<li>How to make a VSCode extension with JavaScript?</li>
</ul>
<p>Make sure your expected keywords are included – be specific.</p>
<p>Googling (How to build a landing page with HTML and CSS?) may yield a generic result. That is an issue. But it can be fixed with exact matches.</p>
<h4 id="heading-use-quotes-to-get-exact-matches-in-google">Use quotes to get exact matches in Google</h4>
<p>For example, "How to build a landing page with HTML and CSS" will give you an outcome with the exact words in that search. </p>
<p>If you want to explore general ideas about building a landing page, remove the quotes.</p>
<h4 id="heading-exclude-a-search-term-with">Exclude a search term with (-)</h4>
<p>Sometimes, you only want a result with HTML and CSS, but you're getting those with HTML, CSS and JavaScript. </p>
<p>You can use "- JavaScript" to exclude JavaScript. For instance, you can search "How to build a landing page with HTML and CSS - JavaScript.</p>
<p>This is useful when you want to exclude certain keywords.</p>
<h4 id="heading-switch-out-your-terms">Switch out your terms</h4>
<p>When you want to move from one language, library, or framework to another, you need to use all you know from the first language or framework. </p>
<p>For instance, you want to move from JavaScript to Python and you know how JavaScript works. All your previous search terms or approaches for JavaScript will still be very useful while using Python. </p>
<p>You only need to switch out your specific terms – replace JavaScript with Python in all your searches. Then, you can google "Array in Python" instead of "Array in JavaScript".</p>
<h2 id="heading-youll-always-get-stuck-and-thats-ok">You'll Always Get Stuck – and That's OK</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-315.png" alt="Image" width="600" height="400" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@ianstauffer?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Ian Stauffer / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
<p>‌The problem with "How to" tutorials is that they don't always inform you that getting stuck is a part of the process. The VSCode extension I have been working on is still not working because I am stuck. After thinking through every part, I was stuck while implementing the features.</p>
<p>The VSCode extension API I was using can't be iterated, so I have to find a way to do that. Also, vscode-hacker-typer doesn't use the approach I am using. It records keystrokes and replays them. I want to avoid recording keystrokes. I only want to display the content of an activeTextEditor character by character whenever any key is pressed.</p>
<p>You will always be stuck, and that is why you have to learn <a target="_blank" href="https://www.freecodecamp.org/news/how-to-improve-your-debugging-skills/">How to improve your debugging skills</a>. Getting stuck is a significant part of the process. Your ability to overcome the challenges of getting stuck will determine how far you go in making projects.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>It can be tempting to want to quit because you feel you are not as good as everyone else. The reality is that we all struggle behind the scenes. We've all solved a lot of problems through trial and error. We all feel dumb and fake because we are always building on the projects of others. </p>
<p>But don't forget that every amazing project has a less glamorous story you know nothing about behind it. What matters, above all, is making sure you build the project in the end.</p>
<p>Don't forget:</p>
<blockquote>
<p>"The genius thing that we did was, we didn't give up" - Jay Z.</p>
</blockquote>
<p><a target="_blank" href="https://twitter.com/codingnninja"><strong>Ayobami</strong></a> loves writing history with software development and is currently helping those who are struggling to understand and build projects with HTML, CSS and JavaScript <a target="_blank" href="https://aw194b5a.aweb.page/p/5c07dec9-f1bd-4a8f-a788-87e4f0a6a6a1">here</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What I've Learned from Building Products – Lessons in Communication and Problem Solving ]]>
                </title>
                <description>
                    <![CDATA[ By Zaid Humayun I spent a year learning how to build products. Rather, I spent that year learning just how hard it is to build good products.  It's been a roller coaster ride so far and I want to share my learnings. I'm going to highlight the most im... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/building-products-lessons-in-communication-and-problem-solving/</link>
                <guid isPermaLink="false">66d461ca787a2a3b05af4427</guid>
                
                    <category>
                        <![CDATA[ communication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                    <category>
                        <![CDATA[ product development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 24 Feb 2021 15:46:49 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/02/learning_to_build_products_header.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Zaid Humayun</p>
<p>I spent a year learning how to build products. Rather, I spent that year learning just how hard it is to build good products. </p>
<p>It's been a roller coaster ride so far and I want to share my learnings.</p>
<p>I'm going to highlight the most important lessons I've learned along the way.</p>
<h2 id="heading-what-to-expect-from-this-article">What to Expect from This Article</h2>
<p>Before I start, I do want to specify that this blog post is not as technical as most things you will read on freeCodeCamp. </p>
<p>While exploring the technology will be valuable, I believe it is just as beneficial for programmers to look at the business aspect of things. This is in part because it is not something most programmers pay attention to.</p>
<p>As programming becomes more and more popular and commoditized, it will become more valuable for programmers to understand exactly how they are adding value to a company.</p>
<p>Answering the <strong>why</strong> of problem solving is the most crucial business aspect while building technological solutions.</p>
<h2 id="heading-a-bit-of-background-and-context">A Bit of Background and Context</h2>
<p>I work at a garment manufacturing company headquartered in Bangalore, India. Nope, you read that right. I work in tech at a garment manufacturing company in Bangalore, India.</p>
<p>Not the most glamorous of jobs, but it does provide a lot of opportunities to experiment.</p>
<p>The garment industry is one of the most unorganized industries in India. For people working in the tech world, it's a little hard to grasp just how unorganized it is. </p>
<p>When people in tech think of a problem, they think of sifting through large sets of data to glean insights that might turn into more effective features. </p>
<p>But, what do you do when the data is still written in pencil on paper? How do you even get access to that information? </p>
<p>Sometimes it feels like the rest of the world stormed ahead leaving certain industries lagging far behind that. And it often feels like the wheel of invention is coming spinning back around again.</p>
<h2 id="heading-how-things-work-at-the-company">How Things Work at the Company</h2>
<p>Before I can present the problems, I need to explain how a garment manufacturing unit works. </p>
<p>Here is an extremely simplistic overview of how the supply chain in garment manufacturing works</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/supply_chain_basic-1.png" alt="supply_chain_basic-1" width="600" height="400" loading="lazy"></p>
<p>Pretty simple, right? It really is! And just like every other industry, the devil is in the details.</p>
<p>Let's dive in a little deeper. For brevity's sake, let's examine just the relationship between the textile mill and the garment manufacturer. </p>
<p>It starts with an order placed by the buyer with the garment manufacturer. The buyer will tell the garment manufacturer that they require a specific kind of fabric for their garments. This is called a style of fabric.</p>
<p>Now, when we refer to the style of fabric, it can mean many different things. Here are a few of the variables that comprise the style of the fabric.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/parts_of_style-1.png" alt="parts_of_style-1" width="600" height="400" loading="lazy"></p>
<p>For now, to keep things simple, let's just focus on fabric colour.</p>
<p>The garment manufacturer will then place an order for the fabric with the textile mill. Once the textile mill is ready to ship the fabric, the complexity starts.</p>
<p>The problem is one of scale. When you have over 30 suppliers of fabric, stationed all over a country, keeping track of when you get shipments of fabric is hard.</p>
<h2 id="heading-how-we-can-define-the-problem">How We Can Define the Problem</h2>
<p>Here are the key problems:</p>
<ul>
<li>Keeping track of when you receive the fabric shipment</li>
<li>Keeping track of how much fabric you've received</li>
<li>Keeping track of which supplier you've received the fabric from</li>
<li>Keeping track of which location you've received the fabric at</li>
<li>Whether the fabric passes quality inspection checks</li>
<li>Whether the fabric passes the lab tests indicated by the buyer</li>
</ul>
<p>Our problem is going to focus on only the following three points:</p>
<ul>
<li>When did we receive a shipment of fabric from a supplier?</li>
<li>How much fabric did we receive in a specific shipment?</li>
<li>At which location did we receive the fabric?</li>
</ul>
<p>The most obvious solution is Excel sheets. </p>
<blockquote>
<p><em>Lesson #1: In big organizations, Excel functions as a distributed database.</em></p>
</blockquote>
<p>Excel works well, for a while, and then quickly becomes difficult to maintain.</p>
<p>Why? Let's start a hypothetical garment manufacturing company to answer that.</p>
<h3 id="heading-phase-1">Phase 1</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/simple_excel_sheet_fabric.png" alt="simple_excel_sheet_fabric" width="600" height="400" loading="lazy"></p>
<p>Okay, so we've just started and we have 2 suppliers, 3 factories, and a head office. That's pretty good for a start!</p>
<p>Let's also say that we have 1 buyer. Having a single buyer means that the number of different styles of fabric that we have to deal with are small.</p>
<p>As and when each factory receives fabric, they let the head office know via email the amount of fabric and the style of fabric they received. Then the head office puts that data into an Excel sheet.</p>
<p>Each factory receives fabric once a day, so that means the head office will receive 3 emails a day. Not too bad! </p>
<p>Even if a supplier delays a shipment, it's relatively easy to track because there are only 2 suppliers.</p>
<h3 id="heading-phase-2">Phase 2</h3>
<p>Things are going well, business is growing, and you decide to expand. You set up 5 more factories. </p>
<p>You also increase the number of buyers you're working with, which in turn increases the number of styles of fabric.</p>
<p>You also want to increase your turnover, so 3 of the factories receive fabric twice a day: once in the morning, once in the evening.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/complicated_excel_sheet_fabric.png" alt="complicated_excel_sheet_fabric" width="600" height="400" loading="lazy"></p>
<p>Things just got a little more real. </p>
<p>You'll notice that each supplier's face is now invisible. This is not a coincidence. Yeah, I did it to save space but I also did it to illustrate how as scale increases, your personal relationships with business partners take a back seat. </p>
<p>It's simply not possible to maintain the same kind of personal relationship you had with 2 suppliers, with 6 suppliers and 8 factories to boot!</p>
<p>You might wonder why the above point is relevant. That's because it leads into the next lesson.</p>
<blockquote>
<p>Lesson #2: Business relationships are built almost entirely on trust, especially in the absence of technology.</p>
</blockquote>
<p>Let's examine the lesson above for a bit. It's important because the goal of most technological systems is to eliminate the need for trust. Of course, that's not entirely possible.</p>
<blockquote>
<p>Before continuing, there is one quick thing I need to mention. When suppliers provide fabric to manufacturing units, they usually provide it in the form of a roll of fabric.</p>
</blockquote>
<p>Let's construct a scenario with you as a garment manufacturer. You have a supplier who provides you with rolls of fabric. </p>
<p>One time, you receive 10 rolls of fabric and based on an anonymous tip-off decide to measure the length of each roll of fabric against what the supplier tells you it is.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/trust_relationship.png" alt="trust_relationship" width="600" height="400" loading="lazy"></p>
<p>The above infographic shows you what that would look like. </p>
<p>To your dismay, you find out that the supplier is cheating you and you're short 36m of fabric. In a low-margin industry like garment manufacturing, this counts for a lot.</p>
<p>Also, this was only for 10 rolls of fabric. As your company grows, you're going to order more rolls of fabric from a supplier. Imagine you had a 100 rolls of fabric to go through instead of 10. </p>
<p>Manually checking each roll of fabric is not an operation that can scale, and as your operations scale, trust becomes more important.</p>
<p>Now, back to our problems of scaling. We have a total of 6 suppliers, 8 factories, and more buyers – and therefore more styles of fabric.</p>
<p>With 5 factories receiving fabric once a day and 3 factories receiving fabric twice a day, the head office will receive <code>5*1 + 3*2 = 11 emails</code> a day.</p>
<p>Things have gotten harder not only because the head office is receiving more emails but because the styles of fabric they are receiving have also increased. This adds to the number of rows in an Excel sheet. </p>
<p>Now, when a supplier delays a shipment, things get a lot harder to keep track of because the factories are receiving 11 shipments a day from 6 different suppliers.</p>
<p>But, even now, Excel is not a bad option at all. However, the fabric department is under a lot of strain trying to keep up with the workload, so the head office does what any good organization would do and adds a couple more employees. </p>
<p>Was adding two employees a bad idea? All answers are opinionated.</p>
<p>A technologist would say: "Why would you add two more employees? You need to simplify the process by adding automation!"</p>
<p>A CEO would reply: "Why? The cost of automation is not worth it. It's simpler to add two employees and keep our process the same."</p>
<blockquote>
<p>Lesson #3: Not everything is worth automating. This is the hardest lesson to accept for me.</p>
<p><a target="_blank" href="https://xkcd.com/1205/">Relevant XKCD</a></p>
</blockquote>
<h3 id="heading-phase-3">Phase 3</h3>
<p>Time passes and business continues to boom. Being a capitalistically inclined CEO, you want to increase the scale of the business again!</p>
<p>This time, you increase the number of factories to 14. You also add more buyers to the portfolio, so this increases the number of styles of fabric the factories need to work with. 6 factories receive fabric twice a day and the remaining 8 receive fabric once a day.</p>
<p>You also work with 20 suppliers now because of all the different styles of fabric you require.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/really_complicated_excel_sheet_fabric.png" alt="really_complicated_excel_sheet_fabric" width="600" height="400" loading="lazy"></p>
<p>I haven't bothered to name any of the suppliers or the factories in the image above cause it would be too much effort. </p>
<p>But, again, this is to illustrate that the personal relationship you might have had with each of the managers of the factories deteriorates. You simply can't maintain each of those relationships to the same degree.</p>
<p>Now, the head office will receive <code>8*1 + 6*2 = 20</code> emails a day! Each email also contains more data because we increased the number of styles we are working with.</p>
<p>Maintaining a manual central Excel sheet becomes harder and harder. Simply adding more employees to the task also won't necessarily help because you might just end up with multiple copies of a centralized Excel sheet in the head office.</p>
<h2 id="heading-how-to-solve-the-problem">How To Solve The Problem</h2>
<p>Now, there are multiple ways to solve this problem. </p>
<p>One could be to ask each of the factories to maintain their own daily Excel sheet and send it as an attachment via email to the head office.</p>
<p>However, this again involves someone copying and pasting the data from each factory into one centralized Excel sheet. Nothing wrong with this, but there is probably a more efficient solution.</p>
<p>Another potential solution is we could ask each of the units to maintain an individual Google Sheet and run a script using <a target="_blank" href="https://developers.google.com/apps-script">Google App Script</a> every day like a <a target="_blank" href="https://en.wikipedia.org/wiki/Cron">cron job</a> and pick up the data.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/google_sheet_cron_job.png" alt="google_sheet_cron_job" width="600" height="400" loading="lazy"></p>
<p>However, if you want more data like the length of each roll, you're out of luck. There is no way you can ask people working in factories to manually enter the length of each roll of fabric everyday. Because, like we said earlier, you could potentially receive 150 rolls of fabric a day.</p>
<h3 id="heading-our-solution">Our Solution</h3>
<p>The solution we ultimately went for, at my company, isn't a surprising one: we decided to use barcodes.</p>
<p>We place a barcode on each roll of fabric. The barcode correlates to the length of a roll, the style of fabric, and which buyer it's for.</p>
<p>We built a small Android application that allows users to scan barcodes with the device camera, and on each scan hits an API indicating that this specific barcode was scanned in a specific location (picked up via GPS).</p>
<p>Scanning a roll of fabric allows us to pick up the location of the roll via GPS and the date and time.</p>
<p>Adding up all the rolls of fabric scanned at a location allows us to know the total length of fabric received by a factory.</p>
<p>Best of all, this reduces the workload for the factories themselves. Their only job now is to scan the rolls of fabric. Scanning one roll of fabric takes ~3 seconds, so scanning 100 rolls of fabric takes ~5 minutes.</p>
<p>Here is a basic schematic of what we built: </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/fabtrak_architecture_deployment.png" alt="fabtrak_architecture_deployment" width="600" height="400" loading="lazy"></p>
<ul>
<li>A web based application that is used to generate the barcodes</li>
<li>An Android application that is used to scan the barcodes</li>
<li>An API that both the web app and Android app communicate with. The API in turn communicates with the MySQL DB.</li>
</ul>
<p>The whole thing is hosted on AWS and the Android app is hosted on Google Play Store.</p>
<p>The solution seems simple enough, but it isn't.</p>
<h3 id="heading-what-we-learned-from-solving-the-problem">What We Learned From Solving The Problem</h3>
<blockquote>
<p>Lesson #4: Building things for people is hard because there is often a disconnect between the people building the thing and the people the thing is being built for.</p>
</blockquote>
<p>This disconnect is why it's a great idea to build a product that fulfills a need you've long wished existed.</p>
<p>One of the first mistakes we made with the Android app was giving our users too many options
<img src="https://www.freecodecamp.org/news/content/images/2021/02/initial_fabscan_sketch.png" alt="initial_fabscan_sketch" width="600" height="400" loading="lazy"></p>
<p>The sketch above shows what a very early verion of our application looked like. Clicking each of those buttons took you to the camera screen. However, each of them made a different API call and so returned a different result. </p>
<p>The rationale for including the Enter button was that, if the barcode were to get scratched and couldn't be picked up by the phone camera, the user could then enter the barcode instead and it would count as a scan.</p>
<p>Here's what one of our barcode numbers looks like: <code>k29_%!s5qG</code>. There is no chance that anybody is going to sit down and enter that sequence of characters. </p>
<p>The rationale for the Read button was that if someone were to want to identify what kind of fabric a specific roll was, they could scan the barcode in Read mode and it would return information about that roll of barcode.</p>
<p>The factories already had their own method of storing information about the roll, though. They just wrote it down in pencil and paper and stuck it to a tag that gets attached to the roll. </p>
<p>Is it the most technologically advanced system? Heck no! But, does it work? Heck yes! And we should have respected the fact that they already had their own way of doing the same operation.</p>
<p>The end result is that almost no one even bothers clicking on either of the Read or Enter buttons.</p>
<p>When building things, keep things to the bare minimum. There is no reason to add additional features unless absolutely required.</p>
<p>The second mistake we made was not knowing our audience.</p>
<p>When we came up with the idea of building a web application for people to use to generate barcodes, it seemed like a no-brainer.</p>
<p>We ran into a funny problem, though.</p>
<p>When we explained to the people working in the factories that they needed to enter the address into the address bar, we got blank looks in response.</p>
<p>You see, with the privileged background most of us come from, we tend to forget that there is a large majority of the population that doesn't know how to interact with a web browser. Why? They've never had the need to. They interact with the internet primarily through smartphone apps.</p>
<p>This might seem like a bit of a stretch but I've seen the evidence with my own eyes. This is not to suggest that people who don't know how to use a browser are less intelligent by any stretch of the imagination. It simply means that we need to communicate things to them differently.</p>
<p>Now, this topic of communication brings me to the final lesson I've learnt. Probably the most hard-earned lesson and definitely the most insightful.</p>
<blockquote>
<p>Lesson #5: All problems in an organization are communication problems.</p>
</blockquote>
<p>Look back at what we've covered in this article. </p>
<p>The first issue we uncovered was the issue of emails. When an organization is small, fewer emails are exchanged. As an organization scales, the number of emails increases and it becomes harder to keep track. Communication problem.</p>
<p>The second issue we uncovered was one of trust between the supplier and the manufacturer. The supplier communicated wrong/false information to the manufacturer. The manufacturer had to spend valuable time correcting this false information. Communication problem.</p>
<p>The third issue we uncovered was how to explain to people who've never used a web browser, how to navigate to a specific page. Communication problem.</p>
<p>I know it sounds a little like pigeon holing where I'm trying to force every problem into a communication problem, but at the heart of most problems is just that: poor communication.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I glossed over the more technical aspects of the solution we built. However, I think that is not the interesting part. What is interesting is how we've attempted to solve problems. </p>
<p>If you think the problems I am working on are interesting, take a look at our <a target="_blank" href="https://www.id-flo.com/careers">job listings</a>.</p>
<p>If you can't find a role that suits you in the listings, please shoot me a mail at zaid@indian-designs.com.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Solve Coding Problems with a Simple Four Step Method ]]>
                </title>
                <description>
                    <![CDATA[ By Madison Kanna I had fifteen minutes left, and I knew I was going to fail. I had spent two months studying for my first technical interview.  I thought I was prepared, but as the interview came to a close, it hit me: I had no idea how to ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-solve-coding-problems/</link>
                <guid isPermaLink="false">66d8518c62a291dea89878dc</guid>
                
                    <category>
                        <![CDATA[ coding challenge ]]>
                    </category>
                
                    <category>
                        <![CDATA[ coding interview ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Interview tips ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 04 Feb 2021 18:33:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/01/iStock-527234840.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Madison Kanna</p>
<p>I had fifteen minutes left, and I knew I was going to fail.</p>
<p>I had spent two months studying for my first technical interview. </p>
<p>I thought I was prepared, but as the interview came to a close, it hit me: I had no idea how to solve coding problems. </p>
<p>Of all the tutorials I had taken when I was learning to code, not one of them had included an approach to solving coding problems. </p>
<p>I had to find a method for problem-solving—my career as a developer depended on it.</p>
<p>I immediately began researching methods. And I found one. In fact, what I uncovered was an invaluable strategy. It was a time-tested four-step method that was somehow under the radar in the developer ecosystem.</p>
<p>In this article, I’ll go over this four-step problem-solving method that you can use to start confidently solving coding problems. </p>
<p>Solving coding problems is not only part of the developer job interview process—it’s what a developer does all day. After all, <em>writing code is problem-solving.</em></p>
<h2 id="heading-a-method-for-solving-problems">A method for solving problems</h2>
<p>This method is from the book <em>How to Solve It</em> by George Pólya. It originally came out in 1945 and has sold over one million copies. </p>
<p>His problem-solving method has been used and taught by many programmers, from computer science professors (see Udacity’s Intro to CS course taught by professor David Evans) to modern web development teachers like Colt Steele.</p>
<p>Let’s walk through solving a simple coding problem using the four-step problem-solving method. This allows us to see the method in action as we learn it. We'll use JavaScript as our language of choice. Here’s the problem:</p>
<p>Create a function that adds together two numbers and returns that value.  </p>
<p>There are four steps to the problem-solving method:</p>
<ol>
<li>Understand the problem.</li>
<li>Devise a plan.</li>
<li>Carry out the plan.</li>
<li>Look back. </li>
</ol>
<p>Let’s get started with step one.</p>
<h2 id="heading-step-1-understand-the-problem">Step 1: Understand the problem.</h2>
<p>When given a coding problem in an interview, it’s tempting to rush into coding. This is hard to avoid, especially if you have a time limit. </p>
<p>However, try to resist this urge. Make sure you actually understand the problem before you get started with solving it.</p>
<p>Read through the problem. If you’re in an interview, you could read through the problem out loud if that helps you slow down. </p>
<p>As you read through the problem, clarify any part of it you do not understand. If you’re in an interview, you can do this by asking your interviewer questions about the problem description. If you’re on your own, think through and/or Google parts of the question you might not understand.</p>
<p><strong>This first step is vital as we often don’t take the time to fully understand the problem. When you don’t fully understand the problem, you’ll have a much harder time solving it.</strong></p>
<p>To help you better understand the problem, ask yourself:</p>
<h3 id="heading-what-are-the-inputs">What are the inputs?</h3>
<p>What kinds of inputs will go into this problem? In this example, the inputs are the arguments that our function will take. </p>
<p>Just from reading the problem description so far, we know that the inputs will be numbers. But to be more specific about what the inputs will be, we can ask:</p>
<p>Will the inputs always be just two numbers? What should happen if our function receives as input <em>three</em> numbers? </p>
<p>Here we could ask the interviewer for clarification, or look at the problem description further. </p>
<p>The coding problem might have a note saying, “You should only ever expect two inputs into the function.” If so, you know how to proceed. You can get more specific, as you’ll likely realize that you need to ask more questions on what kinds of inputs you might be receiving.</p>
<p>Will the inputs always be numbers? What should our function do if we receive the inputs “a” and “b”? Clarify whether or not our function will always take in numbers.</p>
<p>Optionally, you could write down possible inputs in a code comment to get a sense of what they’ll look like: </p>
<p><code>//inputs: 2, 4</code></p>
<p>Next, ask:</p>
<h3 id="heading-what-are-the-outputs">What are the outputs?</h3>
<p>What will this function return? In this case, the output will be one number that is the result of the two number inputs. Make sure you understand what your outputs will be.</p>
<h3 id="heading-create-some-examples">Create some examples.</h3>
<p>Once you have a grasp of the problem and know the possible inputs and outputs, you can start working on some concrete examples.</p>
<p>Examples can also be used as sanity checks to test your eventual problem. Most code challenge editors that you’ll work in (whether it’s in an interview or just using a site like Codewars or HackerRank) have examples or test cases already written for you. Even so, writing out your own examples can help you cement your understanding of the problem.</p>
<p>Start with a simple example or two of possible inputs and outputs. Let's return to our addition function.</p>
<p>Let’s call our function “add.”</p>
<p>What’s an example input? Example input might be:</p>
<p><code>// add(2, 3)</code> </p>
<p>What is the output to this? To write the example output, we can write: </p>
<p><code>// add(2, 3) ---&gt; 5</code></p>
<p>This indicates that our function will take in an input of 2 and 3 and return 5 as its output.</p>
<h3 id="heading-create-complex-examples">Create complex examples.</h3>
<p>By walking through more complex examples, you can take the time to look for edge cases you might need to account for.</p>
<p>For example, what should we do if our inputs are strings instead of numbers? What if we have as input two strings, for example, add('a', 'b')?</p>
<p>Your interviewer might possibly tell you to return an error message if there are any inputs that are not numbers. If so, you can add a code comment to handle this case if it helps you remember you need to do this.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// return error if inputs are not numbers.</span>
</code></pre>
<p>Your interviewer might also tell you to assume that your inputs will always be numbers, in which case you don’t need to write any extra code to handle this particular input edge case.</p>
<p>If you don’t have an interviewer and you’re just solving this problem, the problem might say what happens when you enter invalid inputs. </p>
<p>For example, some problems will say, “If there are zero inputs, return undefined.” For cases like this, you can optionally write a comment.</p>
<p><code>// check if there are no inputs.</code></p>
<p><code>// If no inputs, return undefined.</code></p>
<p>For our purposes, we’ll assume that our inputs will always be numbers. But generally, it’s good to think about edge cases. </p>
<p>Computer science professor Evans says to write what developers call <em>defensive</em> code. Think about what could go wrong and how your code could defend against possible errors.  </p>
<p>Before we move on to step 2, let’s summarize step 1, understand the problem: </p>
<p><code>-Read through the problem.</code></p>
<p><code>-What are the inputs?</code></p>
<p><code>-What are the outputs?</code></p>
<p><code>Create simple examples, then create more complex ones.</code></p>
<h2 id="heading-2-devise-a-plan-for-solving-the-problem">2. Devise a plan for solving the problem.</h2>
<p>Next, devise a plan for how you’ll solve the problem. As you devise a plan, write it out in pseudocode. </p>
<p>Pseudocode is a plain language description of the steps in an algorithm. In other words, your pseudocode is your step-by-step plan for how to solve the problem.</p>
<p>Write out the steps you need to take to solve the problem. For a more complicated problem, you’d have more steps. For this problem, you could write:</p>
<p><code>// Create a sum variable.</code></p>
<p><code>Add the first input to the second input using the addition operator</code>.</p>
<p><code>// Store value of both inputs into sum variable.</code></p>
<p><code>// Return as output the sum variable.</code>  </p>
<p>Now you have your step-by-step plan to solve the problem.  </p>
<p>For more complex problems, professor Evans notes, “Consider systematically how a human solves the problem.” That is, forget about how your code might solve the problem for a moment, and think about how <em>you</em> would solve it as a human. This can help you see the steps more clearly.</p>
<h2 id="heading-3-carry-out-the-plan-solve-the-problem">3. Carry out the plan (Solve the problem!)</h2>
<p><img src="https://cdn.pixabay.com/photo/2017/04/06/15/02/hand-2208491_960_720.jpg" alt="Hand, Rubik, Cube, Puzzle, Game, Rubik Cube" width="960" height="540" loading="lazy"></p>
<p>The next step in the problem-solving strategy is to solve the problem. Using your pseudocode as your guide, write out your actual code. </p>
<p>Professor Evans suggests focusing on a simple, mechanical solution. The easier and simpler your solution is, the more likely you can program it correctly.</p>
<p>Taking our pseudocode, we could now write this:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">a, b</span>) </span>{
 <span class="hljs-keyword">const</span> sum = a + b;
 <span class="hljs-keyword">return</span> sum;
}
</code></pre>
<p>Professor Evans adds, remember not to <em>prematurely optimize.</em> That is, you might be tempted to start saying, “Wait, I’m doing this and it’s going to be inefficient code!”</p>
<p>First, just get out your simple, mechanical solution.</p>
<p>What if you can’t solve the entire problem? What if there's a part of it you still don't know how to solve? </p>
<p>Colt Steele gives great advice here: If you can’t solve part of the problem, ignore that hard part that’s tripping you up. Instead, focus on everything else that you can start writing. </p>
<p>Temporarily ignore that difficult part of the problem you don’t quite understand and write out the other parts. Once this is done, come back to the harder part.</p>
<p>This allows you to get at least <em>some</em> of the problem finished. And often, you’ll realize how to tackle that harder part of the problem once you come back to it.</p>
<h2 id="heading-step-4-look-back-over-what-youve-done">Step 4: Look back over what you've done.</h2>
<p>Once your solution is working, take the time to reflect on it and figure out how to make improvements. This might be the time you refactor your solution into a more efficient one. </p>
<p>As you look at your work, here are some questions Colt Steele suggests you ask yourself to figure out how you can improve your solution:</p>
<ul>
<li>Can you derive the result differently? What other approaches are there that are viable?</li>
<li>Can you understand it at a glance? Does it make sense?</li>
<li>Can you use the result or method for some other problem?</li>
<li>Can you improve the performance of your solution?</li>
<li>Can you think of other ways to refactor?</li>
<li>How have other people solved this problem?</li>
</ul>
<p>One way we might refactor our problem to make our code more concise: removing our variable and using an implicit return:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">a, b</span>) </span>{
 <span class="hljs-keyword">return</span> a + b;
}
</code></pre>
<p>With step 4, your problem might never feel finished. Even great developers still write code that they later look at and want to change. These are guiding questions that can help you.</p>
<p>If you still have time in an interview, you can go through this step and make your solution better. If you are coding on your own, take the time to go over these steps. </p>
<p>When I’m practicing coding on my own, I almost always look at the solutions out there that are more elegant or effective than what I’ve come up with. </p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this post, we’ve gone over the four-step problem-solving strategy for solving coding problems. </p>
<p>Let's review them here:</p>
<ul>
<li>Step 1: <strong>understand the problem.</strong> </li>
<li>Step 2: <strong>create a step-by-step plan for how you’ll solve it</strong>. </li>
<li>Step 3: <strong>carry out the plan</strong> and write the actual code. </li>
<li>Step 4: <strong>look back</strong> and possibly refactor your solution if it could be better.</li>
</ul>
<p>Practicing this problem-solving method has immensely helped me in my technical interviews and in my job as a developer.  </p>
<p>If you don't feel confident when it comes to solving coding problems, just remember that problem-solving is a skill that anyone can get better at with time and practice.</p>
<p>Good luck!</p>
<h3 id="heading-if-you-enjoyed-this-post-join-my-coding-clubhttpsmadisonkannaus14list-managecomsubscribepostu323fd92759e9e0b8d4083d008ampid033dfeb98f-where-we-tackle-coding-challenges-together-every-sunday-and-support-each-other-as-we-learn-new-technologies">If you enjoyed this post, join my <a target="_blank" href="https://madisonkanna.us14.list-manage.com/subscribe/post?u=323fd92759e9e0b8d4083d008&amp;id=033dfeb98f">coding club</a>, where we tackle coding challenges together every Sunday and support each other as we learn new technologies.</h3>
<h3 id="heading-if-you-have-feedback-or-questions-on-this-post-feel-free-to-tweet-me-madisonkannahttpstwittercommadisonkanna">If you have feedback or questions on this post, feel free to Tweet me <a target="_blank" href="https://twitter.com/Madisonkanna">@madisonkanna</a>.</h3>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Find the Number of Vowels in a String with JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ By Madison Kanna In this tutorial, we’ll learn how to find the number of vowels in a string with JavaScript. This is a problem you might be asked in junior developer job interviews, and it’s also a CodeWars problem.  Before we get started coding, let... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/find-the-number-of-vowels-in-a-string-with-javascript/</link>
                <guid isPermaLink="false">66d8517fbdc56847ac959f3a</guid>
                
                    <category>
                        <![CDATA[ interview questions ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 18 Jan 2021 17:27:04 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/01/Screen-Shot-2021-01-17-at-6.16.19-PM.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Madison Kanna</p>
<p>In this tutorial, we’ll learn how to find the number of vowels in a string with JavaScript. This is a problem you might be asked in junior developer job interviews, and it’s also a <a target="_blank" href="https://www.codewars.com/kata/54ff3102c1bad923760001f3">CodeWars</a> problem. </p>
<p>Before we get started coding, let’s read over the problem description in full:</p>
<p><strong>Return the number (count) of vowels in a given string. We will consider a, e, i, o and u as vowels, but not y. The input string will only consist of lower case letters and/or spaces.</strong></p>
<h2 id="heading-step-1-make-a-plan-to-solve-the-problem">Step 1: Make a plan to solve the problem</h2>
<p>For this problem, we’ll create a function, called <code>getCount</code>, which takes as input a string and returns as output the count of how many vowels are in that string.  </p>
<p>Let’s go over some examples.</p>
<p><img src="https://lh4.googleusercontent.com/0NnD6g02UboUYJkZ0KOJMw7abNXVH-e9iuq9kv1qg-OFzJ_k8t3ZVfMzj6MkPE45fjQxVBIshpJJNxF_e6KGDWSCdwp7BWd8vVasgeiJ1nYiK-7ufFJz1XuyIXcHNApmtBhn7Kk9" alt="Image" width="806" height="516" loading="lazy"></p>
<p>With the first example, we see that our function returns 5, which is how many times a vowel appears in the string <code>abracadabra</code>. With the string <code>abc</code>, only 1 is returned, as only one vowel (a) appears.</p>
<p>To solve this problem, we’ll create a <code>vowelsCount</code> variable that will keep track of how many vowels are in the string. </p>
<p>We’ll also create an array, vowels, that holds all of our vowels. We’ll go through each character in our string. If the character is a vowel, we’ll increase our <code>vowelsCount</code> variable.</p>
<p>Finally, we’ll return the <code>vowelsCount</code> variable.  </p>
<p>Let’s get started!</p>
<h2 id="heading-step-2-write-the-code-to-solve-the-problem">Step 2: Write the code to solve the problem</h2>
<p>First we write our function, <code>getCount</code>. Next we’ll create a variable, <code>vowelsCount</code>, and set it to <code>0</code>.</p>
<p><img src="https://lh4.googleusercontent.com/3C2OuHNi9S9SL-SUEYzM8PSodXO1bYULEd9LLec7clus1o5TEvqBBgVy1STfDUoq3hFLT85VLVGAAzL8h949fazt9_36S54Oe97U39IjJhl9LBDTWCpSFd9w9wMFpkHdfSbeFpAq" alt="Image" width="706" height="480" loading="lazy"></p>
<p>We’ll create our vowels array next. This allows us to have every vowel in one place, and we can use this array later.</p>
<p><img src="https://lh6.googleusercontent.com/g6F__ll7kJNmOq6c3kT6Z7X_zcslPkO8AuF5kUDYFcLcnJ9v-rpf3bm1NUSDPCAVWWnfpq9GS7cADMuN5GS3CdiTbAfun9Gth0CBUFGFl5vhviLMrKHKfQa9KPfWkujtV1_SLWHG" alt="Image" width="1008" height="516" loading="lazy"></p>
<p>Now we need to go through every character in our input string, <code>str</code>. We need to go through or look at every character in our string so that we can determine whether or not it is a vowel.</p>
<p>To do this, we can use the <code>for...of</code> statement that works on strings. You can read more on it <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of">here</a>.</p>
<p><img src="https://lh3.googleusercontent.com/mMSkKHhYAhJxh9F71Ccs4B9MyKpjHNlyIumJwJ9n7bTo-o6eR1YQLHsPe13VCVx7XlFU20TQHr2B5bXv52cbIHvTs2Jl2xIwBPo5hD0-ILOAW-o66sG2uyxUF5WljDTgDrsqgP7X" alt="Image" width="1008" height="624" loading="lazy"></p>
<p>Now inside our for loop, we have the ability to look at and go over each character in our string.   </p>
<p>Next, we want to check whether or not each character is a vowel. </p>
<p>To do this, we can use the <code>includes</code> method. The <code>includes()</code> method determines whether an array includes a certain value among its entries. It returns true if so, and false if not. </p>
<p>Using <code>includes</code>, we’ll check if our vowels array contains the character we’re currently iterating over in our loop.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/image-89.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We’ve created our <code>if statement</code> to check whether the current character is a vowel. If the character is a vowel, then we want to increase our <code>vowelsCount</code> variable. To do this, we can use the increment operator in JavaScript:</p>
<p><img src="https://lh4.googleusercontent.com/YELFhUaEOI51eOBznA9delrQlT5_brpGzM71vXiO6S1ARcy-IAbM06mYgPr6zQVC-0eytb87eQX8_5UBcZ0rMPLfTpf3uGHbJhpTWymoXGwLMDscQbp9BR1SIzbsrQSssmH689t2" alt="Image" width="1008" height="696" loading="lazy"></p>
<p>At this point in our code, we’ve looked at each character in the string, determined whether it was a vowel or not, and increased the number we stored in <code>vowelsCount</code> if it was.</p>
<p>Lastly, all we need to do is have our function return our <code>vowelsCount</code> variable. We can do this by returning the variable outside of our loop.</p>
<p><img src="https://lh6.googleusercontent.com/4U_WmVuqES_Z5Tb79te7k7nCorSGuIvsKoWVXPjV1e7dug-pSylt7GMa7MNvkDBX-1PT0EtfFmCi0n-pqN0YGpo2Rs7xntRQViCzLBEYuVi0rDJOQsQJxkgScPdGHXT8ThDLvn5I" alt="Image" width="1008" height="732" loading="lazy"></p>
<p>There we have it.</p>
<h2 id="heading-thats-it">That's it!</h2>
<p>We’ve now written a function that will take as input a string and return as output the number of times a vowel appeared in the string. </p>
<h3 id="heading-if-you-enjoyed-this-post-join-my-coding-clubhttpsmadisonkannaus14list-managecomsubscribepostu323fd92759e9e0b8d4083d008ampid033dfeb98f-where-we-tackle-coding-challenges-together-every-sunday">If you enjoyed this post, join my <a target="_blank" href="https://madisonkanna.us14.list-manage.com/subscribe/post?u=323fd92759e9e0b8d4083d008&amp;id=033dfeb98f">coding club</a>, where we tackle coding challenges together every Sunday.</h3>
<p>If you have feedback or questions on this post, feel free to Tweet me @madisonkanna.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Combine Good Ideas to Get the Best Solution to a Problem ]]>
                </title>
                <description>
                    <![CDATA[ By Jose J. Rodríguez Trade-offs are present in all our activities. Maybe you have heard the so-called "No free lunch theorem" in Machine Learning. The theorem states that there is no silver bullet when it comes to machine learning models. But in fact... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/combining-good-ideas-to-get-the-best-solution/</link>
                <guid isPermaLink="false">66d45f65706b9fb1c166b987</guid>
                
                    <category>
                        <![CDATA[ algorithms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #big o notation ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Computer Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data structures ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 30 Nov 2020 23:22:55 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5fc306db49c47664ed82751b.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Jose J. Rodríguez</p>
<p>Trade-offs are present in all our activities. Maybe you have heard the so-called "No free lunch theorem" in Machine Learning. The theorem states that there is no silver bullet when it comes to machine learning models. But in fact, there is never a silver bullet when it comes to anything. </p>
<p>And that is not a Computer Science principle but an economics principle.</p>
<p>If you have written code for more than a month you have likely experienced the necessity of trade-offs in programming – or at least have heard about them. </p>
<p>Sometimes you sacrifice performance in the name of security, security in the name of scalability, beauty and readability in the name of performance, and so on. Don't forget you also probably sacrifice parties and fun in general in the name of programming, so make it worth it.</p>
<p>In the specific case of algorithms, the main resources are time and memory, so the trade-offs always involve those resources. </p>
<p>It's common to find several solutions for the same problem, because one of them is faster but the other one is cheaper when it comes to storage. And of course, there are other factors like implementation, simplicity, and security. </p>
<p>In this post, I'm going to write about how you can combine several solutions to get the one that fulfills all your requirements.</p>
<p>First I'm going to show an interesting idea that E.W. Dijkstra proposed to find prime numbers. After that, I will show an idea I came up with to obtain a data structure that combines the power of arrays and linked lists. </p>
<h2 id="heading-requirements">Requirements</h2>
<p>I assume you have basic programming skills as well as some knowledge about data structures like arrays, linked lists, and heaps.</p>
<p>You should also have some understanding of big-O notation to calculate complexity.</p>
<p>Lastly, it would be good you were familiar with the algorithm called tje Sieve of Eratosthenes. In case you aren't, you can check out this post <a target="_blank" href="https://www.geeksforgeeks.org/sieve-of-eratosthenes/">link</a>.</p>
<p>There is no other previous knowledge required to understand what I'm about to discuss.</p>
<h2 id="heading-two-algorithms-one-problem">Two algorithms, one problem</h2>
<p>The problem is to find all prime numbers from 0 (zero) to N. It's the kind of problem you learn to do when you are beginning your journey in programming. And I want to start with the simplest solution.</p>
<h3 id="heading-the-naive-algorithm">The Naive Algorithm</h3>
<p>In the naive algorithm, we iterate over all numbers <code>x</code> from 2 to N. Then we check whether <code>x</code> has any divisor besides itself and one. For the last step, we can check for every number <code>d</code> between 2 and <code>x - 1</code> whether it is a divisor or not.</p>
<p>There is room for improvement in the last step, because we only need to check the divisors that are less than or equal to the square root of x. A pseudocode of the algorithm is written below:</p>
<pre><code>   primes(N):
      prime_numbers &lt;- [] # empty list
      <span class="hljs-keyword">for</span> x = <span class="hljs-number">2</span> to N:
          is_prime &lt;- <span class="hljs-literal">true</span>
          <span class="hljs-keyword">for</span> d = <span class="hljs-number">2</span> to sqrt(x):
              <span class="hljs-keyword">if</span> d divides x:
                   is_prime &lt;- <span class="hljs-literal">false</span> # we found a divisor <span class="hljs-keyword">of</span> x so x is not a prime number
          <span class="hljs-keyword">if</span> is_prime:
               prime_numbers.add(x) # <span class="hljs-keyword">if</span> we didn<span class="hljs-string">'t find a divisor then x is prime
       return prime_numbers</span>
</code></pre><p>What's the runtime complexity of the previous algorithm? Well, we take every number from 2 to N and for each one, we iterate over all its possible divisors. So we make <code>O(N*sqrt(N))</code> operations, where <code>sqrt</code> stands for the square root function.</p>
<p>What about memory? We only store the primes we find. For a big enough N, the number of primes is relatively small compared with N. So, let's denote the memory complexity as <code>O(Primes(N))</code>, where <code>Primes(N)</code> is the number of primes between 0 and N. Note that this is optimum in terms of memory because we at least need to store all the prime numbers.</p>
<h3 id="heading-the-sieve-of-eratosthenes">The Sieve of Eratosthenes</h3>
<p>You probably already know that there is a better algorithm to find all the prime numbers in a given range: the sieve of Eratosthenes. Let's look at it.</p>
<p>The idea is to maintain an array of length N where every entry is either false or true. If the i-th position in the array is true, then we say that <code>i</code> is a prime number, otherwise <code>i</code> is not prime.</p>
<p>We start with all positions with a true value, and then for every position, starting with <code>i = 2</code>, we make false every multiple of <code>i</code>. </p>
<p>We end up with an array in which every position with a true value represents a prime number. The code with some optimizations is presented below.</p>
<pre><code>    primes(N):
        prime_numbers &lt;- [] # empty list
        sieve &lt;- a boolean list <span class="hljs-keyword">with</span> length equal to N and all its elements set to <span class="hljs-literal">true</span>

        <span class="hljs-keyword">for</span> i = <span class="hljs-number">2</span> to sqrt(N): # we only need to analyze the numbers less than or equal to sqrt(N)
            <span class="hljs-keyword">if</span> sieve[i]: # <span class="hljs-keyword">if</span> sieve[i] is <span class="hljs-literal">true</span> then i is prime
                prime_numbers.add(i)
                <span class="hljs-keyword">for</span> j = i*i to N: # we can start the inner loop <span class="hljs-keyword">in</span> i*i
                    sieve[j] &lt;- <span class="hljs-literal">false</span>
                    j &lt;- j + i
         <span class="hljs-keyword">return</span> prime_numbers
</code></pre><p>It can be proved that the algorithm described above does <a target="_blank" href="https://www.geeksforgeeks.org/how-is-the-time-complexity-of-sieve-of-eratosthenes-is-nloglogn/">O(N log(N))</a> operations which is better than the naive approach. </p>
<p>Even it can be improved to <a target="_blank" href="https://www.geeksforgeeks.org/sieve-eratosthenes-0n-time-complexity">O(N)</a>! But we need to store an array with all the N numbers, and thus, we end up with a more expensive algorithm in memory terms. Here we have the trade-off: time in exchange for memory.</p>
<p>Can we design an algorithm that is faster than the naive idea but cheaper in memory terms than the sieve of Eratosthenes? </p>
<h2 id="heading-dijkstra-and-the-production-line">Dijkstra and the production line</h2>
<p>In the '60s, E.W. Dijkstra wrote in one of his manuscripts [<a target="_blank" href="https://www.cs.utexas.edu/~EWD/ewd02xx/EWD249.PDF">PDF</a>] an algorithm that combines the naive and the sieve ideas. But before we talk about it, let's analyze the differences between the two previous algorithms.  </p>
<p>When applying the naive algorithm we focus on analyzing whether every number is prime or not. When applying the sieve we analyze, for every prime number, all its multiples. The difference can be illustrated with the following analogy.</p>
<p>Imagine we want to build several products, like action figures. We have two options: building them one by one or applying a production line and in every stage, we add one component of the action figure. With the latter, we end up producing more in less time, but we need the "line infrastructure".</p>
<p>Dijkstra combined those ideas by analyzing a number at a time but taking advantage of the previous operations. We can maintain a pool of primes that have already been discovered, and, for each of those prime numbers, store the smallest multiple that has not been analyzed yet. </p>
<p>For example:</p>
<p>If we are analyzing the number 6, then we have stored primes 2, 3, and 5, along with their smallest-not-analyzed-multiples that are: 6 for 2, also 6 for 3, and 10 for 5.</p>
<p>Then, when analyzing a new number we take the smallest multiple stored until that moment and if that multiple is greater than the new number, then we have found a new prime. Otherwise, we have a composite number and we need to update the multiples of the stored primes that have the new number as its smallest multiple.</p>
<p>We begin storing the prime number <code>2</code> with the smallest multiple <code>4</code> as well. Then when analyzing <code>3</code> we find that <code>4 &gt; 3</code> so <code>3</code> is prime. We store <code>3</code> along with its smallest multiple that has not been analyzed yet (<code>6</code>). When analyzing <code>4</code> we find that <code>4</code> is stored as a multiple of <code>2</code>, then we update the multiple of <code>2</code> that now will be <code>6</code>. When analyzing <code>5</code> we find that <code>6 &gt; 5</code> so <code>5</code> is a prime number and we store it along with <code>10</code>, and so on... The code is presented below.</p>
<pre><code>    primes(N):
        primes_pool &lt;- Heap( (<span class="hljs-number">4</span>, <span class="hljs-number">2</span>) ) # a heap that contains a tuple <span class="hljs-keyword">with</span> a prime number (<span class="hljs-number">2</span>) and its least multiple that hasn<span class="hljs-string">'t been analyzed yet (4).
        prime_numbers &lt;- [2] # a list that contains the number 2
        for i = 3 to N:
            tuple &lt;- getMin(primes_pool) # get the tuple with the minimum multiple, the prime number attached to it is irrelevant
            mult &lt;- tuple.first # the multiple is stored in the first position of the tuple
            if mult &gt; i:
                prime_numbers.add(i) # i is prime!
                primes_pool.insert( (i*i, i) ) # we insert i along with their least multiple, but it can be inserted i*i instead and the algorithm remains correct
                continue
            # otherwise i isn'</span>t prime and then...
            for t such that t is <span class="hljs-keyword">in</span> primes_pool and t.first is equal to mult:
                t.first &lt;- t.first + t.second # we update every tuple <span class="hljs-keyword">in</span> the pool that has i <span class="hljs-keyword">as</span> it<span class="hljs-string">'s least multiple
        return prime_numbers</span>
</code></pre><p>The previous method only stores the prime numbers and another number for each of those primes. So we have a memory complexity of <code>O(Primes(N))</code> which is the same as the naive idea. </p>
<p>If we store the prime numbers along with their multiples in a structure like a heap, we get a time complexity of <code>O(N*log N)</code> which is the same as the sieve. So we got what we wanted!</p>
<p>The trick here is that we don't need to mark every multiple of the given prime but just the smallest multiple.</p>
<p>I need to say that this is not a practical idea in the sense that the memory complexity of the sieve of Eratosthenes is not that bad and it is an algorithm that's very easy to implement. </p>
<p>My point is that sometimes, if you have several ideas, each of which cannot be applied because of some flaw, then maybe is a good idea to combine their strengths. This gives you a hybrid solution for your problem. </p>
<p>Dijkstra's Factory of Primes taught me to think that way, although I have never implemented that algorithm in a real-life scenario. </p>
<h2 id="heading-combining-arrays-with-linked-lists">Combining arrays with linked lists</h2>
<p>Arrays are simple structures that allow us to get an element by its index in constant time. But we need <code>O(N)</code> operations to insert or remove an element to/from the array in the worst case, where N is the length of the array.</p>
<p>On the other hand, linked lists are structures composed of nodes. Every node has a reference to the next one, and, in the case of doubly-linked lists, each node also has a reference to the previous one. </p>
<p>In this case, we need <code>O(N)</code> operations to reach a node in the worst case, but the insert and remove operations can be done in constant time. </p>
<p>I think it's natural to think about a "perfect data structure" that allows us to make the three operations in constant time. Sadly, such a structure does not exist, but I have found a middle point between the two opposite poles.</p>
<p>The "issue" with arrays is that they maintain a reference to all of their elements. That allows us to retrieve any element with the same amount of operations no matter where the element is. </p>
<p>But maintaining those references is what makes the insertions and deletions so costly. </p>
<p>When it comes to linked lists we only maintain a reference to the first and the last node and each node has a reference to its neighbors. So, when inserting or removing a new element we only need to change a few references. </p>
<p>But that lack of references is the reason that we have to spend so many operations to get an element in the worst case.</p>
<p>Viewing the problem from that angle, the idea of finding a middle point in the number of references seems natural. What happens if we maintain a reference to <code>sqrt(N)</code> nodes of the linked list instead of referencing just the first and the last element?</p>
<p>That allows us to have a list of length <code>sqrt(N)</code> such that the distance between each of those nodes in the actual list is <code>sqrt(N)</code>. Having that, we can do each operation (index, insertion, and deletion) in <code>O(sqrt(N))</code>.</p>
<p>If you want to see more details about this structure and a Lisp implementation of it, you can do it <a target="_blank" href="https://github.com/josejorgers/indexed-linked-list">here</a>.</p>
<p>I have also written a post about it in my <a target="_blank" href="https://jj.hashnode.dev/combining-good-ideas-to-get-the-best-solution">personal blog</a>.</p>
<h2 id="heading-conclusions">Conclusions</h2>
<p>We have seen two examples of how you can combine existing solutions to get another one that has some of the good qualities of each of them. My purpose was to show you this way of thinking, not just specific examples. </p>
<p>Note that in the case of Dijkstra's idea, we could achieve the time of the fastest solution and the memory complexity of the naive algorithm. In the second example, we just got a middle point, so the fastest solution is still faster and the memory-cheaper solution is still cheaper. </p>
<p>But the new structure is like a decathlon athlete – it is good in every specificity, but not the best in any one of them. </p>
<p>So don't try to find the silver bullet – remember that there's no free lunch. Even Dijkstra's idea has the disadvantage of being harder to implement and to understand.</p>
<p>Hope you have learned something from this post. You can find more content like this in my <a target="_blank" href="https://jj.hashnode.dev">personal blog</a> and by following me on <a target="_blank" href="https://twitter.com/josejorgexl">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Know When You've Learned Everything You Can From a Programming Problem ]]>
                </title>
                <description>
                    <![CDATA[ By Amy Haddad The answer may seem obvious: you’re done with a problem once you’ve solved it.  That’s how I approached problem-solving when I began learning to code. I was on a problem-solving treadmill: solving as many problems as quickly as possible... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/when-are-you-done-with-a-programming-problem/</link>
                <guid isPermaLink="false">66d45dae33b83c4378a517b8</guid>
                
                    <category>
                        <![CDATA[ productivy ]]>
                    </category>
                
                    <category>
                        <![CDATA[ learn to code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Problem Solving ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 22 Jun 2020 20:30:26 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/06/ashkan-forouzani-m0l9NBCivuk-unsplash-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Amy Haddad</p>
<p>The answer may seem obvious: you’re done with a problem once you’ve solved it. </p>
<p>That’s how I approached problem-solving when I began learning to code. I was on a problem-solving treadmill: solving as many <a target="_blank" href="https://www.freecodecamp.org/news/do-you-solve-programming-problems-or-complete-exercises-the-difference-matters/">problems</a> as quickly as possible.</p>
<p>And why not? There’s no shortage of problems to solve. Besides, don’t you get better by solving more problems? More to the point: what else can you do once you have the answer? As it turns out, quite a bit. The fallacy of my approach soon surfaced. </p>
<p>Although I solved the problem, I didn’t learn much from it. That’s because a few days or weeks later when I tried to re-solve the problem or when I came across a related one, I got really <a target="_blank" href="https://www.freecodecamp.org/news/how-to-get-unstuck/">stuck</a>. Mistakes were made. Concepts were confused. Progress was stalled. </p>
<p>I now realize that getting the solution is only part of the problem-solving process. Then, in the words of a mathematician named George Pólya, it’s time to “look back.”</p>
<h2 id="heading-looking-back">Looking Back</h2>
<p>Pólya writes about the problem-solving process in his book, <em>How to Solve It</em>, through the lens of mathematical problem-solving. But his ideas are applicable to programming. What’s particularly interesting to me is his fourth phase: looking back.</p>
<p>“By looking back at the completed solution, by reconsidering and reexamining the result and the path that led to it, [students] could consolidate their knowledge and develop their ability to solve problems,” Pólya writes.</p>
<p>In some ways, solving a problem is like creating a piece of art. There’s always something more we could do. “We could improve any solution, and, in any case, we can always improve our understanding of the solution,” explains Pólya.</p>
<p>For me, “looking back” is a practice of self-improvement and <a target="_blank" href="https://amymhaddad.com/four-ways-to-learn-programming-topics">learning</a>. The aim is to:</p>
<ul>
<li>Learn from my successes: understand what you wrote and why.</li>
<li>Solidify my learning of new concepts.</li>
<li>See patterns and understand the context for using a particular data structure or algorithm. </li>
</ul>
<p>Consider a basketball player who takes 1,000 shots each day. That sounds admirable. But as he rushes to get the 1,000 shots in, his form gets sloppy. He uses the wrong technique. </p>
<p>He’d benefit more from taking a few hundred shots, then evaluating his performance: watching a video recording of his form, seeing the flaws, and correcting them. Then, he'd hit the court again. </p>
<p>Now he’ll be more informed, since he looked back and evaluated his performance. He’ll practice better.</p>
<p>The same is true with solving problems. The idea isn’t to check a box so you can claim you solved “x” number of problems. Instead it’s doing your best work each time and learning as much as possible along the way. </p>
<p>There are three reasons why looking back matters.</p>
<h3 id="heading-reason-1-see-the-patterns-and-understand-the-context">Reason #1: See the Patterns and Understand the Context</h3>
<p>You’ll see similar patterns over and over again in the problems you solve. </p>
<p>Understand how to use a particular algorithm, like binary search. Train your eye so you know <em>when</em> and <em>how</em> to apply it. So when you encounter a related problem in the future, you’ll be ready. Doing so will save time (and frustration) in the long run.</p>
<h3 id="heading-reason-2-solidify-your-learning">Reason #2: Solidify Your Learning</h3>
<p>Say you used something that’s new to you to solve a problem, like a stack or queue. </p>
<p>Do you really know how to use it again? Do you feel comfortable using a stack in a related problem? Take the time to understand anything new you used so you can use it again in the future.</p>
<h3 id="heading-reason-3-learn-from-your-successes">Reason #3: Learn from Your Successes</h3>
<p>Mathematician Richard Hamming gets to the heart of the matter with this quote from his book, <em>The Art of Doing Science and Engineering.</em></p>
<p>“I regard the study of successes as being basically more important than the study of failures...there are so many ways of being wrong and so few of being right, studying successes is more efficient.”</p>
<p>As programmers, we deal with our fair share of errors. And then (many tries later) we run the program and it works. Now is a great time to put Hamming’s words to practice and study your success. </p>
<p>Do you understand <em>how</em> your program works? Do you understand <em>what</em> you wrote and <em>why</em> you wrote it? </p>
<p>By looking back⁠—when the information is still fresh in your mind⁠—you’re preparing your future self. It’ll help you bridge your understanding and solidify your mental models. It’ll help you improve and prevent repeating the same mistakes over again. In short, it’ll help you get better.</p>
<h2 id="heading-four-ways-to-look-back">Four Ways to Look Back</h2>
<p>There are a few ways that I “look back” at problems. Give them a try.</p>
<h3 id="heading-teach-yourself">Teach Yourself</h3>
<p>A fantastic way to help solidify your mental models is to teach yourself. After you complete a program or problem, go through your code and explain it line by line. It’s one of the best ways of “looking back” when you’re learning something new.</p>
<p>I’ve found this process invaluable while learning web development. After I complete a project, I copy my code into a Google Doc. Starting at the top, I make comments throughout to teach myself about important concepts.</p>
<p>Here’s an example of some code and some of the comments I wrote.</p>
<pre><code class="lang-JS"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ManageTeamMembersPage</span>(<span class="hljs-params">props</span>) </span>{

    <span class="hljs-keyword">const</span> [teammate, setTeammate] = useState({
       <span class="hljs-attr">name</span>:<span class="hljs-string">""</span>,
       <span class="hljs-attr">email</span>: <span class="hljs-string">""</span>,
       <span class="hljs-attr">role</span>: <span class="hljs-string">""</span>,
   })

   ...
</code></pre>
<ul>
<li>Use props to access data passed down from the parent component.</li>
<li>Add state hook. The hook takes a default, which is an object that contains everything I need for the form: name, email, role.</li>
</ul>
<p>This method of “looking back” is about understanding. In this example, I was learning about state, props, and forms in React. </p>
<p>Writing out comments to explain your code will help you solidify concepts in your mind. If you can’t type a short explanation of it on the spot, then revisit the topic. </p>
<p>This method is equally useful for future problems and projects. I regularly pull up old problems and programs I’ve notated. I use them as a reference when writing related programs or solving related problems. Doing so reinforces key ideas, and to Hamming’s point, it helps me remember my successes: what to keep doing.</p>
<h3 id="heading-study-solutions-of-great-programmers">Study Solutions of Great Programmers</h3>
<p>It’s not only useful to study your own code, but also the code of others who have solved the same problem. There are a lot of <a target="_blank" href="https://amymhaddad.com/2-traits-of-great-programmers">great programmers</a> out there and we can learn from them.</p>
<p>After I solve a problem, I apply <a target="_blank" href="https://amymhaddad.com/how-ben-franklin-can-help-you-become-a-better-programmer.mdx">a learning technique that Ben Franklin used</a> to become a better writer. His process involved trying to reproduce an article from a publication he admired after he’d forgotten the details of it. </p>
<p>I follow a similar process to become a better programmer.</p>
<p>Here’s how it works:</p>
<ul>
<li><strong>Solve a problem</strong>.</li>
<li><strong>Find a programmer who’s better than you and who’s solved the same problem.</strong></li>
<li><strong>Study their solution</strong>: read each line of code and type a comment in your editor to explain it.</li>
<li><strong>Re-solve the program</strong> after some time has passed. Use the comments you typed out as hints to guide you along the way.</li>
<li><strong>Compare your program</strong> to the one you studied.</li>
</ul>
<p>To be clear, this practice isn’t about memorizing or copying someone else’s code—far from it. Rather, it’s about learning: get practice <a target="_blank" href="https://amymhaddad.com/why-reading-code-matters">reading</a> code; see another way to solve the same problem; experiment with new parts of a language; and get practice teaching yourself. It’s also about applying what you’ve learned by putting it into your own style.</p>
<h3 id="heading-add-a-constraint">Add a Constraint</h3>
<p>See how different techniques apply to the same problem when you add a constraint. For example, you solved the problem using a hash table. Now try solving it using an array.</p>
<p>The idea is to gain another perspective, and adding a constraint can do just that. It’ll get you out of your comfort zone, forcing you to think creatively. </p>
<p>As a result, you may find a slicker approach and cut the length of your program in half. Or may realize what data structure <em>not</em> to use, which is equally important. </p>
<p>Here’s the point: you’ll have another approach at your ready when you’re faced with a related problem in the future.</p>
<h3 id="heading-solve-a-related-problem">Solve a Related Problem</h3>
<p>The programming website LeetCode is great for many reasons. One is providing similar questions for problems that you solve.</p>
<p>In one problem on LeetCode you are given an array of integers and a target number. The aim is to find two numbers that add up to the target and return their indices. </p>
<p>You solve the problem. </p>
<p>Now solve a related one, which LeetCode provides. This time you’re given an array of integers that’s sorted in ascending order, along with a few additional constraints to differentiate this problem from the previous one.</p>
<p>Solving a related problem is a great way to get practice using a similar technique, data structure, or algorithm in a different context.</p>
<p>Looking back focuses on the <em>process</em>, instead of the end result. And revisiting the process matters. It’s getting out of your comfort zone, trying something new whether that’s a data structure or algorithm. It’s realizing there are different ways to solve the same problem. It’s understanding how to write better code. It’s about learning.  </p>
<p>Yes, it takes some time to look back. But it’s time well spent: it’s how we get better.</p>
<p><em>I write about the programming skills you need to master and the concepts you need to learn, and the best ways to learn them (</em><a target="_blank" href="https://amymhaddad.com/">amymhaddad.com</a>).</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
