<?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 Janardan Pethani on Medium]]></title>
        <description><![CDATA[Stories by Janardan Pethani on Medium]]></description>
        <link>https://medium.com/@jpethani11?source=rss-4b61badf89c0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*nVzVZ7zIGMNwf3WpnOmX-Q.jpeg</url>
            <title>Stories by Janardan Pethani on Medium</title>
            <link>https://medium.com/@jpethani11?source=rss-4b61badf89c0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:40:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jpethani11/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[React Lazy Loading Made easy]]></title>
            <link>https://medium.com/@jpethani11/react-lazy-loading-made-easy-f4d20f5060b8?source=rss-4b61badf89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4d20f5060b8</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[build]]></category>
            <category><![CDATA[suspense]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Janardan Pethani]]></dc:creator>
            <pubDate>Thu, 11 Jan 2024 04:51:20 GMT</pubDate>
            <atom:updated>2024-01-11T04:51:20.798Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZyelPPimG_1g04KX5wqW7Q.png" /><figcaption>Ref: <a href="https://petsitterfrederick.com/6-helpful-ways-to-make-a-lazy-cat-active/">https://petsitterfrederick.com/6-helpful-ways-to-make-a-lazy-cat-active/</a></figcaption></figure><p><strong>What is lazy loading?</strong></p><blockquote>As per the book: lets you defer (to delay) loading component’s code until it is rendered (until it is required) for the first time.</blockquote><blockquote><a href="https://react.dev/reference/react/lazy#reference">https://react.dev/reference/react/lazy#reference</a></blockquote><p><strong>Why lazy matters here?</strong></p><p>For bigger projects, there will be many components and third party libraries used at many different route/page. For production we don’t want to load every page/route at login page. (Common sense)</p><p>For this react introduced lazy loading of the components. To load only when it is required.</p><h3><strong>My approach to lazy loading.</strong></h3><p>I will explain using a code example.</p><h4>A util function to create a lazy load component.</h4><pre>// src/utils/lazyLoadFuncs.js<br>import { lazy } from &#39;react&#39;;<br><br>/**<br> * Function to return lazy loaded component with preload function<br> *<br> * @param {ReactNode} componentToimport<br> * @returns ReactNode<br> */<br>export function importWithPreload(componentToimport) {<br>  const Component = lazy(componentToimport);<br>  // Set component to preload key<br>  Component.preload = componentToimport;<br>  return Component;<br>}</pre><h4><strong>Main Page file</strong></h4><pre>import { Outlet, Route, Routes } from &#39;react-router-dom&#39;;<br><br>import SchoolLayout from &#39;../../layout/SchoolLayout/SchoolLayout&#39;;<br>import SchoolHome from &#39;./home/SchoolHome&#39;;<br>import StudentsPage from &#39;./students/StudentsPage&#39;;<br>import ReportsPage from &#39;./reports/ReportsPage&#39;;<br><br>const SchoolAccountWrapper = () =&gt; {<br>  return (<br>    &lt;SchoolLayout&gt;<br>      &lt;Outlet /&gt;<br>    &lt;/SchoolLayout&gt;<br>  );<br>};<br><br>const SchoolPages = () =&gt; {<br>  return (<br>    &lt;Routes&gt;<br>      &lt;Route element={&lt;SchoolAccountWrapper /&gt;}&gt;<br>        &lt;Route index path=&#39;/home&#39; element={&lt;SchoolHome /&gt;} /&gt;<br>        &lt;Route path=&#39;/students/*&#39; element={&lt;StudentsPage /&gt;} /&gt;<br>        &lt;Route path=&#39;/reports/*&#39; element={&lt;ReportsPage /&gt;} /&gt;<br>      &lt;/Route&gt;<br>    &lt;/Routes&gt;<br>  );<br>};<br><br>export default SchoolPages;</pre><h4>Lazy Routes file</h4><pre>// src/routes/lazyComponents.jsx<br>import { importWithPreload } from &#39;../utils/lazyLoadFuncs&#39;;<br><br>//* School<br>export const SchoolPages = importWithPreload(() =&gt;<br>  // webpackChunkName: To give chunk a specific name instead a random generated one<br>  import(/* webpackChunkName: &#39;SchoolPages&#39; */ &#39;../pages/school/SchoolPages&#39;),<br>);<br>export const RegisterSchool = importWithPreload(() =&gt;<br>  import(/* webpackChunkName: &#39;RegisterSchool&#39; */ &#39;../pages/school/registration/RegisterSchool&#39;),<br>);<br><br><br>/**<br> * Function to preload chunk<br> */<br>export const fetchSchoolPages = () =&gt; {<br>  SchoolPages.preload();<br>};<br><br>export const fetchRegisterSchool = () =&gt; {<br>  RegisterSchool.preload();<br>};<br></pre><h4>Component for Suspense with spinner</h4><pre>// src/components/LazyLoadPage.jsx<br>import React, { Suspense } from &#39;react&#39;;<br>import Spinner from &#39;./Spinner&#39;;<br><br>const LazyLoadPage = ({ component }) =&gt; {<br>  return &lt;Suspense fallback={&lt;Spinner open /&gt;}&gt;{component}&lt;/Suspense&gt;;<br>};<br><br>export default LazyLoadPage;</pre><h4>Main Route file</h4><pre>// src/AppRoutes.jsx<br>import React from &#39;react&#39;;<br>import { Route, Routes } from &#39;react-router-dom&#39;;<br><br>import LazyLoadPage from &#39;./components/LazyLoadPage&#39;;<br><br>import SignIn from &#39;./pages/auth&#39;;<br>import { OrderSummary, RegisterSchool, ParentPages, SchoolPages } from &#39;./routes/lazyComponents&#39;;<br><br>const RouteProvider = () =&gt; {<br>  return (<br>    &lt;Routes&gt;<br>      &lt;Route path=&#39;/&#39; element={&lt;SignIn signin={false} /&gt;} /&gt;<br>      &lt;Route path=&#39;/register-school&#39; element={&lt;LazyLoadPage component={&lt;RegisterSchool /&gt;} /&gt;} /&gt;<br>      &lt;Route path=&#39;/school/*&#39; element={&lt;LazyLoadPage component={&lt;SchoolPages /&gt;} /&gt;} <br>    &lt;/Routes&gt;<br>  );<br>};<br><br>export default RouteProvider;</pre><h4>Pre-loading before school pages requirement</h4><pre>import React, { useEffect, useState } from &#39;react&#39;;<br>import { fetchSchoolPages } from &#39;../../routes/lazyComponents&#39;;<br><br>const ChooseAccount = () =&gt; {<br><br>  useEffect(() =&gt; {<br>    fetchSchoolPages();<br>  }, []);<br>  <br>  return (<br>    ...<br>  )<br>}</pre><p>After generating build. Above config looks like as below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*FIQ2sxIWIxh2xG5DM9mKvw.png" /></figure><p>So, Above approach gives you flexibility to load as per your choice. Other than this react doc also gives simple way for lazy load: <a href="https://react.dev/reference/react/Suspense">https://react.dev/reference/react/Suspense</a>.</p><p>Thanks for reading :).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4d20f5060b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rod cutting using Dynamic Programming.]]></title>
            <link>https://medium.com/@jpethani11/rod-cutting-using-dynamic-programming-b13bb1d858e?source=rss-4b61badf89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b13bb1d858e</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[rod-cutting]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Janardan Pethani]]></dc:creator>
            <pubDate>Sun, 01 Sep 2019 17:18:20 GMT</pubDate>
            <atom:updated>2019-09-01T17:21:19.684Z</atom:updated>
            <content:encoded><![CDATA[<h3>Suppose you have a rod of length n, and you want to cut up the rod and sell the pieces in a way that maximizes the total amount of money you get. A piece of length i is worth pi.</h3><p>as a example..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*GqEb7fo-MliZYyfNFnjb9Q.png" /><figcaption><a href="https://web.stanford.edu/class/archive/cs/cs161/cs161.1168/lecture12.pdf">https://web.stanford.edu/</a> <a href="https://web.stanford.edu/class/archive/cs/cs161/cs161.1168/lecture12.pdf">https://web.stanford.edu/class/archive/cs/cs161/cs161.1168</a> -pdf</figcaption></figure><p>For example, if you have a rod of length 4, there are eight different ways to cut it, and the best strategy is cutting it into two pieces of length 2, which gives you 10.</p><p><strong>So</strong> our main question or intention is How many ways are there to cut up a rod of length n?</p><p>2 ^n−1 , because there are n − 1 places where we can choose to make cuts, and at each place, we either make a cut or we do not make a cut.</p><p>A simple solution for this problem is to generate all configurations of different pieces and find the highest priced configuration. like First we try cutting a piece of length 1, and combining it with the optimal way to cut a rod of length n − 1. Then we try cutting a piece of length 2, and combining it with the optimal way to cut a rod of length n − 2. We try all the possible lengths and then pick the best one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*xy99A66rvY90Ox4n_nsHIg.png" /><figcaption>The recursion Tree for rod of length 4.</figcaption></figure><p>From the Tree, we can see that multiple same calculation is done to find solution. This can be optimized by DP.</p><p><strong>Bottom up approach </strong>: Here we proactively compute the solutions for smaller rods first, knowing that they will later be used to compute the solutions for larger rods. Recomputations of same sub-problems can be avoided by constructing a temporary array val[] in bottom up manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*uXQIoL9qKHTei99_IEmhKA.png" /><figcaption>Algorithm for bottom-up approach.</figcaption></figure><p>Time complexity required for this Algorithm is o(n*n).</p><p><strong>CODE :</strong></p><p>// A Dynamic Programming solution for Rod cutting problem <br>#include&lt;stdio.h&gt; <br>#include&lt;limits.h&gt;</p><p>// A utility function to get the maximum of two integers <br>int max(int a, int b) { return (a &gt; b)? a : b;}</p><p>/* Returns the best obtainable price for a rod of length n and <br>price[] as prices of different pieces */<br>int cutRod(int price[], int n) <br>{ <br>int val[n+1]; <br>val[0] = 0; <br>int i, j;</p><p>// Build the table val[] in bottom up manner and return the last entry <br>// from the table <br>for (i = 1; i&lt;=n; i++) <br>{ <br> int max_val = INT_MIN; <br> for (j = 0; j &lt; i; j++) <br> max_val = max(max_val, price[j] + val[i-j-1]); <br> val[i] = max_val; <br>}</p><p>return val[n]; <br>}</p><p>/* Driver program to test above functions */<br>int main() <br>{ <br> int arr[] = {1, 5, 8, 9, 10, 17, 17, 20,24,30}; <br> int size = sizeof(arr)/sizeof(arr[0]); <br> printf(“Maximum Obtainable Value is %dn”, cutRod(arr, size)); <br> getchar(); <br> return 0; <br>}</p><p>reference : www.geeksforgeeks.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b13bb1d858e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Assembly Line Scheduling?]]></title>
            <link>https://medium.com/@jpethani11/what-is-assembly-line-scheduling-1573d563fcb9?source=rss-4b61badf89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1573d563fcb9</guid>
            <category><![CDATA[assembly-line-scheduling]]></category>
            <category><![CDATA[assembly-line]]></category>
            <category><![CDATA[scheduling]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Janardan Pethani]]></dc:creator>
            <pubDate>Thu, 29 Aug 2019 16:41:14 GMT</pubDate>
            <atom:updated>2019-09-06T03:23:59.925Z</atom:updated>
            <content:encoded><![CDATA[<p>We know that in automobile industry, automobiles are produced using assembly lines. There are multiple lines that are working together to produce products. Then a finished auto exits at the end of the line.</p><p><strong>T</strong>he<strong> </strong>problem is that which line we should choose next from any station that will give best time utilization for company for one auto.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/0*NIpgZoovGG6e-4dS.jpg" /><figcaption>image from <a href="http://problem-g.estad.ucm.es/"><strong>http://problem-g.estad.ucm.es</strong></a></figcaption></figure><p><strong>The main goal </strong>of assembly line scheduling is to give best route or can say fastest from all assembly line.</p><p>In above the diagram we have two main assembly line consider as LINE 1 and LINE 2.</p><ul><li>e[i]: entry time in assembly line i [here i=1,2]</li><li>x[i]: exit time from assembly line i</li><li>a[i,j]: Time required at station S[i,j] (assembly line i, stage j)[i=1 to n] because Every station has some dedicated job that needs to done.</li><li>t[i,j]: Time required to transit from station S[i,j] to the other assembly line.</li></ul><p>Normally, once a chassis enters an assembly line, it passes through that line only. The time to go from one station to the next within the same assembly line is negligible.</p><p>Occasionally, a special rush order comes in, and the customer wants the automobile to be manufactured as quickly as possible. For the rush orders, the chassis still passes through the n stations in order, but the factory manager may switch the partially-completed auto from one assembly line to the other after any station.</p><p>To get jobs done we will use Dynamic Programming.</p><p><strong>Objective: </strong>To find the optimal scheduling i.e., the fastest way from start to exit.</p><p><strong><em>Note</em></strong>: let <strong>f</strong>i [j] denotes the fastest way from start to station S[i,j] .</p><h4><strong>*</strong> An optimal solution to a problem is determined using optimal solutions to sub problems (in turn, sub sub problems and so on). The immediate question is, how to break the problem in to smaller sub problems ?</h4><p><strong>The answer is</strong> : if we know the minimum time taken by the chassis to leave station S[i,j−1] then the minimum time taken to leave station S[i,j] can be calculated quickly by combining a[i,j] and t[i,j] .</p><p><strong>Final Solution:</strong> f o<em>ptimal</em> = min{f1[n] + x1, f2[n] + x2}.</p><p>we can take<strong> </strong>f1[1] = e1 + a[1,1] and f2[1] = e2 + a[2,1].</p><p><strong><em>Recursive Solution: </em></strong>The chassis at station S[1,j] can come either from station S[1,j−1] or station S[2,j−1] (Since, the tasks done by S[1,j] and S[2,j] are same). But if the chassis comes from S[2,j−1], it additionally incurs the transfer cost to change the assembly line ( like t[2,j-1] ). Thus, the recursion to reach the station j in assembly line i are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*Bn7g0Du3IABMzd_qz13G-A.png" /><figcaption>from<strong> </strong><a href="http://www.iiitdm.ac.in/"><strong>http://www.iiitdm.ac.in</strong></a></figcaption></figure><h4><strong>-&gt;Algorithm for Assembly line scheduling :</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*2IiybexcQGmCfdXhKCxqeg.png" /><figcaption>from<strong> </strong><a href="http://www.iiitdm.ac.in/"><strong>http://www.iiitdm.ac.in</strong></a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*_qH4sRbHcb70Q1_yuDy0Jg.png" /><figcaption>from <a href="http://www.nhu.edu.tw/~chun/DS(II)-Ch13-GreedyAlgorithm&amp;DynamicProgram.pdf"><strong>http://www.nhu.edu.tw</strong></a><strong> </strong><a href="http://www.nhu.edu.tw/~chun/DS(II)-Ch13-GreedyAlgorithm&amp;DynamicProgram.pdf"><strong>http://www.nhu.edu.tw/~chun/DS(II)-Ch13-GreedyAlgorithm&amp;DynamicProgram.pdf</strong></a></figcaption></figure><p>Explanation of algorithm:</p><p>If as discussed above we consider 2 assembly line. Then f1[1] and f2[1] is defined as algorithm by adding starting cost and first station cost.</p><p>Then applies our recursive solution for n station points.here l1[j] denotes from which assembly line chassis has come.</p><p>At the last <strong>f<em>opt</em></strong> gives you final solution.</p><p>The<strong> time complexity</strong> of the above dynamic programming implementation of the assembly line scheduling problem is <strong>O(n)</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1573d563fcb9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>