<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:base="https://devspedia.com/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    
    <title>Devspedia - Software Engineering News for Developers</title>
    <link>https://devspedia.com/</link>
    <atom:link href="https://devspedia.com/rss.xml" rel="self" type="application/rss+xml" />
    <description>Devspedia is a publication focused on web development, cloud architecture, performance, security, AI tooling, and developer workflows.</description>
    <language>en</language>
    <item>
      <title>Devspedia respects your preferred OS color scheme!</title>
      <link>https://devspedia.com/devspedia-respects-your-preferred-operating-system-color-scheme/</link><description>&lt;p&gt;Hello there, tech-savvy explorers! We&#39;ve got some exciting news to share that&#39;s all about making your Devspedia experience even more delightful.&lt;/p&gt;
&lt;p&gt;You know that feeling when your favorite app seamlessly adjusts to your preferences? Well, Devspedia is now right there with you, effortlessly embracing the look and feel you love. Whether you&#39;re cruising in dark mode or basking in the light, we&#39;ve got you covered!&lt;/p&gt;
&lt;p&gt;So, here&#39;s the scoop: When you visit Devspedia, our clever website has a little chat with your operating system (iOS, macOS, Ubuntu, and more). It asks, &amp;quot;Hey, what&#39;s the vibe right now? Dark and mysterious or bright and sunny?&amp;quot;&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;And guess what? It listens! If your OS is all about that dark mode life, we&#39;ll flip the switch to a soothing dark color palette, making your nighttime reading sessions a breeze on the eyes. But if you prefer the classics and are in the land of light mode, Devspedia will don its brightest attire to match your style.&lt;/p&gt;
&lt;p&gt;It&#39;s like having your very own theme party every time you visit. So, kick back, relax, and let Devspedia set the mood. Your comfort is our priority, and we&#39;re thrilled to make your tech journey even cozier. Enjoy the ride, and keep exploring the ever-fascinating world of Devspedia! 🌟🌙&lt;/p&gt;
</description><pubDate>Sat, 09 Nov 2019 22:55:44 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/devspedia-respects-your-preferred-operating-system-color-scheme/</guid>
    </item>
    <item>
      <title>Apple Macbook Flexgate issue</title>
      <link>https://devspedia.com/apple-macbook-flexgate-issue/</link><description>&lt;p&gt;
  If you have a new Macbook Pro with Touchbar (except for 2018 and 2019 models),
  your Macbook will screen will most likely fail in a year, or two due to a
  design flaw related to a flex cable connecting the screen to the logical
  board, this cable is ultra thin, and very short.
&lt;/p&gt;
&lt;p&gt;
  So basically as you normally open/close your computer&#39;s lid, this cable will
  fracture over time leading to this issue, check the video below to see how it
  looks like:
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-embed-card&quot;&gt;
  &lt;blockquote class=&quot;twitter-tweet&quot;&gt;
    &lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;
      Apple tech was so sheepish after consulting manager and telling me this
      issue isn&#39;t covered. Weirdly he says the screen doesn&#39;t affect trade in
      value?!
      &lt;a href=&quot;https://twitter.com/hashtag/flexgate?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#flexgate&lt;/a&gt; &lt;a href=&quot;https://t.co/q3QO8nkFQR&quot;&gt;pic.twitter.com/q3QO8nkFQR&lt;/a&gt;
    &lt;/p&gt;
    &amp;mdash; Karl Yang (@akarlyang)&lt;a href=&quot;https://twitter.com/akarlyang/status/1130636618497314816?ref_src=twsrc%5Etfw&quot;&gt;May 21, 2019&lt;/a&gt;
  &lt;/blockquote&gt;
  &lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;/figure&gt;
&lt;!-- In post ad. --&gt;
&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-6152403584587692&quot; data-ad-slot=&quot;1375880989&quot;&gt;&lt;/ins&gt;
&lt;!-- /In post ad. --&gt;
&lt;p&gt;
  Apple have admitted this issue back in May 2019 but only for the 13 inch
  models, leaving 15 inch owners having to pay $600 to replace the entire
  screen, while the cable it self can only cost between $7 and $9 to replace,
  but the screen was designed with this cable built into it, making it
  impossible to replace only the screen.
&lt;/p&gt;
&lt;p&gt;
  I was one of those who have faced this issue, and of course due to having a 15
  inch model, I have no chance for a free repair.
&lt;/p&gt;
&lt;p&gt;
  I heard some people in some countries like Netherlands and Brazil have managed
  to get a free repair from the Genius bar. Not sure how they managed to
  convince them.
&lt;/p&gt;
&lt;!-- In post ad. --&gt;
&lt;ins class=&quot;adsbygoogle&quot; style=&quot;display:block; text-align:center;&quot; data-ad-layout=&quot;in-article&quot; data-ad-format=&quot;fluid&quot; data-ad-client=&quot;ca-pub-6152403584587692&quot; data-ad-slot=&quot;1375880989&quot;&gt;&lt;/ins&gt;
&lt;!-- /In post ad. --&gt;
&lt;p&gt;For more information on the flexgate issue, check this dedicated website (update: website was taken down!):&lt;/p&gt;
&lt;LinkEmbed url=&quot;https://appleissues.net/issues/flexgate/&quot; title=&quot;Flexgate - Apple Issues (Beta)&quot; desc=&quot;MacBook Pro Retina 2016 and later has a critical issue with display. Let&#39;s make Apple cover it under extended warranty program! #flexgate&quot; image=&quot;https://appleissues.net/media/uploads/2019/01/26/flexgate.png&quot;&gt;
&lt;p&gt;
  Also there is a petition was nearly 25,000 people signed it who are facing
  this issue, and Apple is basically acting like nothing is happening
  unfortunately.
&lt;/p&gt;
&lt;LinkEmbed url=&quot;https://www.change.org/p/apple-fix-all-new-macbook-pro-2016-or-later-with-stage-light-effect-or-backlight-shutdown&quot; title=&quot;Sign the Petition&quot; desc=&quot;Fix all MacBook Pro 2016 and later with stage light effect or backlight shutdown #flexgate&quot; image=&quot;https://static.change.org/favicons/favicon-114x114.png&quot;&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;
  Here&#39;s also a video that explains the issue in details by Louis Rossman, a
  reputable YouTube author, working professionally in fixing MacBooks.
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-embed-card&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/NzjoELvrkYo?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Worth to note that Apple have managed to &quot;silently&quot; replace this cable with a
  longer one in 2018 models -both 13 &amp;amp; 15 inch models- in order to fix this
  issue.
&lt;/p&gt;
&lt;p&gt;
  Finally, we all hope Apple can soon admit this issue, and launch a repair
  program for 15 inch models as well.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;Thanks for reading devspedia, I love you, and see you the next time :)&lt;/p&gt;
&lt;/LinkEmbed&gt;&lt;/LinkEmbed&gt;</description><pubDate>Mon, 11 Nov 2019 18:00:00 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/apple-macbook-flexgate-issue/</guid>
    </item>
    <item>
      <title>How to authenticate your JavaScript SDK using AWS Lambda &amp; Serverless</title>
      <link>https://devspedia.com/how-to-authenticate-your-javascript-sdk-using-aws-lambda/</link><description>&lt;p&gt;
  Hello my friends, and welcome to a new story. Today we&#39;ll discuss the shortest
  method to use API key authentication for your JavaScript SDK using AWS Lambda.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;the-use-case&quot;&gt;The use case&lt;/h2&gt;
&lt;p&gt;
  So you have a JavaScript SDK (file) that you want to allow only clients with
  valid &lt;code&gt;key&lt;/code&gt; and valid
  &lt;code&gt;domain&lt;/code&gt; to actually be able to request and download the SDK file.
&lt;/p&gt;
&lt;p&gt;
  Let&#39;s say we want &lt;code&gt;https://mydomain.com/sdk.min.js?key=XXXX&lt;/code&gt; to
  work when requested from
  &lt;code&gt;client.com&lt;/code&gt; website, and of course when the key is valid, and
  should send &lt;code&gt;401&lt;/code&gt; unauthorized if the key is not valid, or the key is
  valid, but from a different domain.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;checklist&quot;&gt;Checklist&lt;/h2&gt;
&lt;p&gt;Here&#39;s our checklist from start to finish:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Install Serverless (if you haven&#39;t already).&lt;/li&gt;
  &lt;li&gt;Initialize project.&lt;/li&gt;
  &lt;li&gt;Create our Lambda.&lt;/li&gt;
  &lt;li&gt;Try locally.&lt;/li&gt;
  &lt;li&gt;Deploy.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;1-install-serverless&quot;&gt;1. Install Serverless&lt;/h3&gt;
&lt;p&gt;
  This method installs serverless globally, but you can also install it locally
  to your project only if you prefer.
&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-g&lt;/span&gt; serverless
&lt;span class=&quot;token function&quot;&gt;yarn&lt;/span&gt; global &lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt; serverless&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;2-initialize-project&quot;&gt;2. Initialize project&lt;/h3&gt;
&lt;p&gt;
  First thing we need is to run the serverless CLI tool, it&#39;ll start an
  interactive process for creating a new project, it&#39;s pretty straightforward.
&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;serverless&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will initialize the interactive CLI of serverless for creating new
project&lt;/p&gt;
&lt;p&gt;The above command will start the interactive process of creating a new serverless project, I&#39;ve included the steps below:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ serverless
    $ Serverless: No project detected. Do you want to create a new one? &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Y/n&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 
    $ Serverless: What &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt; you want to make? &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Use arrow keys&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    ❯ AWS Node.js 
      AWS Python 
    $ Serverless: What &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt; you want to call this project? 
    $ Project successfully created &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;lambda-sdk-auth&#39;&lt;/span&gt; folder.
    $ You can monitor, troubleshoot, and &lt;span class=&quot;token builtin class-name&quot;&gt;test&lt;/span&gt; your new &lt;span class=&quot;token function&quot;&gt;service&lt;/span&gt; with a &lt;span class=&quot;token function&quot;&gt;free&lt;/span&gt; Serverless account.
    $ Serverless: Would you like to &lt;span class=&quot;token builtin class-name&quot;&gt;enable&lt;/span&gt; this? &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Y/n&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    $ Serverless: Would you like to setup a &lt;span class=&quot;token builtin class-name&quot;&gt;command&lt;/span&gt; line &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;tab&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; completion? &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Y/n&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The last 2 steps are optional.&lt;/p&gt;
&lt;p&gt;
  Now we have a directory called &lt;code&gt;lambda-sdk-auth&lt;/code&gt; which include our new
  project.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Files tree&lt;/strong&gt;&lt;/p&gt;
  &lt;img alt=&quot;&quot; src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/1_image-6_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot;&gt;
&lt;p&gt;You should now have 3 files in your project:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;code&gt;.gitignore&lt;/code&gt; Which is used to instruct git to exclude some paths
    like &lt;code&gt;node_modules&lt;/code&gt; &amp;
    &lt;code&gt;.serverless&lt;/code&gt;.
  &lt;/li&gt;
  &lt;li&gt;&lt;code&gt;handler.js&lt;/code&gt; We&#39;ll write our lambda function here.&lt;/li&gt;
  &lt;li&gt;
    &lt;code&gt;serverless.yml&lt;/code&gt; This file include all of our serverless configurations.
  &lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;3-create-our-lambda-function&quot;&gt;3. Create our Lambda function&lt;/h3&gt;
&lt;p&gt;
  Let&#39;s start by updating the default serverless config, replace &lt;code&gt;serverless.yml&lt;/code&gt;&#39;s contents with the following:
&lt;/p&gt;
&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; lambda&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;sdk&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;auth
    
&lt;span class=&quot;token key atrule&quot;&gt;provider&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws
  &lt;span class=&quot;token key atrule&quot;&gt;runtime&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; nodejs10.x

  &lt;span class=&quot;token key atrule&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dev
  &lt;span class=&quot;token key atrule&quot;&gt;region&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;functions&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;sdk&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; handler.default
    &lt;span class=&quot;token key atrule&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; sdk.min.js
          &lt;span class=&quot;token key atrule&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; get&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let me explain what we&#39;ve got here:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    Service: This will be our project name, it&#39;ll be used in the deployment&#39;s
    CloudFormation template.
  &lt;/li&gt;
  &lt;li&gt;
    Provider: The cloud provider, serverless supports Azure, Google Compute
    Cloud and AWS, we&#39;re using AWS in this example, and NodeJS 10 as a runtime
    (choose earlier during initializing project).
  &lt;/li&gt;
  &lt;li&gt;Stage: The API Gateway stage.&lt;/li&gt;
  &lt;li&gt;Region: The region in AWS where you wish to deploy your Lambda to.&lt;/li&gt;
  &lt;li&gt;Functions: List of our Lambda functions, we only have 1.&lt;/li&gt;
  &lt;li&gt;Function.sdk: This is our Lambda function name.&lt;/li&gt;
  &lt;li&gt;
    Function.sdk.handler: The path to our Lambda function in the project, the &lt;code&gt;.default&lt;/code&gt;
    part of the value means it will look for &lt;code&gt;module.exports.default&lt;/code&gt;
    in that file.
  &lt;/li&gt;
  &lt;li&gt;
    Function.sdk.events: Events list for this function, we can have different
    types of events like HTTP or a scheduled/cron. We&#39;re using HTTP, which is
    the only suitable one for our use case.
  &lt;/li&gt;
  &lt;li&gt;Function.sdk.events.http.path: The URL structure for your Lambda.&lt;/li&gt;
  &lt;li&gt;
    Function.sdk.events.http.method: The HTTP request method, we&#39;re using &lt;code&gt;GET&lt;/code&gt;.
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
  Before writing our Lambda code, there&#39;s 1 last step we need to do, is to
  install &lt;code&gt;serverless-offline&lt;/code&gt; node module, which will make local development
  easier by allowing us to invoke our Lambda from the browser, to best simulate AWS
  environment.
&lt;/p&gt;
&lt;p&gt;
  Install &lt;a href=&quot;https://www.npmjs.com/package/serverless-offline&quot;&gt;serverless-offline&lt;/a&gt;:
&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ &lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; serverless-offline &lt;span class=&quot;token parameter variable&quot;&gt;-D&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Install serverless offline as a dev dependency via npm&lt;/p&gt;
&lt;p&gt;Or via Yarn:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;yarn&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt; serverless-offline &lt;span class=&quot;token parameter variable&quot;&gt;-D&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Install serverless offline as a dev dependency via yarn&lt;/p&gt;
&lt;p&gt;
  Finally update serverless file to include plugins section, with this
  serverless plugin:
&lt;/p&gt;
&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; lambda&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;sdk&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;auth

&lt;span class=&quot;token key atrule&quot;&gt;plugins&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; serverless&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;offline

&lt;span class=&quot;token key atrule&quot;&gt;provider&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aws
  &lt;span class=&quot;token key atrule&quot;&gt;runtime&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; nodejs10.x

  &lt;span class=&quot;token key atrule&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dev
  &lt;span class=&quot;token key atrule&quot;&gt;region&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; us&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;east&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;functions&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;sdk&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; handler.default
    &lt;span class=&quot;token key atrule&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; sdk.min.js
          &lt;span class=&quot;token key atrule&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; get&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now let&#39;s do 2 primary things:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Create our SDK file.&lt;/li&gt;
  &lt;li&gt;Create the lambda function.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
  Create a file called &lt;code&gt;sdk.js&lt;/code&gt; in the root of your project, and add anything
  to it, example:
&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;123&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Our SDK&#39;s contents&lt;/p&gt;
&lt;p&gt;
  Now let&#39;s move on to writing our function&#39;s logic; Let&#39;s start by replacing
  our Lambda file with the below contents, then I&#39;ll explain it in details:
&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; fs &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;fs&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    
module&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;exports&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function-variable function&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; context&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Get the &quot;key&quot; from request query params&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; queryParams &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;queryStringParameters&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; key &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; queryParams &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; queryParams&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;key&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  
  &lt;span class=&quot;token comment&quot;&gt;// Return 401 if key is not passed in GET query params&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;key&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;token literal-property property&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Key is missing&#39;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Get requesting domain&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; clientDomain &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;headers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Origin&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// This is a static mock for allowed clients.&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// You should normally get this from your database&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; allowedClients &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;domains&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;devspedia.com&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;example-key&#39;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  
  &lt;span class=&quot;token comment&quot;&gt;// Check if client exists using it&#39;s unique key&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; client &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; allowedClients&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; client&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;key &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; key&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// If client is not found, return 401 as the key is not authrorized&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;client&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;token literal-property property&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Key not registered&#39;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Check if the domain exists within the client&#39;s allowed&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// domains&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; validDomain &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; clientDomain &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; client&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;domains
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;domain&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; domain &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; clientDomain&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;://&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// If the request if coming from a domain that was not &lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// allowed for this key, return 401&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;validDomain&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;token literal-property property&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Domain not registered for this key&#39;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Read the SDK javascript file&#39;s contents&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sdk &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; fs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;readFileSync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;__dirname&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;/sdk.js&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Return the file&#39;s contents with correct headers&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// and transform the sdk buffer array to a string&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token string-property property&quot;&gt;&#39;Content-type&#39;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;text/javascript&#39;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; sdk&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;hander.js&lt;/p&gt;
&lt;p&gt;Here&#39;s what we did in brief points:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Get the &quot;key&quot; from request query params.&lt;/li&gt;
  &lt;li&gt;If key is not passed in query params, we&#39;ll return 401 unauthorized.&lt;/li&gt;
  &lt;li&gt;If above step passed, we&#39;ll get the requesting domain.&lt;/li&gt;
  &lt;li&gt;Then check if this domain is allowed for this requesting key.&lt;/li&gt;
  &lt;li&gt;If not allowed, we&#39;ll return 401 unauthorized.&lt;/li&gt;
  &lt;li&gt;
    If allowed, we read the sdk file&#39;s contents using the native node &lt;code&gt;fs&lt;/code&gt; module.
  &lt;/li&gt;
  &lt;li&gt;
    Finally return the file&#39;s content after setting the correct headers. Viola :)
  &lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;4-try-locally&quot;&gt;4. Try locally&lt;/h3&gt;
&lt;p&gt;
  Now, to try this locally, we&#39;ll use cURL from the terminal. Make sure you&#39;re
  inside the project&#39;s directory, and then run:
&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;serverless invoke &lt;span class=&quot;token builtin class-name&quot;&gt;local&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-f&lt;/span&gt; sdk &lt;span class=&quot;token parameter variable&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;{&quot;&lt;/span&gt;headers&lt;span class=&quot;token string&quot;&gt;&quot;:{&quot;&lt;/span&gt;Origin&lt;span class=&quot;token string&quot;&gt;&quot;:&quot;&lt;/span&gt;https://devspedia.com&lt;span class=&quot;token string&quot;&gt;&quot;},&quot;&lt;/span&gt;queryStringParameters&lt;span class=&quot;token string&quot;&gt;&quot;:{&quot;&lt;/span&gt;key&lt;span class=&quot;token string&quot;&gt;&quot;:&quot;&lt;/span&gt;example-key&lt;span class=&quot;token string&quot;&gt;&quot;}}&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The response should be:&lt;/p&gt;
&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;statusCode&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;headers&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token property&quot;&gt;&quot;Content-type&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;body&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;const test = () =&gt; 123;&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lambda response&lt;/p&gt;
&lt;p&gt;
  Now, when this is requested from the browser, the browser will only render the
  body part of this response, and in this case, it&#39;s our SDK&#39;s content.
&lt;/p&gt;
&lt;p&gt;
  To actually simulate this in the browser, let&#39;s run serverless offline. Make
  sure you&#39;re inside the project directory, and then run:
&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;serverless offline&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
  Then in the browser, you can open devspedia.com and open up browser&#39;s
  developer tools/console, then make a request via fetch:
&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&#39;http://localhost:3000/sdk.min.js?key=example-key&#39;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token parameter&quot;&gt;res&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token parameter&quot;&gt;res&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;res&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;fetch request the SDK&lt;/p&gt;
&lt;p&gt;
  You should see &lt;code&gt;const test = () =&gt; 123;&lt;/code&gt; in the logs, which is the
  file&#39;s contents.
&lt;/p&gt;
&lt;h3 id=&quot;5-deploy&quot;&gt;5. Deploy&lt;/h3&gt;
&lt;p&gt;Deployment is easy, few steps you&#39;ll need to make:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    Install AWS CLI (&lt;a href=&quot;https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html&quot;&gt;https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html&lt;/a&gt;).
  &lt;/li&gt;
  &lt;li&gt;
    Run &lt;code&gt;aws configure&lt;/code&gt; in your terminal, and add your authentication
    info.
  &lt;/li&gt;
  &lt;li&gt;
    Finally, from the root of your project, run &lt;code&gt;serverless deploy&lt;/code&gt;.
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
  That&#39;s it, thanks for reading devspedia, I love you, and I&#39;ll see you the next
  time :)
&lt;/p&gt;
</description><pubDate>Tue, 12 Nov 2019 12:08:37 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/how-to-authenticate-your-javascript-sdk-using-aws-lambda/</guid>
    </item>
    <item>
      <title>Time series databases, what is it, and when to use it?</title>
      <link>https://devspedia.com/timeseries-databases-what-is-it-and-when-to-use-it/</link><description>&lt;p&gt;
  Welcome everyone to a new devspedia story. Today we&#39;ll be talking about time
  series databases, what are they, and when it can be the best choice.
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-image-card kg-width-full kg-card-hascaption&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/1_dan-gold-kARZuSYMfrA-unsplash_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
  &lt;figcaption&gt;Car booking services&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;blockquote&gt;
  A common use cases for time series databases is with autonomous driving
  systems, ride booking apps, delivery apps, and last mile apps.
&lt;/blockquote&gt;
&lt;p&gt;
  So, time series databases are used in many services and industries around us,
  some of these we interact with them day to day, here&#39;s a few examples:
&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Autonomous trading algorithms, they keep track of market changes.&lt;/li&gt;
  &lt;li&gt;
    Car booking apps, they need to keep track of driver and rider coordinates
    before, during, and after the trip to know where you want to be picked up,
    where you were actually picked up, where&#39;s the driver, where did he drop you
    off, ... etc.
  &lt;/li&gt;
  &lt;li&gt;
    Last mile delivery companies tracking coordinates of their fleet of cars, to
    know their locations, and where packages were delivered, ...etc
  &lt;/li&gt;
  &lt;li&gt;
    Cloud computing service providers such as AWS, Google Compute Cloud, Azure,
    ...etc they need to keep track of resources utilization, some of these
    require them to know changes happened to a resource as a time series.
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;so-how-does-it-work&quot;&gt;So how does it work?&lt;/h2&gt;
&lt;p&gt;
  A time series database allows you to keep track of changes on a piece of data
  over time. This happens by combining some fixed and variable properties.
&lt;/p&gt;
&lt;p&gt;
  Let&#39;s take an example to make it clear; Let&#39;s say you&#39;ve booked Uber from
  point A to point B. We need to keep track of your trip&#39;s path from start to
  end as a time series.
&lt;/p&gt;
&lt;p&gt;In a time series database, we can have this fixed property:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Trip ID (trip identifier).&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;And this dynamic/variable property:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;location: [latitude, longitude]&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;
  So since trip starts, and until trip is ended we keep sending new values
  (let&#39;s say every 100 meters) for the &lt;code&gt;location&lt;/code&gt; property, while time
  is passing by.
&lt;/p&gt;
&lt;p&gt;
  At any point of time when we send a new value, this new record is called a
  tag. So now we have information
&lt;/p&gt;
&lt;p&gt;
  Now we have a tremendous amount of very useful data! Simply because it&#39;s
  reflecting 1 thing (a trip) and is tied with a time series. Here&#39;s what we can
  do with the above data.
&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Know how much total time the trip consumed.&lt;/li&gt;
  &lt;li&gt;Know the actual path the driver took during the ride.&lt;/li&gt;
  &lt;li&gt;
    Know how much time the driver took in a particular street, and predict
    congestion in the future.
  &lt;/li&gt;
  &lt;li&gt;
    Know average driver&#39;s car speed during entire trip, or between 2 particular
    coordinates.
  &lt;/li&gt;
  &lt;li&gt;and a lot more!&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;okay-sounds-awesome-but-i-can-do-this-with-a-regular-db-nosql-or-kay-value-pairs-like-redis-&quot;&gt;
  Okay, sounds awesome, but I can do this with a regular DB (NoSQL, or kay-value
  pairs like Redis).
&lt;/h2&gt;
&lt;p&gt;
  You&#39;re actually right! But there are a few differences between time series
  databases and other databases that makes it more valuable and efficient to use
  a time series database over a regular database for use cases as the mentioned
  above, here&#39;s a few below:
&lt;/p&gt;
&lt;h3 id=&quot;scalability-&quot;&gt;Scalability:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    Time series databases can easily handle 100k to +1M inserts per seconds.
  &lt;/li&gt;
  &lt;li&gt;
    Tracking a trip (as in the example above) for the entire day, would take
    roughly (on average) 4 GBs of data, and for only 1000 trips we&#39;re talking
    about 4 TB of data. Time series databases are designed to handle tremendous
    amounts of data easily. If you do the same in an SQL DB you&#39;d have 4 TB of
    data per 1000 trip, millions of rows, and a reduced performance compared to
    a time series database.
  &lt;/li&gt;
  &lt;li&gt;
    Time series databases are designed to operate on time stamped/based data,
    this allows for a much better performance on scale compared to other
    databases.
  &lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;usability-&quot;&gt;Usability:&lt;/h3&gt;
&lt;p&gt;
  Time series databases have built-in operations that are time-based, which does
  not exist in any other type of database, that makes it easier to run powerful
  analysis on these data.
&lt;/p&gt;
&lt;h2 id=&quot;time-series-databases-popularity-is-growing-rapidly&quot;&gt;
  Time series databases popularity is growing rapidly
&lt;/h2&gt;
&lt;p&gt;
  For the past 2 years, time series databases are the fastest growing type of
  database in terms of usage and popularity.
&lt;/p&gt;
&lt;figure class=&quot;image-fig-card&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/1_image-7_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
  &lt;figcaption&gt;
    DB Engines &lt;a href=&quot;https://db-engines.com/en/ranking_categories&quot;&gt;https://db-engines.com/en/ranking_categories&lt;/a&gt;
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Finally, here&#39;s a list of top 20 ranking time series databases:&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-image-card&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/1_image-8_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
&lt;/figure&gt;
&lt;p&gt;
  Time series databases are very useful when used in projects where time series
  is the only choice that makes sense.
&lt;/p&gt;
&lt;h3 id=&quot;resources-&quot;&gt;Resources:&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://blog.timescale.com/blog/what-the-heck-is-time-series-data-and-why-do-i-need-a-time-series-database-dcf3b1b18563/&quot;&gt;https://blog.timescale.com/blog/what-the-heck-is-time-series-data-and-why-do-i-need-a-time-series-database-dcf3b1b18563/&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://db-engines.com/en/ranking_categories&quot;&gt;https://db-engines.com/en/ranking_categories&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://www.influxdata.com/time-series-database/&quot;&gt;https://www.influxdata.com/time-series-database/&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://db-engines.com/en/ranking/time+series+dbms&quot;&gt;https://db-engines.com/en/ranking/time+series+dbms&lt;/a&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
  Finally, thanks for reading devspedia, I love you, and see you the next time
  :)
&lt;/p&gt;
</description><pubDate>Fri, 15 Nov 2019 20:56:37 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/timeseries-databases-what-is-it-and-when-to-use-it/</guid>
    </item>
    <item>
      <title>Many to Many vs Polymorphic relationships</title>
      <link>https://devspedia.com/many-to-many-vs-polymorphic-relationships/</link><description>&lt;p&gt;
  Hello everyone and welcome to a new story. Today we&#39;re discussing the
  differences between Many-to-Many and Polymorphic relationships as pros and
  cons.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;many-to-many-relationship-or-belongs-to-many-&quot;&gt;
  Many to Many relationship (or belongs to many)
&lt;/h2&gt;
&lt;p&gt;
  Many to many relationship comes up to mind immediately when you think of two
  entities that can relate to each other as of many records related to many
  records, something like the very common Tags example.
&lt;/p&gt;
&lt;blockquote&gt;
  An article can have many tags, and a Tag can also have many many articles (or
  belongs to each others).
&lt;/blockquote&gt;
&lt;p&gt;
  An Article with many Tags, and a Tag with many Articles, in this case, you can
  have a junction table like
  &lt;code&gt;Articles_Tags&lt;/code&gt; with columns:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;ID (PK)&lt;/li&gt;
  &lt;li&gt;ArticleID (FK)&lt;/li&gt;
  &lt;li&gt;TagID (FK)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
  Now it&#39;s easy to link many Articles with many Tags using foreign keys. Now
  let&#39;s see pros and cons of this solution:
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;PROS:&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Allows us to use foreign keys effectively.&lt;/li&gt;
  &lt;li&gt;Efficient data querying.&lt;/li&gt;
  &lt;li&gt;Maintains data consistency.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;CONS:&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    More tables as each type requires a separate table – imagine adding Song to
    the mix, so you&#39;ll also need Songs_Tags in case you want to tag Songs too –.
  &lt;/li&gt;
  &lt;li&gt;
    Results in multiple classes, each representing the separate &lt;code&gt;Type_Tags&lt;/code&gt; table.
  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
  So in particular when having this scenario in 1st point in cons (more than 2
  models), this is exactly where a polymorphic relationships kicks in, let&#39;s
  take a look into this.
&lt;/p&gt;
&lt;h2 id=&quot;polymorphic-relationship-&quot;&gt;Polymorphic relationship:&lt;/h2&gt;
&lt;p&gt;
  A polymorphic relationship is used when you want something like Many to Many
  relationship, but without having to create extra tables every time you want to
  add a new Model to the mix.
&lt;/p&gt;
&lt;blockquote&gt;
  Polymorphic helps you combine all the junction tables into 1 very slim table,
  but at a cost.
&lt;/blockquote&gt;
&lt;p&gt;
  So, let&#39;s take the same example of Articles and Tags above, but let&#39;s also add
  another Model called Songs.
&lt;/p&gt;
&lt;p&gt;
  With polymorphic we can have only 1 table to achieve that, the table should
  have these columns:
&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;ID (PK)&lt;/li&gt;
  &lt;li&gt;TaggableID (INT)&lt;/li&gt;
  &lt;li&gt;TaggableType (VARCHAR)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now we can new records like:&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-code-card&quot;&gt;
&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  ID&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  TaggableID&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  TaggableType&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;article&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;figcaption&gt;A record for linking an article with a tag&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-code-card&quot;&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  ID&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  TaggableID&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  TaggableType&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;song&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;figcaption&gt;A record for linking a song with a tag&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Now let&#39;s explore pros and cons of this solution:&lt;/p&gt;
&lt;p&gt;PROS:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    Easy to scale, more models can be easily associated with the polymorphic
    class.
  &lt;/li&gt;
  &lt;li&gt;No need for extra table when you add an extra Model to the mix.&lt;/li&gt;
  &lt;li&gt;Results in one class that can be used by many other classes (DRY).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;CONS&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    More types can make querying more difficult and expensive as the data grows.
  &lt;/li&gt;
  &lt;li&gt;
    Cannot have a foreign key constrains (you can virtually insert any
    TaggableID and any TaggableType.
  &lt;/li&gt;
  &lt;li&gt;Lack of data consistency.&lt;/li&gt;
  &lt;li&gt;Weak ORM support.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;
  Now, hope this story give you more insights on these 2 types of relationships,
  and help you decide which type to pick for your project.
&lt;/p&gt;
&lt;p&gt;Thanks for reading devspedia, I love you, and see you the next time :)&lt;/p&gt;
</description><pubDate>Wed, 20 Nov 2019 14:02:38 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/many-to-many-vs-polymorphic-relationships/</guid>
    </item>
    <item>
      <title>How to deliver experiences best suited to a user&#39;s device and network constraints in React</title>
      <link>https://devspedia.com/how-to-deliver-experiences-best-suited-to-a-users-device-and-network-constraints-in-react/</link><description>&lt;p&gt;
  Hello everyone, and welcome to a new story. Today I&#39;d like to discuss with you
  a very interesting open source library &quot;&lt;strong&gt;&lt;a href=&quot;https://github.com/GoogleChromeLabs/react-adaptive-hooks&quot;&gt;react-adaptive-hooks&lt;/a&gt;&lt;/strong&gt;&quot; which will make it very easy for you to implement awesome features into
  your app to deliver the best possible experience based on the capabilities of
  the devices of your audience.
&lt;/p&gt;
&lt;LinkEmbed url=&quot;https://github.com/GoogleChromeLabs/react-adaptive-hooks&quot; title=&quot;GoogleChromeLabs/react-adaptive-hooks&quot; desc=&quot;Deliver experiences best suited to a user&#39;s device and network constraints - GoogleChromeLabs/react-adaptive-hooks&quot; image=&quot;https://repository-images.githubusercontent.com/220358364/70be8a80-02f5-11ea-9bd4-426ed4d02775&quot;&gt;
&lt;p&gt;
  This open source library provided by &lt;a href=&quot;https://github.com/GoogleChromeLabs&quot;&gt;Google Chrome Labs&lt;/a&gt;, it&#39;s designed for &lt;a href=&quot;https://reactjs.org/&quot;&gt;React&lt;/a&gt;. It&#39;s currently
  maintained by 9 open source contributors, lead by
  &lt;a href=&quot;https://github.com/addyosmani&quot;&gt;Addy Osmani&lt;/a&gt;, who&#39;s a Speed team
  lead at Chrome.
&lt;/p&gt;
&lt;p&gt;
  Although the project have started 18 days ago (November 9th, 2019), it now
  have (as of this writing) 3400 stars, 72 forks, 7 issues, and 16 merged pull
  requests on Github!
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;what-does-it-provides&quot;&gt;What does it provides?&lt;/h2&gt;
&lt;p&gt;
  Well, the library gives you 4 primary hooks that will allow you to tailor your
  users&#39; experience based on the following:
&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    Network conditions and effective connection type (slow-2G, 2G, 3G, 4G).
  &lt;/li&gt;
  &lt;li&gt;Browser&#39;s data saving preferences. (load smaller resources)&lt;/li&gt;
  &lt;li&gt;Available device memory. (0.5, 1, 2, 3, 4,... GiB).&lt;/li&gt;
  &lt;li&gt;Device&#39;s logical CPU cores. (1, 2, 3, 4,.. cores).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;
  Imagine what you can do with the above capabilities! One use case is as
  follows:
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-code-card&quot;&gt;
  &lt;pre&gt;
&lt;/pre&gt;
&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;react&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useSaveData &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;react-adaptive-hooks/save-data&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;MyComponent&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; saveData &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useSaveData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; saveData &lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;...&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;video&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;muted&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;controls&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;video&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;figcaption&gt;Save user&#39;s data, provide better experience&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;
  In the above example, we&#39;re checking via &lt;code&gt;useSaveData&lt;/code&gt; function whether
  the user&#39;s browser have the data saving feature enabled or not, if it&#39;s enabled,
  we&#39;ll go ahead and serve an image preview instead of a video which will reduce
  data consumption, and also provide a faster loading time.
&lt;/p&gt;
&lt;p&gt;
  For more usage examples, check the repo&#39;s &lt;a href=&quot;https://github.com/GoogleChromeLabs/react-adaptive-hooks/blob/master/README.md&quot;&gt;README file&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h3 id=&quot;installation-is-simple&quot;&gt;Installation is simple&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code&gt;npm i react-adaptive-hooks --save&lt;/code&gt; or&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;yarn add react-adaptive-hooks&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&#39;s all.&lt;/p&gt;
&lt;p&gt;
  Thanks for reading devspedia, I love you, and I&#39;ll see you the next time :)
&lt;/p&gt;
&lt;/LinkEmbed&gt;</description><pubDate>Wed, 27 Nov 2019 21:15:20 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/how-to-deliver-experiences-best-suited-to-a-users-device-and-network-constraints-in-react/</guid>
    </item>
    <item>
      <title>Here&#39;s a tool that&#39;ll help you build a solid webpack or parcel config files in no time</title>
      <link>https://devspedia.com/use-createapp-dev-to-quickly-build-your-next-webpack-or-parcel-config-file/</link><description>&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;
  Welcome my friends to a new story. Today I&#39;ll be discussing an awesome tool I
  found that helps you create your &lt;a href=&quot;https://webpack.js.org/&quot;&gt;Webpack&lt;/a&gt;
  or &lt;a href=&quot;https://parceljs.org/&quot;&gt;Parcel&lt;/a&gt; config in a fraction of time,
  via an easy to use web interface. Meet
  &lt;a href=&quot;https://createapp.dev/&quot;&gt;Create App&lt;/a&gt;!
&lt;/p&gt;
&lt;LinkEmbed url=&quot;https://createapp.dev/&quot; title=&quot;Create App - your tool for starting a new webpack or Parcel project&quot; desc=&quot;Create your own webpack config or Parcel app with React, Vue, Typescript, CSS, SCSS, SASS, less, codesplitting, etc, with this online tool&quot; image=&quot;https://createapp.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Frocket.00d48bc3.png&amp;w=96&amp;q=75&quot;&gt;
&lt;p&gt;
  The app lists every possible config for both Webpack and Parcel, and let you
  fine tune them, while showing you the changes to both your config file and
  your package.json file in real time.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;
  So for example if you choose Vue – Webpack context – ; It&#39;ll create a Vue
  file, add &lt;code&gt;vue-loader&lt;/code&gt; and &lt;code&gt;vue-template-compiler&lt;/code&gt;
  packages to your &lt;code&gt;package.json&lt;/code&gt; file, and update the
  &lt;code&gt;webpack.config.js&lt;/code&gt; file to reflect these changes and implement the
  new loader.
&lt;/p&gt;
&lt;p&gt;
  Of course, if you&#39;re using Parcel, you don&#39;t need any of these extra steps
  (ex: no loader needed) as Parcel itself automates this.
&lt;/p&gt;
&lt;p&gt;
  That&#39;s all, thanks for reading devspedia, I love you, and I&#39;ll see you the
  next time!
&lt;/p&gt;
&lt;/LinkEmbed&gt;</description><pubDate>Thu, 28 Nov 2019 21:39:54 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/use-createapp-dev-to-quickly-build-your-next-webpack-or-parcel-config-file/</guid>
    </item>
    <item>
      <title>Here&#39;s how you can start using feature flags today</title>
      <link>https://devspedia.com/here-is-how-you-can-start-using-feature-flags-today/</link><description>&lt;p&gt;
  Welcome everyone to a new devspedia story. Today I&#39;ll be talking about feature
  flag concept/practice in software development.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;blockquote&gt;
  Feature Toggles (often also refered to as Feature Flags) are a powerful
  technique, allowing teams to modify system behavior without changing code — &lt;a href=&quot;https://martinfowler.com/articles/feature-toggles.html&quot;&gt;Martin Folwer&lt;/a&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-is-a-feature-flag&quot;&gt;What is a feature flag?&lt;/h2&gt;
&lt;p&gt;
  A feature flag is a technique to turn on/off a feature at any time without
  having to maintain separate branches for each feature, and then once merged,
  is on by default.
&lt;/p&gt;
&lt;p&gt;
  It&#39;ll basically allow you to ship a product with a feature switched off, then
  switch it on again any time in the future.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot;&gt;How it works?&lt;/h2&gt;
&lt;p&gt;Take this minimal example into consideration:&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-code-card&quot;&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sendSMSConfirmation &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sendOrderConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;sendEmailConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;sendSMSConfirmation&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;sendSMSConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;figcaption&gt;Simple example showing feature flags usage&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;
  In this example, we have a toggle/bool to tell us whether or not to send SMS
  messages after sending email confirmation. It&#39;s &lt;code&gt;false&lt;/code&gt; or off by default.
&lt;/p&gt;
&lt;p&gt;
  Whenever business requires to switch on this feature at any time, we can
  easily set &lt;code&gt;sendSMSConfirmation&lt;/code&gt;
  to &lt;code&gt;true&lt;/code&gt;. Now it works.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;ways-to-implement-feature-flags-&quot;&gt;Ways to implement feature flags:&lt;/h2&gt;
&lt;p&gt;
  There are many ways you can implement feature flags, most common are the
  following:
&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;By decoupling decision points from decision logic.&lt;/li&gt;
  &lt;li&gt;Inversion of Control.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let&#39;s briefly explain these 2 main techniques.&lt;/p&gt;
&lt;h3 id=&quot;1-decoupling-decision-points-from-decision-logic&quot;&gt;
  1- Decoupling decision points from decision logic
&lt;/h3&gt;
&lt;p&gt;
  This means the feature flags will have absolutely nothing to do with the rest
  of your application logic, they are just bools, and then you can use them
  however you wish, take this example for better illustration:
&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; features &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getFeatureFlags&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  
&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sendOrderConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;sendEmailConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;features&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;TRANSACTIONAL_SMS&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  		&lt;span class=&quot;token function&quot;&gt;sendSMSConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
  Here, we can freely use this feature flag anywhere in our app logic, simply by
  doing this conditional.
&lt;/p&gt;
&lt;p&gt;
  Now, given we have a more broader feature flag: &lt;code&gt;TRANSACTIONAL_SMS&lt;/code&gt;
  which maybe indicate a set of features, this direct usage is introducing few challenges:
&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;What if we want to rollout this feature to a particular set of users?&lt;/li&gt;
  &lt;li&gt;
    What if we want to turn on some parts of &lt;code&gt;TRANSACTIONAL_SMS&lt;/code&gt; but
    without this
    &lt;code&gt;sendSMSConfirmation&lt;/code&gt; part?
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
  Now, there&#39;s a way to solve this be decoupling the decision point of sending
  SMS confirmation from the actual logic of &lt;code&gt;sendOrderConfirmation&lt;/code&gt;.
  Take this example:
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-code-card&quot;&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;orderConfirmationDecisions&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;features&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;sendSMSConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;subscription&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; features&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;TRANSACTIONAL_SMS&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; subscription&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isPaid&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;figcaption&gt;Order confirmation decisions&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;
  Now in this decisions file, we have a decision maker for order confirmations,
  here we can add more login to this
  &lt;code&gt;sendSMSConfirmation&lt;/code&gt; decision (ex: by checking the flag and
  &lt;code&gt;subscription.isPaid&lt;/code&gt;).
&lt;/p&gt;
&lt;p&gt;
  Now let&#39;s see the refactored &lt;code&gt;&lt;code&gt;sendSMSConfirmation&lt;/code&gt;&lt;/code&gt; function:
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-code-card&quot;&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; features &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getFeatureFlags&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; decisions &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;orderConfirmationDecisions&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;features&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// from prev file&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; subscription &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getUserSubscriptionSomehow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sendOrderConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;sendEmailConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;decisions&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sendOrderConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;subscription&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;sendSMSConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;figcaption&gt;
    Refactored &lt;code&gt;senOrderConfirmation&lt;/code&gt; function, now with decision decouple
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;
&lt;/p&gt;&lt;h3 id=&quot;2-inversion-of-control-&quot;&gt;2- Inversion of Control.&lt;/h3&gt;
&lt;p&gt;
  In the above example we&#39;ve introduced a new function that&#39;s responsible for
  taking order confirmation decisions, which is a dependency for &lt;code&gt;sendOrderConfirmation&lt;/code&gt;, also decisions must be aware of flagging.
&lt;/p&gt;
&lt;p&gt;
  This way, and by expanding to other system modules, will add extra layer of
  dependency to all modules logic, make testing harder, and will create a global
  feature flags dependency.
&lt;/p&gt;
&lt;p&gt;
  In Software design there&#39;s a technique called Inversion of Control, which we
  can use here to solve this problem.
&lt;/p&gt;
&lt;p&gt;Take the example below for better illustration:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sendOrderConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;sendEmailConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;sendSMSConfirmation&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  		&lt;span class=&quot;token function&quot;&gt;sendSMSConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
  Now in order to use this &lt;code&gt;sendOrderConfirmation&lt;/code&gt; function, we can have
  it go through a feature flagging factory, which will give the function the necessary
  config with all decision pre-made at run-time.
&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sendOrderConfirmation &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getSendOrderConfirmationFunction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;createFeatureAwareFactoryBasedOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;decisions&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;sendOrderConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; config &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token literal-property property&quot;&gt;sendSMSConfirmation&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; decisions&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sendOrderConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sendOrderConfirmation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;config&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
  What we did is basically adding a layer between the &lt;code&gt;sendOrderConfirmation&lt;/code&gt;
  function, and between the decisions it should take, through constructing a
  &lt;code&gt;config&lt;/code&gt; for this function.
&lt;/p&gt;
&lt;p&gt;
  This &lt;code&gt;config&lt;/code&gt; can be not only the decisions, but can also include extra
  logic outside of the scope of feature flags.
&lt;/p&gt;
&lt;h2 id=&quot;how-to-configure-the-feature-flags-&quot;&gt;
  How to configure the feature flags:
&lt;/h2&gt;
&lt;p&gt;
  Now figured out how to implement feature flags in our application logic, but
  how to actually build feature flags. There are few ways.
&lt;/p&gt;
&lt;h3 id=&quot;1-maintaining-config-files-&quot;&gt;1- Maintaining config files:&lt;/h3&gt;
&lt;p&gt;This is basically by having a file like so:&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-code-card&quot;&gt;
&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&quot;PARENT_SET_OF_FEATURES&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;TRANSACTIONAL_SMS&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&quot;ANOTHER_FLAG&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;figcaption&gt;feature flags config file.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;
  This is probably the simplest way, but it has it&#39;s drawbacks specially in
  larger applications, it becomes very difficult to guarantee consistency of
  feature flags across a large number of distributed servers.
&lt;/p&gt;
&lt;h3 id=&quot;2-use-the-application-database&quot;&gt;2- Use the application database&lt;/h3&gt;
&lt;p&gt;
  This will guarantee consistency somehow, and is a natural place to keep your
  feature flags, however, nowadays there are better ways to manage feature
  flags, there are hierarchical key-value stores that can be used.
&lt;/p&gt;
&lt;h3 id=&quot;3-use-these-tools-if-you-have-a-distributed-cluster&quot;&gt;
  3- Use these tools if you have a distributed cluster
&lt;/h3&gt;
&lt;p&gt;
  If you have a distributed cluster, you can use tools like &lt;a href=&quot;https://www.consul.io/&quot;&gt;Consul&lt;/a&gt;, &lt;a href=&quot;https://zookeeper.apache.org/&quot;&gt;Zookeeper&lt;/a&gt;, or
  &lt;a href=&quot;https://etcd.io/&quot;&gt;etcd&lt;/a&gt;.
&lt;/p&gt;
&lt;LinkEmbed url=&quot;https://www.consul.io/index.html&quot; title=&quot;Consul by HashiCorp&quot; desc=&quot;Consul is a service networking solution to connect and secure services across any runtime platform and public or private cloud&quot; image=&quot;https://www.datocms-assets.com/58478/1638551112-offerings-graphic.svg&quot;&gt;
&lt;LinkEmbed url=&quot;https://etcd.io&quot; title=&quot;etcd&quot; desc=&quot;A distributed, reliable key-value store for the most critical data of a distributed system&quot; image=&quot;https://etcd.io/favicon.png&quot;&gt;
&lt;p&gt;
  These services from a distributed cluster, will allow you to have a shared
  source of environmental configurations for all of your cluster nodes. This
  guarantees that changes in your system environment configurations will get
  distributed on all node everywhere.
&lt;/p&gt;
&lt;p&gt;
  &lt;a href=&quot;https://www.consul.io/&quot;&gt;Consul&lt;/a&gt; provides a web interface where you
  can manage these configurations easily, however in most cases developers will create
  a administration app for managing these feature flags.
&lt;/p&gt;
&lt;h2 id=&quot;the-final-bit-&quot;&gt;The final bit:&lt;/h2&gt;
&lt;p&gt;
  There are many other details I didn&#39;t yet cover in this story, like for
  example, how to override feature flags value per environment (some real world
  cases require you to have different config for a particular set of your app
  deployments based on geographical or other constraints). There are also some
  techniques to override feature flags based on the user&#39;s HTTP request, and
  more.  But I&#39;d like you to go ahead, do more research and dive deeper,
  knowledge about this topic is endless everywhere.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://martinfowler.com/articles/feature-toggles.html&quot;&gt;https://martinfowler.com/articles/feature-toggles.html&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;http://featureflags.io/feature-flags/&quot;&gt;http://featureflags.io/feature-flags/&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://en.wikipedia.org/wiki/Feature_toggle&quot;&gt;https://en.wikipedia.org/wiki/Feature_toggle&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
  That&#39;s all, thanks for reading devspedia, I love you, and see you the next
  time :)
&lt;/p&gt;
&lt;/LinkEmbed&gt;&lt;/LinkEmbed&gt;</description><pubDate>Sat, 30 Nov 2019 22:56:52 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/here-is-how-you-can-start-using-feature-flags-today/</guid>
    </item>
    <item>
      <title>Amazon Web Services (AWS) just introduced it&#39;s fully managed Quantum computing service &#39;Braket&#39;</title>
      <link>https://devspedia.com/aws-just-introduced-its-fully-managed-quantum-computing-service-braket/</link><description>&lt;p&gt;
  Hello everyone, welcome to a new devspedia story. Today we have some very
  exciting news; just hours ago Amazon&#39;s cloud computing service (&lt;a href=&quot;https://aws.amazon.com/&quot;&gt;AWS&lt;/a&gt;) introduced a new fully managed service that allows programmers and
  researchers from around the world to finally start experimenting with
  &lt;a href=&quot;https://en.wikipedia.org/wiki/Quantum_computing&quot;&gt;Quantum Computing&lt;/a&gt;. They called it &lt;a href=&quot;https://aws.amazon.com/braket/&quot;&gt;Braket&lt;/a&gt;!
&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;
  Earlier on Monday December 2nd 2019, AWS&#39;s release an &lt;a href=&quot;https://aws.amazon.com/about-aws/whats-new/2019/12/introducing-amazon-braket/&quot;&gt;official announcement&lt;/a&gt;
  introducing &lt;a href=&quot;https://aws.amazon.com/braket/&quot;&gt;Braket&lt;/a&gt;, their new
  fully managed service that helps you get started with quantum computing by
  providing a development environment to explore and design quantum algorithms,
  test them on simulated quantum computers, and run them on your choice of
  different quantum hardware technologies.
&lt;/p&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;
  In fact, that was kind of an unexpected move from AWS, specially other cloud
  computing giants such as Google, IBM, and Microsoft have been talking so much
  recently about their experiments and achievements with Quantum Computing, but
  none of them have released this to the public as a managed service, and during
  all this buzz, AWS was completely silent!
&lt;/p&gt;
&lt;figure class=&quot;image-fig-card&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/2_image_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
  &lt;figcaption&gt;
    &lt;a href=&quot;https://aws.amazon.com/braket/&quot;&gt;AWS Braket&lt;/a&gt;
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;
  Amazon Web Services (AWS) are not building their own Quantum Computing
  hardware tho, in fact, they&#39;re partnering with big names to offer hardware
  like:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    Gate based superconductor computers from &lt;a href=&quot;https://www.rigetti.com/&quot;&gt;Rigetti&lt;/a&gt;.
  &lt;/li&gt;
  &lt;li&gt;
    Quantum annealing superconductor computers from &lt;a href=&quot;https://www.dwavesys.com/&quot;&gt;D-Wave&lt;/a&gt;.
  &lt;/li&gt;
  &lt;li&gt;Ion trap computers from IonQ.&lt;/li&gt;
&lt;/ul&gt;
&lt;LinkEmbed url=&quot;https://www.rigetti.com&quot; title=&quot;Rigetti&quot; desc=&quot;Welcome to Quantum Cloud Services. The world&#39;s only quantum-first cloud platform. Start writing and testing programs on our quantum-classical hybrid computers today.&quot; image=&quot;https://www.rigetti.com/assets/img/logo-mark.svg&quot;&gt;
&lt;LinkEmbed url=&quot;https://ionq.com&quot; title=&quot;IonQ&quot; desc=&quot;We&#39;re building the world&#39;s best quantum computers to solve the world&#39;s hardest problems.&quot; image=&quot;https://ionq.com/static/ionq-logo-one-color-586a705c908b7095fd51efa0b63d8d62.svg&quot;&gt;
&lt;p&gt;
  The new service allows you to execute your quantum algorithm on your choice of
  quantum hardware, paying only for the time that you use, similar to most of
  their other cloud services.
&lt;/p&gt;
&lt;p&gt;
  Read the official announcement here: &lt;a href=&quot;https://aws.amazon.com/about-aws/whats-new/2019/12/introducing-amazon-braket/&quot;&gt;https://aws.amazon.com/about-aws/whats-new/2019/12/introducing-amazon-braket/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;Or view Braket product page here: https://aws.amazon.com/braket/&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;p&gt;Thanks for reading devspedia, I love you, and see you the next time!&lt;/p&gt;
&lt;/LinkEmbed&gt;&lt;/LinkEmbed&gt;</description><pubDate>Tue, 03 Dec 2019 00:21:03 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/aws-just-introduced-its-fully-managed-quantum-computing-service-braket/</guid>
    </item>
    <item>
      <title>Sorting algorithms, with visualizations and complexity comparisons</title>
      <link>https://devspedia.com/sorting-algorithms-with-visualizations-and-complexity-comparisons/</link><description>&lt;p&gt;
  Welcome everyone to a new story on devspedia. Today I&#39;ll showcase 8 sorting
  algorithms in JavaScript, with examples and complexity comparisons.
&lt;/p&gt;
&lt;hr&gt;
&lt;figure class=&quot;kg-card kg-embed-card&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/kPRA0W1kECg?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;Let&#39;s get straight to it. Below is a list of these sorting techniques:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Bubble Sort&lt;/li&gt;
  &lt;li&gt;Selection Sort&lt;/li&gt;
  &lt;li&gt;Insertion Sort&lt;/li&gt;
  &lt;li&gt;Heap Sort&lt;/li&gt;
  &lt;li&gt;Merge Sort&lt;/li&gt;
  &lt;li&gt;Quicksort&lt;/li&gt;
  &lt;li&gt;Shellsort&lt;/li&gt;
  &lt;li&gt;Radix Sort&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;bubble-sort-&quot;&gt;Bubble Sort:&lt;/h2&gt;
&lt;figure class=&quot;kg-card kg-embed-card kg-card-hascaption&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/6Gv8vg0kcHc?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
  &lt;figcaption&gt;Bubble Sort&lt;/figcaption&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Bubble sort works basically by iterating through the list while comparing list
  each adjacent pair of items in the list. If the order of these 2 items is
  invalid (based on whether you&#39;re sorting ascending or descending) then it
  swaps them.
&lt;/p&gt;
&lt;p&gt;
  It keeps repeating this same pattern over and over again until no extra
  swapping is necessary.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best case: &lt;code&gt;n&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst: &lt;code&gt;n&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average: &lt;code&gt;n&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;selection-sort-&quot;&gt;Selection Sort:&lt;/h2&gt;
&lt;figure class=&quot;kg-card kg-embed-card kg-card-hascaption&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/g-PGLbMth_g?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
  &lt;figcaption&gt;Selection Sort&lt;/figcaption&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Selection sort is has significant time complexity &lt;code&gt;O(&lt;em&gt;n&lt;/em&gt;&lt;sup&gt;2&lt;/sup&gt;)&lt;/code&gt; which makes it very slow for large lists. Selection sort works by doing in-place
  comparison, so it&#39;ll iterate through all items and compare them 1 to 1, then start
  over. It keeps repeating again no more replacing is necessary.
&lt;/p&gt;
&lt;p&gt;
  Selection sort is similar to insertion sort, however it performs worse.  But
  in some scenarios selection sort can perform well in low memory systems, and
  with smaller lists.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best: &lt;code&gt;n&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst: &lt;code&gt;n&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average: &lt;code&gt;n&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;insertion-sort-&quot;&gt;Insertion Sort:&lt;/h2&gt;
&lt;figure class=&quot;kg-card kg-embed-card kg-card-hascaption&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/lCzQvQr8Utw?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
  &lt;figcaption&gt;Insertion Sort&lt;/figcaption&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Insertion sort is — similar to previous selection sort — takes on item at a
  time too, it compares one item with it takes first item to the left, and
  compare it with the next item, then second item, and put before or after first
  item, then third item and compare it with second then first item and keep
  repeating this until all list is sorted.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best: &lt;code&gt;n&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst: &lt;code&gt;n&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average: &lt;code&gt;n&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;{ad-block}&lt;/p&gt;
&lt;h2 id=&quot;heap-sort-&quot;&gt;Heap Sort:&lt;/h2&gt;
&lt;figure class=&quot;kg-card kg-embed-card kg-card-hascaption&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/2DmK_H7IdTo?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
  &lt;figcaption&gt;Heap sort (using max heap)&lt;/figcaption&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Heap sort performs also runs on comparisons, but it&#39;s more efficient than
  selection or insertion sort because with every iteration it shrinks down the
  sortable scope of the list, resulting in fewer iterations until list is fully
  sorted.
&lt;/p&gt;
&lt;p&gt;
  It works by creating a max (or min) heap, and then take the top item of the
  heap tree and put it in the far right (if max heap) or far left (if min heap),
  and consider that number sorted, and then work only on the remaining items.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;merge-sort-&quot;&gt;Merge Sort:&lt;/h2&gt;
&lt;figure class=&quot;kg-card kg-embed-card kg-card-hascaption&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/KF2j-9iSf4Q?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
  &lt;figcaption&gt;Merge Sort&lt;/figcaption&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Merge sort is a divide and conquer algorithm. Merge sort works by splitting
  the list into halves, and further until each group is only at most 2 items.
  Then it keep merging and growing up again to the full length of the list.
&lt;/p&gt;
&lt;p&gt;
  The steps for sorting will be by splitting them into smaller groups, compare
  groups together, then merge sorted items to a bigger group, then compare, then
  merge, and keep repeating until all items are sorted.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;quick-sort-&quot;&gt;Quick Sort:&lt;/h2&gt;
&lt;figure class=&quot;kg-card kg-embed-card kg-card-hascaption&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/SLauY6PpjW4?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
  &lt;figcaption&gt;Quick sort&lt;/figcaption&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Quicksort is also a divide and conquer algorithm. It works by dividing the
  list into two smaller groups: group with lowest elements, and group with
  highest elements. It knows the lowest and highest elements by picking an item
  from the middle off the list, and grouping smaller values in 1 group, and
  higher values in another. Then quicksort can then recursively sort the the
  smaller groups by repeating the same steps.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst: &lt;code&gt;n&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;shell-sort-&quot;&gt;Shell sort:&lt;/h2&gt;
&lt;figure class=&quot;kg-card kg-embed-card kg-card-hascaption&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/ddeLSDsYVp8?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
  &lt;figcaption&gt;Shell sort&lt;/figcaption&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Quick sort is another in-place comparison sort algorithm. It works by sorting
  pairs of elements far apart from each other using an interval value for this
  distance that decreases while iterating, then progressively reducing the gap
  between elements to be compared. Starting with far apart elements, it can move
  some out-of-place elements into position faster than a simple nearest neighbor
  swap.
&lt;/p&gt;
&lt;p&gt;Check the following graphs for better explanation:&lt;/p&gt;
&lt;p&gt;
  Let us consider the following example to have an idea of how shell sort works.
  We take the same array we have used in our previous examples. For our example
  and ease of understanding, we take the interval of 4. Make a virtual sub-list
  of all values located at the interval of 4 positions. Here these values are {`{(35,14)}, {(33, 19)}, {(42, 27)} and {(10, 44)}`}
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-image-card&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/2_image-2_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
&lt;/figure&gt;
&lt;p&gt;
  We compare values in each sub-list and swap them (if necessary) in the
  original array. After this step, the new array should look like this:
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-image-card&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/2_image-3_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
&lt;/figure&gt;
&lt;p&gt;
  Then, we take interval of 1 and this gap generates two sub-lists - {`{(14, 27, 35, 42)}, {(19, 10, 33, 44)}`}
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-image-card&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/2_image-4_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
&lt;/figure&gt;
&lt;p&gt;
  We compare and swap the values, if required, in the original array. After this
  step, the array should look like this:
&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-image-card&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/2_image-5_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
&lt;/figure&gt;
&lt;p&gt;
  Finally, we sort the rest of the array using interval of value 1. Shell sort
  uses insertion sort to sort the array.
&lt;/p&gt;
&lt;p&gt;Following is the step-by-step depiction:&lt;/p&gt;
&lt;figure class=&quot;kg-card kg-image-card&quot;&gt;
  &lt;img src=&quot;https://firebasestorage.googleapis.com/v0/b/devspedia.com/o/2_image-6_1000x1000.webp?alt=media&quot; class=&quot;kg-image&quot; alt=&quot;&quot;&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best: &lt;code&gt;n log(n)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst: &lt;code&gt;n (log(n))2&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average: Depends on gap sequence&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;radix-sort-&quot;&gt;Radix Sort:&lt;/h2&gt;
&lt;figure class=&quot;kg-card kg-embed-card kg-card-hascaption&quot;&gt;
  &lt;iframe title=&quot;&quot; width=&quot;780&quot; height=&quot;570&quot; src=&quot;https://www.youtube.com/embed/XiuSW_mEn7g?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;
  &lt;figcaption&gt;Radix Sort&lt;/figcaption&gt;
&lt;/iframe&gt;&lt;/figure&gt;
&lt;p&gt;
  Radix sort is a non-comparative integer sorting algorithm that sorts data with
  integer keys by grouping keys by the individual digits which share the same
  significant position and value. A positional notation is required, but because
  integers can represent strings of characters (e.g., names or dates) and
  specially formatted floating point numbers, radix sort is not limited to
  integers.
&lt;/p&gt;
&lt;h3 id=&quot;what-does-radix-mean&quot;&gt;What does Radix mean?&lt;/h3&gt;
&lt;p&gt;
  In mathematical numeral systems, the radix or base is the number of unique
  digits, including the digit zero, used to represent numbers in a positional
  numeral system. For example, a binary system (using numbers 0 and 1) has a
  radix of 2 and a decimal system (using numbers 0 to 9) has a radix of 10.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Complexity: (k means the longest key) &lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best: &lt;code&gt;n * k&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst: &lt;code&gt;n * k&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average: &lt;code&gt;n * k&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://en.wikipedia.org/wiki/Bubble_sort&quot;&gt;https://en.wikipedia.org/wiki/Bubble_sort&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://en.wikipedia.org/wiki/Selection_sort&quot;&gt;https://en.wikipedia.org/wiki/Selection_sort&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://en.wikipedia.org/wiki/Insertion_sort&quot;&gt;https://en.wikipedia.org/wiki/Insertion_sort&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://en.wikipedia.org/wiki/Heapsort&quot;&gt;https://en.wikipedia.org/wiki/Heapsort&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://en.wikipedia.org/wiki/Merge_sort&quot;&gt;https://en.wikipedia.org/wiki/Merge_sort&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://en.wikipedia.org/wiki/Shellsort&quot;&gt;https://en.wikipedia.org/wiki/Shellsort&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://www.tutorialspoint.com/data_structures_algorithms/shell_sort_algorithm.htm&quot;&gt;https://www.tutorialspoint.com/data_structures_algorithms/shell_sort_algorithm.htm&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://en.wikipedia.org/wiki/Radix_sort&quot;&gt;https://en.wikipedia.org/wiki/Radix_sort&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://www.researchgate.net/figure/Simplistic-illustration-of-the-steps-performed-in-a-radix-sort-In-this-example-the_fig1_291086231&quot;&gt;https://www.researchgate.net/figure/Simplistic-illustration-of-the-steps-performed-in-a-radix-sort-In-this-example-the_fig1_291086231&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sorting&quot;&gt;https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sorting&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;Thanks for reading devspedia, I love you, and see you the next time :)&lt;/p&gt;
</description><pubDate>Thu, 05 Dec 2019 01:45:38 +0000</pubDate>
      <dc:creator>Islam Magdy</dc:creator>
      <guid>https://devspedia.com/sorting-algorithms-with-visualizations-and-complexity-comparisons/</guid>
    </item>
  </channel>
</rss>