<?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 Ruwan Bandara on Medium]]></title>
        <description><![CDATA[Stories by Ruwan Bandara on Medium]]></description>
        <link>https://medium.com/@ruwan.se.uok?source=rss-271977bd5260------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oRhA9aP3nLBK2bfTUZ85dQ.jpeg</url>
            <title>Stories by Ruwan Bandara on Medium</title>
            <link>https://medium.com/@ruwan.se.uok?source=rss-271977bd5260------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:19:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ruwan.se.uok/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[ref() vs reactive() In Vue 3]]></title>
            <link>https://medium.com/@ruwan.se.uok/ref-vs-reactive-in-vue-3-59df1b861507?source=rss-271977bd5260------2</link>
            <guid isPermaLink="false">https://medium.com/p/59df1b861507</guid>
            <dc:creator><![CDATA[Ruwan Bandara]]></dc:creator>
            <pubDate>Thu, 03 Jul 2025 15:38:45 GMT</pubDate>
            <atom:updated>2025-07-03T15:38:45.145Z</atom:updated>
            <content:encoded><![CDATA[<h3>What’s the Difference and When to Use Each?</h3><p>If you’ve recently started using Vue 3 and felt a little confused about when to use ref() vs reactive().You’re not alone. These two are at the heart of Vue’s new reactivity system under the Composition API — and while they seem similar at first glance, they serve very different purposes.</p><p>In this article, I’ll walk you through what they do, how they differ, and which one to choose depending on your use case. I’ll also throw in a few examples, common mistakes, and some practical tips.</p><h3>So, what is ref()?</h3><p>Think of ref() as Vue’s way of making a single value reactive. It’s perfect for primitives like strings, numbers, or booleans.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>  import { ref } from &#39;vue&#39;<br>  const count = ref(0)function increment() {<br>    count.value++<br>  }<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;p&gt;Count: {{ count }}&lt;/p&gt;<br>  &lt;button @click=&quot;increment&quot;&gt;Increment&lt;/button&gt;<br>&lt;/template&gt;<br></pre><p>With ref(), the key thing to remember is: you always access the actual value with .value in JavaScript. But don&#39;t worry — inside templates, Vue unwraps it for you, so you can just use {{ count }}.</p><h3>What about reactive()?</h3><p>reactive() is for objects or arrays — basically, when you have more than just a single value to manage.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>  import { reactive } from &#39;vue&#39;<br>  const state = reactive({<br>    count: 0,<br>    user: {<br>      name: &#39;Ruwan&#39;,<br>      age: 28<br>    }<br>  })<br>  function increment() {<br>    state.count++<br>  }<br>&lt;/script&gt;<br>&lt;template&gt;<br>  &lt;p&gt;{{ state.user.name }} ({{ state.user.age }})&lt;/p&gt;<br>  &lt;p&gt;Count: {{ state.count }}&lt;/p&gt;<br>  &lt;button @click=&quot;increment&quot;&gt;Increment&lt;/button&gt;<br>&lt;/template&gt;</pre><p>With reactive(), you get deep reactivity out of the box — Vue tracks changes even inside nested objects. No need for .value here — you can use properties directly.</p><h3>Key Differences at a Glance</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*14EOh1wPEs23roudllyhNw.png" /></figure><h3>Common Mistakes</h3><p>Here are a few “gotchas” that tripped me up when I started:</p><h3>Using reactive() for a primitive</h3><pre>const count = reactive(0) // Doesn’t work!</pre><p>Always use ref() for single values. reactive() only works with objects or arrays.</p><h3>Losing reactivity when destructuring</h3><pre>const state = reactive({ count: 0 })<br>const { count } = state // Not reactive anymore!</pre><p>To keep reactivity, use toRefs():</p><pre>import { toRefs } from &#39;vue&#39;<br>const state = reactive({ count: 0 })<br>const { count } = toRefs(state) // Still reactive</pre><h3>Performance Notes</h3><p>In most real-world apps, you won’t notice much performance difference between <strong>ref()</strong> and <strong>reactive()</strong>. That said:</p><ul><li><strong>ref()</strong> is generally lighter for primitive values.</li><li><strong>reactive(</strong>) Adds a bit of overhead with deep proxies, especially if your object is large and deeply nested.</li></ul><p>So unless you’re building something super data-heavy or performance-critical, choose based on clarity, not micro-optimizations.</p><h3>Which Should You Use?</h3><p>Here’s a simple guide I follow:</p><p>counter, toggle, flag =&gt; ref()</p><p>User form data or complex state =&gt;reactive()</p><p>Need to destructure reactive state =&gt; reactive() + toRefs()</p><p>Computed or watched primitives =&gt;ref()</p><h3>Best Practices</h3><ul><li>Use ref() for single values or simple toggles.</li><li>Use reactive() for grouped state (especially if it’s nested).</li><li>If you’re destructuring a reactive object, always use toRefs().</li><li>Try not to mix ref() and reactive() inside a single object — things can get weird.</li><li>Keep it simple: use what makes the code easier to understand.</li></ul><h3>Real-World Example</h3><p>Here’s how I typically structure things in a component:</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>import { ref, reactive, toRefs } from &#39;vue&#39;<br>  const name = ref(&#39;Alice&#39;)<br>  const state = reactive({<br>    count: 0,<br>    items: [] as string[]<br>  })<br>  const { count } = toRefs(state)<br>&lt;/script&gt;<br>&lt;template&gt;<br>  &lt;p&gt;{{ name }}&lt;/p&gt;<br>  &lt;p&gt;{{ count }}&lt;/p&gt;<br>  &lt;button @click=&quot;count++&quot;&gt;Add&lt;/button&gt;<br>&lt;/template&gt;<br></pre><p>Super clean — and reactive where it matters.</p><h3>Final Thoughts</h3><p>Vue 3’s reactivity system is powerful, but you don’t need to overthink it.</p><p>Just remember:</p><p><strong><em>Use </em></strong><strong><em>ref() for primitives. Use </em></strong><strong><em>reactive() for objects and arrays.<br>When in doubt, go with what feels simplest and clearest for your code.</em></strong></p><p>Let me know in the comments: Have you been using ref() and reactive() correctly? Or did you learn something new today?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59df1b861507" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Software Licensing]]></title>
            <link>https://medium.com/@ruwan.se.uok/software-licensing-b1bb8451cd1f?source=rss-271977bd5260------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1bb8451cd1f</guid>
            <category><![CDATA[software-licensing]]></category>
            <category><![CDATA[copyleft]]></category>
            <category><![CDATA[mit]]></category>
            <category><![CDATA[apache-license]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Ruwan Bandara]]></dc:creator>
            <pubDate>Wed, 09 Sep 2020 03:58:22 GMT</pubDate>
            <atom:updated>2020-09-09T03:58:22.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IeVIyBNGzUfBDY2jSORd5g.jpeg" /></figure><h3>What is a software license?</h3><p>A software license is a document that provides legally binding guidelines for the use and distribution of software.</p><p>Software licenses typically provide end-users with the right to one or more copies of the software without violating copyrights. The license also defines the responsibilities of the parties entering into the license agreement and may impose restrictions on how the software can be used. Software licensing terms and conditions usually include fair use of the software, the limitations of liability, warranties, and disclaimers, and protections if the software or its use infringes on the intellectual property rights of others.</p><p>Software licenses typically are either proprietary, free or open-source, the distinguishing feature being the terms under which users may redistribute or copy the software for future development or use.</p><h3><strong>Why is a software licensing important?</strong></h3><p>Licensing is important because it helps companies more efficiently provision their software. A lot of products are far more complex and boast many more features than we may need at any given time, so vendors create multiple tiers and permission sets and package them up into easy-to-distribute licenses. In turn, by purchasing a license, you allow the vendor to set contractual terms for how you will use the service. This helps prevent pirating as others have said, as well as over-usage on the user side. Simply put, licensing is for the convenience of the user and the protection of the software company’s intellectual property.</p><h3><strong>What is the main category of Software Licensing?</strong></h3><p>There are two main categories of Software licenses: Open-Source and Closed Source Licenses.</p><p><strong>Open Source Licenses:</strong></p><p>In general, open-source software licenses allow the end-user to view and edit and distribute the software and the source code. There are a few different flavors of open-source licenses giving more or less freedom on all of these attributes. Popular Open-Source Software Licenses include:</p><ul><li><a href="https://opensource.org/licenses/Apache-2.0">Apache License 2.0</a></li><li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD 3-Clause “New” or “Revised” license</a></li><li><a href="https://opensource.org/licenses/BSD-2-Clause">BSD 2-Clause “Simplified” or “FreeBSD” license</a></li><li><a href="https://opensource.org/licenses/gpl-license">GNU General Public License (GPL)</a></li><li><a href="https://opensource.org/licenses/lgpl-license">GNU Library or “Lesser” General Public License (LGPL)</a></li><li><a href="https://opensource.org/licenses/MIT">MIT license</a></li><li><a href="https://opensource.org/licenses/MPL-2.0">Mozilla Public License 2.0</a></li><li><a href="https://opensource.org/licenses/CDDL-1.0">Common Development and Distribution License</a></li><li><a href="https://opensource.org/licenses/EPL-2.0">Eclipse Public License version 2.0</a></li></ul><p>More information on selecting an open-source license appropriate for your project can be found here: <a href="https://choosealicense.com/">Choose an open-source license</a></p><p><strong>Closed Source Software Licenses: </strong>Also sometimes known as proprietary licenses or commercial licenses, these are the license types that are usually (but not always) bought and sold. They typically do not allow modification of the program or its distribution. These licenses will deal with rules around the following concepts:</p><ul><li>Are there any limitations on the number of devices that a license is granted to?</li><li>How many devices can run the software simultaneously using the same license?</li><li>Is a license granted to allow usage of the software forever, or does it expire eventually, (if payment is not renewed for instance)?</li><li>Are there any limitations on the number of times a program or a part of the program are allowed to run over a certain time interval.</li></ul><p>Some of the common attributes of commercial licenses include:</p><ul><li><strong>Perpetual / Time-Based</strong>: Does a license expire in time or is it granted forever?</li><li><strong>Node-Locked vs site licenses</strong>: Is the license bound to a specific machine or device, or to a specific private network and can be shared between any device connected to the network?</li><li><strong>Trial-License</strong>: Will running the application during an evaluation have separate usage rights compared to a commercial license?</li><li><strong>Subscription</strong>: common for cloud services and other SaaS, the right to use the software is tied to a recurring payment</li><li><strong>Floating / Concurrent</strong>: Can multiple end-users run the application simultaneously using the same license?</li><li><strong>Key vs user-based licensing</strong>: with the authentication system require a license key and will run on any machine that the key is entered on, or will the license be assigned to the end-user in some other way, such as requiring authentication via email/password combination?</li></ul><p>There are a few other considerations to a commercial software license such as the rules around distributing the software.</p><p><strong>Royalties for distribution, or royalty-free? </strong>Software distributed to the end-user usually does not allow for redistribution. However, if the software is an SDK or as OEM, it is usually allowed to be redistributed with or without royalties due.</p><h3>Open Source Licenses and their Compatibility</h3><p>There are a large number of Free-Libre / Open Source Software (FLOSS) licenses, but only a few are widely used. The widely-used licenses tend to be compatible, i.e., the software can be combined to produce a larger work. The following figure shows how licenses can be combined:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b8zcx8dfR4yKx6O7.png" /></figure><p>In this figure, the boxes are the names of different FLOSS licenses. An arrow from box A to box B means that you can combine software with these licenses; the combined result effectively has the license of B, possibly with additions from A. To see if the software can be combined, just start at their respective licenses, and find a common box by following the arrows. For example, Apache 2.0-licensed software and GPLv2+-licensed software can both reach “GPLv3 or GPLv3+”, so they can be combined using GPLv3 or GPLv3+. This figure has been carefully crafted so following a path determines if two licenses are compatible.</p><p>At the left are the “permissive” licenses, which permit the software to become proprietary (i.e., not FLOSS). At the top left is “Public Domain”, which strictly speaking isn’t a license but in effect, it works like one. You can do anything with public domain software, but it is rare; the software must be explicitly released to the public domain or be created by a U.S. Government employee in their official capacity. Next is the so-called “MIT” or “X11” license, which is very permissive (you can do just about anything except sue the author). Software under the MIT license is easily combined with the modern 3-clause Berkeley Software Distribution (BSD-new) license, which compared to the MIT license adds a clause forbidding the use of the author’s name to endorse or promote products without permission. It’s debatable if this clause actually does anything since you typically have to have such permission anyway. Finally, we have the Apache version 2.0 license.</p><p>Many of the <a href="https://janelia-flyem.github.io/dependencies.html">software packages used within FlyEM</a> have permissive licenses. Packages like “libjpeg”, “HDF5”, “freetype 2”, “libpng”, and boost have their own licenses but are very similar to the BSD license and can be grouped in that category.</p><p>At the right are the “strongly protective” (“strong copyleft”) licenses, which prevent the software from becoming proprietary. This includes the most popular FLOSS license, the GNU General Public License (GPL). The GPL has a version 2 (GPLv2) and 3 (GPLv3); a “+” afterward means “version X or later”. GPLv2-only cannot be combined with the network-protective Affero GPLv3, but GPLv2+ (“version 2 or later”) can via GPLv3.</p><p>In the middle are the “weakly protective” (“weak copyleft”) licenses, a compromise between permissive and strongly protective licenses. These prevent the software component (often a software library) from becoming proprietary, yet permit it to be part of a larger proprietary program. This figure shows the rules when you are making other software parts of the weakly protected component; there are other possibilities if you are only using the component as a library. The GNU Lesser General Public License (LGPL) is the most popular weakly protective license and has a version 2.1 (LGPLv2.1) and 3 (LGPLv3). Note that LGPLv2.1 gives you permission to relicense the code under any version of the GPL since GPLv2. Another such license is the Mozilla Public License 1.1 (MPL 1.1), but the MPL has the serious drawback of being incompatible with the widely-popular GPL; you can’t even use an MPL module in a larger GPL’ed program.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1bb8451cd1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ethical Whistleblowing]]></title>
            <link>https://medium.com/@ruwan.se.uok/ethical-whistleblowing-f3ac87bf2fbe?source=rss-271977bd5260------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3ac87bf2fbe</guid>
            <dc:creator><![CDATA[Ruwan Bandara]]></dc:creator>
            <pubDate>Sat, 25 Jul 2020 18:26:12 GMT</pubDate>
            <atom:updated>2020-07-25T19:32:22.598Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Ethical Whistleblowing?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/0*gj16HSbkLtEuSkw9.jpeg" /></figure><p>The ethics of whistleblowing is a tricky matter. Informativeness brings two moral values ​​to the conflict — justice and loyalty. Doing what is fair or fair (for example, promoting an employee based on a single talent) often conflicts with expressions of loyalty (for example, promoting a long-time but unskilled employee). Taken to the extreme in terms of loyalty, disclosure can involve excruciating conflicts when, for example, it involves breaching trust by employees who engage in misconduct or threaten “team player” status by going against the prevailing winds in the organization. that encourages unethical behavior.</p><h3>Elements of ethical whistleblowing</h3><p>There are four element of whistle-blowing process</p><p>The whistle-blower</p><p>The whistle-blowing act or complaint</p><p>The party to whom the complaint is made</p><p>The organization against which the complaint is lodged</p><p>Now we are toking about what are the steps/procedure for a whistleblowing.</p><h3>Steps/procedure for a whistleblowing</h3><p>There are five steps of proceeding for a whistleblowing. Now we talk each step one by one.</p><h3>Step 1 — Get Evidence</h3><p>This is the most important step in your disclosure statement. It is imperative that you obtain documentary evidence of the fraud. Such evidence may include emails, internal research, billing records, or test results. If you can witness the wrongdoing first-hand, that’s great, but not necessary. This evidence will help support your claim when you submit it to the government. The more evidence you have, the more likely your case is.</p><h3>Step 2 — Presenting the Evidence</h3><p>Under the False Claims Act, the whistleblower must file a complaint in court as well as submit it to the government, along with a Disclosure Statement that details the alleged misconduct. However, before filing the claim, we will set up a meeting with the appropriate government agency to discuss the claim. This is when you have to show the government that you have enough evidence of the fraud to support your claim.</p><h3>Step 3 — Government Investigation</h3><p>Now the longest part of the claims process is the government investigation. During this time, all aspects of this matter, including the identity of the applicant and the investigation itself, will remain confidential. Any formal complaints filed with the court are sealed, so even the accused don’t know what’s going on. During this time, the government may give you interviews, as well as other witnesses who have participated in or learned of the fraud.</p><h3>Step 4 — The Decision</h3><p>If the government decides to open a case, the whistleblower may be asked to testify in court or in a grand jury trial. It is at this point that your identity will be revealed. Roughly 90 percent of cases of False Claims that government intervenes tend to be successful. But if the government refuses to intervene, these whistleblower cases will be less than successful. Without government support, cases can be costly and time-consuming. Plus, you may be prepared for retaliation from your employer. While it is illegal for a company or organization to retaliate against an applicant, it still happens.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3ac87bf2fbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js MongoDb User Registration]]></title>
            <link>https://medium.com/@ruwan.se.uok/node-js-mongodb-user-registration-cb1956c5563?source=rss-271977bd5260------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb1956c5563</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Ruwan Bandara]]></dc:creator>
            <pubDate>Tue, 17 Mar 2020 20:07:25 GMT</pubDate>
            <atom:updated>2020-03-17T20:07:25.029Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*XElkBpSnsJwGiIdi.jpeg" /></figure><p>So we are going to start building the basic of User Registration System in Node.js using MongoDB as the data store , Express as the routing system, and of course Mongoose to make interacting with Mongodb from Node easy.</p><p>Below the sample project layout . User- Registration in the top level directory which hold the server.js file , and the we have a models directory and a routes directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ivShHhhvwGcymStEjCX6A.png" /></figure><h3>Step 1. Create a User Model</h3><p>First up we need to create a User Model. You can create a <strong><em>users.js</em></strong> file and place it in the model directory. At the top of the file , require Mongoose as we will crating the User <strong><em>Mongodb Schema.</em></strong> Then, We create the User Schema and define the requirement for name, email, and password,etc . The User Schema is Stored in <strong><em>User</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dk2SZFX3KXJG6c1niuG4CA.png" /></figure><h3>Step 2. Set Up Users Routes</h3><p>Now that we have User Model set up which both defines the schema we need to follow and the validation rules, we can create a api.js routes file in our router directory .In this file , the first things we do right at the top to require, or import, the User Schema that we just exported in <strong><em>user.js</em></strong>. Next we make sure Express is initialized. The router.post() function does all the heavy lifting here. first the http post request gets validated, then we check to see if the user already exist in the database. and finally we create a new user if they do not exist in the database and also if they pass all validation requirements. lastly we export the router, so we can use it in the <strong><em>server.js</em></strong> file.</p><pre>const express = require(&#39;express&#39;);<br>const <strong><em>router </em></strong>= express.Router();<br>const User = require(&#39;../model/users&#39;);<br>const mongoose = require(&#39;mongoose&#39;);<br>const db = &quot;mongodb://localhost/&lt;Your DB Name&gt;&quot;;<br>mongoose.connect(db, err =&gt; {<br>    if (err) {<br>        <strong><em>console</em></strong>.log(&#39;Error in connect the database&#39; + err);<br>    } else {<br>        <strong><em>console</em></strong>.log(&#39;Connected to Mongodb&#39;);<br>    }<br>});<br><br><strong><em>router</em></strong>.get(&#39;/&#39;, (req, res) =&gt; {<br>    res.send(&quot;From API router&quot;)<br>});<br><br><br><strong><em>router</em></strong>.post(&#39;/register&#39;, (req, res) =&gt; {<br>    User.find({&quot;email&quot;: req.body.email})<br>        .then(<br>            result =&gt; {<br>                <strong><em>console</em></strong>.log(result.length);<br>                if (result.length !== 0) {<br>                    res.json({<br>                        message: &#39;Email already exists&#39;,<br>                        status: false<br>                    })<br><br>                } else {<br>                    let userData = req.body<br>                    let user = new User(userData)<br>                    user._id = new mongoose.Types.<strong><em>ObjectId</em></strong>()<br>                    <strong><em>console</em></strong>.log(user);<br>                    user.save()<br>                        .then(<br>                            result =&gt; {<br>                                res.json({<br>                                   message: &#39;User register success&#39;,<br>                                   status: true,<br>                                   send: (userData)<br>                                })<br>                            }<br>                        )<br>                        .catch(<br>                            error =&gt; {<br>                                res.json({<br>                                   message: &#39; User Register fail&#39;,<br>                                   status: false,<br>                                })<br>                            }<br>                        )<br>                }<br>            }<br>        )<br>        .catch(<br>            error =&gt; {<br>                res.json({<br>                    message: &#39; User Register fail&#39;,<br>                    status: false,<br><br>                })<br>            }<br>        )<br>});<br>module.<strong><em>exports </em></strong>= <strong><em>router</em></strong>;</pre><h3><strong>Step 3. Register User Route in server.js</strong></h3><p><strong>server.js</strong></p><p>Most of the boilerplate here should look familiar to you if you followed the tutorial already. The key points for thi tutorial here are highlighted. Note we require the<strong><em> api.js</em></strong> and this allow us to set up the the route for<strong><em> /route/api.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Y1GpbZsADxfWa4erb9ywA.png" /></figure><h3><strong>Step 4. Test Post Requests with Postman</strong></h3><p>Now we can make use of Postman to send a Post request to our server to see if we can persist a new user to MongoDB. First, let’s launch the application.</p><p>we first check the existing email in database and post request using postman.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAgTP_Qrxn9LmI4QvRkVLw.png" /></figure><p>And check new register user .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P-rvMM5u4mV6gMSNXuH9vA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb1956c5563" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Apps Using MVVM with Clean Architecture.]]></title>
            <link>https://medium.com/@ruwan.se.uok/android-apps-using-mvvm-with-clean-architecture-e50216f4a52b?source=rss-271977bd5260------2</link>
            <guid isPermaLink="false">https://medium.com/p/e50216f4a52b</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ruwan Bandara]]></dc:creator>
            <pubDate>Tue, 24 Dec 2019 18:07:26 GMT</pubDate>
            <atom:updated>2020-01-10T20:20:34.133Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*wOmAHDN_zKZJns9YDjtrMw.jpeg" /></figure><p>If you don’t choose the right architecture for your <a href="https://www.toptal.com/android">Android</a> project, you will have a hard time maintaining it as your codebase grows and your team expands.</p><p>This isn’t just an Android MVVM tutorial. In this article, we are going to combine MVVM (Model-View-ViewModel or sometimes stylized “the ViewModel pattern”) with Clean Architecture. We are going to see how this architecture can be used to write decoupled, testable, and maintainable code.</p><p><strong>Why MVVM with Clean Architecture?</strong></p><p>MVVM separates your view (i.e. Activitys and Fragments) from your business logic. MVVM is enough for small projects, but when your codebase becomes huge, your ViewModels start bloating. Separating responsibilities becomes hard.</p><p>MVVM with Clean Architecture is pretty good in such cases. It goes one step further in separating the responsibilities of your code base. It clearly abstracts the logic of the actions that can be performed in your app.</p><p>Note: You can combine Clean Architecture with the model-view-presenter (MVP) architecture as well. But since Android Architecture Components already provides a built-in ViewModel class, we are going with MVVM over MVP — no MVVM framework required!</p><p><strong>Advantages of Using Clean Architecture</strong></p><p>· Your code is even more easily testable than with plain MVVM.</p><p>· Your code is further decoupled (the biggest advantage.)</p><p>· The package structure is even easier to navigate.</p><p>· Your team can add new features even more quickly.</p><p>· The project is even easier to maintain.</p><p><strong>Disadvantages of Clean Architecture</strong></p><p>· It has a slightly steep learning curve. How all the layers work together may take some time to understand, especially if you are coming from patterns like simple MVVM or MVP.</p><p>· It adds a lot of extra classes, so it’s not ideal for low-complexity projects.</p><p>Data flow will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*QRSeKDCITJL2GG6RLVO2iQ.png" /></figure><p>Business logic is completely decoupled from UI. It makes our code very easy to maintain and test.</p><p>The example we are going to see is quite simple. It allows users to create new posts and see a list of posts created by them. I’m not using any third-party library (like Dagger, RxJava, etc.) in this example for the sake of simplicity.</p><p><strong>The Layers of MVVM with Clean Architecture</strong></p><p>The code is divided into three separate layers:</p><p>1. Presentation Layer</p><p>2. Domain Layer</p><p>3. Data Layer</p><p>We’ll get into more detail about each layer below. For now, resulting package structure looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*HlwH1Y_R6rEUzC-Mmq5MdQ.png" /></figure><p>Even within the Android app architecture we’re using, there are many ways to structure your file/folder hierarchy. I like to group project files based on features. I find it neat and concise. You are free to choose whatever project structure suits you.</p><p><strong>The Presentation Layer</strong></p><p>This includes our Activitys, Fragments, and ViewModels. <strong>An </strong>Activity<strong> should be as dumb as possible. Never put your business logic in </strong>Activity<strong>s.</strong></p><p>An Activity will talk to a ViewModel and a ViewModel will talk to the domain layer to perform actions. A ViewModel never talks to the data layer directly.</p><p>Here we are passing a UseCaseHandler and two UseCases to our ViewModel. We’ll get into that in more detail soon, but in this architecture, a UseCase is an action that defines how a ViewModel interacts with the data layer.</p><p>Here’s how our Kotlin code looks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f1762f9163c8b00ed1c74098c9f59cd/href">https://medium.com/media/7f1762f9163c8b00ed1c74098c9f59cd/href</a></iframe><p><strong>The Domain Layer</strong></p><p>The domain layer contains all the <strong>use cases</strong> of your application. In this example, we have UseCase, an abstract class. All our UseCases will extend this class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d11b6ffba88666dcf4ab3eb9e837a9cd/href">https://medium.com/media/d11b6ffba88666dcf4ab3eb9e837a9cd/href</a></iframe><p>And UseCaseHandler handles execution of a UseCase. We should never block the UI when we fetch data from the database or our remote server. This is the place where we decide to execute our UseCase on a background thread and receive the response on the main thread.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ab15d616a26d48e3b3468597bb894ef/href">https://medium.com/media/9ab15d616a26d48e3b3468597bb894ef/href</a></iframe><p>As its name implies, the GetPosts UseCase is responsible for getting all posts of a user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61078d129eaf55b87c922b0667fbe2a1/href">https://medium.com/media/61078d129eaf55b87c922b0667fbe2a1/href</a></iframe><p><strong>The purpose of the </strong>UseCase<strong>s is to be a mediator between your </strong>ViewModel<strong>s and </strong>Repository<strong>s.</strong></p><p>Let’s say in the future you decide to add an “edit post” feature. All you have to do is add a new EditPost UseCase and all its code will be completely separate and decoupled from other UseCases. <strong>We’ve all seen it many times: New features are introduced and they inadvertently break something in preexisting code.</strong> Creating a separate UseCase helps immensely in avoiding that.</p><p>Of course, you can’t eliminate that possibility 100 percent, but you sure can minimize it. This is what separates Clean Architecture from other patterns: The code is so decoupled that you can treat every layer as a black box.</p><p><strong>The Data Layer</strong></p><p>This has all the repositories which the domain layer can use. This layer exposes a data source API to outside classes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/518a3a9202d47979dda99f0a239873d2/href">https://medium.com/media/518a3a9202d47979dda99f0a239873d2/href</a></iframe><p>PostDataRepository implements PostDataSource. It decides whether we fetch data from a local database or a remote server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/807e2f554d9af56c67db0fcde9207f0f/href">https://medium.com/media/807e2f554d9af56c67db0fcde9207f0f/href</a></iframe><p>The code is mostly self-explanatory. This class has two variables, localDataSource and remoteDataSource. Their type is PostDataSource, so we don’t care how they are actually implemented under the hood.</p><p>That is the advantage of decoupled code. Changing any given class shouldn’t affect other parts of your code.</p><p>Some of the extra classes we have are:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/019a949e681626bd9a1833a62ce3228e/href">https://medium.com/media/019a949e681626bd9a1833a62ce3228e/href</a></iframe><p>UseCaseThreadPoolScheduler is responsible for executing tasks asynchronously using ThreadPoolExecuter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25a71bb0f2eda58022ac676df50549da/href">https://medium.com/media/25a71bb0f2eda58022ac676df50549da/href</a></iframe><p>This is our ViewModelFactory. You have to create this to pass arguments in your ViewModel constructor.</p><p><strong>Dependency Injection</strong></p><p>I’ll explain dependency injection with an example. If you look at our PostDataRepository class, it has two dependencies, LocalDataSource and RemoteDataSource. We use the Injection class to provide these dependencies to the PostDataRepository class.</p><p>Injecting dependency has two main advantages. One is that you get to control the instantiation of objects from a central place instead of spreading it across the whole codebase. Another is that this will help us write unit tests for PostDataRepository because now we can just pass mocked versions of LocalDataSource and RemoteDataSource to the PostDataRepository constructor instead of actual values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e6ce24e295dd8d0d7cb0cac63316283/href">https://medium.com/media/9e6ce24e295dd8d0d7cb0cac63316283/href</a></iframe><p>Note: I prefer using Dagger 2 for dependency injection in complex projects. But with its extremely steep learning curve, it’s beyond the scope of this article. So if you’re interested in going deeper, I highly recommend <a href="https://medium.com/@harivigneshjayapalan/dagger-2-for-android-beginners-dagger-2-part-i-f2de5564ab25">Hari Vignesh Jayapalan’s introduction to Dagger 2</a>.</p><p><strong>MVVM with Clean Architecture: A Solid Combination</strong></p><p>Purpose with this project was to understand MVVM with Clean Architecture, so we skipped over a few things that you can try to improve it further:</p><p>1. Use LiveData or RxJava to remove callbacks and make it a little neater.</p><p>2. Use states to represent your UI.</p><p>3. Use Dagger 2 to inject dependencies.</p><p>This is one of the best and most scalable architectures for Android apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e50216f4a52b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple OS Design & Implementation To Show Hardware Information]]></title>
            <link>https://medium.com/@ruwan.se.uok/a-simple-os-design-implementation-to-show-hardware-information-6197bac13997?source=rss-271977bd5260------2</link>
            <guid isPermaLink="false">https://medium.com/p/6197bac13997</guid>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[os]]></category>
            <category><![CDATA[qemu]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[nasm]]></category>
            <dc:creator><![CDATA[Ruwan Bandara]]></dc:creator>
            <pubDate>Sat, 15 Jun 2019 12:45:30 GMT</pubDate>
            <atom:updated>2019-06-18T05:48:24.193Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*AyaYE-nGLP7jqLf8RmlIkA.png" /></figure><p><strong><em>Introduction</em></strong></p><p>The RB_OS kernel is written in 16-bit x86 real mode assembly language. This gives the information of the hardware. This provides easy access to BIOS routines for handling the keyboard, screen and floppy drive, so that we don’t need complicated drivers.</p><h3>Structure</h3><p>These are the most important files and directories in the AchiOS zip file:</p><ul><li>source/ — Contains the entire OS source code</li><li>source/bootload/ — Source to generate BOOTLOAD.BIN, which is added to the disk image when building</li><li>source/features/ — Components of AchiOS such as FAT12 support, string routines, the BASIC interpreter etc.</li><li>source/kernel.asm — The core kernel source file, which pulls in other source files</li><li>programs/ — Source code for programs added to the disk image</li></ul><p>so that we have to download two things before starting of making the operating system.</p><h4>nasm</h4><p>nasm is for converting <strong>.asm </strong>files to <strong>.bin </strong>files. Before start making the operating system we need to download this with ubuntu terminal. Code is given below.</p><p>sudo apt-get install nasm</p><h4>qemu</h4><p>qemu is used for making the operating system run on our Ubuntu OS terminal.</p><pre>sudo apt-get install qemu<br></pre><h4>How to build</h4><pre>sudo bash ./build-linux.sh</pre><h4>How to run on Ubuntu terminal</h4><pre>sudo qemu-system-i386 -soundhw pcspk -drive format=raw,file=disk_images/RBos.flp,index=0,if=floppy</pre><h3>Following screenshots are from RBOS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*gjY87DiK3UoK_78EKwO8EQ.png" /><figcaption>This is the homepage of the RBOS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*efEVQI0Xdj2jeSi0CmjVwg.png" /><figcaption>Shows hardware information</figcaption></figure><h3>Reference</h3><p>Mike OS — <a href="http://mikeos.sourceforge.net/#handbooks">http://mikeos.sourceforge.net/#handbooks</a></p><p>NASM — <a href="https://www.nasm.us/">https://www.nasm.us/</a></p><p>Qemu — <a href="https://www.qemu.org/">https://www.qemu.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6197bac13997" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[There are five silent philosophers (P1 — P5) sitting around a circular table, spending their lives…]]></title>
            <link>https://medium.com/@ruwan.se.uok/there-are-five-silent-philosophers-p1-p5-sitting-around-a-circular-table-spending-their-lives-d46d764976f1?source=rss-271977bd5260------2</link>
            <guid isPermaLink="false">https://medium.com/p/d46d764976f1</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ruwan Bandara]]></dc:creator>
            <pubDate>Sun, 05 May 2019 16:34:06 GMT</pubDate>
            <atom:updated>2020-01-17T02:09:40.658Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/236/0*h18XQo17Mq7TV0QO" /><figcaption>Diagram</figcaption></figure><h3>The Dining philosophers problem- Using JAVA.</h3><p>There are five silent philosophers (P1 — P5) sitting around a circular table, spending their lives eating and thinking.</p><h3>1.The Problem</h3><p>The dining philosophers problem states that there are 5 philosophers sharing a circular table and they eat and think alternatively. There is a bowl of rice for each of the philosophers and 5 chopsticks. A philosopher needs both their right and a left chopstick to eat. A hungry philosopher may only eat if there are both chopsticks available. Otherwise, a philosopher puts down their chopstick and begin thinking again.</p><h3>2.The Goal</h3><p>The goal is to come up with a scheme/protocol that helps the philosophers achieve their goal of eating and thinking without getting starved to death.</p><h3>3.A Solution</h3><p>Each philosopher is initially thinking. After a certain amount of time, the philosopher gets hungry and wishes to eat. At this point, he reaches for the chopsticks on his either side and once he’s got both of them, proceeds to eat. Once the eating is done, the philosopher then puts the chopsticks down, so that they’re available for his neighbor.</p><h3>5.Implementation</h3><p>We model each of our philosophers as classes that implement the <em>Runnable</em>interface so that we can run them as separate threads. Each <em>Philosopher</em> has access to two chopsticks on his left and right sides. We also have a method that instructs a <em>Philosopher</em> to perform an action — eat, think, or acquire chopsticks in preparation for eating. Now, let’s implement the core logic of a <em>Philosopher</em>. To simulate acquiring a fork, we need to lock it so that no two <em>Philosopher</em> threads acquire it at the same time. To achieve this, we use the <em>synchronized</em> keyword to acquire the internal monitor of the fork object and prevent other threads from doing the same. A guide to the <em>synchronized</em>keyword in Java can be found <a href="https://www.baeldung.com/java-synchronized">here</a>. We proceed with implementing the <em>run()</em>method in the <em>Philosopher</em> class now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f8A8EGnpgftKN68j944gWQ.png" /></figure><p>This scheme exactly implements the one described earlier: a <em>Philosopher</em>thinks for a while and then decides to eat. After this, he acquires the forks to his left and right and starts eating. When done, he places the forks down. We also add timestamps to each action, which would help us understand the order in which events occur. To kick start the whole process, we write a client that creates 5 <em>Philosophers</em> as threads and starts all of them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*VcXZ0WYOlt5pw50gKAL-EQ.png" /></figure><p>We model each of the forks as generic Java objects and make as many of them as there are philosophers. We pass each <em>Philosopher</em> his left and right forks that he attempts to lock using the <em>synchronized</em> keyword. Running this code results in an output similar to the following. Your output will most likely differ from the one given below, mostly because the <em>sleep()</em> method is invoked for a different interval:</p><h3>6.The Problem with the Solution: Deadlock</h3><p>We can confirm the same by running the above code a few times and checking that some times, the code just hangs. Here’s a sample output that demonstrates the above issue:</p><p>In this situation, each of the <em>Philosopher</em>s has acquired his left fork, but can’t acquire his right fork, because his neighbor has already acquired it. This situation is commonly known as the <strong>circular wait</strong> and is one of the conditions that results in a deadlock and prevents the progress of the system.</p><h3>7. Resolving the Deadlock</h3><p>As we saw above, the primary reason for a deadlock is the circular wait condition where each process waits upon a resource that’s being held by some other process. Hence, to avoid a deadlock situation we need to make sure that the circular wait condition is broken. There are several ways to achieve this, the simplest one being the follows:</p><p>The change comes in lines 17–19 of the above code, where we introduce the condition that makes the last philosopher reach for his right fork first, instead of the left. This breaks the circular wait condition and we can avert the deadlock. Following output shows one of the cases where all the <em>Philosopher</em>s get their chance to think and eat, without causing a deadlock:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*d3ZGofNNkDDghRJbVpijCg.jpeg" /><figcaption>1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*vvVEjr1zNxg2RlOVY0n0wg.jpeg" /><figcaption>2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*8CNm0sPRuf4NRqfaN2JWqQ.jpeg" /><figcaption>3</figcaption></figure><p>Now this code shows the output that indicates: all the philosophers get their chance to think and eat, without causing deadlock.</p><p>In this article we analyzed the famous Dining Philosophers problem using threads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d46d764976f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>