<?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[Engineering at Classpro - Medium]]></title>
        <description><![CDATA[How we work at Classpro - Medium]]></description>
        <link>https://medium.com/classpro-tech-blog?source=rss----45925fcd9b5c---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Engineering at Classpro - Medium</title>
            <link>https://medium.com/classpro-tech-blog?source=rss----45925fcd9b5c---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:14:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/classpro-tech-blog" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to use Stimulus in your Rails App]]></title>
            <link>https://medium.com/classpro-tech-blog/how-to-use-stimulus-in-your-rails-app-82f9dc6fde8c?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/82f9dc6fde8c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[stimulus]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Tejasvi Raut]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 10:45:19 GMT</pubDate>
            <atom:updated>2018-11-12T10:45:19.492Z</atom:updated>
            <content:encoded><![CDATA[<p>Stimulus binds events to the HTML elements just by specifying attributes in the HTML elements. The stimulus has helped me to build cleaner and reusable code.</p><p>Consider building a rails app, you have to filter data on different index pages all over your app. To do so you have to bind DOM elements to your javascript events and write javascript functions for each index page. The conventional way would be to create index.js and write javascript functions for each index page. While the functional logic remains same in all index.js files. That leads to redundant code.</p><p>To reuse code and easily bind elements we can use Stimulus. To integrate Stimulus with or without web packer use this <a href="https://stimulusjs.org/handbook/introduction">link</a>.</p><p>Stimulus is a small framework revolving around just three main concepts: Controllers, actions, and targets.</p><p><strong>Controllers</strong>: Stimulus’ purpose is to connect DOM elements to JavaScript objects. Those objects are called <em>controllers</em>.</p><p><strong>Actions</strong>: The <em>action</em> which is to be performed on some event triggered.</p><p><strong>Targets</strong>: DOM Element on which the change is to be reflected. The change can be in its attribute or value, we can access these <em>target</em> elements in our controller.</p><p>Let&#39;s start with our search filter example, we will first create a filter controller under app/javascripts/controllers/filters_controller.js:</p><pre>import { Controller } from &quot;stimulus&quot;;<br>import _ from &quot;lodash&quot;;</pre><pre>export default class extends Controller {<br>  static targets = [&quot;submit&quot;];</pre><pre>  debouncedSubmit = _.debounce(this.submit, 500);</pre><pre>  submit() {<br>    this.submitTarget.click();<br>  }</pre><pre>  onSearchKeyup() {<br>    this.debouncedSubmit();<br>  }<br>}</pre><p>Well, this is a hell lot of code here. We will understand it in chunks later. First, let’s check how will we connect this to our DOM element.</p><p>It is as simple as adding data-controller attribute with the value of our controller name that is “<em>filters</em>” in our case. We have connected our controller to our filter form element, you can check the following snippet.</p><pre>= form_with( url: students_path, method: &#39;get&#39;, data: { controller: &#39;filters&#39; }) do |form|</pre><pre>  = form.text_field :search, placeholder: &#39;Search&#39;, data: { action: &#39;keyup-&gt;filters#onSearchKeyup&#39; }</pre><pre>  = form.submit &#39;Search&#39;, name: nil, class: &#39;d-none&#39;, data: { target: &#39;filters.submit&#39; }</pre><p>As we have connected our controller to our DOM element we are ready to go.</p><p>Now we have to add an action on which we want our filter to work. We may trigger it on key press (Enter key: using code 13) or on key up. Here I have demonstrated it on key up. We have to set data-action attribute with setting its value to “<em>action-&gt;controller-name#invoking-function</em>” on our search text-field as demonstrated in above snippet. This will trigger the <em>onSearchKeyup()</em> on every key up.</p><p>In our <em>onSearchKeyup()</em> we have called <em>debouncedSubmit()</em> which in return submits after every 500ms. I have used <a href="https://lodash.com/">Lodash</a> <a href="https://lodash.com/docs/4.17.11#debounce">debounce</a> method that delays invoking function until after wait milliseconds have elapsed since the last time the debounced function was invoked.</p><p>The <em>submit()</em> which is passed as an argument to debounce function triggers the click event of our submit button of the filter form which is our submit target. We set it by setting data-target attribute to “<em>controller-name.target-name</em>”. You need to include index.js in which you need to update the list.</p><p>Stimulus helps the code to be reusable and maintainable. We can connect this controller to all search fields in our rails app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82f9dc6fde8c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/how-to-use-stimulus-in-your-rails-app-82f9dc6fde8c">How to use Stimulus in your Rails App</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Render Latex  in React using Mathjax]]></title>
            <link>https://medium.com/classpro-tech-blog/render-latex-in-react-using-mathjax-f9742504678?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/f9742504678</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[latex]]></category>
            <category><![CDATA[mathjax]]></category>
            <dc:creator><![CDATA[Nikil Arigela]]></dc:creator>
            <pubDate>Fri, 09 Nov 2018 10:37:36 GMT</pubDate>
            <atom:updated>2018-11-09T10:37:36.251Z</atom:updated>
            <content:encoded><![CDATA[<h3>Render Latex in React using Mathjax</h3><p>The simple way to render Latex in React using Mathjax is to add Mathjax Configuration in the <strong>index.html</strong> file under <strong>Javascript script </strong>tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_T-ha0RSrHYO1JU3GAerrg.png" /></figure><p>But the problem arises when the DOM updates, the Mathjax doesn’t render.</p><p>Mathjax provides a solution to our problem with <strong>Mathjax Hub Queue</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*dQMTGBgsprE-siZqBXljZg.png" /></figure><p>In React, the above snippet goes in <strong>componentDidUpdate()</strong>.</p><p>The better way is to create reusable component and wrap it at High Level Hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NLsNrXExAuPoIfM7laZVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kNk7lZ0p1X1PMS2WonZTPA.png" /></figure><p>The above code creates a reusable <strong>Latex </strong>component and we have wrapped it at a higher level hierarchy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9742504678" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/render-latex-in-react-using-mathjax-f9742504678">Render Latex  in React using Mathjax</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Authentication Flow with flutter]]></title>
            <link>https://medium.com/classpro-tech-blog/building-authentication-flow-with-flutter-29b6924da8fd?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/29b6924da8fd</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Aravind]]></dc:creator>
            <pubDate>Fri, 13 Apr 2018 06:13:23 GMT</pubDate>
            <atom:updated>2019-01-18T18:53:47.388Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FaFIryZm_bjg%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DaFIryZm_bjg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FaFIryZm_bjg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b99f5a23c2a66fe2bf1204c84f57d617/href">https://medium.com/media/b99f5a23c2a66fe2bf1204c84f57d617/href</a></iframe><blockquote>Note: visit <a href="https://authflow.herokuapp.com/">https://authflow.herokuapp.com</a> and sign up.</blockquote><ol><li>Login or Authenticate API endpoint. <a href="https://authflow.herokuapp.com/api/v1/auth_user">https://authflow.herokuapp.com/api/v1/auth_user</a></li></ol><pre>$ sudo apt install jq # optional for json format <br>$ curl -d &quot;<a href="/service/mailto:email=aravind@classpro.in">email=your@</a>email.com&amp;password=password&quot; -X POST <a href="https://authflow.herokuapp.com/api/v1/auth_user">https://authflow.herokuapp.com/api/v1/auth_user</a> | jq</pre><pre># response<br>{<br>  &quot;auth_token&quot;: &quot;eyJ0eXAiOiJKV1QiLCJhbGciOijIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.mmDWpUjOz6jC9zdcpfuL6DyLc9siLWyLiBAzSHndo5I&quot;,<br>  &quot;user&quot;: {<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Aravind&quot;<br>  }<br>}</pre><p>2. User or Home API endpoint.</p><pre>$ aravind@dell:~$ curl -H &quot;Authorization:eyJ0eXAiOiJKV1QiLCJhbGciOijIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.mmDWpUjOz6jC9zdcpfuL6DyLc9siLWyLiBAzSHndo5I&quot; -X GET <a href="https://authflow.herokuapp.com/api/v1/home">https://authflow.herokuapp.com/api/v1/home</a> | jq</pre><pre>#response<br>{<br>  &quot;id&quot;: 1,<br>  &quot;email&quot;: &quot;<a href="/service/mailto:aravind@classpro.in">aravind@classpro.in</a>&quot;,<br>  &quot;created_at&quot;: &quot;2018-04-10T13:27:34.319Z&quot;,<br>  &quot;updated_at&quot;: &quot;2018-04-13T04:30:13.999Z&quot;<br>}</pre><p>Source code @ <a href="https://github.com/Aravind99/auth_flow">https://github.com/vemarav/auth_flow</a>.</p><p>App available on <a href="https://play.google.com/store/apps/details?id=com.aravind.authflow&amp;hl=en">Play Store</a>.</p><p>Let’s get started.</p><h3>Clone the repository</h3><pre>$ git clone https://github.com/vemarav/auth_flow.git</pre><h4>Login Page</h4><p>open the file at lib/app/pages/login_page.dart.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62a8a38c7304d9eb9915617f4b69cbdf/href">https://medium.com/media/62a8a38c7304d9eb9915617f4b69cbdf/href</a></iframe><p>We will focus on only two cases</p><ol><li>If user logged in then navigate to home page/screen.</li></ol><p>In Snippet 1.01, on line 38 <strong>LoginPageState#_fetchSessionAndNavigate </strong>in this method we are fetching user authToken.</p><p>If the authToken already present then we need to redirect the user to the <strong>HomePage</strong>. Otherwise, the user will log in manually.</p><pre>Navigator.of(context).pushReplacementNamed(&#39;route&#39;)<br># This will replace the current stack page/screen with the given &#39;route&#39; page/screen.</pre><p>2. Authenticate user.</p><p>In snippet 1.01, on line 59 <strong>LoginPageState#_authenticateUser </strong>in this method we do network request and based on the response we redirect user to HomePage or we show the problem occurred while network request.</p><p>I have separated the network request logic from the views using network_utils.dart(class NetworkUtils). currently, it solves my problem. If you have a better approach do drop a comment below.</p><p>Here is my NetworkUtils class.</p><p>file at lib/app/utils/network_utils.dart</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbfbb878297ec3a46f4188aeaf82fcac/href">https://medium.com/media/dbfbb878297ec3a46f4188aeaf82fcac/href</a></iframe><p>In snippet 1.02, on line 12 <strong>NetworkUtils#authenticateUser </strong>method will return the response. I have used the <a href="https://pub.dartlang.org/packages/http">http</a> plugin for network requests.</p><p>AuthUtils class has the key strings to store and retrieve the values from shared preferences.</p><p>Here is AuthUtils snippet.</p><p>file at lib/app/utils/auth_utils.dart</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab100417e981af876a85abb10071735c/href">https://medium.com/media/ab100417e981af876a85abb10071735c/href</a></iframe><p>Let&#39;s see HomePage</p><p>file at lib/app/pages/home_page.dart</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0d3add7cb4ade3d1cc4200779548a5b/href">https://medium.com/media/d0d3add7cb4ade3d1cc4200779548a5b/href</a></iframe><p>In snippet 1.04, on line 30 <strong>_HomePageState#_fetchSessionAndNavigate</strong> in this method we fetch the authToken and using authToken we perform async network request in <strong>_HomePageState#_fetchHome </strong>if the user is authorized then we set the state of<strong> _homeResponse </strong>to the response we obtained.</p><p>If the authToken is null then the user will be navigated to the login screen.</p><p>That’s it.</p><p>Now explore my <a href="http://github.com/vemarav/auth_flow"><strong>repository</strong></a> to learn more. If you have any suggestions or improvements do drop the comment.</p><p>Build some great stuff and comment below about what you did.</p><p>If you like the article, express with claps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29b6924da8fd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/building-authentication-flow-with-flutter-29b6924da8fd">Building Authentication Flow with flutter</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter 2: Dynamic Drawer List, Stateful Widgets, Forms and Validation]]></title>
            <link>https://medium.com/classpro-tech-blog/flutter-2-dynamic-drawer-list-stateful-widgets-forms-and-validation-6389fc625d2e?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/6389fc625d2e</guid>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Aravind]]></dc:creator>
            <pubDate>Sat, 24 Feb 2018 11:37:04 GMT</pubDate>
            <atom:updated>2018-10-25T08:20:20.020Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQ497zwrgek_7bvAaTxkDA.jpeg" /><figcaption>image 2.01 Made with ❤️ Flutter</figcaption></figure><p>We have completed implementation of <a href="https://engineering.classpro.in/flutter-1-navigation-drawer-routes-8b43a201251e">Navigation Drawer and Routing</a> in the previous article. In this article we will see implementation of <strong>Dynamic Drawer List, Stateful Widgets, Forms and Validation</strong>. see video 2.01 for Final snapshot</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fl2hKJQFIuWI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dl2hKJQFIuWI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fl2hKJQFIuWI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c7d26954b5a332fd33d788c892c0429/href">https://medium.com/media/6c7d26954b5a332fd33d788c892c0429/href</a></iframe><h4>Index</h4><p><a href="https://engineering.classpro.in/flutter-1-navigation-drawer-routes-8b43a201251e">Flutter 1: Navigation Drawer and Routing</a></p><p>Flutter 2: Dynamic Drawer List, Stateful Widgets, Forms and Validation</p><p>In previous article, we changed the lib/main.dart itself. But it will be tedious to do all the work in single file for large projects. so I have divided them into respective files. And below is my lib directory(image 2.02).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*7pSBT1aPBRPT3wcWAJsKDA.png" /><figcaption>image 2.02 split files</figcaption></figure><p>We will focus on keeper_drawer.dart and label_form.dart .</p><p>Tip: I recommend you to checkout my Github Repo at <a href="https://github.com/Aravind99/keeper">https://github.com/Aravind99/keeper</a>.</p><h4>2.1 Dynamic Drawer List</h4><p>Let’s see what lies in KeeperDrawer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7baa6087d568349c0b169b69e048b571/href">https://medium.com/media/7baa6087d568349c0b169b69e048b571/href</a></iframe><p>On line no. <a href="https://github.com/Aravind99/keeper/blob/2.01_add_label_form-Solution/lib/views/keeper_drawer.dart#L12">1</a>1 KeeperDrawer constructor accepts the labels as a List&lt;String&gt;. So, that we can iterate through them to build our dynamic drawer list. visit <a href="https://www.dartlang.org/resources/dart-tips/dart-tips-ep-11">here</a>(<a href="https://www.dartlang.org/resources/dart-tips/dart-tips-ep-11">https://www.dartlang.org/resources/dart-tips/dart-tips-ep-11</a>) to know more about constructor viz. explained by <a href="https://medium.com/u/959963b55d43">Seth Ladd</a>.</p><p>Then in <a href="https://github.com/Aravind99/keeper/blob/2.01_add_label_form-Solution/lib/views/keeper_drawer.dart#L113">KeeperDrawer#_buildLabelWidgets</a> (see line no. 112, snippet 2.01), we iterate through the labels passed to constructor to build List&lt;Widget&gt; .</p><p>In KeeperDrawer#_buildDrawerList we add widgets to build our list.</p><h4>2.2 Stateful Widgets</h4><p>A widget that has mutable state.</p><p>State is information that</p><p>(1) can be read synchronously when the widget is built.</p><p>(2) Might change during the lifetime of the widget. It is the responsibility of the widget implementer to ensure that the <a href="https://docs.flutter.io/flutter/widgets/State-class.html">State</a> is promptly notified when such state changes, using <a href="https://docs.flutter.io/flutter/widgets/State/setState.html">State.setState</a>. Refer <a href="https://docs.flutter.io/flutter/widgets/StatefulWidget-class.html">docs here</a>.</p><p>Lets’s see LabelForm Stateful Widget</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c48dbb58ec5c965a02eee30732756298/href">https://medium.com/media/c48dbb58ec5c965a02eee30732756298/href</a></iframe><p>we will discuss on <strong>Keypoints</strong> rather how it is implemented.</p><ol><li><a href="https://github.com/Aravind99/keeper/blob/2.01_add_label_form-Solution/lib/views/label_form.dart#L12">_scaffoldKey</a> (a specific widget key for Scaffold in #build at <a href="https://github.com/Aravind99/keeper/blob/2.01_add_label_form-Solution/lib/views/label_form.dart#L23">line no. 23</a>)</li></ol><p>Defining key for the widget provides the following features or may be more.</p><pre>i. currentContext<br>_scaffoldKey has a  field named <strong>currentContext</strong>,with which you can access current context of the Scaffold widget and perform operations which are based on <strong>context.<br></strong>Example:<br>Navigator.of(_scaffoldKey.currentContext).pushNamed(routeName);</pre><pre><br>ii. currentState<br>_scaffoldKey has a field named <strong>currentState, </strong>with the use of <strong>currentState</strong> we can show Snackbar or close Drawers and many more.<br>Example:<br>a. _scaffoldKey.currentState.openDrawer()<br>b. _scaffoldKey.currentState.closeDrawer()</pre><p>2. <a href="https://docs.flutter.io/flutter/widgets/State/initState.html">initState()</a> (must call super.initState())</p><p>The framework will call this method exactly once for each <a href="https://docs.flutter.io/flutter/widgets/State-class.html">State</a> object it creates.</p><p>Override this method to perform initialization of objects that are relevent to State of the given Widget in Widget tree.</p><p>3. <a href="https://docs.flutter.io/flutter/widgets/State/setState.html">setState()</a></p><p>Notify the widget that the State of objects changes in setState callback.</p><pre>_editLabelAt(index) {<br>  setState(() {<br>    _updateController.clear(); // clears text and sets to empty text<br>    updateError = null;        // error set to null<br>    _buildLabels(index);       // Rebuild the labels<br>  }); <br>}</pre><p>4. <a href="https://docs.flutter.io/flutter/widgets/State/dispose.html">dispose()</a></p><p>Called when object is removed from widget tree that never build again.</p><h4>2.3 Forms and Validation</h4><p>Here I have used only <a href="https://docs.flutter.io/flutter/material/TextField-class.html"><strong>TextField</strong></a><strong> </strong>. To build complex forms with validators(as callbacks) consider Form widget, to know more you can visit <a href="https://flutter.io/widgets/input/">https://flutter.io/widgets/input</a>/.</p><p>I have created methods for <a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> operations to update the label value. Since, <strong>labels </strong>is a Global Variable (not recommended for use in production) we can directly change it’s values. Based on index(replaced with SQL id in future) we are performing <a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> operations. <strong>The code snippet 2.02 can be improved by using </strong><strong>ListTile as Stateful Widget by which we can toggle between </strong><strong>Text and TextField widget. </strong>Using ListTile Stateful widget we can avoid iterate through each label in LabelForm#_buildLabels.</p><p>To apply theme for any widget, pass the target widget as a child to Theme widget.</p><pre>new Theme(<br>  data: new ThemeDate(...),<br>  child: new Text(...)<br>)</pre><h4>Summary</h4><p>Prompting user what went wrong while doing CRUD operations makes the app intuitive and user friendly. Dynamic Drawer List provides easy way to filter out content which is most frequently done by user.</p><p>In next article we will implement <a href="https://www.sqlite.org/index.html">SQLite</a> Database using <a href="https://pub.dartlang.org/packages/sqflite">sqflite</a> plugin and Form Widget.</p><p>If you have any suggestions, improvements or found any mistakes do drop a comment.</p><p>If you like the article please click the clap 👏 button as a appreciation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6389fc625d2e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/flutter-2-dynamic-drawer-list-stateful-widgets-forms-and-validation-6389fc625d2e">Flutter 2: Dynamic Drawer List, Stateful Widgets, Forms and Validation</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter 1: Navigation Drawer & Routes]]></title>
            <link>https://medium.com/classpro-tech-blog/flutter-1-navigation-drawer-routes-8b43a201251e?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/8b43a201251e</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Aravind]]></dc:creator>
            <pubDate>Thu, 15 Feb 2018 11:21:20 GMT</pubDate>
            <atom:updated>2018-11-16T11:09:42.984Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*e8_kRq_NyQc011hMO_nFaA.gif" /><figcaption>image 1.01 Final Snapshot</figcaption></figure><p>This is the first part of Keeper. Keeper is a simple app to capture quickly what’s on your mind. I mean a simple notes app. we will also see how to create an offline app with <a href="https://www.sqlite.org/">SQLite</a> as backend and then we will implement <a href="https://firebase.google.com/docs/database/">Firebase Realtime Database</a> . After that we will implement Reminder feature to our mobile app to learn Push Notification.</p><p><em>Note 1: Keeper is clone of Google Keep App 😉.</em></p><p><em>Note 2: Remaining posts will be available soon.</em></p><p><em>Tip 1: I have created a </em><a href="https://github.com/aravind99/keeper"><em>github repo</em></a><em> with branch wise Exercise and Solution.</em></p><p>Prerequisites for this article are Basic knowledge in object oriented programming language. If you have developed any mobile application then you will find it much easier.</p><p>Before, we go on I will give you a small introduction on Flutter. Flutter is mobile application development<a href="https://flutter.io/"> SDK</a> to build cross platform apps for <strong>Android</strong> and <strong>iOS. </strong><a href="https://en.wikipedia.org/wiki/Google_Fuchsia"><strong>Fuschia</strong></a><strong> </strong>is also in list but currently being developed by Google<strong>. </strong>Flutter is a Reactive framework just like<a href="https://reactjs.org/"> React</a>. To know more about flutter visit <a href="https://flutter.io/">https://flutter.io</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*-KIRMN5WiEiSlOs2EpHt8g.png" /><figcaption>image 1.02 <a href="https://flutter.io/widgets-intro/">Flutter Introduction on https://flutter.io</a></figcaption></figure><h4>Index</h4><ol><li>Flutter 1: Navigation Drawer &amp; Routes</li><li><a href="https://medium.com/@vemula.aravind336/flutter-2-dynamic-drawer-list-stateful-widgets-forms-and-validation-6389fc625d2e">Flutter 2: Dynamic Drawer List, Stateful Widgets, Forms and Validation</a></li></ol><p>Lets implement Navigation Drawer.</p><h4><strong>1.1 Navigation Drawer</strong></h4><p>I have skipped the installation part. To install flutter, visit <a href="https://flutter.io/setup/">here</a>, select operating system and follow the steps.</p><p>We will write most of our code into lib directory. To get started just comment out code in test/widget_test.dart<em> or delete it. As shown</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43cd7cb6616504a5906cd7f04d3de38e/href">https://medium.com/media/43cd7cb6616504a5906cd7f04d3de38e/href</a></iframe><p>Next Remove all the code in lib/main.dart and write the code shown in below snippet 1.02 in lib/main.dart.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f02107cf27bb2a108206f0a778417c25/href">https://medium.com/media/f02107cf27bb2a108206f0a778417c25/href</a></iframe><p>Now connect mobile device and turn on USB debugging in Developer options.<br>To enable Developer options, go to Settings &gt; Tap on About phone &gt; scroll to Build number and Tap it seven times.</p><p>Go to project directory in command line terminal and type command $ flutter run or Click on Run <a href="https://www.jetbrains.com/idea/download">IntelliJ Idea IDE</a>. Now app will be installed and open with name of project directory. Click on hamburger icon to see drawer. currently drawer is empty. see image 1.03 Navigation Drawer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*WGcuuHVSwWD9vVgeWj9Vsg.gif" /><figcaption>image 1.03 Navigation Drawer</figcaption></figure><p>On line no. 16 in snippet 1.02, we have initialized drawer object as</p><pre>Drawer drawer = new Drawer();`</pre><p>And passed to Scaffold constructor as(line no.21, snippet 1.02)</p><pre>new Scaffold(<br>   drawer: drawer,<br> ‎  .<br> ‎  .<br>);</pre><p>that’s it. we have now drawer in our app. Let’s add a header to our app.</p><h4>1.2 Drawer Header</h4><p>Change lib/main.dart as shown in snippet 1.03.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7fd6fa7210797a04fed194b0a44b483/href">https://medium.com/media/b7fd6fa7210797a04fed194b0a44b483/href</a></iframe><p>Let’s see what’s going on. we are passing new Column as Drawer(child:...) . Column is a widget that displays its children in a vertical list with array of widget children, new Column(children: &lt;Widget&gt;[...]). Column widget doesn’t scroll. To know more visit <a href="https://docs.flutter.io/flutter/widgets/Column-class.html">here</a>. we are passing UserAccountsDrawerHeader object as a child to Column.</p><p><a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader-class.html">UserAccountsDrawerHeader</a> accepts following type of properties.</p><p><a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader/accountEmail.html">accountEmail</a> → A widget that represents the email address of the user’s current account. It is displayed on the left, below the accountName.</p><p><a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader/accountName.html">accountName</a> → A widget that represents the user’s current account name. It is displayed on the left, below the currentAccountPicture.</p><p><a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader/currentAccountPicture.html">currentAccountPicture</a> → A widget placed in the upper-left corner that represents the current user’s account. Normally a CircleAvatar.</p><p><a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader/decoration.html">decoration</a> → The header’s background. If decoration is null then a BoxDecoration with its background color set to the current theme&#39;s primaryColor is used.</p><p><a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader/margin.html">margin</a> → The margin around the drawer header.</p><p><a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader/onDetailsPressed.html">onDetailsPressed</a> → A callback that is called when the horizontal area which contains the accountName and accountEmail is tapped.</p><p><a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader/otherAccountsPictures.html">otherAccountsPictures</a> → <a href="https://docs.flutter.io/flutter/dart-core/List-class.html">List</a>&lt;<a href="https://docs.flutter.io/flutter/widgets/Widget-class.html">Widget</a>&gt;A list of widgets that represent the current user’s other accounts. Up to three of these widgets will be arranged in a row in the header’s upper-right corner. Normally a list of CircleAvatar widgets.</p><p>We need to setup only three properties to see Account Name, Account Email, and Account Image. That’t it we have now a nice Drawer Header in image 1.04 Drawer Header.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*MbUDINDhRcOE4FxfTXFqMQ.gif" /><figcaption>image 1.04 Drawer Header</figcaption></figure><h4>1.3 Adding Lists</h4><p>Let’s see how to add list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe4959f2de3e8f3abcf2cd2c57850bd4/href">https://medium.com/media/fe4959f2de3e8f3abcf2cd2c57850bd4/href</a></iframe><p>In snippet 1.04 we added <a href="https://docs.flutter.io/flutter/material/UserAccountsDrawerHeader-class.html">otherAccountsPictures</a> with <a href="https://docs.flutter.io/flutter/widgets/GestureDetector-class.html">GestureDetector</a>. Refer docs for GestureDetector class.</p><p>Drawer child,<strong> Column Widget doesn’t support scroll. So we replaced it with </strong><a href="https://docs.flutter.io/flutter/widgets/ListView-class.html"><strong>ListView</strong></a>. ListView adds padding at the top, that makes drawer header with a white background under notification bar. So we added top padding as 0.0.</p><p><a href="https://docs.flutter.io/flutter/material/ListTile-class.html">ListTile</a> is a single fixed-height row that typically contains some text widgets as well as a leading or trailing widgets. Please refer to the flutter docs for more information. If we run the above snippet then we see drawer as shown in image 1.01 Final Snapshot.</p><h4>1.4 Routing</h4><p>Let’s see how routing works.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09b82b75cd665be34a475b79d5bececc/href">https://medium.com/media/09b82b75cd665be34a475b79d5bececc/href</a></iframe><p>step 1 -&gt; create Notes class. (see line no. 80 ,snippet 1.05).</p><p>step 2 -&gt; create a static final routeName for the Notes class.</p><p>step 3 -&gt; set <a href="https://www.dartdocs.org/documentation/flutter/0.0.1/material/MaterialApp-class.html">MaterialApp</a> routes property with Notes object. routes accepts a Map&lt;String, WidgetBuilder&gt;. Now, as we added routes when we push the Notes.routName to <a href="https://docs.flutter.io/flutter/widgets/Navigator-class.html">Navigator</a> then it will route to Notes widget with the widget that returns through Notes#build method. To push routName to Navigator we simply call</p><pre> Navigator.of(context).pushNamed(Notes.routName)</pre><p>But, the animation is not accepted as it will open it as a new Activity or Modal.</p><p>So to add smooth Fade transition we use <a href="https://docs.flutter.io/flutter/widgets/PageRouteBuilder-class.html"><strong>PageRouteBuilder</strong></a> . As show in the following snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb5d966952ef4df4354e8f45a69c48cb/href">https://medium.com/media/bb5d966952ef4df4354e8f45a69c48cb/href</a></iframe><p>step 4 -&gt; push PageRouteBuilder to Navigator. PageRouteBuilder provides properties astransitionDuration and transitionBuilder to define animations. In our case we need <a href="https://docs.flutter.io/flutter/widgets/FadeTransition-class.html">FadeTransition</a>.So, FadeTransition widget returned to transitionBuilder and transitionDuration set to default if not specified explicitly.</p><p>Then, change primaryColor to Colors.amber.shade500 in MaterialApp themes property. (line no 15, snippet 1.05).</p><p>That’s it. See image 1.01 <strong>Final Snapshot</strong> for the output. <strong>Notice the Fade Transition in the appBar between Keeper and Notes.</strong></p><h4>Summary</h4><p>Building an application following Navigation Drawer makes app, user friendly and easy to access all features at one place. It makes more room for the app to display content as compared to bottom or tabs navigation.</p><p>Next we will see Dynamic Labels in Drawer, StatefulWidgets, Forms and Validations in Flutter.</p><p>If you have any suggestion, or found any mistakes or improvements do drop a comment.</p><p>You can watch my github repo at <a href="https://github.com/aravind99/keeper">https://github.com/vemarav/keeper</a> for more updates. You can contact me at <a href="http://vemula.aravind336@gmail.com/">vemaravv@gmail.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b43a201251e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/flutter-1-navigation-drawer-routes-8b43a201251e">Flutter 1: Navigation Drawer &amp; Routes</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native: How I solved my lagging drawer problem]]></title>
            <link>https://medium.com/classpro-tech-blog/react-native-how-settimout-saved-my-life-803346bf18a5?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/803346bf18a5</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[navigation-drawer]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Akash Gupta]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 09:22:43 GMT</pubDate>
            <atom:updated>2022-03-17T09:39:42.070Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*7lwP90uD_PsbkbLek7ffyQ.jpeg" /><figcaption>React Native</figcaption></figure><p>I am developing apps on React Native. I released my first version of an app in pure react. I was very happy. Everything was perfect until I introduced redux in my app.</p><blockquote>I have uploaded a GIF below. See those slow ripple effect and lag in closing of drawer.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*rQTBJtKV-6s6-vpbFTg9vg.gif" /><figcaption>Lagging Drawer</figcaption></figure><p><strong>Note that this is not</strong> <strong>in development mode</strong>. These ripples are even slower on some android phones.</p><p>I tried changing my navigator. I tried <a href="https://github.com/react-community/react-navigation">react-navigation</a>, <a href="https://github.com/wix/react-native-navigation">wix navigation</a>, etc. All my navigators were showing a lag effect. Experiencing the same janky on press effect on touching drawer icons on every navigator I tried. Finally, I chose react-navigation and stuck with it.</p><p>I noticed certain things. At first, I thought that a lot of processing was going on componentDidMount, for example, <em>API requests, dispatches, setState, etc</em>. Then I removed all these things and used static data to render my list. Then also the lag was there for eg, <em>very slow ripple on drawer icons after pressing, janky drawer closing, etc</em>.</p><p>For a few months, I worked on making a drawer trying to make it as smooth as possible. I read about many things like <a href="https://github.com/redux-saga/redux-saga"><em>redux-saga</em></a><em>, </em><a href="https://mobx.js.org/"><em>MobX</em></a>, <a href="https://facebook.github.io/relay/"><em>relay</em></a><em>, etc</em>. I must say Relay is very good. I started learning relay. I had to write my APIs in <a href="http://graphql.org/">GQL</a> and finally made a sample app in Relay. Initially, it had the server data in just <a href="https://facebook.github.io/react-native/docs/text.html">Text</a> component. It was very fast. I decided to make my app in Relay. As soon as I made list using <a href="https://docs.nativebase.io/Components.html#list-def-headref">ListItem</a> of <a href="https://nativebase.io/">native-base</a> my app started to behave the same way as it was before. Boom… everything was shattered.</p><h3>Is Native base the culprit? No.</h3><p>I thought it was NativeBase, because of which the rendering of their component was a very expensive task. I thought that ListItem is the culprit. Also, there were issues opened regarding this, like <a href="https://github.com/GeekyAnts/NativeBase/issues/759">this</a> one. I removed NativeBase, checked f8 GitHub repo whether they are using it or not. They weren’t using it. So, I made my own list with <a href="https://facebook.github.io/react-native/docs/view.html">View</a> of React Native. The lagging and janky behavior of the drawer was reduced by some amount. But still, it wasn’t at par with the performance of native apps. What does it mean? I shouldn’t have anything on my screen? Ridiculous!!!</p><p>What’s the point in making my own components if there is <strong>still </strong>some performance issue. So, I chose to use NativeBase in my app.</p><h3>FlatList and its optimization</h3><p>I heard that <a href="https://facebook.github.io/react-native/docs/flatlist.html">FlatList</a> renders list in the same style as android native apps would do. I decided to use that to make my list. Even after using FlatList to generate my list, the performance was not satisfactory. Then I found <a href="http://matthewsessions.com/2017/05/15/optimizing-list-render-performance.html">this</a> article. From this article, I came to know about the <a href="https://facebook.github.io/react-native/docs/flatlist.html#initialnumtorender"><em>initialNumToRender</em></a><em> </em>prop. When I gave <em>initialNumToRender={4} </em>the drawer closing was improved. And after giving <em>initialNumToRender={0} </em>it improved by 50%.</p><p>For more performance optimization let’s move to the next part.</p><h3>Deferred Rendering</h3><p>I deduced that in order to render it smoothly there should be minimum load on the page. There should be a very light component. I thought is there any way by which, I can process rendering of all the components sequentially from light to heavy ones after the drawer closes? Yes, I can do that by putting my rendering of components in the following way by using setTimeout:</p><pre>setTimeout(() =&gt; {<br>// do rendering here<br>}, 0);</pre><p>The scheduler will invoke this only after the current code is complete i.e. in this case<em> — the closing of the drawer</em>. I call this as <strong>deferred rendering</strong>.</p><p>You can read more about setTimeout from <a href="https://javascript.info/settimeout-setinterval">here</a>.</p><h3>The code for flawless side drawer working and deferred rendering is as follows:</h3><p><em>Consider, I have a header, a list (of about 25 items or more), and footer components.</em></p><pre>// import statements...</pre><pre>class MyApp extends Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      renderHeader: false,<br>      renderList: false,<br>      renderFooter: false<br>    }<br>  }<br> .<br> .<br> .</pre><pre>componentDidMount() {<br>  setTimeout(() =&gt; {this.setState({renderHeader: true})}, 0);<br>  setTimeout(() =&gt; {this.setState({renderList: true})}, 0);<br>  setTimeout(() =&gt; {this.setState({renderFooter: true})}, 0);<br>}</pre><pre>render() {<br>  const {<br>    renderHeader,<br>    renderList,<br>    renderFooter<br>  } = this.state;</pre><pre>  const = {<br>    data,<br>    meta<br>  } = this.props;</pre><pre> return(<br>  &lt;Container&gt;<br>    {<br>      renderHeader &amp;&amp; <br>      &lt;Header&gt;<br>        // left side open drawer icon and a title in center<br>      &lt;/Header&gt;<br>    }</pre><pre>    &lt;Content&gt;<br>      {isFetching &amp;&amp; data.length === 0 &amp;&amp; &lt;CenterSpinner /&gt;}<br>      {!isFetching &amp;&amp; data.length === 0 &amp;&amp; &lt;EmptyPlaceholder /&gt;}  <br>      {<br>       renderHeader &amp;&amp; renderList &amp;&amp;<br>       &lt;FlatList     <br>        data={data}  <br>        renderItem={this._renderItem}<br>        keyExtractor={(item) =&gt; item.id}    <br>        ListFooterComponent={() =&gt;      <br>         !isFetching &amp;&amp; !_.isNull(meta.next_page) &amp;&amp;  <br>          &lt;Spinnercolor=&#39;#3F51B5&#39;/&gt;}<br>        refreshing={isRefreshing}<br>        onRefresh={()=&gt; this._onRefresh()}    <br>        onEndReached={()=&gt; this._onEndReached()}           <br>        onEndReachedThreshold={0.5}        <br>       /&gt;<br>      } <br>    &lt;/Content&gt;   <br>     {<br>       renderHeader &amp;&amp; renderList &amp;&amp; renderFooter &amp;&amp;<br>       &lt;Footer&gt;<br>        // footer code here...<br>       &lt;/Footer&gt;<br>     } <br>   &lt;/Container&gt;<br>  );<br> }<br>}<br>const mapStateToProps = state =&gt; {/* your code */}<br>export default connect(mapStateToProps)(MyApp);</pre><p>The above code will <strong>run smoothly</strong> with the side drawer. It will be rendered in sequence as the conditions on component rendering are dependent on previous components’ rendering.</p><p>The above will be executed like this:</p><ol><li>Drawer closing starts.</li><li>Setting up state.</li><li><strong><em>componentWillMount()</em></strong> // no code here</li><li><strong><em>render()</em></strong> // nothing will render as condition is not true for rendering</li><li><strong><em>componentDidMount()</em></strong> // scheduling of making render variables true after current execution of code is finished i.e. closing of the drawer</li><li>Drawer closes smoothly <em>(or somewhere in between these points)</em>.</li><li>renderHeader, renderList, renderFooter is set to true, sequentially in the order mentioned.</li></ol><p><strong>Don’t believe me? See for yourself.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*PWxEaPV46CXcExh3wb01cA.gif" /><figcaption>Faster drawer</figcaption></figure><p>I chose to render in this sequence because <strong>(i)</strong> header is lighter component then list component, <strong>(ii)</strong> rendering of header first, which at the top, gives a good UX and <strong>(iii)</strong> if I had rendered list first or footer first then it would be at the top and when header component’s renderHeader variable would be set to <strong>true </strong>then it would just appear and push already existing component down, thereby making a place for itself. This would look bad.</p><blockquote>As far as drawer closing process is going on, there will be nothing to render on the page. And as soon as the drawer is finished closing smoothly<em>(again because nothing was there to render on the page with data in their prop which is passed by redux) </em>the setTimeout code will run, thereby rendering each component in sequence because of <a href="https://facebook.github.io/react/docs/conditional-rendering.html#inline-if-with-logical--operator">conditional rendering</a>.</blockquote><p>I have seen apps like f8 and some other react native apps not having a side drawer, I don’t know why.</p><p>This may not be the perfect or ideal solution or some better solution may come in the future, but this solves my problem of lagging after touching drawer items.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=803346bf18a5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/react-native-how-settimout-saved-my-life-803346bf18a5">React Native: How I solved my lagging drawer problem</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Score 100 on Google’s - Page Speed Insights Tools(PGI)]]></title>
            <link>https://medium.com/classpro-tech-blog/how-to-score-100-on-googles-page-speed-insights-tools-pgi-61178edbed99?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/61178edbed99</guid>
            <category><![CDATA[page-speed]]></category>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[insights]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Aravind]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 08:24:41 GMT</pubDate>
            <atom:updated>2018-02-05T13:11:00.346Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nq40lEDDNqUSVpN7lutMqA.png" /></figure><p>Recently, I developed a campaign page for <a href="https://www.classpro.in/">classpro</a>. And Got <strong>98/100</strong> for optimization. To know more on how PGI score will affect your page ranking follow this link <a href="https://moz.com/learn/seo/page-speed">https://moz.com/learn/seo/page-speed</a>.</p><blockquote><strong>No matter how you measure it, a faster page speed is better. Many people have found that faster pages both rank and convert better.</strong></blockquote><h3>The Problem</h3><h4>Why I didn’t used BootStrap and jQuery?</h4><p><strong>BootStrap CSS</strong>(minified) requires <strong>121KB</strong>. <strong>BootStrap JavaScript</strong> requires <strong>37KB</strong>. And BootStrap depends on <strong>jQuery</strong> and it requires <strong>86KB</strong>. If we assume <strong>Images</strong> take <strong>200kb</strong> more.</p><p>Then the overall page requires ~<strong>444KB.</strong></p><p>But this method scored <strong>78/100</strong> on PageSpeed Insights.</p><h3>Here is what I did to solve the problem.</h3><p>I removed the frameworks and I just wrote the CSS and JavaScript as minimum as possible to beautify the web page. And guess what?</p><p>My score decreased to <strong>68/100</strong> and the PGI tool suggested many optimization for the web page.</p><p>On the basis of PGI optimization suggestions. I did the following improvements to my page.</p><ol><li>Minify CSS &amp; JS</li></ol><p>There are many online and offline solutions to do this. To minify CSS I used <a href="https://cssminifier.com/">https://cssminifier.com/</a> and to minify JavaScript, I used <a href="https://javascript-minifier.com/">https://javascript-minifier.com/</a>.</p><p>2. Image Optimization</p><p>For image optimization I followed the tutorial from <a href="https://developers.google.com/speed/docs/insights/OptimizeImages">page speed insights</a>. There are lots of tools available but I used the <a href="https://www.imagemagick.org/script/convert.php">covert program</a>, a linux based command line tool from ImageMagick.</p><p>Here are the commands I have used to optimize Images.</p><pre># command to convert gif or png images<br><strong>$</strong> magick convert INPUT.gif_or_png -strip [-resize WxH] [-alpha Remove] OUTPUT.png</pre><pre># JPEG images are lossy formats but the compression ratio can be <br># <strong>10x</strong> larger than GIF or PNG.<br># command to convert jpg or jpeg <br><strong>$</strong> magick convert INPUT.jpg -sampling-factor 4:2:0 -strip [-resize WxH] [-quality N] [-interlace JPEG] [-colorspace Gray/sRGB] OUTPUT.jpg</pre><p>To minify <strong>SVG</strong> images I visited <a href="http://www.svgminify.com/">http://www.svgminify.com/</a>.</p><p>And that’s how I reduced the web page from~<strong>444KB</strong> to ~<strong>184KB</strong>.</p><p>And added necessary configuration to web server (ex. Nginx) for compressing resources. In my case, We use Nginx Server and for the configuration I followed <a href="https://www.nginx.com/resources/admin-guide/compression-and-decompression/">Nginx Documentation</a>.</p><pre>server {<br>    listen 443 ssl;</pre><pre>    .<br>    .<br>    .</pre><pre>    gzip on;</pre><pre>    location ~ ^/(images|javascripts|stylesheets)/ {<br>        gzip_static on;<br>        expires 12h;<br>    }</pre><pre>    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {<br>        expires 1d;<br>        log_not_found off;<br>    }<br>}</pre><p>That’s how I created a web page that scored <strong>98/100</strong> on PageSpeed Insights.</p><p><strong>If you have any suggestions, queries or concerns feel free to drop a comment.</strong></p><p>Thanks to <a href="https://medium.com/u/7ed7fda812d2">Jayesh Gopalan</a>(CEO) and <a href="https://medium.com/u/ff1baf642ca0">Deepak Dargade</a>(CTO) for encouraging me to write this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61178edbed99" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/how-to-score-100-on-googles-page-speed-insights-tools-pgi-61178edbed99">How To Score 100 on Google’s - Page Speed Insights Tools(PGI)</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When we started Classpro, we were building our working development environment for a smoother…]]></title>
            <link>https://medium.com/classpro-tech-blog/when-we-started-classpro-we-had-to-build-up-our-working-development-environment-810d97f5e93c?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/810d97f5e93c</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Deepak Dargade]]></dc:creator>
            <pubDate>Mon, 17 Jul 2017 12:10:30 GMT</pubDate>
            <atom:updated>2018-04-16T10:54:01.829Z</atom:updated>
            <content:encoded><![CDATA[<p>When we started <a href="https://www.classpro.in/">Classpro</a>, we were building our working development environment for a smoother workflow.</p><h3>Enter SVN</h3><p>We started using <strong>SVN</strong> as Revision Control for Source code. SVN has the advantage of easier to learn especially with TortoiseSVN GUI.</p><h3>Why we switched to Git?</h3><p>Fast-forward 4 months: we were 3 developers, so our requirements were fairly minimal. However, it seemed like a good time to make the switch for a few reasons:</p><ul><li><strong>Decentralized</strong>: You developed on your local machine and you want to have source control so that you can go back to previous version. With Subversion, you have a Problem: The SVN Repository may be in a location you can’t reach (in your company, and you don’t have internet at the moment), you cannot commit. If you want to make a copy of your code, you have to literally copy/paste it. With Git, you do not have this problem. Your local copy is a repository, and you can commit to it and get all benefits of source control. When you regain connectivity to the main repository, you can commit against it.</li><li><strong>Branching</strong>: We had 5 different branches (master, development, user specific features repos). We had horrible flashbacks of late nights trying to merge an SVN branch back into master trunk. In less words: SVN merging sucks. In Git, Branches are lightweight and merging is easy, and I mean really easy.</li><li><strong>Fear</strong>: Having all of our revision history and development code on one machine, especially on local machine, is terrifying.</li></ul><p>Where Git really shines is branching and working with other people.</p><h3>Conclusion</h3><p>Though git is harder to learn than SVN, since it has more concepts, commands and sometimes more confusing for a starter. What is a remote? and How to properly set up the initial repository? are two questions that come up at the beginning, especially compared to SVN’s simple “svnadmin create”, Git’s “git init” can take the parameters –bare and –shared which seems to be the “proper” way to set up a centralized repository. There are reasons for this, but it adds complexity. But once you get it all, it is simple to use.</p><p>Git is not better or worse, it’s just different and I’m confident that the switch was a good move. It didn’t cause much downtime for the three of us, and it’s a lot easier to switch while you’re small company. I’d definitely recommend at least looking into Git.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=810d97f5e93c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/when-we-started-classpro-we-had-to-build-up-our-working-development-environment-810d97f5e93c">When we started Classpro, we were building our working development environment for a smoother…</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Project collaboration using Git]]></title>
            <link>https://medium.com/classpro-tech-blog/why-we-moved-to-git-6e1432823467?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/6e1432823467</guid>
            <category><![CDATA[classpro]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Deepak Dargade]]></dc:creator>
            <pubDate>Mon, 17 Jul 2017 12:10:12 GMT</pubDate>
            <atom:updated>2018-04-16T11:05:15.754Z</atom:updated>
            <content:encoded><![CDATA[<p>In earlier <a href="https://engineering.classpro.in/when-we-started-classpro-we-had-to-build-up-our-working-development-environment-810d97f5e93c">post</a>, I discussed why we switched from SVN to Git for <a href="https://www.classpro.in/">Classpro</a> Source Code revision control. The very next concern for us was where to store the initial git repository. We had the option of going for a git hosting service such as Github or create our own git server. We decided to create our own git server on remote server.</p><h3>Install Git on both Server and Client machines.</h3><p>if you’re on a Debian-based distribution like Ubuntu, try</p><blockquote>apt-get to install Git:</blockquote><h3>Prferred way of doing GIT on server:</h3><p>In order to initially set up any Git server, you have to export an existing repository into a new bare repository — a repository that doesn’t contain a working directory.</p><p>This is generally straightforward to do. In order to clone your repository to create a new bare repository, you run the clone command with the — bare option. By convention, bare repository directories end in .git, like so:</p><blockquote>git clone — bare my_project.git</blockquote><h3>On Client machine</h3><p><strong>Step 1</strong> on client machine clone the remote repository using,</p><blockquote>git clone <a href="/service/mailto:user@www.deepakdargade.me">user@deepakdargade.</a>com:/home/user/www/my_app.git</blockquote><p><strong>Step 2</strong> create a Readme file inside the my_app folder and add it to the stage and commit it,</p><blockquote>git add Readme<br>git status<br>git commit -m “Initial commit adding readme file”</blockquote><p><strong>Step 3</strong> check the remote repository information using</p><blockquote>git remote -v</blockquote><p><strong>Step 4</strong> check your branches in local repository</p><blockquote>git branch</blockquote><p><strong>Step 5</strong> lets create a new branch that reflect new code in the project.</p><blockquote>git checkout -b develop master</blockquote><p><strong>Step 6</strong> again, check your branches in local repository</p><blockquote>git branch</blockquote><p><strong>Step 7</strong> lets switch to master branch</p><blockquote>git checkout master</blockquote><p><strong>Step 8</strong> adding remote path to git</p><blockquote>git remote add origin ssh://<a href="/service/mailto:user@www.deepakdargade.com">user@deepakdargade.com</a>/home/user/www/my_app.git</blockquote><p><strong>Step 9</strong> pushing local master code to remote repository</p><p><strong>Step 10</strong> same way push the develop code to remote repository</p><p><strong>Step 11</strong> to fetch the latest code from the remote repository</p><blockquote>git fetch origin &lt; branch name &gt;</blockquote><p><em>Originally published at </em><a href="http://devblog.classpro.in/post/23476449693/why-we-moved-to-git-at-classpro"><em>devblog.classpro.in</em></a><em>.</em></p><p><strong>P.S.</strong> We have moved to Github 2 years ago.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e1432823467" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/why-we-moved-to-git-6e1432823467">Project collaboration using Git</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Google Drive with Rails]]></title>
            <link>https://medium.com/classpro-tech-blog/integrate-google-drive-with-rails-c9514191249e?source=rss----45925fcd9b5c---4</link>
            <guid isPermaLink="false">https://medium.com/p/c9514191249e</guid>
            <category><![CDATA[google-drive]]></category>
            <category><![CDATA[refresh-token]]></category>
            <category><![CDATA[oauth]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[token]]></category>
            <dc:creator><![CDATA[Akash Gupta]]></dc:creator>
            <pubDate>Mon, 17 Jul 2017 11:21:41 GMT</pubDate>
            <atom:updated>2017-10-21T14:39:18.034Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*PIIrO2Ocd_QG7DNlY0TXTg.jpeg" /></figure><h4><em>Do you want each user to connect their Google Drive account to Rails app? So that they can do Google Drive stuffs?</em></h4><h4><strong>Use </strong><a href="http://railscasts.com/episodes/241-simple-omniauth?autoplay=true"><strong>OAuth</strong></a><strong> to connect the user</strong></h4><p><em>Set your origin and redirect URI in your Google Developer Console. <br>Use </em>gem “<a href="https://github.com/zquestz/omniauth-google-oauth2">omniauth-google-oauth2</a>”</p><pre>= link_to<em> </em>&quot;Connect to Google Drive&quot;, <strong>&quot;</strong>https://www.yourwebsite.com/auth/google_oauth2/callback</pre><p>In routes.rb:</p><pre>get &#39;/auth/google_oauth2/callback&#39;,<br>to:&#39;omniauth_authentications#google_oauth2&#39;</pre><p>Our <strong>omniauth_authentications_controller.rb</strong>:</p><pre><strong>def </strong>google_oauth2<br>  auth = request.env[&#39;omniauth.auth&#39;]  <br>  omniauth_params = request.env[&#39;omniauth.params&#39;]</pre><pre>  <em># fetch customs params and find_or_create user to login...<br></em> <br>  <em>redirect_to your_path</em><br><strong>end</strong></pre><p>request.env[‘omniauth.auth’] will contain a hash as follows</p><pre>{<br>    :provider =&gt; &quot;google_oauth2&quot;,<br>    :uid =&gt; &quot;123456789&quot;,<br>    :info =&gt; {<br>        :name =&gt; &quot;John Doe&quot;,<br>        :email =&gt; &quot;john@company_name.com&quot;,<br>        :first_name =&gt; &quot;John&quot;,<br>        :last_name =&gt; &quot;Doe&quot;,<br>        :image =&gt; &quot;https://lh3.googleusercontent.com/url/photo.jpg&quot;<br>    },<br>    :credentials =&gt; {<br>        :token =&gt; &quot;token&quot;,<br>        :refresh_token =&gt; &quot;another_token&quot;,<br>        :expires_at =&gt; 1354920555,<br>        :expires =&gt; true<br>    },<br>    .<br>    .<br>    .</pre><pre>}</pre><h3><strong>How will you know who initiated the oauth request?</strong></h3><p>Suppose, for example, you want to log in with oauth and there are different kinds of users — <em>eg: Teacher, Student, etc,</em> you ought to know their details. So that you can find record of the user in appropriate table in your database. This can be achieved by passing params as follows.</p><p>request.env[‘omniauth.params’] will contains params which are send after the URL, for eg:</p><pre>= link_to<em> </em>&quot;Connect to Google Drive&quot;, &quot;https://www.yourwebsite.com.in/auth/google_oauth2?user_id=1&quot;</pre><p>For the above URL,</p><pre>puts request.env[‘omniauth.params’][‘user_id’]<br>=&gt; 1</pre><p>To access Google Drive easily, use gem ‘<a href="https://github.com/gimite/google-drive-ruby">google_drive</a>’.</p><p>With this gem we can log in as follows:</p><pre>google_drive_session = GoogleDrive.login_with_oauth(request.env[&#39;omniauth.auth&#39;].credentials.token)</pre><pre>puts google_drive_session<br>=&gt; #&lt;GoogleDrive::Session:0x007f8d9a80a960&gt;</pre><p>Here, we get a Google Drive session object in <em>google_drive_session</em> variable. Now you can upload files, create folder, etc. see the <a href="https://github.com/gimite/google-drive-ruby">documentation</a> page of the gem.</p><h3>Does your token gets expired? Want to request a new token?</h3><p>If you want a user to keep using Google Drive service, its better to save it in database. For requesting a new token, we should have <em>‘refresh_token’.</em></p><p>Token comes with an expiration time (<em>request.env[‘omniauth.auth’].credentials.expires_at)</em></p><p>Check if your token has been expired or not:</p><pre>Time.at(expires_at.to_i) &lt; Time.now</pre><p>Get the new token using current refresh token as follows:</p><pre>data = {<br>    client_id:  <em>&#39;client_id&#39;</em>,<br>    client_secret: <em>&#39;client_secret&#39;</em>,<br>    refresh_token: <em>&#39;refresh_token&#39;</em>,<br>    grant_type: &#39;refresh_token&#39;<br>}</pre><pre>post_form = Net::HTTP.post_form(URI.parse(&#39;https://accounts.google.com/o/oauth2/token&#39;), data)</pre><pre>puts post_form<br>=&gt; <em>#&lt;Net::HTTPOK 200 OK readbody=true&gt;</em></pre><pre>puts JSON.parse(post_form.body)<br>=&gt; <em>{&quot;access_token&quot;=&gt;&quot;ya29.Gl3uAw9iNfMXk9D2-wAB9Lrlwun-CQprCyqZgPUC_CY1dEHwqVbx8VBGLc4Tdlhk5KAL-9rvrEzGkoFJPMxZfo3GrdqOO52GHxIrPWl5qYCkI0VSAbda4psBST6PdsA&quot;, &quot;expires_in&quot;=&gt;3600,&quot;token_type&quot;=&gt;&quot;Bearer&quot;}</em></pre><p>As you can see above, we get our <strong>new access token</strong> which expires in 3600 seconds.</p><p><strong>Note:</strong> Initially in <em>request.env[‘omniauth.auth’].credentials.expires_at </em>we get the time at which token <em>‘expires at’</em> and while generating new access token we get <em>‘expires_in’.</em></p><h3>Not getting refresh token while connecting to Google Drive?</h3><p>While getting new access token, its mandatory that we have refresh token. And to get refresh token on each request, we can pass <strong>prompt</strong> param in the URL.</p><pre>= link_to<em> </em>&quot;Connect to Google Drive&quot;,<em> </em>&quot;https://www.yourwebsite.com.in/auth/google_oauth2?prompt=consent&quot;</pre><p>This will prompt for connection with Google Drive and provide you with a <em>refresh token </em><strong>each time</strong><em>.</em></p><p>In fact, you can pass redirect URI, scope and custom params in the URL.</p><p>For eg:</p><pre>= link_to<em> </em>&quot;Connect to Google Drive&quot;,<em> </em>&quot;https://www.yourwebsite.com.in/auth/google_oauth2?prompt=consent&amp;user_id=<strong>#{current_user.id}</strong>&amp;scope=userinfo.email,userinfo.profile,https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/drive&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9514191249e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classpro-tech-blog/integrate-google-drive-with-rails-c9514191249e">Integrate Google Drive with Rails</a> was originally published in <a href="https://medium.com/classpro-tech-blog">Engineering at Classpro</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>