<?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>Forem: Nukala Suraj</title>
    <description>The latest articles on Forem by Nukala Suraj (@lucidmach).</description>
    <link>https://forem.com/lucidmach</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%2F514809%2F16218d85-292b-47cf-b68a-73318b47ab70.jpg</url>
      <title>Forem: Nukala Suraj</title>
      <link>https://forem.com/lucidmach</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lucidmach"/>
    <language>en</language>
    <item>
      <title>Overcoming my DoomScrolling Addiction [Reels and Shorts]</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Sat, 27 Jan 2024 12:30:19 +0000</pubDate>
      <link>https://forem.com/lucidmach/overcoming-my-doomscrolling-addiction-reels-and-shorts-4jfn</link>
      <guid>https://forem.com/lucidmach/overcoming-my-doomscrolling-addiction-reels-and-shorts-4jfn</guid>
      <description>&lt;p&gt;consider this...&lt;br&gt;
you're working on a project that you've been pretty excited about for a while &lt;/p&gt;

&lt;p&gt;now... &lt;br&gt;
you are someone who keeps your phone on &lt;strong&gt;battery saver/DND mode&lt;/strong&gt; when you're working but you forgot to this time...&lt;/p&gt;

&lt;p&gt;and you get a notification on your phone&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mI6Jgf89--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://static1.srcdn.com/wordpress/wp-content/uploads/2020/07/Instagram-notification.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mI6Jgf89--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://static1.srcdn.com/wordpress/wp-content/uploads/2020/07/Instagram-notification.jpg" alt="img" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it's from a childhood friend of yours, someone who you haven't had a conversation with for a while now&lt;/p&gt;

&lt;p&gt;you reply to them and also &lt;strong&gt;habitually&lt;/strong&gt; click on the "reels" icon&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jw334q-V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.vlipsy.com/vlips/K4QjsNmc/preview-small.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jw334q-V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.vlipsy.com/vlips/K4QjsNmc/preview-small.jpg" alt="5 mins" width="256" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;BOOOM 180 minutes pass by and you remember you had something you wanted to work on&lt;/p&gt;
&lt;h2&gt;
  
  
  You're not alone
&lt;/h2&gt;

&lt;p&gt;I'm someone whose tried everything out there that didn't work to prevent this from happening again ranging from:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;uninstalling insta [only to later eventually install it]&lt;/li&gt;
&lt;li&gt;increase my willpower [failed miserably]&lt;/li&gt;
&lt;li&gt;shifting to the web version [but needing to install it everytime I want to post something on stories]&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;all these attempts made me think deep on why this was happening and the answer was... the existence of this stupid little icon&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AxYIE1aV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/74430503/194645762-add49df5-1bc9-4a04-801f-2b32bcb79df3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AxYIE1aV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/74430503/194645762-add49df5-1bc9-4a04-801f-2b32bcb79df3.png" alt="reels" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Removing the Problem
&lt;/h2&gt;

&lt;p&gt;I initially tried to see if I could make a mod APK where the whole reels section wouldn't be there but &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_XvTxZXw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://media1.tenor.com/m/BiiTsQ_0j7AAAAAC/mendokusai-what-a-drag.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_XvTxZXw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://media1.tenor.com/m/BiiTsQ_0j7AAAAAC/mendokusai-what-a-drag.gif" alt="drag" width="498" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and then I remembered how adblockers work... they identify ads in a website and not render them... so what if I could configure an adblocker to treat the icon as an ad&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P7t8mudI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://image.spreadshirtmedia.net/image-server/v1/compositions/T6A1PA5835PT17X30Y120D157209553W24979H5975/views/1%2Cwidth%3D550%2Cheight%3D550%2CappearanceId%3D1%2CbackgroundColor%3DFFFFFF%2CnoPt%3Dtrue/shruggie-emoji-mens-t-shirt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P7t8mudI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://image.spreadshirtmedia.net/image-server/v1/compositions/T6A1PA5835PT17X30Y120D157209553W24979H5975/views/1%2Cwidth%3D550%2Cheight%3D550%2CappearanceId%3D1%2CbackgroundColor%3DFFFFFF%2CnoPt%3Dtrue/shruggie-emoji-mens-t-shirt.jpg" alt="shrugiee" width="550" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;after surfing reddit for less than 3 minutes [at least in my head]... I found a someone who configured their ublock origin [the best adblocker] to treat youtube's shorts icon as an &lt;strong&gt;ad&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementing a Fix
&lt;/h2&gt;

&lt;p&gt;I am a long term user of brave, and I knew that brave's inbuilt adblocker uses a lot of similar components of ublock origin... &lt;/p&gt;

&lt;p&gt;so I went ahead to &lt;code&gt;brave://adblock&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp93wrjvhole7m98l9f0f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp93wrjvhole7m98l9f0f.jpg" alt="Image description" width="604" height="1280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and copy-pasted the following into custom filters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;! Hide Reels Icon Desktop
instagram.com##a[href="/reels/"]:upward(3)

! Hide Reels Icon Mobile
instagram.com##a[href="/reels/"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;my instagram through brave didn't have the reels icon&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pBIjr0gm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgflip.com/3wp5du.jpg%3Fa473688" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pBIjr0gm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgflip.com/3wp5du.jpg%3Fa473688" alt="gta" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;for a filter list to completely remove shorts copy-paste &amp;gt; this &lt;a href="https://github.com/LucidMach/brave-for-productivity"&gt;list&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>productivity</category>
      <category>socialmedia</category>
      <category>career</category>
    </item>
    <item>
      <title>Appreciating the "Learning Problem" - Why AI will never replace your job</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Thu, 28 Dec 2023 15:00:31 +0000</pubDate>
      <link>https://forem.com/lucidmach/appreciating-the-learning-problem-why-ai-will-never-replace-your-job-b68</link>
      <guid>https://forem.com/lucidmach/appreciating-the-learning-problem-why-ai-will-never-replace-your-job-b68</guid>
      <description>&lt;p&gt;so... let's play a game !!!&lt;/p&gt;

&lt;p&gt;i'll show you a series of patterns, and each pattern maps to a value of either 0 or 1&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcr89knc7gt2ybm0dn2vq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcr89knc7gt2ybm0dn2vq.png" alt="a game of puzzles"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;now consider this pattern, which number would this pattern map to?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0tu4zubdu1dxnehikxq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0tu4zubdu1dxnehikxq.png" alt="a question from the puzzles"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;if you said 0 you're probabily right&lt;/p&gt;

&lt;p&gt;if you said 1 you're also probabily right&lt;/p&gt;

&lt;p&gt;¯\_(ツ)_/¯&lt;/p&gt;

&lt;p&gt;the point here is that whatever your guess was...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;you had no idea what each of the tiles represented&lt;/li&gt;
&lt;li&gt;you had no idea what the co-relation between the tiles was&lt;/li&gt;
&lt;li&gt;you had no idea what 0 or 1 represents&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;just like AI and this guy here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F2ji8hx.jpg%3Fa473208" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F2ji8hx.jpg%3Fa473208" alt="meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;he has 0 understanding of what the puzzle means and what his guess means, but he made the correct guess&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Learning Problem
&lt;/h2&gt;

&lt;p&gt;the game we just played right now, is presicely what every &lt;strong&gt;ML/DL/RL/AI&lt;/strong&gt; algorithm does&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;take data that has been cleaned/processed (into a puzzle)&lt;/li&gt;
&lt;li&gt;find a pattern in the data&lt;/li&gt;
&lt;li&gt;use the pattern on new data (it has never seen before)&lt;/li&gt;
&lt;li&gt;hope it gets appriciated&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;but keep in mind that not every problem can be solved this way&lt;/p&gt;

&lt;p&gt;because...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;not every problem has (enough) data on it&lt;/li&gt;
&lt;li&gt;not every data has a pattern in it&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;some of them also/already have a (not so) simple mathematical answer to them, you don't need rely to finding patterns&lt;/p&gt;

&lt;p&gt;but for the rest, they can probabily (maybe not efficiently) be solved by having &lt;strong&gt;a computer find a pattern&lt;/strong&gt; AKA &lt;strong&gt;learning from data&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does a Computer Learn from Data
&lt;/h2&gt;

&lt;p&gt;short answer, you solve the learning problem 😝&lt;/p&gt;

&lt;p&gt;long answer to solve any &lt;strong&gt;learning problem&lt;/strong&gt; (ML, DL, RL)👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4plogikgepldv3meton8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4plogikgepldv3meton8.png" alt="the learning process"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;unknown solution:&lt;/strong&gt; think of this the true pattern/source of all the data we have&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;training data:&lt;/strong&gt; data that we have collected and processed so a computer can find a pattern&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;learning algorithm:&lt;/strong&gt; the actual algorithm that refines a model so the model learns from the data
&amp;gt; eg: Perceptron Learning Algorithm, Backpropagation Algorithm, etc&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;hypothesis set:&lt;/strong&gt; a set of all possible models that can find a solution
&amp;gt; eg: Perceptron, Neural Networks, etc&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;final hypothesis solution:&lt;/strong&gt; a pattern with the heighest accuracy&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;while this &lt;strong&gt;IS&lt;/strong&gt; the long answer to solve any &lt;strong&gt;learning problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;this long answer lacks details...&lt;br&gt;
the details which would be dealt with in the forthcoming blog articles&lt;/p&gt;

&lt;p&gt;originally posted on &lt;a href="https://ziro2mach.com/blog/appriciating-ml/" rel="noopener noreferrer"&gt;my personal blog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;thank you for reading&lt;br&gt;
do let me know what you think in the comment section&lt;br&gt;
✌️&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Intro to Data Pre-Processing using Quantified Emotion Recognition</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Wed, 14 Jun 2023 12:38:12 +0000</pubDate>
      <link>https://forem.com/lucidmach/intro-to-data-pre-processing-using-quantified-emotion-recognition-4bn4</link>
      <guid>https://forem.com/lucidmach/intro-to-data-pre-processing-using-quantified-emotion-recognition-4bn4</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This blog was originally posted on &lt;a href="https://ziro2mach.com"&gt;https://ziro2mach.com&lt;/a&gt; my learning "machine learning" blog&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;perhaps the only thing about machine learning that's more important than machine learning itself is &lt;strong&gt;data pre-processing&lt;/strong&gt; 🙃&lt;/p&gt;

&lt;p&gt;that's cuz as defined before machine learning is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;the ~science~ math of &lt;strong&gt;taking in real world info&lt;/strong&gt;, converting it into numbers and then ~finding~ learning a pattern out of it&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and &lt;strong&gt;info&lt;/strong&gt; out in the &lt;strong&gt;real world&lt;/strong&gt; brings along with it, ton of &lt;strong&gt;noise&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Example Data from the Real World
&lt;/h1&gt;

&lt;p&gt;as an advocate of learning by getting your hands dirty, here's an example&lt;/p&gt;

&lt;p&gt;there's something called the &lt;strong&gt;russel's circumplex&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K-ybleiU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://psu.pb.unizin.org/app/uploads/sites/251/2020/12/Screen-Shot-2021-02-03-at-1.41.51-PM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K-ybleiU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://psu.pb.unizin.org/app/uploads/sites/251/2020/12/Screen-Shot-2021-02-03-at-1.41.51-PM.png" alt="alt text" width="800" height="629"&gt;&lt;/a&gt;&lt;br&gt;
something that helps &lt;strong&gt;quantify emotions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;cuz ML algorithms learn &lt;strong&gt;best&lt;/strong&gt; when the data they work with is &lt;strong&gt;continuous numbers&lt;/strong&gt; instead of traditional encoded classification data like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tfQMgoE4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/class-emotion.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tfQMgoE4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/class-emotion.png" alt="" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;while the &lt;strong&gt;class-ified data&lt;/strong&gt; does represent numbers, the numberical value of a class &lt;strong&gt;doesn't always represent the intensity of&lt;/strong&gt; an emotion, while &lt;em&gt;russel's model gives you an &lt;strong&gt;activation&lt;/strong&gt; and an &lt;strong&gt;pleseantness&lt;/strong&gt; value that are already intensities of an emotion&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Unclean Data
&lt;/h1&gt;

&lt;p&gt;let's say we find a dataset with paramenters we are looking for&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9JYe70ig--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/unclean.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9JYe70ig--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/unclean.png" alt="" width="800" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;here the column &lt;strong&gt;pic&lt;/strong&gt; represents an 3d array of red, green and blue pixel values of an image containing an emotion and the rest are pretty straight forward&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--74BdujBn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/image2layers.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--74BdujBn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/image2layers.png" alt="" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step - 1 : Splitting The Data
&lt;/h2&gt;

&lt;p&gt;the whole goal of training an ML model is so that we could us it to actively predict output on unseen data/situations. a simple way of doing that is&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qn5bbXjm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/splitting.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qn5bbXjm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/splitting.png" alt="" width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the remaining 20% can be used to value the performance of the model developed&lt;/p&gt;

&lt;h2&gt;
  
  
  Step - 2 : Dealing with Missing Data
&lt;/h2&gt;

&lt;p&gt;notice that there's some missing data in the age column,&lt;br&gt;
so there are 2 common ways of dealing with that missing data&lt;/p&gt;

&lt;h4&gt;
  
  
  1. deleting entire rows if a required column is missing
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x_BgHRq7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/delete.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x_BgHRq7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/delete.png" alt="" width="800" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;note: works great for super ultra large datasets but since &lt;strong&gt;more data = better&lt;/strong&gt;&lt;/em&gt;...&lt;/p&gt;

&lt;h4&gt;
  
  
  2. substituting the middle value of the column (depends on type of data)
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WGmExtz1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/middle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WGmExtz1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/middle.png" alt="" width="800" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step - 3 : Dealing with Class Data
&lt;/h2&gt;

&lt;p&gt;many a times, the data in datasets is class data and while encoded class data might not always accurately represent the intensity of a parameter, something is better than nothing&lt;/p&gt;

&lt;p&gt;there are 2 common ways of dealing with class data, lets take the gender column&lt;/p&gt;

&lt;h4&gt;
  
  
  1. one hot encoding
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i5X5Sh0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/one-hot-encoding.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i5X5Sh0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/one-hot-encoding.png" alt="" width="800" height="129"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;when &lt;strong&gt;one column&lt;/strong&gt; is split &lt;strong&gt;into number of class&lt;/strong&gt; columns, like &lt;em&gt;gender has 2 classes&lt;/em&gt;: male and female, so the &lt;em&gt;gender columns gets split into 2 columns: a male column and female column&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2. label encoding
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iye_0jsK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/label-encoding.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iye_0jsK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/label-encoding.png" alt="" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;for columns with binary classes, like true or false, male or female, yes or no, etc so that one of the class label is replaced with 0 and the other with 1&lt;/p&gt;

&lt;h2&gt;
  
  
  Step - 4 : Feature Scaling
&lt;/h2&gt;

&lt;p&gt;different columns usually represent different parameters, and not all paraneters have the same proportion. assuming a dataset of age and height, the age column has a range of 1 to 100, while the height column perhaps has a range of 100cm to 200cm&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;why is this important?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;when we plot these values without scaling em to the same range it would look like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tAMLC2cl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/unscaled.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tAMLC2cl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/unscaled.png" alt="" width="800" height="699"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and let's say we tried to find a line that best fit through the points it would look like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0ix1vtT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/line-unscaled.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0ix1vtT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/line-unscaled.png" alt="" width="800" height="699"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;however if we scaled the inputs to the same range, it would look like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kmEBdNWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/line-scaled.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kmEBdNWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/line-scaled.png" alt="" width="800" height="699"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;which even from a glance we can tell that the line better fits the model, i.e there is lesser error to predict for unseen data&lt;/p&gt;

&lt;p&gt;now feature scaling is commonly done using 2 methods&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; normalization&lt;/li&gt;
&lt;li&gt; standardization&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--otDog5JU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/norm-vs-stand.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--otDog5JU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/norm-vs-stand.png" alt="" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;where x is the current input we want to scale, here's an example of normalization on the dataset we were working on&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AWzTmAtc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/normalization.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AWzTmAtc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/normalization.png" alt="" width="800" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;this leaves us with a ready for training dataset&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WoCTlz1o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/clean-training.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WoCTlz1o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/clean-training.png" alt="" width="800" height="135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step - 5 : Dealing with the Testing Data
&lt;/h2&gt;

&lt;p&gt;we've done a lot of pre-processing on the training dataset, and testing data is going to look like the unclean training data&lt;/p&gt;

&lt;p&gt;so we've to remember to&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;replace missing data with the middle value of &lt;strong&gt;training data&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;encode class data to match the &lt;strong&gt;training data&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;feature scale using parameters of the &lt;strong&gt;training data&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;you get the point we've use the exact &lt;strong&gt;same operation tools&lt;/strong&gt; used on the &lt;strong&gt;training dataset&lt;/strong&gt; for the operation we would be doing on the &lt;strong&gt;testing dataset&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;yuppp data people shouldn't become doctors 😝&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Db931TW8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/clean-testing.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Db931TW8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ziro2mach.com/data-pre-processing/clean-testing.png" alt="" width="800" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and with that we have testing data that is ready to be taken for a ride in our ML model&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How I Built a Meme Bot for Instagram</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Sat, 16 Jul 2022 18:44:43 +0000</pubDate>
      <link>https://forem.com/lucidmach/how-i-built-a-meme-bot-for-instagram-28l1</link>
      <guid>https://forem.com/lucidmach/how-i-built-a-meme-bot-for-instagram-28l1</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;build&lt;/strong&gt; your own instagram bot from &lt;strong&gt;scratch&lt;/strong&gt; (or) &lt;strong&gt;set&lt;/strong&gt; one &lt;strong&gt;up&lt;/strong&gt; in like &lt;strong&gt;10s&lt;/strong&gt; for free&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;a brief overview of this blog post:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Wr-6jx4DILA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine you have a &lt;strong&gt;cool meme page&lt;/strong&gt; on &lt;em&gt;instagram&lt;/em&gt; with about a &lt;strong&gt;1M+ followers&lt;/strong&gt; and the best part - &lt;strong&gt;you never&lt;/strong&gt; really need to &lt;strong&gt;interfere&lt;/strong&gt; with it...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feefd4ew38ryyrfk6m5nk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feefd4ew38ryyrfk6m5nk.png" alt="for real"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;not kidding... but well &lt;em&gt;there sure is a &lt;strong&gt;catch&lt;/strong&gt; here&lt;/em&gt; cuz otherwise 1M+ followers would not longer be a feat anymore:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfqpvt01di70r4pnze17.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfqpvt01di70r4pnze17.png" alt="maji ka yo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;any page&lt;/strong&gt; on instagram/social media in general has got &lt;strong&gt;2 aspects&lt;/strong&gt; to it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;content creation&lt;/strong&gt; 🎨&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;marketing&lt;/strong&gt; 📢&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;this &lt;strong&gt;bot&lt;/strong&gt; system has got your back &lt;strong&gt;for content creation&lt;/strong&gt; and &lt;strong&gt;you&lt;/strong&gt;'ve gotta take care of the &lt;strong&gt;marketing&lt;/strong&gt; and making sure the page grows...&lt;/p&gt;

&lt;p&gt;here's an example of a successfully automated meme page w/ poor marketing: &lt;a href="https://www.instagram.com/taewonsu/" rel="noopener noreferrer"&gt;@taewonsu&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and I've really gotta mention &lt;strong&gt;I absolutely suck at marketing&lt;/strong&gt; and hence...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8pmo7xyan1vsfc6gx2vd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8pmo7xyan1vsfc6gx2vd.png" alt="treasure"&gt;&lt;/a&gt;&lt;br&gt;
and yea obviously &lt;a href="https://www.instagram.com/taewonsu/" rel="noopener noreferrer"&gt;@taewonsu&lt;/a&gt; is my automated instagram meme page&lt;/p&gt;


&lt;h2&gt;
  
  
  So What Exactly Does The Bot Do
&lt;/h2&gt;

&lt;p&gt;doesn't matter if you're a human or a bot(AI), &lt;strong&gt;creating memes&lt;/strong&gt; people ❤️ is &lt;strong&gt;tough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;but... &lt;strong&gt;there exists reddit&lt;/strong&gt;, the front page of the internet&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0yradeckntcd0fzbsu1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0yradeckntcd0fzbsu1b.png" alt="reddit"&gt;&lt;/a&gt;&lt;br&gt;
this is where &lt;strong&gt;memes first hit the internet&lt;/strong&gt; and then they &lt;em&gt;trickle down to instagram&lt;/em&gt;/facebook/twitter/discord&lt;/p&gt;

&lt;p&gt;and most &lt;strong&gt;people&lt;/strong&gt; shamelessly just &lt;strong&gt;steal memes&lt;/strong&gt; from &lt;strong&gt;reddit&lt;/strong&gt; (i.e. they do not credit the original creator of the meme)&lt;/p&gt;

&lt;p&gt;that however that doesn't apply to a &lt;strong&gt;bot&lt;/strong&gt; so... it'll &lt;strong&gt;will credit the original&lt;/strong&gt; &lt;code&gt;u/creator&lt;/code&gt; of the meme and then just post the meme to our page&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn5ns03l6l9nje84nu60b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn5ns03l6l9nje84nu60b.png" alt="big brain time"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Creating Your Own Bot
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favmp3hvp3imkifado5b4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favmp3hvp3imkifado5b4.png" alt="Red Pill Blue Pill"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is your last chance, after this there's no turning back. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;you take the &lt;strong&gt;blue pill...&lt;/strong&gt; I give you the easy way... &lt;strong&gt;setting up a meme bot&lt;/strong&gt; from my source code. &lt;/li&gt;
&lt;li&gt;you take the &lt;strong&gt;red pill...&lt;/strong&gt; I show you how the bot works and how you can build your &lt;strong&gt;bot from scratch&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Blue Pill
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Q9vDaU8piKc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;clone&lt;/strong&gt; this repository off &lt;a href="https://github.com/LucidMach/taewonsu" rel="noopener noreferrer"&gt;github&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;create an instance on &lt;strong&gt;heroku&lt;/strong&gt; (or) whatever&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;configure&lt;/strong&gt; the environment &lt;strong&gt;variables&lt;/strong&gt; for your bot&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GG&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Red Pill
&lt;/h2&gt;

&lt;p&gt;the bot does 3 thing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;scrape&lt;/strong&gt; for &lt;strong&gt;top memes&lt;/strong&gt; of the &lt;strong&gt;day&lt;/strong&gt; in the specified &lt;code&gt;r/subreddit&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;check&lt;/strong&gt; if a meme has been previously &lt;strong&gt;posted&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;post&lt;/strong&gt; the &lt;strong&gt;unique&lt;/strong&gt; memes to &lt;code&gt;instagram&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Scraping
&lt;/h3&gt;

&lt;p&gt;working with reddit's API has been an absolute pleasure&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fivp6qn9a9lfadei6bmyt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fivp6qn9a9lfadei6bmyt.png" alt="mua"&gt;&lt;/a&gt;&lt;br&gt;
let's say the URL for top content in a subreddit say &lt;code&gt;r/animemes&lt;/code&gt; is &lt;code&gt;https://www.reddit.com/r/Animemes/top/&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;then the endpoint for the API would be &lt;code&gt;https://www.reddit.com/r/Animemes/top.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;so fetching the top 3 memes of the day would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// fetching new memes from reddit
const res = await axios.get(`https://www.reddit.com/r/${subreddit}/top.json?limit=${top_x ? top_x : 3}`);
animemes = res.data.data.children;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Unique
&lt;/h3&gt;

&lt;p&gt;when we're posting a bunch of meme's per day it'll be pretty likely that we may re-post something&lt;/p&gt;

&lt;p&gt;so the bot maintains an hashmap, where the key is the &lt;code&gt;id&lt;/code&gt; of the meme in reddit's database and the value is the meme data&lt;/p&gt;

&lt;p&gt;when ever it gets a new meme, it quickly checks if the id exists in the hashmap, if it doesn't the bot posts the meme and then adds the meme to the hashmap&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// fetching past memes
const raw_pa = fs.readFileSync(posted_animemes_location);
const posted_animemes: animeme_in_json = JSON.parse(raw_pa.toString());

// cross-referencing a new meme
if (posted_animemes[animeme.data.id]) {
  console.log("seen this!");
  return null;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Posting
&lt;/h3&gt;

&lt;p&gt;while building the bot, I was pleasantly surprised at how less bug I was running into and I'm not gonna lie it did feal really good... and then instagram API happened&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp94y4mkpk229yjvmfi5o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp94y4mkpk229yjvmfi5o.png" alt="regret"&gt;&lt;/a&gt;&lt;br&gt;
interacting with instagram's API was an absolute pain in the ass... spent like 3 days and I still couldn't properly set up the access tokens required&lt;/p&gt;

&lt;p&gt;luckily I found a god send &lt;a href="https://www.npmjs.com/package/instagram-private-api" rel="noopener noreferrer"&gt;instagram-private-api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;instagram-private-api is basically a &lt;strong&gt;typescript&lt;/strong&gt; 🤩 wrapper over instagram's private API [the endpoints you'd find if you inspected the network panel of your browser's dev tools]&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx0be9f4x5r9xqhinnjr8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx0be9f4x5r9xqhinnjr8.png" alt="network"&gt;&lt;/a&gt;&lt;br&gt;
instagram-private-api greatly sped up and made the developer experience just way more greater and I was able to implement the auto post to insta reletively quickly&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// logging into instagram
try {
  const auth = await ig.account.login(ig_uname, ig_pass);
  if (!auth.pk) return "LOGIN FAILED";
} catch (error) {
  console.log(error);
  return "LOGIN BLOCKED";
}

// uploading an meme
try {
  const publishResult = await ig.publish.photo({
    file: imageBuffer,
    caption: `credits: u/${animeme_to_post.author}\n${animeme_to_post.title} ¯\\_(ツ)_/¯\n.\n.\n.\n.\n.\n#${hashtags}`,
  });
} catch (error) {
  console.log("work on fixing that image size thing you sucker");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the best thing here is since we're basically using instagram-private-api, instagram can't really recognize us a bot&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fomqo1itugbw2ip30ozek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fomqo1itugbw2ip30ozek.png" alt="mission accomplished"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;and that's how I built an automated instagram meme page from scratch&lt;/p&gt;

&lt;p&gt;If You ❤️ This Blog Post&lt;br&gt;
Be Sure To Drop a DM on &lt;a href="https://twitter.com/lucidmach" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;also here're all the links throughout the blog post&lt;br&gt;
&lt;strong&gt;og automated bot @taewonsu:&lt;/strong&gt; &lt;a href="https://www.instagram.com/taewonsu/" rel="noopener noreferrer"&gt;https://www.instagram.com/taewonsu/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;source code on github:&lt;/strong&gt; &lt;a href="https://github.com/LucidMach/taewonsu" rel="noopener noreferrer"&gt;https://github.com/LucidMach/taewonsu&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;my twitter:&lt;/strong&gt; &lt;a href="https://twitter.com/lucidmach" rel="noopener noreferrer"&gt;https://twitter.com/lucidmach&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;✌️,&lt;br&gt;
LucidMach&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>opensource</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>You've Gotta Check Out SnowPack...</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Sat, 01 Jan 2022 09:52:22 +0000</pubDate>
      <link>https://forem.com/lucidmach/youve-gotta-check-out-snowpack-15a3</link>
      <guid>https://forem.com/lucidmach/youve-gotta-check-out-snowpack-15a3</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;So like most 2020 developers I used to give 0 fucks about bundlers... &lt;/p&gt;

&lt;p&gt;I mean &lt;strong&gt;react/next/svelte takes care of it&lt;/strong&gt; for us right&lt;/p&gt;

&lt;p&gt;but then, I started doing this course called &lt;a href="https://threejs-journey.com/" rel="noopener noreferrer"&gt;threejs journey&lt;/a&gt; by &lt;a href="https://bruno-simon.com/" rel="noopener noreferrer"&gt;brunosimon&lt;/a&gt; in which bruno makes us understand why bundlers are important&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FFH_p4ihUUAEAXSQ%3Fformat%3Djpg%26name%3D900x900" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FFH_p4ihUUAEAXSQ%3Fformat%3Djpg%26name%3D900x900" alt="node_modules meme"&gt;&lt;/a&gt;&lt;br&gt;
TL;DR helps client import node_modules files that are stored on the server&lt;/p&gt;
&lt;h2&gt;
  
  
  WebPack
&lt;/h2&gt;

&lt;p&gt;The world's most popular javascript bundler "webpack" has a bunch of disadvantages&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is pretty &lt;strong&gt;complex&lt;/strong&gt;, for context and it took me 2 days to understand and be able to configure webpack on my own&lt;/li&gt;
&lt;li&gt; It is kinda really &lt;strong&gt;slow&lt;/strong&gt; cuz it rebuilds and rebundles the files for every change
&lt;em&gt;[especially if you want to use typescript]&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Here's Recordings of WebPack
&lt;/h3&gt;

&lt;p&gt;Time to Initial Load: &lt;strong&gt;35s&lt;/strong&gt;&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ZaX9vVwpEsA"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Time to Load Changes: &lt;strong&gt;20s&lt;/strong&gt;&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/zaSyyna3RTI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter Snowpack
&lt;/h2&gt;

&lt;p&gt;Snowpackjs has a fundamentally different approach to bundling... &lt;br&gt;
It builds each file and caches it for future use, while webpack rebuilds and rebundles every single time&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.snowpack.dev%2Fimg%2Fsnowpack-unbundled-example-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.snowpack.dev%2Fimg%2Fsnowpack-unbundled-example-3.png" alt="Help"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Bonus
&lt;/h3&gt;

&lt;p&gt;Snowpack is &lt;em&gt;&lt;strong&gt;super easy&lt;/strong&gt; to configure&lt;/em&gt;&lt;br&gt;
here's the config I used in the below test&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  mount: {
    src: { url: "/" },
    public: { url: "/", static: true },
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it mounts files in src, public dir to "/" (root directory of served content) &lt;/p&gt;

&lt;h3&gt;
  
  
  Here's Recordings of Snowpack
&lt;/h3&gt;

&lt;p&gt;Time to Initial Load: &lt;strong&gt;20s&lt;/strong&gt;&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/L7sIkfxBHbg"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Time to Load Changes: &lt;strong&gt;14ms&lt;/strong&gt; 😱&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FFH_vdR2UUAIDtNp%3Fformat%3Djpg%26name%3D900x900" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FFH_vdR2UUAIDtNp%3Fformat%3Djpg%26name%3D900x900" alt="screenshot"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Thanks
&lt;/h2&gt;

&lt;p&gt;if you ❤️ this blog post... I'd ❤️ to tell you that this is the blogified version of the following thread&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1477165287384305665-425" src="https://platform.twitter.com/embed/Tweet.html?id=1477165287384305665"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1477165287384305665-425');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1477165287384305665&amp;amp;theme=dark"
  }



&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>DAOs Can End World Poverty (Probabily)</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Thu, 11 Nov 2021 18:23:29 +0000</pubDate>
      <link>https://forem.com/lucidmach/daos-can-end-world-poverty-probabily-5e86</link>
      <guid>https://forem.com/lucidmach/daos-can-end-world-poverty-probabily-5e86</guid>
      <description>&lt;p&gt;By the end of this blog post, &lt;/p&gt;

&lt;p&gt;I'm pretty sure that you would be able to convince anyone that DAOs could potentially end world poverty&lt;/p&gt;

&lt;h2&gt;
  
  
  but first what are DAOs???
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;DAO&lt;/em&gt;&lt;/strong&gt; stands for Decentralized Autonomous Organizations&lt;/p&gt;

&lt;p&gt;and the best way to explain DAOs would be on elaborating the individual terms&lt;/p&gt;

&lt;h3&gt;
  
  
  Decentralized AO:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WYWZT-ti--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://encrypted-tbn0.gstatic.com/images%3Fq%3Dtbn:ANd9GcR-cS61y0ZoQiiEH7xk1u-KN0TRcqBGZoH_yPY34Zx3MZ2ZqQes1fL-JiL-2iuFHHPxyfo%26usqp%3DCAU" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WYWZT-ti--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://encrypted-tbn0.gstatic.com/images%3Fq%3Dtbn:ANd9GcR-cS61y0ZoQiiEH7xk1u-KN0TRcqBGZoH_yPY34Zx3MZ2ZqQes1fL-JiL-2iuFHHPxyfo%26usqp%3DCAU" alt="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR-cS61y0ZoQiiEH7xk1u-KN0TRcqBGZoH_yPY34Zx3MZ2ZqQes1fL-JiL-2iuFHHPxyfo&amp;amp;usqp=CAU" width="238" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You know how democracy is defined as &lt;em&gt;by the people, for the people, of the people&lt;/em&gt; but then it rarely does much about the people.&lt;/p&gt;

&lt;p&gt;We'd imagine on just listening to that definition that the people would make decisions and hence govern themselves... that my friend is a decentralized government i.e. there is no central authoritative, it's the locals/individuals that make the decisions&lt;/p&gt;

&lt;p&gt;Now here in DAOs, that is done using blockchain... you know that ledger system that every member of the network has access to and on verifying new transactions gets money(mining lol).&lt;/p&gt;

&lt;h3&gt;
  
  
  D Autonomous O:
&lt;/h3&gt;

&lt;p&gt;I don't know about you, but when I hear the term "Autonomous", I get a picture of Arnold Swazenblahblahger as the terminator.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8CCqvV4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.denofgeek.com/wp-content/uploads/2019/10/header_main_image_2.jpg%3Fresize%3D768%252C432" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8CCqvV4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.denofgeek.com/wp-content/uploads/2019/10/header_main_image_2.jpg%3Fresize%3D768%252C432" alt="https://www.denofgeek.com/wp-content/uploads/2019/10/header_main_image_2.jpg?resize=768%2C432" width="768" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This term means that something that is carried out without human intervention...&lt;/p&gt;

&lt;p&gt;and in DAOs that is done using &lt;strong&gt;smart contracts&lt;/strong&gt; basically just contracts that are recorded on a blockchain.&lt;/p&gt;

&lt;p&gt;You do know that a contract is essentially a paper that records a promise of payment upon completion of the job right&lt;/p&gt;

&lt;p&gt;So smart contracts can be made for pre-agreed upon terms &lt;/p&gt;

&lt;p&gt;eg) every time the company makes a sale... 5% of the profit go to that NGO we're supporting   &lt;/p&gt;

&lt;h3&gt;
  
  
  DA Organizations:
&lt;/h3&gt;

&lt;p&gt;we'll do I really have to break this term down lmao...&lt;/p&gt;

&lt;p&gt;basically any group of people doing anything... be it a business or a club or a charity &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZrdsLT-E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.insperity.com/wp-content/uploads/organization_structure1200x600.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZrdsLT-E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.insperity.com/wp-content/uploads/organization_structure1200x600.png" alt="https://www.insperity.com/wp-content/uploads/organization_structure1200x600.png" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  So how the actual f would DAOs end world poverty ffs
&lt;/h2&gt;

&lt;p&gt;lol If you could determine how DAOs could end world poverty just be reading that... you're probably Einstein level genius&lt;/p&gt;

&lt;p&gt;So let's say a hypothetical country "A" has a DAO based government.&lt;/p&gt;

&lt;p&gt;a government like any other organization requires income to function... &lt;/p&gt;

&lt;p&gt;how does a government earn money?&lt;/p&gt;

&lt;p&gt;through taxes of course&lt;/p&gt;

&lt;p&gt;let's say this government has adopted etherium/cardano/polygon/(any crypto that supports smart contracts)&lt;/p&gt;

&lt;p&gt;Every time a citizen in this country makes a purchase, he pays some sort of Goods and Service Tax.&lt;/p&gt;

&lt;p&gt;There could be a smart contract that says "whenever citizen makes a payment to a business, transfer 5% to military, 5% to the infrastructure fund, 5% to &lt;del&gt;bank account&lt;/del&gt; etherium addresses of people living below the poverty line"&lt;/p&gt;

&lt;p&gt;This need not be just on GST, or to the military/infrastructure/NPL fund. We could apply it to any tax paid inside the country and the money being transferred based on the proposed annual budget of the nation... all &lt;del&gt;automatically&lt;/del&gt; autonomously&lt;/p&gt;

&lt;p&gt;You get the point right...&lt;/p&gt;

&lt;p&gt;in a DAO based government &lt;/p&gt;

&lt;p&gt;the money goes directly to people who need money from people who have surplus&lt;/p&gt;

&lt;p&gt;instead of &lt;/p&gt;

&lt;p&gt;the money goes to the government, out of which some who knows and finally a negligible amount to the ones in need&lt;/p&gt;

&lt;h3&gt;
  
  
  But
&lt;/h3&gt;

&lt;p&gt;Ok, so you might ask me how would the DAO know that a person is actually BPL and not someone who no longer is BPL&lt;/p&gt;

&lt;p&gt;well, the entire transaction history of every citizen of the country is recorded on the blockchain... we could have another smart contract that adds/removes people from the BPL list based on the gross income every month&lt;/p&gt;

&lt;h2&gt;
  
  
  Fun Fact
&lt;/h2&gt;

&lt;p&gt;The above scenario is kinda implemented except it was implemented to help the refugees that flocked to the country of Ethiopia&lt;/p&gt;

&lt;p&gt;A company called Atala Prism developed a smart contract-based system in Ethiopia to fund the student refugee and the system was pretty much what we discussed in this blog post.&lt;/p&gt;

&lt;h3&gt;
  
  
  Link:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://forum.cardano.org/t/emergency-identification-and-financial-inclusion-for-refugees-and-disaster-victims-through-blockchain/60685"&gt;https://forum.cardano.org/t/emergency-identification-and-financial-inclusion-for-refugees-and-disaster-victims-through-blockchain/60685&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;DAOs are basically a collection of pre-agreed upon smart contracts that control the finances of an organization&lt;/li&gt;
&lt;li&gt;any organization that adopts a DAO approach can get rid of corruption&lt;/li&gt;
&lt;li&gt;the benefits of adapting DAO will make blockchain more mainstream&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Homework
&lt;/h2&gt;

&lt;p&gt;Try to see how a local business you know would be if it were a DAO. What would the smart contracts controlling the finances of the business look like?&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect???
&lt;/h2&gt;

&lt;p&gt;I'm pretty active on twitter and that's where you could reach out and we DM/PM talking about random tech stuff&lt;br&gt;
&lt;a href="https://twitter.com/lucidmach"&gt;@lucidmach&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React UI for Python Scripts using Node.JS</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Wed, 04 Aug 2021 18:40:54 +0000</pubDate>
      <link>https://forem.com/lucidmach/react-ui-for-python-scripts-on-node-js-1dfa</link>
      <guid>https://forem.com/lucidmach/react-ui-for-python-scripts-on-node-js-1dfa</guid>
      <description>&lt;p&gt;If you are familiar with &lt;strong&gt;node.js&lt;/strong&gt;, you know that it is &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ultra Fast ⚡&lt;/li&gt;
&lt;li&gt;Ultra Scalable ⚖️&lt;/li&gt;
&lt;li&gt;Ultra Powerful 💥&lt;/li&gt;
&lt;li&gt;Ultra Simple 😁&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;and &lt;strong&gt;python&lt;/strong&gt; has great &lt;strong&gt;scientific computing libraries&lt;/strong&gt; [NumPy,Pandas,etc] &lt;em&gt;that make it the go to choice for academics, data scientists, deep learning engineers, etc&lt;/em&gt;.&lt;/p&gt;




&lt;p&gt;Some time ago, I wanted to &lt;em&gt;explore &lt;strong&gt;computer vision&lt;/strong&gt;, something that I had been really fascinated&lt;/em&gt; for quite a while.&lt;/p&gt;

&lt;p&gt;So I started learning CV and wrote &lt;em&gt;a python script that would take an &lt;strong&gt;image&lt;/strong&gt; and &lt;strong&gt;remove color channels&lt;/strong&gt; to make it look like as if a &lt;strong&gt;color filter&lt;/strong&gt; had been applied to it&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It was &lt;strong&gt;super cool&lt;/strong&gt; and I wanted to make a fun little &lt;strong&gt;website/webUI&lt;/strong&gt; out of it so I could &lt;strong&gt;share&lt;/strong&gt; it to the rest of the &lt;strong&gt;world&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Being a self-taught &lt;em&gt;MERN Stack&lt;/em&gt; Developer, I started to research upon how one could &lt;em&gt;combine python and javascript&lt;/em&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;A Week or Two Later&lt;/em&gt;, I Did It.&lt;/p&gt;

&lt;p&gt;And this blog is a documentation of how I solved this challenge.&lt;/p&gt;

&lt;p&gt;I have also including here, the full code I used to deploy my application to &lt;strong&gt;Heroku&lt;/strong&gt;&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/i1QW52spBD4"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Live Deployment: &lt;a href="https://color-filter.netlify.app" rel="noopener noreferrer"&gt;https://color-filter.netlify.app&lt;/a&gt;&lt;br&gt;
Source Code: &lt;a href="https://github.com/LucidMach/ColorFilter" rel="noopener noreferrer"&gt;https://github.com/LucidMach/ColorFilter&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  How Does It Work
&lt;/h2&gt;

&lt;p&gt;The Projecct has 4 phases&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Webcam -&amp;gt; React -&amp;gt; NodeJS &lt;/li&gt;
&lt;li&gt;NodeJS Py Child Process&lt;/li&gt;
&lt;li&gt;Actual Python Program&lt;/li&gt;
&lt;li&gt;NodeJS -&amp;gt; React -&amp;gt; Canvas&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Phase 1: Webcam -&amp;gt; React -&amp;gt; NodeJS
&lt;/h2&gt;

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

&lt;p&gt;We begin by first extracting an image from the webcam, we can use plain HTML5's &lt;code&gt;navigator.getUserMedia API&lt;/code&gt; but there's an react package that simplifies the whole process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add react-webcam
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can use &lt;code&gt;getScreenshot({width: 1920, height: 1080})&lt;/code&gt; to take a &lt;strong&gt;1080p snapshot&lt;/strong&gt; of the user.&lt;/p&gt;

&lt;p&gt;🔗: &lt;a href="https://www.npmjs.com/package/react-webcam" rel="noopener noreferrer"&gt;React-WebCam Docs&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now that we have a snapshot (as a &lt;strong&gt;base64&lt;/strong&gt; string), we've to send it to the server&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Any &lt;strong&gt;browser&lt;/strong&gt; can &lt;strong&gt;only&lt;/strong&gt; run &lt;strong&gt;javascript&lt;/strong&gt; on the client, so we've to run &lt;strong&gt;python on the server&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;we make a post request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios.post(url, { image: imageSrc, color: selectedColor })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;I also send the selected color, as I need it for the application that I'm building  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;By default&lt;/strong&gt; the server(bodyParser middleware) &lt;strong&gt;limits&lt;/strong&gt; the size of data it can get(post) to &lt;strong&gt;1MB&lt;/strong&gt; and pictures are usually way big&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Unless you used an image optimizer like I did in a &lt;a href="https://github.com/LucidMach/Shrimkage" rel="noopener noreferrer"&gt;previous project&lt;/a&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's Push the Limits&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(bodyParser.json({ limit: "5mb" }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also we need to extract the image from the base64 string&lt;/p&gt;

&lt;p&gt;Example base64 PNG String&lt;br&gt;
&lt;code&gt;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKsAAADVCAMAAAAfHvCaAAAAGFBMVEVY&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Actual base64 Image&lt;br&gt;
&lt;code&gt;iVBORw0KGgoAAAANSUhEUgAAAKsAAADVCAMAAAAfHvCaAAAAGFBMVEVY&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const base64Image = req.body.image.split(";base64,").pop();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Phase 2: NodeJS Py Child Process
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0g69527yrxarpuz24uel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0g69527yrxarpuz24uel.png" alt="P2"&gt;&lt;/a&gt;&lt;br&gt;
Now that we have the image back on the server, we need to run the python script&lt;/p&gt;

&lt;p&gt;If you've ever &lt;em&gt;passed parameters(&lt;strong&gt;argv&lt;/strong&gt;) to a python script / built a CLI tool&lt;/em&gt;, what we're going to be doing is very similar&lt;/p&gt;

&lt;p&gt;Before that let's save the image temporarily cuz we can't pass images as argv(script parameter)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require("fs");

fs.writeFileSync("input/image.png", base64Image, { encoding: "base64" });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we spawn a python child process&lt;br&gt;
we do this my representing terminal commands to an array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { spawn } = require("child_process");

const py = spawn("python", ["color-filter.py", body.color]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every python script probabily sends data back to the terminal/console&lt;/p&gt;

&lt;p&gt;To read py console log, we create a callback function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var data2send

py.stdout.on("data", (data) =&amp;gt; {
    data2send = data.toString();
});

console.log(data2send);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Phase 3: Actual Python Program
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fogbqfc1nxltahppnlmn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fogbqfc1nxltahppnlmn9.png" alt="P3"&gt;&lt;/a&gt;&lt;br&gt;
The python script gets executed, in my case it's a numpy script that conditionally removes color channels&lt;/p&gt;

&lt;p&gt;If you're interested you can check out the &lt;a href="https://github.com/LucidMach/ColorFilter" rel="noopener noreferrer"&gt;source-code&lt;/a&gt; on github&lt;/p&gt;
&lt;h2&gt;
  
  
  Phase 4: NodeJS -&amp;gt; React -&amp;gt; Canvas
&lt;/h2&gt;

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

&lt;p&gt;now when the py child process terminates we need to encode the image back to base64 and send back a response&lt;/p&gt;

&lt;p&gt;we can do that by latching a callback to when the child process ends&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;py.on("close", () =&amp;gt; {
  // Adding Heading and converting image to base64
  const image = `data:image/png;base64,${fs.readFileSync("output/image.png", {
    encoding: "base64",
  })}`;

  // sending image to client
    res.json({ image });
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  BONUS PHASE: Heroku Deployment
&lt;/h2&gt;

&lt;p&gt;This most important part of any project&lt;/p&gt;

&lt;p&gt;It no longer only "works on your machine"&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.devrant.com%2Fdevrant%2Frant%2Fr_54040_zGEQB.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.devrant.com%2Fdevrant%2Frant%2Fr_54040_zGEQB.jpg" alt="wmm"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The process is basically the exact same as you deploy vanilla node apps + config for python childprocess&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Standard Deploy Node to Heroku&lt;br&gt;
&lt;a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs" rel="noopener noreferrer"&gt;Heroku Node App Deployment Docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add Python Packages&lt;br&gt;
In the JavaScript World we have a &lt;code&gt;package.json&lt;/code&gt; which tells every node instance all the packages required to run&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We make something similar for python called &lt;code&gt;requirements.txt&lt;/code&gt; to replicate that behavior.&lt;/p&gt;

&lt;p&gt;It would look sorta like a &lt;code&gt;.gitignore&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// requirements.txt

numpy
cv2
matplotlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when Heroku notices the &lt;code&gt;requirements.txt&lt;/code&gt; file it runs &lt;code&gt;pip install -r requirements.txt&lt;/code&gt;, hence installing all the required packages&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Configure Buildpacks
&lt;a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs" rel="noopener noreferrer"&gt;Heroku Node App Deployment Docs&lt;/a&gt;
Here's the TL:DR; version
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// terminal


// This command will set your default buildpack to Node.js
heroku buildpacks:set heroku/nodejs

// This command will set it up so that the Heroku Python buildpack will run first
heroku buildpacks:add --index 1 heroku/python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If You ❤️ This Blog Post&lt;br&gt;
Be Sure To Drop a DM on &lt;a href="https://twitter.com/lucidmach" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;✌️,&lt;br&gt;
LucidMach&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>python</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The 20% Optimization That Improves 80% Web Performance</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Mon, 26 Jul 2021 14:49:27 +0000</pubDate>
      <link>https://forem.com/lucidmach/how-to-make-websites-load-faster-524i</link>
      <guid>https://forem.com/lucidmach/how-to-make-websites-load-faster-524i</guid>
      <description>&lt;p&gt;In today's ultra fast paced world,&lt;br&gt;
3 Seconds of a not-yet-loaded-website is more than enough for the user to click that close button&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq7q0dmfz7u6tl0o6xu7i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq7q0dmfz7u6tl0o6xu7i.png" alt="3 secs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is especially important if you're trying to build a web based startup.&lt;br&gt;
Having an optimized website could lead to significantly more revenue&lt;/p&gt;
&lt;h2&gt;
  
  
  Components of a WebSite
&lt;/h2&gt;

&lt;p&gt;Anything on the Web has 3 main components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;FrontEnd&lt;/li&gt;
&lt;li&gt;BackEnd&lt;/li&gt;
&lt;li&gt;Network&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkcatsygvaziwho6m4gd0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkcatsygvaziwho6m4gd0.png" alt="Components"&gt;&lt;/a&gt;&lt;br&gt;
No Matter How Optimized the backend is (a common huge mistake kinda 😅)&lt;/p&gt;

&lt;p&gt;End of the day it is the network that impacts 80% of a website's performance&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5a969makrhacau9thdhb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5a969makrhacau9thdhb.png" alt="pareto"&gt;&lt;/a&gt;&lt;br&gt;
So by Pareto's Rule,&lt;br&gt;
We focus on the &lt;strong&gt;NETWORK&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpyb34cd0yiqn3imds01m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpyb34cd0yiqn3imds01m.png" alt="network"&gt;&lt;/a&gt; The network is what connects the &lt;em&gt;frontend&lt;/em&gt; to the &lt;em&gt;backend&lt;/em&gt;.&lt;br&gt;
Most sites make &lt;em&gt;&lt;strong&gt;100s of requests&lt;/strong&gt; in the background&lt;/em&gt; as the site loads.&lt;/p&gt;

&lt;p&gt;If each response carries a lot of data&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The time for the data to reach the client increases&lt;/li&gt;
&lt;li&gt;The time for each resource to render increases&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;basically the website take forever to load&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

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

&lt;ol&gt;
&lt;li&gt;Reduce the size of files by

&lt;ol&gt;
&lt;li&gt;Sending only what the user (and not the website needs) aka code splitting&lt;/li&gt;
&lt;li&gt;Removing &lt;code&gt;whitespaces&lt;/code&gt; or &lt;code&gt;uglifying&lt;/code&gt; the file&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;If you use webpack, this is automatically done for you&lt;br&gt;
&lt;strong&gt;BONUS&lt;/strong&gt;: You could PWA and cache data on the client [But That Topic Is For Another Blog]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Reducing the size of images by optimizing them&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Reducing the size of images by optimizing them
&lt;/h2&gt;
&lt;h3&gt;
  
  
  What does this mean?
&lt;/h3&gt;

&lt;p&gt;We don't reduce the size by reducing resolution,&lt;br&gt;
We reduce the size by reducing the scale of colors.&lt;/p&gt;

&lt;p&gt;Let me explain,&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5xqp4n2sbkwz24r5rca.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5xqp4n2sbkwz24r5rca.png" alt="demo"&gt;&lt;/a&gt;&lt;br&gt;
The human eye can't distinguish between #000000 and #010101.&lt;br&gt;
So when we optimize images we're reducing the bits used to store color data of pixels&lt;/p&gt;
&lt;h3&gt;
  
  
  How do we do that?
&lt;/h3&gt;

&lt;p&gt;There are libraries that take care of this for us. &lt;/p&gt;

&lt;p&gt;However we can't create a program to do this every time for every image so, I created a CLI Tool [My First CLI Application] called &lt;code&gt;Shirmkage&lt;/code&gt; which stands for &lt;code&gt;shrink&lt;/code&gt; + &lt;code&gt;image&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can check out/play around with the &lt;a href="https://github.com/LucidMach/Shrimkage" rel="noopener noreferrer"&gt;source code&lt;/a&gt; on my github.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g shrimkage 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Shrimkage makes optimizing images in bulk easy&lt;/p&gt;

&lt;p&gt;You can use it directly in the terminal [that's what a CLI is tho 😅]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;shrimkage folder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The default level of reduction is 50 (/100). so if you want more optimization you can &lt;code&gt;shrimkage folder --level=10&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Shimkage also give you the option to apply optimizations to individual images&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;shrimkage file --path=./test.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And That is The 20% Effort to gain an 80% increase in web performance&lt;br&gt;
✌ &lt;/p&gt;

&lt;p&gt;If You ❤️ This,&lt;/p&gt;

&lt;p&gt;Follow Me on &lt;a href="https://twitter.com/LucidMach" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, &lt;/p&gt;

&lt;p&gt;Where you can see updates on all my work [including blogs]&lt;/p&gt;

&lt;p&gt;Also, Don't forget to DM Me&lt;br&gt;
Let's have small dev talk&lt;br&gt;
😁✌&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>performance</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Firebase Auth | Understanding The Auth</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Tue, 13 Jul 2021 16:21:54 +0000</pubDate>
      <link>https://forem.com/lucidmach/firebase-auth-understanding-the-auth-17go</link>
      <guid>https://forem.com/lucidmach/firebase-auth-understanding-the-auth-17go</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;NOTE: This blog post assumes that you are at-least familiar with setting up firebase SDK&lt;br&gt;
If you don't I'd recommend reading my blog on &lt;a href="https://dev.to/lucidmach/the-20-firebase-that-ll-do-80-of-the-task-a-firestore-cheatsheet-304p"&gt;firebase firestore&lt;/a&gt; first&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you've built an application, you've probably had to deal with authentication and authorization&lt;/p&gt;

&lt;p&gt;Contrary to Popular Belief&lt;br&gt;
&lt;code&gt;authentication !== authorization&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Difference Between Authentication and Authorization
&lt;/h2&gt;

&lt;p&gt;Consider A School&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fwww.pngall.com%2Fwp-content%2Fuploads%2F2018%2F04%2FSchool-PNG-Pic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fwww.pngall.com%2Fwp-content%2Fuploads%2F2018%2F04%2FSchool-PNG-Pic.png" alt="School"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The School has a Principal&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimage.flaticon.com%2Ficons%2Fpng%2F512%2F1999%2F1999321.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimage.flaticon.com%2Ficons%2Fpng%2F512%2F1999%2F1999321.png" alt="Principal"&gt;&lt;/a&gt;&lt;br&gt;
He Decides&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If a Student Joins the School&lt;/li&gt;
&lt;li&gt;If a Student Gets Debarred&lt;/li&gt;
&lt;li&gt;If a Student Gets Promoted (Despite Failing Tests)&lt;/li&gt;
&lt;li&gt;If a Student Gets Demoted
...&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The School also has a Security Guard&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimage.flaticon.com%2Ficons%2Fpng%2F512%2F2124%2F2124268.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimage.flaticon.com%2Ficons%2Fpng%2F512%2F2124%2F2124268.png" alt="Security"&gt;&lt;/a&gt;&lt;br&gt;
He Decides&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If/When a Person can Enter the Campus&lt;/li&gt;
&lt;li&gt;If/When a Person can Leave the Campus
...&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now as an Analogy&lt;br&gt;
&lt;code&gt;Authentication: Principal&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Authorization: Security Guard&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Authentication
&lt;/h3&gt;

&lt;p&gt;The Process of Verifying the Identity of a User&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps in Authentication
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Creating An Account&lt;/li&gt;
&lt;li&gt;Verifying An Account Email Address&lt;/li&gt;
&lt;li&gt;Login/Sign-In&lt;/li&gt;
&lt;li&gt;Password Recovery&lt;/li&gt;
&lt;li&gt;Sign Out&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Firebase Authentication
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Creating An Account
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase.auth().createUserWithEmailAndPassword(
  email,
  password
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;NOTE: You Receive a Promise from any Function from Firebase &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  2. SignOut
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase.auth().signOut()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;NOTE: Firebase removes the token stored on the client's localStorage (indexdb to be precise). It'll talk about it in detail in &lt;code&gt;Authorization&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  3. Login
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase.auth().signInWithEmailAndPassword(
  email, 
  password
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Verifying An Account Email
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// sends a pre-templated message to a specified email address
firebase.auth().sendEmailVerification(
  email,
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Password Recovery
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase.auth().sendPasswordResetEmail(
  email
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Authorization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Authorization
&lt;/h3&gt;

&lt;p&gt;The Process of Controlling Access to an Asset &lt;/p&gt;

&lt;h3&gt;
  
  
  How Does Firebase Authorize
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;When Ever A User's Auth State Changes

&lt;ol&gt;
&lt;li&gt;It Updates A User Token
&amp;gt; Very Similar To JWT but not restricted to web application&lt;/li&gt;
&lt;li&gt;It Stores the Token in the browser's indexDB (and not in the cookies) so it has a more controllable timeline&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;If A Valid User Token is Present, A User is allowed to Access the Resource&lt;/li&gt;

&lt;/ol&gt;

&lt;h4&gt;
  
  
  Accessing User Token / Checking Auth State
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase.auth().onAuthStateChanged((user) =&amp;gt; {
  if (user) {
    // User is signed in, see docs for a list of available properties
    // https://firebase.google.com/docs/reference/js/firebase.User
    var uid = user.uid;
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>firebase</category>
      <category>security</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>A Faster Free Heroku (Kinda) | Quick Hack</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Wed, 30 Jun 2021 08:27:24 +0000</pubDate>
      <link>https://forem.com/lucidmach/a-faster-free-heroku-kinda-quick-hack-2622</link>
      <guid>https://forem.com/lucidmach/a-faster-free-heroku-kinda-quick-hack-2622</guid>
      <description>&lt;p&gt;If you've been building stuff on web for a while now, you've probably heard of &lt;strong&gt;HEROKU&lt;/strong&gt; and &lt;strong&gt;NETLIFY&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just-In-Case you haven't heard about it&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Intro on Heroku and Netlify
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Heroku&lt;/em&gt;&lt;/strong&gt;: A &lt;strong&gt;free&lt;/strong&gt; PaaS (Platform as a Service), basically a cloud service that let's you &lt;strong&gt;host&lt;/strong&gt; and &lt;strong&gt;share&lt;/strong&gt; your web apps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Netlify&lt;/em&gt;&lt;/strong&gt;: A &lt;strong&gt;free hosting service&lt;/strong&gt; for &lt;strong&gt;static sites&lt;/strong&gt;, basically react, vanilla javascript, etc projects.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;NETLIFY&lt;/strong&gt; is Usually Used on &lt;strong&gt;Frontend Projects&lt;/strong&gt;.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;HEROKU&lt;/strong&gt; is Usually Used on &lt;strong&gt;Backend Projects&lt;/strong&gt;.&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.fabiofranchino.com%2Fassets%2Fposts%2Fhow-to-deploy-webapp-heroku-netlify%2Fcover.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.fabiofranchino.com%2Fassets%2Fposts%2Fhow-to-deploy-webapp-heroku-netlify%2Fcover.jpg" alt="Netlify + Heroku"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Problem with Heroku
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pro's:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Heroku is Easy to Use. &lt;/li&gt;
&lt;li&gt;Heroku is Free.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Con's:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Heroku has Premium&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.hostingmanual.net%2Fwp-content%2Fuploads%2Fwebsite-speed-3seconds.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.hostingmanual.net%2Fwp-content%2Fuploads%2Fwebsite-speed-3seconds.png" alt="3 sec"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Heroku's &lt;strong&gt;free tier&lt;/strong&gt; uses dynos (Stuff That Hosts Your Code) that &lt;strong&gt;sleeps&lt;/strong&gt; after &lt;strong&gt;30 mins of inactivity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once a dyno falls asleep, It takes time for it to awaken.&lt;br&gt;
So the initial response is slow and the damage is already done.&lt;/p&gt;
&lt;h2&gt;
  
  
  Work Around
&lt;/h2&gt;

&lt;p&gt;Re-Read This Line&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Heroku's &lt;strong&gt;free&lt;/strong&gt; tier uses dynos (Stuff That Hosts Your Code) that &lt;strong&gt;sleeps&lt;/strong&gt; after &lt;strong&gt;30 mins of inactivity&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If You Haven't Got It Yet, Re-Read It Again&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Heroku's free tier uses dynos (Stuff That Hosts Your Code) that sleeps after &lt;strong&gt;30 mins of inactivity&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;💡Light Bulb💡&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;30 mins of inactivity&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;All We Need To Do is Do Something Every 30mins.&lt;br&gt;
Nah 15mins to be on the safer side&lt;/p&gt;

&lt;p&gt;For node.js dev(s) Out There&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Run Every 15 mins =&amp;gt; 900 secs =&amp;gt; 900000 ms
setInterval(()=&amp;gt;console.log("😂😜🤣🤓"),900000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GGWP,&lt;br&gt;
&lt;a href="https://twitter.com/LucidMach" rel="noopener noreferrer"&gt;@LucidMach&lt;/a&gt;&lt;br&gt;
 ✌&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>cloud</category>
      <category>heroku</category>
    </item>
    <item>
      <title>Essential FireStore | CheatSheet/Tutorial</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Sat, 19 Jun 2021 09:04:21 +0000</pubDate>
      <link>https://forem.com/lucidmach/the-20-firebase-that-ll-do-80-of-the-task-a-firestore-cheatsheet-304p</link>
      <guid>https://forem.com/lucidmach/the-20-firebase-that-ll-do-80-of-the-task-a-firestore-cheatsheet-304p</guid>
      <description>&lt;p&gt;In the &lt;a href="https://dev.to/lucidmach/the-battle-of-the-nosql-databases-when-to-use-what-1e2o"&gt;prequel to this blog&lt;/a&gt;, we took a look at the concept of databases (noSQL to be more specific).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: FIRESTORE is a DATABASE as a Service(DaaS 😅), while FIREBASE is a BACKEND as a Service(BaaS)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this blog, we’ll learn how to use firebase firestore in projects.&lt;br&gt;
We’ll set up firestore as the database for a todo-list web app, without diving into the UI part [no HTML/JSX, CSS].&lt;/p&gt;
&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;The 1st thing to do before we jump in is obviously installing firebase and firestore.&lt;/p&gt;

&lt;p&gt;We have 2 ways of doing this&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Browser:&lt;/strong&gt; adding firebase and firestore as links inside file.html
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
  &amp;lt;script src="[https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js](https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js)"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;script src="[https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js](https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js)"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Server&lt;/strong&gt;: install it through npm/yarn (if you use react/node.js)
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// in the terminal
npm install firebase

// in a js file
const firebase = require("firebase");
require('firebase/auth');
require('firebase/database');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Initializations
&lt;/h2&gt;

&lt;p&gt;Now, that we’ve installed firebase, we’ve to connect it to the cloud(initialization).&lt;/p&gt;

&lt;p&gt;This is done by copying API keys…, etc into the project.&lt;/p&gt;

&lt;p&gt;You can get all the config details from the project settings page&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2A3eaKV6rYP63f570NVs1vqA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2A3eaKV6rYP63f570NVs1vqA.png" alt="A ScreenShot of Configurations for Web"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To initialise firebase we paste the config into &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; or a javascript file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const firebaseConfig = {
        apiKey: "AIzaSyBSABaeBTG4mteo-FrDtO-8qOIAxCX6yug",
        authDomain: "lucid-fireship-basics.firebaseapp.com",
        projectId: "lucid-fireship-basics",
        storageBucket: "lucid-fireship-basics.appspot.com",
        messagingSenderId: "316115989732",
        appId: "1:316115989732:web:935a8eefaca4bd9512a8f1",
        measurementId: "G-1V9QBWT3MG",
    };

    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we make an instance of firestore into a variable, so we reduce a few keystrokes every time we interact with firestore &lt;a href="https://emojipedia.org/face-with-tears-of-joy/" rel="noopener noreferrer"&gt;😂&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const db = firebase.firestore();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;before we can start doing anything with the database, we need to understand the data model (how data is stored in firestore)&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Firestore Data Model&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Firestore see’s data as collections of documents, and a collection can store sub-collections too.&lt;/p&gt;

&lt;p&gt;It’s like “file explorer”, you can create folders and store documents or folders in it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;ANALOGY:&lt;/strong&gt;&lt;br&gt;
collections = folders&lt;br&gt;
documents = files (eg: json)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AK8FscB7M3IT3UbGT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AK8FscB7M3IT3UbGT.png" alt="a idk what this is but i hope you're not reading this"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;CRUD operations with firestore&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now whenever we deal with any form of database, we can basically do 4 kinds of operations&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create Documents&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read Documents&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update Documents&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Delete Documents&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But before we can perform a CRUD operation, we need to select a collection to work with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// to reduce a few keystokes to access the todos collection
const todos = db.collection("todos")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  1. Create Documents
&lt;/h2&gt;

&lt;p&gt;The documents stored would be converted to JSON so you’ve to follow an object-like structure.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: if you’ve done some python, it’s like a dictionary in python&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;doc = {name:"clap this article"};
todos.add(doc);

// or
db.collection("todos").add({name:"clap this article"});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Read Documents
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;2.1 To quickly get all the documents inside a collection.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection("todos").get().then(snapshot=&amp;gt;snapshot.docs.forEach(doc=&amp;gt;console.log(doc.data())))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now, that might seem complicated but its actually really simple&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It takes a screenshot of the current state of collection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From the screenshot, we extract the docs stored in the collection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The forEach is a for loop that console logs data stored in every doc&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: =&amp;gt; is an syntax for &lt;a href="https://www.w3schools.com/js/js_arrow_function.asp" rel="noopener noreferrer"&gt;arrow function&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;2.2 To get a specific document.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const docid = "sfdagerfkajilf";
db.collection("todos").doc(docid);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when we add a doc to a collection, firestore generates a random id and uses it as the name of a doc&lt;br&gt;
To fetch a certain doc, we need to specify the id&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Update Documents
&lt;/h2&gt;

&lt;p&gt;While updating a document, we can&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.1. Reset the Whole Document&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;when the document has only 1 key in the document(object), it doesn't matter which one you use&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    db.collection("todos").doc("dagfshdjhkdfagsh").set({
      task1: "follow LucidMach on medium",
      task2: "share this article to everyone"
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.2. Modify a Part of the Document&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    db.collection("todos").doc("afdghrujfkhotdf").update({
      task2: "follow LucidMach on twitter"
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;notice that, on using .update(), we only change the specified part of the document, so the unspecified doesn’t change,&lt;/p&gt;

&lt;p&gt;so task1 remains as follow LucidMach on medium so don’t forget to do both of them 😜&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Delete Documents
&lt;/h2&gt;

&lt;p&gt;This operation is very similar to updating a document, you need to specify a doc id&lt;/p&gt;

&lt;p&gt;&lt;code&gt;db.collection("todos").doc("afdghrujfkhotdf").delete()&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Final Words&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;No, I’m not dying 😜, but if you’re reading this line,&lt;/p&gt;

&lt;p&gt;I appreciate the time spent reading this post. I hope this helps/serves as a cheat sheet for whenever may you need it&lt;/p&gt;

&lt;p&gt;✌, LucidMach&lt;/p&gt;

&lt;p&gt;Come HangOut With Me&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/LucidMach" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCeiqLNsKT95FGM8obq1GH4g" rel="noopener noreferrer"&gt;YouTube&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.instagram.com/lucidmach/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>database</category>
    </item>
    <item>
      <title>The Battle of The NoSQL Databases | When To Use What</title>
      <dc:creator>Nukala Suraj</dc:creator>
      <pubDate>Sat, 19 Jun 2021 08:14:50 +0000</pubDate>
      <link>https://forem.com/lucidmach/the-battle-of-the-nosql-databases-when-to-use-what-1e2o</link>
      <guid>https://forem.com/lucidmach/the-battle-of-the-nosql-databases-when-to-use-what-1e2o</guid>
      <description>&lt;p&gt;Let’s start from the very beginning….&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a database?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s just a base/place for data, it's as simple as that.&lt;/p&gt;

&lt;p&gt;However, the bigger question is “why can’t you use something like an excel sheet to store data?”&lt;/p&gt;

&lt;p&gt;The answer is yes you can &lt;strong&gt;but&lt;/strong&gt; it depends more on what you’re trying to do&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;excel sheet&lt;/strong&gt; is &lt;strong&gt;perfect&lt;/strong&gt; if &lt;strong&gt;you&lt;/strong&gt;’re the &lt;strong&gt;only person using&lt;/strong&gt;/updating the data, now when you scale up to &lt;strong&gt;more than&lt;/strong&gt; say &lt;strong&gt;3 people&lt;/strong&gt; (in different locations), try &lt;strong&gt;to&lt;/strong&gt; have the excel file &lt;strong&gt;store&lt;/strong&gt; the most &lt;strong&gt;up-to-date&lt;/strong&gt; data as possible, you’ll see exactly why the &lt;strong&gt;excel file&lt;/strong&gt; is a &lt;strong&gt;terrible&lt;/strong&gt; idea.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are the different types of databases?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Traditionally people used something called &lt;strong&gt;Structured Query Language&lt;/strong&gt; (SQL, &lt;a href="https://emojipedia.org/speaker-high-volume/#:~:text=A%20speaker%20cone%20displayed%20with,to%20Emoji%201.0%20in%202015." rel="noopener noreferrer"&gt;🔊&lt;/a&gt;: sequel), It basically created &lt;strong&gt;commands&lt;/strong&gt; to do what you would to in an &lt;strong&gt;excel table&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;example: if you wanted to insert a row into the table, instead of opening the table and manually entering values to the table, you would now do&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO table(column1, column2,...)

VALUES (value1, value2,...);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;TL;DR it kinda made excel programmable.&lt;/p&gt;

&lt;p&gt;Present-day humanity, we have 2 main types of databases&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;SQL: uses tables to store data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NoSQL: uses key-value pairs to store data&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AnmORrH0sI9zETbKi5SMwlQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AnmORrH0sI9zETbKi5SMwlQ.png" alt="A Depiction of data in a NoSQL database"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reading that you may be thinking why did humans bother to come up with NoSQL, it &lt;strong&gt;seems easier&lt;/strong&gt; to &lt;strong&gt;store&lt;/strong&gt; data in &lt;strong&gt;tables&lt;/strong&gt; rather than in key-value pairs.&lt;/p&gt;

&lt;p&gt;Well, on that you aren’t wrong, it is easier to store data in an SQL database disregarding the fact that you have to learn an entire language for it.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;main problem&lt;/strong&gt; occurs when you’re looking to &lt;strong&gt;scale&lt;/strong&gt; beyond 1000 people(ig), especially when the storage on the server(or pc in this case) is exhausted.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;NoSQL&lt;/strong&gt;, you can do this very easily by &lt;strong&gt;simply&lt;/strong&gt; just &lt;strong&gt;splitting&lt;/strong&gt; data into n parts and &lt;strong&gt;merging&lt;/strong&gt; it in &lt;strong&gt;different systems&lt;/strong&gt; later,&lt;/p&gt;

&lt;p&gt;unlike in &lt;strong&gt;SQL&lt;/strong&gt; where &lt;strong&gt;merging&lt;/strong&gt; is &lt;strong&gt;complicated&lt;/strong&gt;, you have to create a pre-defined schema(&lt;strong&gt;blueprint&lt;/strong&gt;), share the blueprint and then split data, not to mention ensure your &lt;strong&gt;index&lt;/strong&gt; for each row is &lt;strong&gt;unique&lt;/strong&gt; especially for the new data that you add.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Major Players in the NoSQL Battleground&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So for the average developer, while choosing a NoSQL database, typically has 2 choices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Firestore&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;MongoDB&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;… ( There is always a 3rd option, you just may not know what it is &lt;a href="https://emojipedia.org/face-with-tears-of-joy/" rel="noopener noreferrer"&gt;😂&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Let’s Talk About MongoDB&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a pretty well-established database and it’s currently the database of choice for most people (excluding me), but that is obviously because they have their needs.&lt;/p&gt;

&lt;p&gt;MongoDB came out in 2009, and it was basically the only noSQL database easily available for public use at that time.&lt;/p&gt;

&lt;p&gt;That led to the butterfly effect that made it so well established, but that doesn’t explain why no other database has overthrown it yet.&lt;/p&gt;

&lt;p&gt;Now, when mongoDB came it was an offline database (it wasn’t on the cloud), but as the times changed it adapted to the changes, actually the community (fans that use+love+live it) ensured it adapted to changes.&lt;/p&gt;

&lt;p&gt;The community came up with mLabs, a cloud-based mongoDB database.&lt;/p&gt;

&lt;p&gt;mLabs is what turned out to become the present day’s mongoDB atlas&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s Talk About Firestore&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Firestore is the flagship database of google’s BaaS &lt;a href="https://dev.topre-coded/setup%20server"&gt;backend as a service&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;QuickNote&lt;/strong&gt;: Firebase runs on top of GCP google’s IaaS &lt;a href="https://dev.tothe%20server%20hardware,%20uncoded/setup"&gt;infrastructure as a service&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most people think firebase is the database (due to a common ending “base”), but NO, firebase is a backend and offers a lot of additional services like hosting, authentication and analytics.&lt;/p&gt;

&lt;p&gt;That is firestore’s key selling point right now.&lt;/p&gt;

&lt;p&gt;Easy to use, free ( as long as you are in the free-tier ), with a lot of additional features&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When To Use MongoDB over Firestore&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Firestore comes under firebase, where you have 0 control over what you can configure/host there.&lt;/p&gt;

&lt;p&gt;**Use Case: **When you need a server, where you plan to have custom-built APIs like&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;ML model&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;APIs that serve sensor data [eg: open weather map, etc.]&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this case, you already have and are paying for computation resources, so it’s most economical to stick to 1 service.&lt;/p&gt;

&lt;p&gt;You could:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;host a local mongoDB instance in the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;connected to the cloud-hosted mongoDB Altas cluster.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;When To Use Firestore over MongoDB&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the only central(server) resource that you’re using is a database, it’s more beneficial to use than mongoDB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt; an app or a SPA(client-rendered web app)&lt;/p&gt;

&lt;p&gt;Lemme place more emphasis on using firebase if the only additional resources you need is a database.&lt;/p&gt;

</description>
      <category>database</category>
      <category>beginners</category>
      <category>node</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
