<?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 Imal Kumarage on Medium]]></title>
        <description><![CDATA[Stories by Imal Kumarage on Medium]]></description>
        <link>https://medium.com/@imalkumarage?source=rss-fdebb734306d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*AvNDbAPEdIC7MQli</url>
            <title>Stories by Imal Kumarage on Medium</title>
            <link>https://medium.com/@imalkumarage?source=rss-fdebb734306d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 01:20:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@imalkumarage/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[Git Cheat Sheet]]></title>
            <link>https://medium.com/@imalkumarage/git-cheat-sheet-f432bfa554b8?source=rss-fdebb734306d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f432bfa554b8</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[gitlab]]></category>
            <dc:creator><![CDATA[Imal Kumarage]]></dc:creator>
            <pubDate>Tue, 13 Jul 2021 06:33:43 GMT</pubDate>
            <atom:updated>2021-07-13T06:33:43.319Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YHTAkqc0nywMf48_" /></figure><ul><li>Initialize a git repository locally</li></ul><pre>git init</pre><ul><li>Clone a remote repository</li></ul><pre>git clone &lt;url&gt;</pre><ul><li>Clone a specific branch. In this case the branch ‘develop’</li></ul><pre>git clone -branch develop &lt;url&gt;</pre><ul><li>Staging/Adding files and directories</li></ul><pre>git add .  ---&gt; <em>Add all files in current directory</em><br>git add ./path/to/folder ---&gt; <em>Add all files in specific directory</em><br>git add test.txt ---&gt; Add single file</pre><ul><li>Commit all added/staged files</li></ul><pre>git commit -m &quot;Commit message&quot;</pre><ul><li>Create a new branch in local repository</li></ul><pre>git checkout -b branch_name</pre><ul><li>Pull master branch and merge with current local branch</li></ul><pre>git pull origin master</pre><ul><li>Push changes to branch in remote repository. <em>(If no branch exists branch is created in remote)</em></li></ul><pre>git push origin branch_name</pre><ul><li>Fetches all remote refs <em>(reference to remote branches)</em></li></ul><pre>git fetch</pre><ul><li>Checkout remote branch <em>(As long as you have only one remote)</em></li></ul><pre>git checkout remote_branch_name</pre><ul><li>Untrack file/folder and remove from repository without deleting actual physical file</li></ul><pre>git rm --cached file_name</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f432bfa554b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React state management with React Recoil]]></title>
            <link>https://medium.com/swlh/react-state-management-with-react-recoil-124c1a6ae0e1?source=rss-fdebb734306d------2</link>
            <guid isPermaLink="false">https://medium.com/p/124c1a6ae0e1</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[state-management]]></category>
            <dc:creator><![CDATA[Imal Kumarage]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 02:37:13 GMT</pubDate>
            <atom:updated>2020-07-13T02:37:13.820Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jKdcSYQ-OZODN0dv" /><figcaption>Photo by <a href="https://unsplash.com/@flowforfrank?utm_source=medium&amp;utm_medium=referral">Ferenc Almasi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>State management is a consistent problem faced by most if not all React developers. Due to this, there have been several attempts at creating a clean and robust mechanism for state management of React applications. Redux is probably the most popular tool used in this regard and has accomplished its purpose quite well. Later down the line Context API was introduced along with React Hooks to manage application state. Both of these solutions have been adopted by modern developers. But during the recent React Europe 2020 event, the world was introduced to an experimental React state management system called Recoil. In this article, we will look at how Recoil works under the hood and gain an understanding as to why it may hold an edge over both Redux and Context API.</p><h4>Why not Redux or Context API?</h4><p>Redux has been a reliable solution for most developers and once the initial hurdle of setting up the boilerplate code is done it provides an efficient method of maintaining global state. However, even for maintaining global state for a simple application, it requires complicated setting up stores and verbose boilerplate code. Further, to add to Redux to an existing project the entire codebase will have to be restructured. Redux, in addition, does not support the new concurrent mode of React or contain built-in async support.</p><p>To those wanting a simpler way to manage global state, the Context API was an elegant solution. Context API allows us to have a provider and consumers that can access the global state accordingly. One limitation is when we have numerous items that need to render separately and maintain global state. A provider could be maintained for each item if the number of items is known. In the case of a dynamic list of items, a provider will have to be added to the component tree. This approach would cause the entire sub-tree to re-render causing inefficiency.</p><h4>The Recoil Solution</h4><blockquote><em>“</em>Recoil lets you create a data-flow graph that flows from atoms (shared state) through selectors (pure functions) and down into your React components. Atoms are units of state that components can subscribe to. Selectors transform this state either synchronously or asynchronously<em>”</em></blockquote><p>The above explanation quoted directly from the Recoil documentation [1] explains the fundamental components of Recoil — atoms and selectors.</p><p>Atoms are bits of state that any component can subscribe to and changes to the atom’s state will cause all components subscribed to that atom to re-render. Atoms can be created at runtime as well.</p><p>Atoms require a unique key and use a special hook called <em>‘useRecoilState’ </em>to read and write to the state (The functionality mirrors the <em>‘useState’ </em>hook).</p><p>Atoms are structure orthogonal to the regular component tree and thus does not face sub-tree re-rendering issues similar to React Context and illustrated in the diagram presented by David McCabe during React Europe 2020 [2].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*tq9ERixnVaWt-dazwg4YHQ.png" /></figure><pre><em>const</em> todoListState = atom({</pre><pre>   key: &#39;todoListState&#39;,</pre><pre><em>   default</em>: [],</pre><pre>});</pre><pre><em>function</em> TodoList() {</pre><pre><em>&lt;&gt;   <br>const</em> todoList = useRecoilValue(todoListState);<br><em>   return</em> (<br>      &lt;TodoItemCreator /&gt;<br>      {todoList.map((todoItem) =&gt; (<br>         &lt;TodoItem key={todoItem.id} item={todoItem} /&gt;</pre><pre>   ))}</pre><pre>&lt;/&gt;</pre><pre>);</pre><pre>}</pre><p>Selectors are functions that can accept atoms or other selectors and transform the atom’s state accordingly. As the passed in atoms get updated the selector is re-evaluated and components that subscribe to the selector will be re-rendered. The following is a simple example displaying how atoms and selectors can be used to create a list filter.</p><p>We have discussed the need for having a state management mechanism for React and looked at both Redux and React Context as the currently existing solutions. React Recoil has managed to address several concerns the community has had with both above state management solutions. We can look forward to a stable release of React Recoil soon and in the meantime, I urge you to also check out the below references for more information.</p><p>[1] <a href="https://recoiljs.org/">https://recoiljs.org/</a></p><p>[2]<a href="https://www.youtube.com/watch?v=_ISAA_Jt9kI">https://www.youtube.com/watch?v=_ISAA_Jt9kI</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=124c1a6ae0e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/react-state-management-with-react-recoil-124c1a6ae0e1">React state management with React Recoil</a> was originally published in <a href="https://medium.com/swlh">The Startup</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 Machine Learning With JavaScript Using Brain.Js]]></title>
            <link>https://medium.com/swlh/introduction-to-machine-learning-with-javascript-using-brain-js-90cd351b6a19?source=rss-fdebb734306d------2</link>
            <guid isPermaLink="false">https://medium.com/p/90cd351b6a19</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Imal Kumarage]]></dc:creator>
            <pubDate>Thu, 09 Jul 2020 05:51:05 GMT</pubDate>
            <atom:updated>2020-07-17T19:22:40.200Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tSRKbPignI9ptnu3" /><figcaption>Photo by <a href="https://unsplash.com/@pietrozj?utm_source=medium&amp;utm_medium=referral">Pietro Jeng</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Machine learning has been an exponentially growing field in modern software and technology development. Python or other high-level languages have traditionally been used in developing machine learning solutions but in this article, we will explore how it can be done with basic JavaScript and explore a practical implementation.</p><p>Beginners curious to explore the possibilities and basic methodology of machine learning can use Brain.js as a starting point as it is a simple library that allows us to implement neural networks without the requirement of complicated mathematics. Before we dive into a practical example let’s cover some basics of Machine Learning that will be relevant to understand the inner workings of the library and neural networks.</p><h4>Forward and Backward propagation</h4><p>Forward and backward propagation is how a neural network learns. During the training phase of the data set, this process occurs constantly. Imagine a cricketer that must score a boundary. They will estimate the distance to the boundary and the force needed. This is the concept of forward propagation. Backwards propagation is measuring the distance from the boundary (propagation) to the cricketer (source). This estimation happens repeatedly until an accurate estimation can be made. Thus, each layer takes in data from the input layer, processes it in accordance with the activation function and passes it on to the successive layers.</p><h4>Hidden Layers</h4><p>Hidden layers are the layers that lie between the input and output layer of a neural network. The hidden layers run the activation functions and transforms the input to a value that the output layer can use. The more hidden layers in our network the better the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*0TUtOl9cFJGXpD78oOJ8_Q.png" /><figcaption><a href="https://www.kdnuggets.com/2017/10/neural-network-foundations-explained-gradient-descent.html">https://www.kdnuggets.com/2017/10/neural-network-foundations-explained-gradient-descent.html</a></figcaption></figure><p>Setting up Brain.js is extremely simple and you can follow the well-documented guide at the GitHub <a href="https://github.com/BrainJS/brain.js">repository</a>. We will move to understand the basic syntax and implementing a solution that will be useful in a JavaScript context.</p><p>After importing Brain.js we must instantiate our network as follows:</p><pre>const network = new brain.NeuralNetwork()</pre><p>We will use the machine learning capabilities of Brain.js to dynamically decide if the font colour of some text should be black or white based on a changing background colour. First, we must train our network by providing a dataset. Here I have provided a set of RGB colour values and what the font colour must be for each one. The <em>train</em> method utilizes the forward and backward propagation methods discussed above.</p><pre>network.train([<br> { input: { r: 0.62, g: 0.72, b: 0.88 }, output: { light: 1 } },<br> { input: { r: 0.1, g: 0.84, b: 0.72 }, output: { light: 1 } },<br> { input: { r: 0.33, g: 0.24, b: 0.29 }, output: { dark: 1 } },<br> { input: { r: 0.74, g: 0.78, b: 0.86 }, output: { light: 1 } },<br> { input: { r: 0.31, g: 0.35, b: 0.41 }, output: { dark: 1 } },<br> { input: {r: 1, g: 0.99, b: 0}, output: { light: 1 } },<br> { input: {r: 1, g: 0.42, b: 0.52}, output: { dark: 1 } },<br> ])</pre><p>Finally, we will provide a test value and pass it on to the neural network and it will output either “light” or “dark”:</p><pre>const result = brain.likely(rgb, network)<br>console.log(result);<br>example.style.background = e.target.value<br>example.style.color = result === “dark” ? “white” : “black”</pre><p>Based on the above implementation we can implement a dynamic solution to change the font colour on the fly based on a changing background (<a href="https://codepen.io/imalk96/pen/gOPeVKm?editors=1010">demo</a>).</p><p>As demonstrated above we can implement several machine learning based concepts using Brain.js without being limited by the JavaScript language and can be quite handy if implemented in a smart way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90cd351b6a19" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/introduction-to-machine-learning-with-javascript-using-brain-js-90cd351b6a19">Introduction to Machine Learning With JavaScript Using Brain.Js</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-Time Location Tracking Using Google’s Fused Location Provider API]]></title>
            <link>https://medium.com/swlh/real-time-location-tracking-using-googles-fused-location-provider-api-2fc8023f2c1c?source=rss-fdebb734306d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fc8023f2c1c</guid>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[fused-location-provider]]></category>
            <dc:creator><![CDATA[Imal Kumarage]]></dc:creator>
            <pubDate>Thu, 09 Jul 2020 05:21:46 GMT</pubDate>
            <atom:updated>2020-07-17T19:23:00.666Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yjtpqhzX3irM37xg" /><figcaption>Photo by <a href="https://unsplash.com/@hjkp?utm_source=medium&amp;utm_medium=referral">henry perks</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Location tracking and monitoring have seen a surge in modern application development with various services such as Uber heavily relying on location services that require consistency and accuracy. With businesses and corporations requiring location information and monitoring of their various assets, delivering comprehensive location solutions has been a tricky science for many developers.</p><p>Identifying the growing demand for a convenient location providing service Google introduced the Fused Location Provider API. This article will focus on using the API to track a user’s real-time location using an android application and through the example demonstrate the beauty of the API.</p><p>The API focuses on providing location information using a combination of a device’s GPS, Wi-Fi and internal sensors. The main selling point is that it decides in what combination to use these three resources based on the request parameters provided. In this context managing these resources is abstracted from the developer.</p><p>A simple use case to demonstrate the capacity of the API is tracking the movement of an individual walking towards a building, entering it and then leaving. In this scenario when the person is outdoors, the GPS service will function well. However, as he enters the building the GPS signal may drop. The Fused Location Provider handles the above scenario by tracking the location outdoors via GPS and when the GPS signal drops within the building, it utilizes Wi-Fi. During the switching process from GPS to Wi-Fi, to provide a smoother transition, the device’s internal sensors are used to predict the movement. In this manner, the management of available resources to provide reliable location services in a battery efficient manner is the true power of the API.</p><p>Integrating the API into your android application is a simple process. In this example, we will walk through the necessary steps required to build a simple location tracking application.</p><p>First, create an android project in Android Studio and within the application’s build.gradle file, ensure the following dependency is present:</p><pre>dependencies{<br>   implementation ‘com.google.android.gms:play-services:11.8.0’<br>}</pre><p>Secondly, within the Manifest file you must provide either the Fine or Coarse location permission by adding the below snippet:</p><pre>&lt;uses-permission        android:name=”android.permission.ACCESS_FINE_LOCATION”<br>/&gt; <br>&lt;uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”<br>/&gt;</pre><p>Now, create instances of <strong><em>FusedLocationProviderClient</em></strong>, <strong><em>LocationRequest</em></strong><em> </em>and <strong><em>LocationCallBack</em></strong><em> </em>in your activity.</p><pre>private FusedLocationProviderClient fusedLocationClient;</pre><pre>private LocationRequest locationRequest;<br>private LocationCallback locationCallback;</pre><pre>@Override<br>protected void onCreate(Bundle savedInstanceState) {<br>      fusedLocationClient =       LocationServices.getFusedLocationProviderClient(this);<br>   }<br>}</pre><p>The <strong>LocationRequest</strong> object is used to build a location request in accordance with parameters of our use case by providing details such as the update frequency, accuracy level and battery efficiency. Create a method to build the location request based on your desired parameters. An example is provided below:</p><pre>private void buildLocationRequest() {</pre><pre>locationRequest = new LocationRequest(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(100);</pre><pre>locationRequest.setFastestInterval(100); locationRequest.setSmallestDisplacement(1);<br>}</pre><pre>//Build the location callback object and obtain the location results //as demonstrated below:</pre><pre>private void buildLocationCallBack() {<br>  locationCallback = new LocationCallback() {<br>    @Override<br>    public void onLocationResult(LocationResult locationResult) {<br>      for (Location location: locationResult.getLocations()){<br>         String latitude = String.valueOf(location.getLatitude());<br>         String longitude = String.valueOf(location.getLongitude());<br>      }<br>    }<br>  };<br>}</pre><p>Once the <strong><em>locationRequest</em></strong><em> </em>object and the <strong><em>locationCallBack</em></strong><em> </em>objects are initialized, request location data by calling the FusedLocationProviderClient’s <strong><em>requestLocationUpdates</em></strong> method. Pass the <strong><em>locationRequest</em></strong> and <strong><em>locationCallback</em></strong> objects as parameters.</p><pre>FusedLocationProviderClient.requestLocationUpdates<br>(<br>   locationRequest,<br>   locationCallback,<br>   null<br>);</pre><p>Based on the parameters defined by the request the API will continue to provide relevant location information that can be utilized to perform numerous functions such as location monitoring and real time speed tracking.</p><p>The Fused Location Provider API provides a convenient method to manage all underlying location technologies by abstracting their inner workings from the developer and providing high-level methods to specify the quality and accuracy of services required.</p><p>What is explored here is merely a fraction of what the API provides, and Google has provided comprehensive documentation that can be used to build diverse and robust applications in the future. Follow the link below to get started:</p><p><a href="https://developers.google.com/location-context/fused-location-provider">https://developers.google.com/location-context/fused-location-provider</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fc8023f2c1c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/real-time-location-tracking-using-googles-fused-location-provider-api-2fc8023f2c1c">Real-Time Location Tracking Using Google’s Fused Location Provider API</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>