<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ali Sherief</title>
    <description>The latest articles on DEV Community by Ali Sherief (@zenulabidin).</description>
    <link>https://dev.to/zenulabidin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F282762%2F5fe08aec-77c1-41ed-bf02-220f1c240edc.jpeg</url>
      <title>DEV Community: Ali Sherief</title>
      <link>https://dev.to/zenulabidin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zenulabidin"/>
    <language>en</language>
    <item>
      <title>How to avoid "Too many open files" error in NodeJS</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Tue, 02 Sep 2025 08:30:35 +0000</pubDate>
      <link>https://dev.to/zenulabidin/how-to-avoid-too-many-open-files-error-in-nodejs-2586</link>
      <guid>https://dev.to/zenulabidin/how-to-avoid-too-many-open-files-error-in-nodejs-2586</guid>
      <description>&lt;p&gt;Hi guys, I know it's been quite a long time since I last posted here, but I have had this one development problem that had been bugging me for several months, until I finally found a solution for it this morning.&lt;/p&gt;

&lt;p&gt;It specifically affects Linux desktops, but might also apply to Macs.&lt;/p&gt;

&lt;p&gt;You might notice when you have a lot of browser tabs open like Chrome, Firefox, Opera and so on, when you try to use &lt;code&gt;npm run dev&lt;/code&gt; on your Node project to run it locally, you get a hundred errors that all look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin/Documents/talksearch.io/app'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin/Documents/talksearch.io'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin/Documents'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin/Documents/talksearch.io/app'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin/Documents/talksearch.io'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin/Documents'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/zenulabidin'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And it just keeps printing this continuously forever. Alternatively, if you are not using NextJS, it will simply terminate &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This can be a very frustrating error to deal with if you have many open programs at once and don't want to close most of them, especially the browser.&lt;/p&gt;

&lt;p&gt;The conventional solution that you will find on Stack Overflow and blogs is to change the maximum file limit of the current user, using &lt;code&gt;ulimit&lt;/code&gt; programs. I will not cover these here, because they did not work for me. The problem was still the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the cause of Webpack EMFILE errors?
&lt;/h2&gt;

&lt;p&gt;The "too many open files" error is almost always caused by having too many inodes open on your system. An inode is just a file in Linux. It is the internal representation of the file.&lt;/p&gt;

&lt;p&gt;Sometimes if you use VScode, you see this error very frequently and then it gives you some instructions on how to resolve the error by running &lt;code&gt;sysctl&lt;/code&gt; commands in your terminal. It is the same type of error, and it is especially prevalent when using &lt;strong&gt;Webpack inside React projects&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to fix Webpack EMFILE errors on Linux
&lt;/h2&gt;

&lt;p&gt;This is an approach I have only found when I was using Claude Code. I specifically instructed it to 'find a way to work around too many open files errors when running npm'.&lt;/p&gt;

&lt;p&gt;What I have found is that it used set the environment variable: &lt;code&gt;WATCHPACK_POLLING=true&lt;/code&gt; inside the terminal before running &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you only want to run it once, use the following command: &lt;code&gt;WATCHPACK_POLLING=true npm run dev&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Otherwise, if you want it to apply to all runs of &lt;code&gt;npm run dev&lt;/code&gt; inside this terminal, run the command &lt;code&gt;export WATCHPACK_POLLING=true&lt;/code&gt; in the shalle. Or place it in your &lt;code&gt;.bashrc&lt;/code&gt; file.&lt;/p&gt;




&lt;p&gt;That is all. I hope you found this helpful. Don't forget to follow me on X (@Zenul_Abidin) for more posts like this.&lt;/p&gt;

</description>
      <category>npm</category>
      <category>webdev</category>
      <category>node</category>
    </item>
    <item>
      <title>Formatting HTML and CSS For Beginners</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Fri, 11 Oct 2024 09:13:26 +0000</pubDate>
      <link>https://dev.to/zenulabidin/formatting-html-and-css-for-beginners-3fmk</link>
      <guid>https://dev.to/zenulabidin/formatting-html-and-css-for-beginners-3fmk</guid>
      <description>&lt;p&gt;Well, I see it's been a long time since I last posted here. A lot of interesting stuff have happened over the past few years! But let's get back to the subject - you want to know how to format your HTML and CSS correctly, and this is how you're going to do it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some Benefits of Styling with CSS
&lt;/h2&gt;

&lt;p&gt;Many of these benefits also translate to HTML too, when you organize your markup using HTML5 elements.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;By keeping style separate from structure, CSS allows for cleaner, more maintainable code. This separation improves content accessibility and makes styling changes across a website much more manageable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS provides extensive control over the presentation, from fonts to layout, enabling developers to create responsive designs that adapt across devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;External CSS files can be cached, improving load times for subsequent page views.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Techniques for Applying CSS With Your HTML
&lt;/h2&gt;

&lt;p&gt;CSS can be applied in three primary ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inline Styling&lt;/strong&gt;: Using the &lt;code&gt;style&lt;/code&gt; attribute directly within HTML elements. While this method is straightforward, it's generally discouraged for its lack of maintainability.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;   &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"color: blue;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This text is blue.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Internal Styling&lt;/strong&gt;: Using a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag in the HTML &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;. This method is useful for small projects or unique styling for a single page.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;   &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;External Styling&lt;/strong&gt;: Linking to a separate .css file, which is the most recommended for extensive projects due to its maintainability and reusability.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;   &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;styles.css&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;   &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use Semantic HTML, as I wrote above.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid Inline Styles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prefer Classes Over IDs when creating selectors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consider organizing your CSS properties alphabetically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use class names that are descriptive but avoid overly specific selectors that might conflict or be hard to override.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Media Queries&lt;/strong&gt;. They're good for responsive design. I cannot stress this enough.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  On a different note...
&lt;/h2&gt;

&lt;p&gt;Did you know that I am running a &lt;strong&gt;free eBook giveaway&lt;/strong&gt; on X/Twitter? You will learn how Google formats their own HTML and CSS and their own advice. If you like free stuff, then &lt;a href="https://x.com/Zenul_Abidin/status/1844662275912970689" rel="noopener noreferrer"&gt;check out my tweet.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Electron vs. The Native Windows Frameworks</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 13 Sep 2021 05:38:03 +0000</pubDate>
      <link>https://dev.to/zenulabidin/electron-vs-the-native-windows-frameworks-27om</link>
      <guid>https://dev.to/zenulabidin/electron-vs-the-native-windows-frameworks-27om</guid>
      <description>&lt;p&gt;Electron is starting to be used in many different popular applications, such as VSCode and WhatsApp, simply because of its cross-platform feature. But is that the only advantage that Electron provides?&lt;/p&gt;

&lt;p&gt;As we will see by the end of this article, it is not the only benefit. We will look at how simpler it is to write a Windows app in Electron vs. native frameworks such as C++/C# WindowsForms and WPF. Why just Windows? Because the vast majority of programs are written for it, so for many categories of programs (e.g. games) there is a standardized library stack that's used.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background (tray) apps that display modal dialogs
&lt;/h2&gt;

&lt;p&gt;Electron is probably overkill for this category. Modal dialogs are simple to create using WindowsForms, and C# also makes minimizing windows and displaying their notification (tray) icon very simple. This can also be done in Electron, but &lt;a href="https://stackoverflow.com/questions/37828758/electron-js-how-to-minimize-close-window-to-system-tray-and-restore-window-back"&gt;with a little more work&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Apps with a custom theme
&lt;/h2&gt;

&lt;p&gt;Because WindowsForms does not support making custom window themes, developers use the WPF framework when they want to create a custom theme for their C# app. This process could take a lot of time, depending on the complexity of the theme.&lt;/p&gt;

&lt;p&gt;Of course, theme-designing in Electron also takes time, but it's helped by the abundance of HTML UI components that can be installed and inserted directly from &lt;code&gt;npm&lt;/code&gt;, the NodeJS package manager. Only some WPF UI controls are free to use, while the vast majority remain closed-source, internal, and private, away from the public eye. While most HTML UI components are open-source and easy to obtain from Github.&lt;/p&gt;

&lt;h2&gt;
  
  
  Apps with heavy API/web service integration
&lt;/h2&gt;

&lt;p&gt;Messaging clients such as Discord, Telegram, and Slack fall into this category. On C#, networking is done using the System.Net namespace, or more usually, with the &lt;a href="https://dotnet.microsoft.com/apps/aspnet"&gt;ASP.NET&lt;/a&gt; framework. In C++, more low-level socket functions are used, hence why complex networking is traditionally done in C#.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.net?view=net-5.0"&gt;System.Net&lt;/a&gt; has classes to manage cookies, network credentials, requests and responses, and HTTP listeners, among others. When used correctly, formidable network-enabled C# programs can be developed.&lt;/p&gt;

&lt;p&gt;A positive trait of C# networking classes is that the compiler will detect most of the incorrect usages of these classes, which can save you hours of runtime debugging. This is not the case for Node.js and Electron apps, where all code is evaluated at runtime, and could silently fail then.&lt;/p&gt;

&lt;p&gt;Worse (for Electron), as the bundled code is usually minified, it is difficult to get a stack trace that corresponds to your source code.&lt;/p&gt;

&lt;p&gt;That is not to say that Electron is not good for building network apps. On the contrary, libraries such as Axios and node-fetch take care of networking very well. Asynchronous requests are also (slightly) easier to perform on NodeJS due to the language architecture. Additionally, NestJS is often used to make entire back-end APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Video games and other GPU-intense apps
&lt;/h2&gt;

&lt;p&gt;While HTML5 games built using WebGL-emitting game engines such as Unity are starting to emerge, C#/C++ and WPF still dominate the video game industry, due to the heavy use of graphics frameworks such as DirectX and OpenGL. In particular, there is no easy way to integrate Electron and DirectX, because the latter is a Windows-specific technology.&lt;/p&gt;

&lt;p&gt;CAD &amp;amp; designer programs, and other kinds of graphics-accelerated programs, make use of OpenGL instead of DirectX, and since Electron apps can use WebGL, the level of difficulty of developing these kinds of applications in both platforms is about the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Microsoft Store apps
&lt;/h2&gt;

&lt;p&gt;Here is a surprise: &lt;a href="https://www.electronjs.org/docs/tutorial/windows-store-guide"&gt;You can publish Microsoft Store apps that are built with Electron&lt;/a&gt;. They will need at least Windows 10 1607 to run, and they will compile to AppX packages that you can publish on the Store after Microsoft manually verifies the application.&lt;/p&gt;

&lt;p&gt;So in this area, it doesn't look like there are advantages or drawbacks to using either language, because the end-product is the same - with the exception that C# can make UWP apps, but Electron can't, but to be fair, most people are not running UWP apps on the alternate platforms such as Xbox anyway.&lt;/p&gt;




&lt;p&gt;The conclusion of all this is that whether you choose to write your app in C# and WPF or in NodeJS and Electron depends on whether you plan to port it to browsers eventually, or whether you want to use GPU acceleration. C#/C++ is the clear winner for GPU-accelerated programs, while for deploying your desktop app to the web, Electron is the way to go.&lt;/p&gt;

&lt;p&gt;Desktop app deployment to web browsers has some uses. For instance, if you make an open-source code editor using Electron, then services that let you run and test code online can embed your editor inside their service, for people to use on the web. This is actually how Stackblitz is embedding VScode and a Chromium browser window in its web IDE.&lt;/p&gt;

&lt;p&gt;Cover image by &lt;a href="https://elements.envato.com/solar-panel-with-blue-sky-ME7TRYT"&gt;Envato Elements&lt;/a&gt;&lt;/p&gt;

</description>
      <category>windows</category>
      <category>electron</category>
      <category>node</category>
      <category>healthydebate</category>
    </item>
    <item>
      <title>Google Chrome Media History: How Does It Work?</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 06 Sep 2021 18:52:30 +0000</pubDate>
      <link>https://dev.to/zenulabidin/google-chrome-media-history-how-does-it-work-183i</link>
      <guid>https://dev.to/zenulabidin/google-chrome-media-history-how-does-it-work-183i</guid>
      <description>&lt;p&gt;The first thing you're probably wondering after reading the article title is, "What is Media History?" Indeed, there is no such feature when looking externally at Google Chrome. However, this is just the name of a database that is stored in Chrome's local storage. This database stores a history of URLs on which you played an audio or video stream on, hence the name "Media".&lt;/p&gt;

&lt;p&gt;Now, it does not store the media files themselves, but just the length of the time played or watched, and the URL it was playing on.&lt;/p&gt;

&lt;p&gt;So, let us see what are the high-level parts that make up the Google Chrome media history feature.&lt;/p&gt;

&lt;p&gt;The source code for the Media History feature lies in the &lt;a href="https://github.com/chromium/chromium/tree/d7da0240cae77824d1eda25745c4022757499131/chrome/browser/media/history"&gt;chromium/chrome/browser/media/history/&lt;/a&gt; folder of the repository. Here, I have linked the Github mirror of the chromium repo, because it's much easier to browse than Google's own source listing.&lt;/p&gt;

&lt;p&gt;The Chromium Media History feature consists of these parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Contents Observer&lt;/li&gt;
&lt;li&gt;Images Table&lt;/li&gt;
&lt;li&gt;Keyed Service&lt;/li&gt;
&lt;li&gt;Keyed Service Factory&lt;/li&gt;
&lt;li&gt;Origin Table&lt;/li&gt;
&lt;li&gt;Playback Table&lt;/li&gt;
&lt;li&gt;Session Images Table&lt;/li&gt;
&lt;li&gt;Session Table&lt;/li&gt;
&lt;li&gt;Store&lt;/li&gt;
&lt;li&gt;Table Base&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of these items resides in its own file and we'll be taking a look at them one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Elements
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Contents Observer
&lt;/h3&gt;

&lt;p&gt;It implements the Observer pattern documented in the famous Design Patterns book by the Gang of Four. As a recap, directly from &lt;a href="https://en.wikipedia.org/wiki/Observer_pattern"&gt;Wikipedia - Observer pattern&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, the Media History is notifying its subscribers when new events happen. Among the possible events to listen to, are the &lt;code&gt;DidStartNavigation&lt;/code&gt;, &lt;code&gt;DidFinishNavigation&lt;/code&gt;, and &lt;code&gt;WebContentsDestroyed&lt;/code&gt; events, inherited from the &lt;code&gt;WebContentsObserver&lt;/code&gt; parent class, which we shall cover on a later date.&lt;/p&gt;

&lt;p&gt;Novel event methods include &lt;code&gt;MediaSessionInfoChanged&lt;/code&gt;, &lt;code&gt;MediaSessionMetadataChanged&lt;/code&gt;, &lt;code&gt;MediaSessionActionsChanged&lt;/code&gt;, &lt;code&gt;MediaSessionImagesChanged&lt;/code&gt;, and &lt;code&gt;MediaSessionPositionChanged&lt;/code&gt; which alert subscribers when those respective fields change. It has fields for whether media has ever been played on this particular &lt;code&gt;WebContents&lt;/code&gt; object, and whether a web navigation is occurring right now to pause state updates.&lt;/p&gt;

&lt;p&gt;These event callbacks also update any caches that have these old objects inside them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Images Table
&lt;/h3&gt;

&lt;p&gt;This is an SQL table entity that saves information about images into the database. It contains a method to export images to the database and returns their ID.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keyed Service
&lt;/h3&gt;

&lt;p&gt;The Keyed Service holds a pointer to the Store object (more on that later), which could either be at a local or remote place. Each Keyed Service also has one pointer to a Google Chrome profile.&lt;/p&gt;

&lt;p&gt;Keyed Service objects have methods to save watch times and stats to the Store.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keyed Service Factory
&lt;/h3&gt;

&lt;p&gt;This is the Factory pattern from the Design Patterns book, applied to keyed services. As you have probably guessed, this class is in charge of creating Keyed Service objects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Origin Table
&lt;/h3&gt;

&lt;p&gt;It is like the Image Table but it stores URLs in SQL-like tables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Playback Table
&lt;/h3&gt;

&lt;p&gt;Similarly, the Playback Table exports the timestamp and watch time specifically to the data store.&lt;/p&gt;

&lt;h3&gt;
  
  
  Session Images Table
&lt;/h3&gt;

&lt;p&gt;This is a supporting table that correlates the image ID with the session ID.&lt;/p&gt;

&lt;h3&gt;
  
  
  Session Table
&lt;/h3&gt;

&lt;p&gt;Yet another table, this one saves URLs, metadata, and the position of the media being placed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Store
&lt;/h3&gt;

&lt;p&gt;This object contains the actual pointer to the database, as well as to each of the tables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table Base
&lt;/h3&gt;

&lt;p&gt;This is the parent class of all of the other table classes in this section. It is responsible for initializing the database member object inside the table object.&lt;/p&gt;




&lt;p&gt;As I briefly hinted in the last section, each Table object has its own database pointer. Consequently, when you save an entry inside the Chromium Media History, it is assigned to one of these tables, and as a result, one of the databases. There is no single Media History database: It is split into several different databases for each table.&lt;/p&gt;

&lt;p&gt;Here is a diagram of how these components of the media history connect together.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1BvrW16O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/880/1%2AKeVIjTO8GHkard_BKlNoVg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1BvrW16O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/880/1%2AKeVIjTO8GHkard_BKlNoVg.jpeg" alt="Google Chrome Media History Component Diagram"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
    </item>
    <item>
      <title>MSYS2 Build Processes Driving You Crazy?</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 30 Aug 2021 16:32:14 +0000</pubDate>
      <link>https://dev.to/zenulabidin/msys2-build-processes-driving-you-crazy-4bh1</link>
      <guid>https://dev.to/zenulabidin/msys2-build-processes-driving-you-crazy-4bh1</guid>
      <description>&lt;p&gt;At work, I have the task of making builds for a particular cryptocurrency wallet for multiple platforms. Among them is Windows, and we don't build with Visual Studio - instead, we using CMake with MSYS2 so we don't have to rewrite the whole codebase just for Windows-specific edge cases.&lt;/p&gt;

&lt;p&gt;There was just one problem though. When I was assigned to this, the codebase just wouldn't pass the CMake configuring process on Windows according to the build instructions. There didn't seem to be anything wrong at first, but later on, there were a few red herrings of an error that threw off my debugging.&lt;/p&gt;

&lt;p&gt;Eventually, I was able to nudge it past CMake. Here's how I did it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some background information about MSYS2
&lt;/h2&gt;

&lt;p&gt;You don't actually build applications inside MSYS2. You build them inside MinGW - that's because MSYS2 is just a shell. That's right, MSYS2 only provides you with a bash-like shell, and the rest of the GNU tools are provided by MinGW.&lt;/p&gt;

&lt;p&gt;In particular, all the build tools are only available if you run the MinGW version of the MSYS2 shell. So every Windows project's build instructions that don't use Visual Studio will require you to build it under MSYS2.&lt;/p&gt;

&lt;p&gt;MSYS2 and MinGW use the &lt;code&gt;pacman&lt;/code&gt; package manager to install software. There are two sets of packages (well, there are actually more than that, but I'm not counting the 32-bit or Universal C Runtime or cross-platform packages). The &lt;code&gt;mingw-w64-x86_64-*&lt;/code&gt; packages install in MinGW's "namespace", and the unqualified (with no crazy prefixes) packages install in MSYS2's namespace.&lt;/p&gt;

&lt;p&gt;Unqualified packages are visible from the MinGW program, but apparently, the &lt;code&gt;mingw*&lt;/code&gt; packages are not visible from MSYS2, but please let me know in the comments if this is wrong, because I discovered this from trial and error.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CMake Error: File &amp;lt;REDACTED&amp;gt;/external/unbound/win32pthread-NOTFOUND does not exist.
-- Could NOT find Readline (missing: Readline_INCLUDE_DIR)
Doxygen: graphviz not found - graphs disabled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Do any of these errors look familiar to you? Well apparently, Google returns a few hits on them, but doesn't really offer answers for any of them.&lt;/p&gt;

&lt;p&gt;Some of these errors can be resolved by installing the relevant &lt;code&gt;mingw-*&lt;/code&gt; packages. This is the case for Doxygen and graphviz not being found. Others, like the first two, are more subtle and cannot be resolved just by installing the package - there is a little more work you have to do in your CMake files.&lt;/p&gt;

&lt;p&gt;Only the pthreads error was fatal, but all of them are equally annoying. Let's start with the Readline error first.&lt;/p&gt;

&lt;p&gt;First though, ensure that &lt;code&gt;mingw-w64-x86_64-readline&lt;/code&gt; is already installed. The same goes for the Doxygen and graphviz packages. The MinGW packages are necessary, not the unqualified MSYS2 packages.&lt;/p&gt;



&lt;p&gt;Your Readline package configuration probably looks something like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;A call to find_package, followed by a check whether Readline is found (and a diagnostic printing that it will build without Readline support otherwise).&lt;/p&gt;

&lt;p&gt;The problem here is, find_package never finds the path to Readline. This is strange, for two reasons. One, find_package has no problem finding other packages, and two, the Readline library is already installed inside MinGW. So what could be the problem?&lt;/p&gt;

&lt;p&gt;After doing some inspection, I discovered that find_package does find the Readline &lt;strong&gt;library&lt;/strong&gt;, but not the include path. Apparently, this is because it was told to look for a specific filename (readline/readline.h) that had a forward slash in it, as the path separator.&lt;/p&gt;

&lt;p&gt;MinGW programs don't understand UNIX paths because they are programmed to understand only Windows paths. This is to make them work under Windows.&lt;/p&gt;

&lt;p&gt;To make things worse, MSYS only works with UNIX paths, not the Windows paths that MinGW programs use.&lt;/p&gt;

&lt;p&gt;This causes some confusion in CMake, because the find_package function ultimately just calls the find(1) program, which is a MinGW program and only understands Windows paths.&lt;/p&gt;

&lt;p&gt;Worse, CMake itself will only take UNIX paths for file specification no matter whether you install the MSYS or MinGW version of it. This leads to a situation where you have to mix Windows and UNIX paths in the same configuration file, which can get quite messy.&lt;/p&gt;

&lt;p&gt;I could've gone that way and modified the file responsible for finding the Readline package, but since that wouldn't be portable, I decided to implement a fallback condition instead, just for MinGW.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see, there is a special condition in the fixed code that detects the case where find_package can't find Readline, and if the program is being built under MinGW. In this case, I just emit a warning, hardcode the path that Readline is supposed to be, and proceed with the rest of the CMake file.&lt;/p&gt;

&lt;p&gt;This particular case also has checks for 32- and 64-bit MinGW.&lt;/p&gt;




&lt;p&gt;As I mentioned before, the pthreads error was the one that halted CMake execution, and not any of the other errors. In this case, it complained that it could not find the pthread &lt;strong&gt;library&lt;/strong&gt; under Windows.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This can get confusing, because Windows doesn't use pthreads - It uses it's own OS-specific threading library. So MinGW emulates pthreads on Windows by shipping a pthreads .dll library specifically for Windows.&lt;/p&gt;

&lt;p&gt;This error is basically saying it can't find that file.&lt;br&gt;
First, ensure that &lt;code&gt;mingw-w64-x86_64-winpthreads-git&lt;/code&gt; is installed - this will install the pthreads development files, and will also pull the &lt;code&gt;*-libwinpthread&lt;/code&gt; package, which provides the /mingw64(or 32)/bin/libwinpthread-1.dll library that needs to be found.&lt;/p&gt;

&lt;p&gt;Here, we have to use Windows paths to specify this file, because the (unshown) copy function that happens immediately after this search will not work with UNIX paths.&lt;/p&gt;

&lt;p&gt;The result will look something like this, along with warnings and 64-bit checks:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;You should now be able to build your codebase without these errors displayed, and the compiler will automatically be able to find these files itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://elements.envato.com/stressed-computer-programmer-in-front-of-computer-NE3XYMG"&gt;Cover Image by Envato Elements&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>The 4 Parts Of The WebUI: View Google Chrome’s Code</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 23 Aug 2021 00:07:07 +0000</pubDate>
      <link>https://dev.to/zenulabidin/the-4-parts-of-the-webui-view-google-chrome-s-code-43nj</link>
      <guid>https://dev.to/zenulabidin/the-4-parts-of-the-webui-view-google-chrome-s-code-43nj</guid>
      <description>&lt;p&gt;This is the first of a series of posts that will dive deep inside Google Chrome's codebase and understand how it works as much as possible.&lt;/p&gt;

&lt;p&gt;I believe that it's a great idea to know what on earth is going on in the software you run, the first and foremost of them being your browser, especially as &lt;a href="https://www.forbes.com/sites/gordonkelly/2021/08/21/google-chrome-warning-high-security-hacks-upgrade-chrome-now/?sh=11ce222ceac2"&gt;a flurry of universal security vulnerabilities were discovered&lt;/a&gt; inside Chrome recently.&lt;/p&gt;

&lt;p&gt;Google Chrome is a slightly modified and reskinned copy of &lt;a href="https://chromium.org/"&gt;Chromium&lt;/a&gt;, an open-source browser. This means that source code is available, which makes this investigation possible.&lt;/p&gt;

&lt;p&gt;The objective is not to understand every single function and line of code - it's to get an overview of the high-level components that make up the software.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the WebUI?
&lt;/h2&gt;

&lt;p&gt;It is a special web page that has access to the Google Chrome internal machinery itself. For example, the New Tab page, the Settings page, the Extensions page, etc.&lt;/p&gt;

&lt;p&gt;The URLs that use the chrome:// prefix (which is a protocol in its own right) are all WebUIs. They are scripted using the same web technologies used in normal web pages such as HTML, CSS, and Javascript, but they have permission to access browser internals.&lt;/p&gt;

&lt;p&gt;When I say "internals", I am referring to the renderer, which I will talk about later. For now, it suffices to say that it is the component that generates a bitmap from the HTML and CSS and draws it on the screen.&lt;/p&gt;

&lt;p&gt;The renderer is usually written in some form of Javascript. You might have heard of the &lt;strong&gt;V8 engine&lt;/strong&gt; (not to be confused with the car engine of the same name). This is the renderer that powers not only Chrome, but also NodeJS. It has some methods which allow you to run arbitrary Javascript on it [&lt;a href="https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/docs/webui_explainer.md#webuimessagehandler_calljavascriptfunction"&gt;WebUIMessageHandler::CallJavascriptFunction()&lt;/a&gt;] and send messages to the window object using &lt;a href="https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/docs/webui_explainer.md#chrome_send"&gt;chrome.send()&lt;/a&gt;. This is used to implement things like service workers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Google Chrome pages are sandboxed
&lt;/h2&gt;

&lt;p&gt;The vast majority of pages have no access to the filesystem or any part of the world outside the browser whatsoever. Since implementing access controls on each and every tab would be prohibitively slow, this sandbox is enforced on the renderer.&lt;/p&gt;

&lt;p&gt;As a result, the renderer (and all the pages under it) can only draw stuff to the screen but not interact with the OS. They cannot access the camera or microphone. They cannot show you popups or use your on-device location services. Chrome even supports USB and serial port interfacing - which is not surprising when you consider it's the basis of ChromeOS - and obviously, a page has no access to those either.&lt;/p&gt;

&lt;p&gt;I can make a long list of resources that are off-limit to pages, but you can find many of them by going to the Site Permissions area for that particular page.&lt;/p&gt;

&lt;h2&gt;
  
  
  The WebUI as an attack vector
&lt;/h2&gt;

&lt;p&gt;Most security vulnerabilities like the one you saw above rely on breaking through the sandbox using maliciously crafted Javascript served in a webpage that bypasses the renderer.&lt;/p&gt;

&lt;p&gt;WebUI pages are special because they are not sandboxed like this. This makes them an attractive attack vector, especially when you consider Chrome supports extensions. See that New Tab Page extension in the results for example? It can technically replace the chrome://newtab WebUI with its own page.&lt;/p&gt;

&lt;p&gt;Also, since WebUIs receive all the service worker messages, it's possible that a malicious service worker sends something that's designed to gain access to some internal Chrome functionality.&lt;/p&gt;

&lt;p&gt;These issues can be mitigated by disallowing WebUIs from loading random HTTP(S) fetches and data URLs. If they need to embed content from an external page for some reason, such as the Google Doodles, they can use iframes for that, which are sandboxed like a standard web page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parts of the WebUI
&lt;/h2&gt;

&lt;p&gt;Chrome makes a WebUI by creating a C++ class of the same name, along with a WebUIDataSource, a WebUIMessageHandler, and a WebUIController which is responsible for pulling the strings that make the puppet move (figuratively). All of these are neatly documented consecutively &lt;a href="https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/docs/webui_explainer.md#c_classes"&gt;on this page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The WebUI represents the actual super-privileged Chrome page. The WebUIDataSource adds resources to a WebUI that it can access later, for example, images or translation strings. The WebUIMessageHandler receives Javascript events on behalf of the WebUI.&lt;/p&gt;




&lt;p&gt;To summarize what we have learned, I have made this simple diagram of linked concepts. Who ever knew that learning parts of your programs could be so simple?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iDNj5nDm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/gPY4XPC.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iDNj5nDm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/gPY4XPC.jpg" alt="Google Chrome WebUI Sandbox Renderer source code diagram"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image by NotATether.com. Do not share without attribution.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
    </item>
    <item>
      <title>What's all this fuss about spying with light bulbs?</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 16 Aug 2021 03:27:46 +0000</pubDate>
      <link>https://dev.to/zenulabidin/what-s-all-this-fuss-about-spying-with-light-bulbs-49fc</link>
      <guid>https://dev.to/zenulabidin/what-s-all-this-fuss-about-spying-with-light-bulbs-49fc</guid>
      <description>&lt;p&gt;At first, hearing this might sound ridiculous. How could a hacker possibly monitor your activity through a light bulb?&lt;/p&gt;

&lt;p&gt;Except that's exactly what I read on &lt;a href="https://www.forbes.com/sites/daveywinder/2020/06/14/how-to-use-an-ordinary-light-bulb-to-spy-on-conversation-80-feet-away-security-research-lamphone-hack/?sh=18beac045be1"&gt;Forbes&lt;/a&gt; the other day. It particularly affects virtual assistants such as Alexa, Google Home, Siri, and &lt;em&gt;any&lt;/em&gt; other microphone input (such as meeting apps) and involves you, unwittingly, literally shining a light at the microphone piece.&lt;/p&gt;

&lt;p&gt;Now obviously, shining any old light at your home assistant isn't going to do anything, it's a special type of exposure that was found to cause the vulnerability. In the research paper &lt;a href="https://ad447342-c927-414a-bbae-d287bde39ced.filesusr.com/ugd/a53494_443addc922e048d89a664c2423bf43fd.pdf"&gt;Lamphone: Real-Time Passive Sound Recovery from Lightbulb Variations&lt;/a&gt;, the researchers demonstrate how "dumb" light bulbs are sensitive to sound and make different vibrations depending on the audio coming out from the home assistant.&lt;/p&gt;

&lt;p&gt;Theoretically, any object in the room could've been used to record vibrations, but light bulbs are the only ones that reflect any light to a long distance, and this attack needs light rays to work properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The attack method
&lt;/h2&gt;

&lt;p&gt;The reason this method works is that it emulates how a microphone works. You see, a microphone consists of a diaphragm that converts analog sound into vibrations, a transducer that runs the vibrations through a magnetic field, turning them into an electrical current, and an Analog-to-Digital Converter (ADC) that samples the current using frequencies (e.g. 44.1KHz) that the device can understand. As far as the device is concerned, this is intelligible audio to them.&lt;/p&gt;

&lt;p&gt;Obviously, the diaphragm part that makes vibrations can't be replicated by some thieving machinery far away, but those vibrations can be "stolen" from the room with the help of an &lt;strong&gt;extremely close&lt;/strong&gt; light bulb. This technique will not work with light bulbs more than a few centimeters away from the microphone piece because the intercepted sounds will be full of unintelligible noise.&lt;/p&gt;

&lt;p&gt;Also, it will not work if the light bulb has an enclosure, as most home lights have, that limits light radiation, since that reverts it to a normal household object that can't be inspected without lots of noise.&lt;/p&gt;

&lt;p&gt;So don't worry about this device gleaming audio from your ceiling light. It simply is not possible (yet).&lt;/p&gt;

&lt;p&gt;Basically, instead of vibrations, light signals are fed through a makeshift transducer and ADC some close distance away. This can record people's voice input.&lt;/p&gt;

&lt;p&gt;To be honest, the attack is only practical if you're somewhere within 25 meters (a little above 80 feet) of the target device. Understandably, this means that you have to be &lt;em&gt;really close&lt;/em&gt; to the target building to record a strong enough light signal. So it's only practical if attached to places such as your neighbor's building, or in the case of the researchers, a bridge.&lt;/p&gt;

&lt;p&gt;But if you had those high-security requirements, you wouldn't be placing sensitive stuff near a public bridge, now would you?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--swfduWAW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/880/1%2AN06zMibwg2iX4siNreI69w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--swfduWAW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/880/1%2AN06zMibwg2iX4siNreI69w.png" alt="spy camera, spy camera light bulb, camera spying on building"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The setup used to spy on audio in a room.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, as fancy as this vulnerability sounds, there's one obvious patch for it. &lt;strong&gt;Closing your curtains or blinds.&lt;/strong&gt; This has been the standard privacy guard for decades for sensitive stuff you don't want neighbors and snoops listening on or seeing. The researchers have also implied that opening the door might produce unintended side effects.&lt;/p&gt;

&lt;p&gt;(Also, if you see giant telescopes outside pointing directly at your building, you should definitely go out and enquire about that. It's not like there are scientific planetary objects of interest in your room.)&lt;/p&gt;

&lt;h2&gt;
  
  
  The power LED to the audio
&lt;/h2&gt;

&lt;p&gt;Yesterday, &lt;a href="https://www.forbes.com/sites/daveywinder/2021/08/15/hackers-use-flickering-power-leds-to-spy-on-conversations-100-feet-away/?sh=3b5d05b54530"&gt;another article&lt;/a&gt; was published on Forbes that describes how a variant of this attack, aptly called "Glowworm", can be carried out using power LEDs instead of light bulbs.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/z4-OFLTHtiw"&gt;
&lt;/iframe&gt;
 &lt;br&gt;
This video linked in the article demonstrates how the "Glowworm" attack works.&lt;/p&gt;

&lt;p&gt;The Forbes author also points out in the article the no-brainer precautions also work for power LEDs as they do for light bulbs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You've probably already jumped to the most obvious mitigation conclusion: as Glowworm requires a clear line of sight to the power LED, closing the curtains, turning speakers around to face away from any window or sticking a piece of, oh the irony, electrical tape over the LED will all kibosh it.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;So should you be concerned about these things? Probably not. As well as having ridiculously simple precautions, it needs specialized equipment that you can probably see from your window, and take the appropriate actions: closing blinds, calling the police on that location, and such.&lt;/p&gt;

&lt;p&gt;Cover Image by &lt;a href="https://elements.envato.com/user/LightFieldStudios"&gt;LightFieldStudios&lt;/a&gt; from &lt;a href="https://elements.envato.com/suspicious-young-man-with-binoculars-spying-throug-FXNUVHY"&gt;Envato Elements&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
    </item>
    <item>
      <title>Pro Tips For Designing Robust React Components Part II: Bundle Size</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 09 Aug 2021 03:47:58 +0000</pubDate>
      <link>https://dev.to/zenulabidin/pro-tips-for-designing-robust-react-components-part-ii-bundle-size-2o1i</link>
      <guid>https://dev.to/zenulabidin/pro-tips-for-designing-robust-react-components-part-ii-bundle-size-2o1i</guid>
      <description>&lt;p&gt;A few weeks ago, I shared some tips for improving React app performance. Let's see how another metric can be improved - the bundle size.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/zenulabidin" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hYlL-yJx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--a3g0Tfu---/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/282762/5fe08aec-77c1-41ed-bf02-220f1c240edc.jpeg" alt="zenulabidin"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/zenulabidin/pro-tips-for-designing-robust-react-components-2aii" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Pro Tips For Designing Robust React Components&lt;/h2&gt;
      &lt;h3&gt;Ali Sherief ・ Jul 19 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Why is bundle size important?
&lt;/h2&gt;

&lt;p&gt;Because that affects how quickly your app will load when a user opens your page. It is vital because many users will probably be connecting from dodgy 3G or wireless connections, where the speed is slow, and thus a small bundle size is essential so that users don't leave your site. &lt;a href="https://www.getfeedback.com/resources/ux/need-speed-fast-loading-key-satisfying-ux/"&gt;Users tend to leave a site if a page takes longer than 3 seconds to load.&lt;/a&gt; The 2-second threshold is the "danger zone" where most users expect the app to be fully loaded within that time and begin to get impatient if it isn't.&lt;/p&gt;

&lt;p&gt;Granted, React app loading is not symmetrical to page loading - generally, you can load a bunch of HTML and CSS much faster than a React.js bundle file. However, load time is still important even though you have a slightly longer amount of time to render the app. So while users will forgive you for your app taking 10 seconds to render, the same cannot be said for 60 seconds, 45, and possibly even 30 seconds.&lt;/p&gt;

&lt;p&gt;Nobody's expecting you to render a React app in 2 seconds, though if you can, then your team should throw a pizza and beer celebration. For the rest of you, here are some techniques to shrink the bundle size.&lt;/p&gt;

&lt;h2&gt;
  
  
  Split your bundles into smaller ones
&lt;/h2&gt;

&lt;p&gt;This is a very powerful technique to make the app load faster because instead of one large bundle, it is now a bunch of smaller ones that Webpack can load on-demand. So, you can package your app's dashboard as a bundle that loads immediately and delay the loading of bundles representing other auxiliary pages. I imagine this is what Facebook, Instagram, and others use to keep the load time of their main sites - which are written in React - manageable.&lt;/p&gt;

&lt;p&gt;Splitting bundles is a feature available since Webpack 4. Apps made nowadays likely are not building using Webpack 3 or lower, so there should be no worries about upgrading to a slightly incompatible version.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does code-splitting work?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://webpack.js.org/guides/code-splitting/"&gt;The Webpack documentation&lt;/a&gt; gives us 3 methods to implement code splitting. The first one uses entry points using &lt;code&gt;entry&lt;/code&gt; configuration lines in the Webpack config. This basically means that each component tree you want to split off has some ancestor component in a specific file referenced in the Webpack configuration. The entire tree is bundled down to a single bundle.&lt;/p&gt;

&lt;p&gt;This is how you use &lt;code&gt;entry&lt;/code&gt; to define different bundles Webpack needs to make:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You must include &lt;code&gt;dependOn: 'shared'&lt;/code&gt; for all the bundles, and then list any external libraries you're importing as dependencies and the file name of each component used by the multiple component trees. Otherwise, the shared dependencies are duplicated in both bundles and defeat the purpose of code splitting. The lodash dependency in this example will occupy more than 500KB in each of the created bundles without shared dependencies.&lt;/p&gt;

&lt;p&gt;Of course, it is usually not feasible to place all your shared components in one file. Whatever you write in the &lt;code&gt;dependOn:&lt;/code&gt; the directive will have a key right below the &lt;code&gt;entry&lt;/code&gt; object, such as &lt;code&gt;shared&lt;/code&gt; in this example, and is an array of strings if a bundle has multiple dependencies. Creating multiple &lt;code&gt;dependOn&lt;/code&gt; names for different bundles allow you to define multiple shared entry points whose paths reflect the structure of your React app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Refactor long lists of content as separate XHR calls
&lt;/h2&gt;

&lt;p&gt;If you have any long arrays of text strings in your React app, these might be weighing down the load time. Try to make an API endpoint to supply this data, then use &lt;code&gt;node-fetch&lt;/code&gt; to retrieve it at runtime, using a progress indicator as a placeholder while the request completes. You can use this alongside code splitting to fetch the content before additional bundles are loaded, which reduces the time to render before a user can interact with the app.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/bvaughn/react-window"&gt;react-window&lt;/a&gt; module has been designed to fetch long lists of content. It has an additional performance optimization, however. Instead of fetching the entire list, it only fetches the amount that fits in the viewport and then issues a DOM update. This is useful if, for some reason, your list, along with all its properties, is several megabytes large. It happens sometimes.&lt;/p&gt;

&lt;p&gt;Additionally, you might be able to set up your API endpoint to prefetch the request, which will make the server cache the response by the time you're ready to issue the actual API call. In some cases, this can speed up the time it takes to fetch long lists of content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use tree-shaking
&lt;/h2&gt;

&lt;p&gt;Tree-shaking is a process that eliminates dead code from bundles. For this to work, you must only import the functions you need from modules (i.e., don't import the whole thing), and you have to place &lt;code&gt;"sideEffects": false&lt;/code&gt; in your package.json on the same level as the &lt;code&gt;name&lt;/code&gt; property. You can also add it in the Webpack configuration file under the &lt;code&gt;rules&lt;/code&gt; property object.&lt;/p&gt;

&lt;p&gt;A side effect is any module that, when imported, runs some background function in addition to importing items from the module. Webpack wants to make sure that removing unused functions from the bundle does not accidentally inhibit important code from running. If there are such modules, you should include their file names as an array of strings in the &lt;code&gt;sideEffects&lt;/code&gt; property and Webpack will keep those in the bundle.&lt;/p&gt;

&lt;p&gt;Note that for this to work, you have to use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import"&gt;ES2015 import syntax&lt;/a&gt; in your files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use service workers
&lt;/h2&gt;

&lt;p&gt;Applicable to all kinds of web apps, not React apps per se.&lt;/p&gt;

&lt;p&gt;A service worker is a Javascript file that a page deploys in the background. It "installs" this file by caching all files specified in the "install" event listener. Then, it communicates with the page by sending a &lt;code&gt;window.postMessage()&lt;/code&gt;` call, whose data is then intercepted by the "message" event listener on the webpage.&lt;/p&gt;

&lt;p&gt;But how does a service worker know which page to communicate with? It turns out that &lt;code&gt;postMessage()&lt;/code&gt; also takes an origin parameter that tells the browser which pages it should broadcast the message to. So tabs in a browser window that have the same origin will all receive the message.&lt;/p&gt;

&lt;p&gt;So service workers don't really do one-to-one messaging unless there's only one matching page. Think of it as a publish-subscribe channel where all open pages of the same origin will get the data received in the message. Remember that an origin is a tuple of hostname or domain name, port number, and protocol (HTTP or HTTPS).&lt;/p&gt;

&lt;p&gt;Service workers can improve app performance by caching the files specified at install time and then returning them in the "message" payload to open the page. These files are effectively cached in the browser, so apps can use this method to read items such as CSS files, fonts, and other dependencies defined in the HTML, such as &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags. It doesn't work well for caching bundles (use the Webpack server instead), Also without specifying the origin, you create security holes in your app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developers.google.com/web/fundamentals/primers/service-workers"&gt;Google Developers&lt;/a&gt; has some terrific code samples for service worker events in their documentation. They also have an &lt;a href="https://developers.google.com/web/ilt/pwa/introduction-to-service-worker"&gt;older tutorial&lt;/a&gt; that explains how service workers work.&lt;/p&gt;




&lt;p&gt;I hope this post has benefited you in your quest to make your React app faster. If you have any other performance ideas, let me know about them in the comments below.&lt;/p&gt;

&lt;p&gt;Cover Image by @bobbinio2112 via &lt;a href="https://www.twenty20.com/photos/36eb7b62-ed97-4f1a-8713-39163704ebbc/"&gt;Twenty20&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>webpack</category>
    </item>
    <item>
      <title>Musings about Database Indexes</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 02 Aug 2021 13:13:49 +0000</pubDate>
      <link>https://dev.to/zenulabidin/musings-about-database-indexes-14dm</link>
      <guid>https://dev.to/zenulabidin/musings-about-database-indexes-14dm</guid>
      <description>&lt;p&gt;And not "Indicies"; I just took the Triplebyte backend developer test last night, and this was on the assessment.&lt;/p&gt;

&lt;p&gt;Never take a Triplebyte assessment late at night. Your concentration falls if you're not blasting loud music in your headphones and the prolonged drowsiness dulls your comprehension as smooth as an unsharpened №2 pencil.&lt;/p&gt;

&lt;p&gt;Notwithstanding all that, I didn't do so badly. In fact, I'm just shy of the 50th percentile of backend devs. But my DB indexes skills need some reflexing.&lt;/p&gt;

&lt;p&gt;A caveat: I admit I'm not the best at handling databases, and while I got my relational DB theory and basic types, rows/column/keys, and SQL nomenclature out of the way, indices are a bit advanced for me, so we'll try to journey through it in this post, and hopefully by then we all will get the gist of them.&lt;/p&gt;

&lt;p&gt;Also, before we begin, I would like to go through the subject of why they are called database &lt;strong&gt;Indexes&lt;/strong&gt; and not &lt;strong&gt;Indices&lt;/strong&gt;. The topic is apparently so confusing that even &lt;a href="https://www.nasdaq.com/articles/indexes-or-indices-whats-the-deal-2016-05-12"&gt;Nasdaq&lt;/a&gt; wrote an article about it. Technically either is correct since they are both plural forms of the word "index," but I see pages universally saying indexes so we will stick with that throughout this article.&lt;/p&gt;

&lt;p&gt;TL;DR: the word "indices" paired with any word ranks higher on search engines. It is generally more ubiquitous on the web but we Americans have gotten used to saying the word "indexes" so often that we wrote them all over technical documentation. Sigh.&lt;/p&gt;

&lt;h2&gt;
  
  
  So… what exactly is a DB index?
&lt;/h2&gt;

&lt;p&gt;Now that the naming hoo-ha is out of the way, let's turn our attention to the &lt;a href="https://en.wikipedia.org/wiki/Database_index"&gt;Wikipedia&lt;/a&gt; article about the subject:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"A database index is a &lt;a href="https://en.wikipedia.org/wiki/Data_structure"&gt;data structure&lt;/a&gt; that improves the speed of data retrieval operations on a &lt;a href="https://en.wikipedia.org/wiki/Table_%28database%29"&gt;database table&lt;/a&gt; at the cost of additional writes and storage space to maintain the index data structure. Indexes are used to quickly locate data without having to search every row in a database table every time a database table is accessed. Indexes can be created using one or more &lt;a href="https://en.wikipedia.org/wiki/Column_%28database%29"&gt;columns of a database table&lt;/a&gt;, providing the basis for both rapid random &lt;a href="https://en.wikipedia.org/wiki/Lookup"&gt;lookups&lt;/a&gt; and efficient access of ordered records."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Woah. Let's break this down into detail. We have &lt;em&gt;"improves the speed of data retrieval operations,"&lt;/em&gt; which implies that &lt;strong&gt;indexes speed up queries&lt;/strong&gt;. But how? And why not just improve table lookup speeds instead?&lt;/p&gt;

&lt;h2&gt;
  
  
  How does DB indexing work?
&lt;/h2&gt;

&lt;p&gt;From what I gathered, an index stores an entire column into an internal structure with faster read times than the database table itself. You can store any column you want inside an index using the following SQL statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE INDEX &amp;lt;index_name&amp;gt;
ON &amp;lt;table_name&amp;gt; (column1, column2, ...)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not universal syntax - the exact command might vary depending on the database management system used.&lt;/p&gt;

&lt;p&gt;It also allows for multiple columns to be indexed simultaneously, potentially speeding up read times for values in those columns. &lt;/p&gt;

&lt;p&gt;It's like a mini-table with just those columns but sorted on the first column &lt;code&gt;column1&lt;/code&gt;. This sorting feature is the crucial part that makes the whole indexing system work. A DB already knows where a particular primary key is, so having the ability to find the rest of the filtered columns by another "key" allows the entire (filtered) row to be fetched rapidly.&lt;/p&gt;

&lt;p&gt;You may not know this, but primary keys are &lt;a href="https://www.codecademy.com/articles/sql-indexes"&gt;already stored inside indexes&lt;/a&gt; without any additional coding on your side.&lt;/p&gt;

&lt;p&gt;However, it is worth noting that while indexes are read faster than tables, they are &lt;strong&gt;slower&lt;/strong&gt; at writing than tables. Hence, do not create indexes on tables frequently updated with new rows or new column values.&lt;/p&gt;




&lt;p&gt;So now that we know when not to use indexes let's look at an analogy that demonstrates its practical use.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Book Index
&lt;/h2&gt;

&lt;p&gt;A brilliant example of an index is given by Stack Overflow user &lt;a href="https://stackoverflow.com/users/2629588/sankarganesh-eswaran"&gt;Sankarganesh Eswaran&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Classic example "Index in Books"&lt;br&gt;
Consider a "Book" of 1000 pages, divided by 10 Chapters, each section with 100 pages.&lt;/p&gt;

&lt;p&gt;Simple, huh?&lt;/p&gt;

&lt;p&gt;Now, imagine you want to find a particular Chapter that contains a word &lt;strong&gt;"Alchemist"&lt;/strong&gt;. Without an index page, you have no other option than scanning through the entire book/Chapters. i.e: 1000 pages.&lt;/p&gt;

&lt;p&gt;This analogy is known as &lt;strong&gt;"Full Table Scan"&lt;/strong&gt; in database world.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NKjOI3hE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/880/0%2Adcx_otVoMDojpXLj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NKjOI3hE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/880/0%2Adcx_otVoMDojpXLj.jpg" alt="A book index"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But with an index page, you know where to go! And more, to lookup any particular Chapter that matters, you just need to look over the index page, again and again, every time. After finding the matching index you can efficiently jump to that chapter by skipping the rest.&lt;/p&gt;

&lt;p&gt;But then, in addition to actual 1000 pages, you will need another ~10 pages to show the indices, so totally 1010 pages.&lt;/p&gt;

&lt;p&gt;In the case of a database, the book index could be a table with the entry and page number as columns with some other metadata columns (for example, whether it is a child entry of another entry) and an ID primary key. But the entry and page number can be stored by themselves in an index. And since there will only be one unique entry in a book index, that can be used as the sorting column of the index as well.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/questions/1108/how-does-database-indexing-work"&gt;https://stackoverflow.com/questions/1108/how-does-database-indexing-work&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Most of the time, when people read about a topic, some of it tends to stick in their heads, so at that next Triplebyte test in four months time (which you hopefully are not taking at night!), you'll at least have a cursory idea of what database indexes are.&lt;/p&gt;

&lt;p&gt;Cover image by @Zozulinskyi via &lt;a href="https://www.twenty20.com/photos/19f9cccb-0cf3-45c5-af4b-977e22bc4c4f/?utm_t20_channel=bl"&gt;Twenty20&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>healthydebate</category>
    </item>
    <item>
      <title>Who's responsible for securing software?</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 26 Jul 2021 18:34:25 +0000</pubDate>
      <link>https://dev.to/zenulabidin/who-s-responsible-for-securing-software-3bi7</link>
      <guid>https://dev.to/zenulabidin/who-s-responsible-for-securing-software-3bi7</guid>
      <description>&lt;p&gt;A &lt;a href="https://www.venafi.com/resource/more-solarwinds-style-attacks-whitepaper"&gt;Venify report&lt;/a&gt; showed that the number of companies where DevOps is responsible for the security and the number who assign this to their Infosec department is almost evenly split. But should there really be this ambiguity regarding the responsibility of software security?&lt;/p&gt;

&lt;p&gt;When you look at the situation on paper, you might say that Information Security should find holes in the apps because they are normally penetration testing the company's running software anyway. But equally compelling is to claim that because DevOps knows how the software works and is likely one of the few units with access to the codebase, they should be at work making sure hackers cannot exploit the software.&lt;/p&gt;

&lt;p&gt;From this perspective, it seems that both of these views are right. DevOps should patch their programs - and make sure there are none of those pesky off-by-one errors - while Infosec has the knowledge necessary to send a running program off the rails.&lt;/p&gt;

&lt;p&gt;So for you and me, it seems obvious to us what the roles of those two departments should be. But what about who takes responsibility when a cyberattack happens?&lt;/p&gt;

&lt;p&gt;I'm not really the one posing this question. Executives often assign this taking-in-charge to either DevOps or Infosec, provided that both exist. We don't see most businesses sharing collective blame when they are hacked, &lt;a href="https://www.theverge.com/2017/10/3/16410806/equifax-ceo-blame-breach-patch-congress-testimony"&gt;right?&lt;/a&gt; So why don't they just make one department responsible for protecting the company from breaches?&lt;/p&gt;

&lt;p&gt;That would be a poor approach to the problem because merely pentesting the program for vulnerabilities ignores the fact that hackers can try a completely new attack vector to enter the organization. And while DevOps can guard against basic flaws such as null dereference, they don't have the time that Infosec has to run different tests to catch new vulnerabilities continuously.&lt;/p&gt;

&lt;p&gt;I don't believe that incident response should be a blame game and that all departments which play a part in the application interacting process should take responsibility to protect the software they use at their company and write, not only for their own company but for clients that also use the software in their products as well.&lt;/p&gt;

&lt;p&gt;This post was originally published on &lt;a href="https://notatether.com/code-life/whos-responsible-for-securing-software/"&gt;NotATether.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cover Image by &lt;a href="https://elements.envato.com/user/maxxyustas"&gt;maxxyustas&lt;/a&gt; from &lt;a href="https://elements.envato.com/computer-security-or-safety-concept-laptop-keyboar-PQ7RZZ5"&gt;Envato Elements&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
    </item>
    <item>
      <title>Pro Tips For Designing Robust React Components</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 19 Jul 2021 06:51:43 +0000</pubDate>
      <link>https://dev.to/zenulabidin/pro-tips-for-designing-robust-react-components-2aii</link>
      <guid>https://dev.to/zenulabidin/pro-tips-for-designing-robust-react-components-2aii</guid>
      <description>&lt;p&gt;As you already know, React components are written as functions these days, not classes. Among other things, it allows us to dispense with binding methods and the this prop. But with both ways, you ultimately have to write a render method that returns a part of the DOM in the form of JSX.&lt;/p&gt;

&lt;p&gt;They return a part of the DOM and do not generate a completely new one because the DOM is quite expensive to update, so developers try to minimize the number of DOM updates as much as possible.&lt;/p&gt;

&lt;p&gt;Hence, most web developers reduce the number of components renders to a minimum to reduce the load on both the client's browser and the server.&lt;/p&gt;

&lt;p&gt;Another important requirement of React components is that they update their UI fairly quickly. This prevents users from unnecessarily waiting on the app frontend and improves user experience.&lt;/p&gt;

&lt;p&gt;Finally, it helps when your components are reusable. Not only do you avoid writing the same code twice, thus satisfying the DRY (Don't Repeat Yourself) principle, you can also be confident that each instance of your reusable, independent components will do a minimal number of re-renders.&lt;/p&gt;

&lt;p&gt;In this article, and in the next few articles in this series, I will share with you some tips to reduce the number of renders your web app makes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try to partition the app so that each component is independent of others
&lt;/h2&gt;

&lt;p&gt;The reason for this is, if your components are interdependent, then each state update in one component will likely require a state update in the other component. This causes a re-render, so you end up rendering multiple times when you do a higher-level component update. Ideally, you want to update components once per high-level update, but of course, this may not always be possible.&lt;/p&gt;

&lt;p&gt;It would help if you tried to make each component partitioned in such a way that represents the UI layout of your app. For example, most apps have a header bar with buttons and links on it. So you should contain your button components in that location inside a header component.&lt;/p&gt;

&lt;p&gt;Each component you create adds complexity to the whole application. You have to make sure the parameters are correct, and the returned JSX is what you expected, and, in the case of arrow or lambda functions, that they are defined in an order such that a function does not call another such arrow or lambda function above it in the file.&lt;/p&gt;

&lt;p&gt;Try to make the nesting level of components as flat as possible. Although the way React updates the DOM ensures that nested components are not re-rendered if they have not been modified in a parent component, the advantage of making the component tree flat is that it makes it easier for you to debug each component by itself.&lt;/p&gt;

&lt;h3&gt;
  
  
  When to use prop destructuring
&lt;/h3&gt;

&lt;p&gt;Prop destructuring in methods can greatly cut down the length of your prop variable names - if done properly. For one thing, it is not recommended to destructure multiple layers of props simultaneously (nested destructuring) because you cannot validate the data in the intermediate-level props, so that is a source for semantic errors.&lt;/p&gt;

&lt;p&gt;It is not uncommon for components to have a few dozen props, so just the spelling of those props by itself will get messy when you write your functional component.&lt;/p&gt;

&lt;p&gt;You should destructre your props, one level at a time, when there are a small number of them like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Credits: &lt;a href="https://javascript.plainenglish.io/destructure-react-props-with-es6-object-destructuring-for-cleaner-code-3984453e484d"&gt;https://javascript.plainenglish.io/destructure-react-props-with-es6-object-destructuring-for-cleaner-code-3984453e484d&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So that you avoid writing functions that continuously reference &lt;code&gt;props&lt;/code&gt; like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Credits: &lt;a href="https://javascript.plainenglish.io/destructure-react-props-with-es6-object-destructuring-for-cleaner-code-3984453e484d"&gt;https://javascript.plainenglish.io/destructure-react-props-with-es6-object-destructuring-for-cleaner-code-3984453e484d&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Using another component as an example, we can do two different destructuring assignments to drill down the props, doing the equivalent of nested destructuring:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Credits: &lt;a href="https://stackoverflow.com/questions/60589914/destructuring-props-in-react"&gt;https://stackoverflow.com/questions/60589914/destructuring-props-in-react&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In addition to that, the spread operator fits nicely on the right side of the assignment involving a destructured variables.&lt;/p&gt;




&lt;p&gt;That's all for today folks. Stay tuned for next week's post where I write about pro tips for managing component state. Also, let me know in the comments below if you have any questions.&lt;/p&gt;

&lt;p&gt;Cover image by &lt;a href="https://unsplash.com/@les_photos_de_raph?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Raphaël Biscaldi&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/atoms?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Using Babel to write cross-browser modern ECMAScript</title>
      <dc:creator>Ali Sherief</dc:creator>
      <pubDate>Mon, 12 Jul 2021 14:16:30 +0000</pubDate>
      <link>https://dev.to/zenulabidin/using-babel-to-write-cross-browser-modern-ecmascript-3bm7</link>
      <guid>https://dev.to/zenulabidin/using-babel-to-write-cross-browser-modern-ecmascript-3bm7</guid>
      <description>&lt;p&gt;This is going to be a short write-up to demonstrate how Babel can make your modern JS more portable.&lt;/p&gt;

&lt;p&gt;Here's a familiar situation you might relate to: You're a Javascript developer who wants to use ECMAscript 2015 features in your code, but you can't because you either a) have to support Internet Explorer or b) have to support mobile browsers. And believe it or not, with all the mobile-first craze, that's a very common concern!&lt;/p&gt;

&lt;p&gt;So you're probably scratching your head thinking: "Well, how will I ever write ECMAscript 2015 like this?" Enter Babel.&lt;/p&gt;

&lt;p&gt;Babel is an open-source JSX to JS compiler. So what it does is that it takes your element-wise JSX markup and converts it to JS that'll work on a particular browser. And what happens is you can insert your ECMAScript 2015 code inside the JSX and that will also get converted using polyfills for older browsers, and this allows you to utilize newer features that would otherwise result in a syntax error on some browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation and Running
&lt;/h2&gt;

&lt;p&gt;Babel actually consists of a collection of packages. The library itself is located under babel-core, while the commands are contained in babel-cli and extensions to babel start with &lt;code&gt;babel-plugin-&lt;/code&gt;. You usually want to install only &lt;code&gt;babel-cli&lt;/code&gt; and this will automatically pull &lt;code&gt;babel-core&lt;/code&gt;, and only install one of the &lt;code&gt;babel-plugin-&lt;/code&gt; packages if you need that particular functionality.&lt;/p&gt;

&lt;p&gt;Since it is a NodeJS package, you'll usually want to install it locally, not globally. This can be done with &lt;code&gt;npm install babel-cli&lt;/code&gt;. You also need to install the &lt;code&gt;babel-preset-es2015&lt;/code&gt; package as well because, without it, Babel will just spit out the input files onto the console. Then you can call Babel like this: &lt;code&gt;babel src --preset es2015 --out-dir dir&lt;/code&gt;, where src is simply your root directory of source code, and "dir" is the folder where our files will be mirrored in but with the transpiled code, so that it's not sent to the console.&lt;/p&gt;

&lt;p&gt;There are many other flags that can be passed to Babel such as -s, for source maps. Source maps are special files that assist in debugging Babel-compiled Javascript. Another useful flag is -w which means "watch the current folder for any changes in the files and automatically compile them". It's an integral part of making webapps automatically load after a code update. All of these settings, including presets, can be placed in a .babelrc file so that you don't have to spell them out on each run. See &lt;a href="https://babeljs.io/docs/en/configuration#babelrcjson"&gt;this page&lt;/a&gt; for details.&lt;/p&gt;




&lt;p&gt;Also, by using libraries such as &lt;a href="https://www.npmjs.com/package/ui-logger-dom"&gt;ui-logger-dom&lt;/a&gt; and services like &lt;a href="https://www.browserstack.com/"&gt;BrowserStack&lt;/a&gt;, you can emulate any browser online to test your app on, and the console errors will be printed in the main (DOM) window instead of in the respective browser's console, which may be difficult to access.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>babel</category>
    </item>
  </channel>
</rss>
