<?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[Backyard Programmers - Medium]]></title>
        <description><![CDATA[Don’t comment bad code — rewrite it. - Medium]]></description>
        <link>https://medium.com/backyard-programmers?source=rss----164a34fe7068---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Backyard Programmers - Medium</title>
            <link>https://medium.com/backyard-programmers?source=rss----164a34fe7068---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 13 Nov 2026 22:05:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/backyard-programmers" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Startup (Pocketbook) with KMM [3/n] — Database and System Design]]></title>
            <link>https://medium.com/backyard-programmers/building-startup-pocketbook-with-kmm-3-n-database-and-system-design-92775dbd74d6?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/92775dbd74d6</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 17:50:21 GMT</pubDate>
            <atom:updated>2023-04-17T17:50:21.179Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Startup (Pocketbook) with KMM [3/n] — Database and System Design</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rTuVEVdgZvuZvLkY_YvYeg.png" /><figcaption>Image generated by <a href="https://stablediffusionweb.com/">Stable Diffusion</a></figcaption></figure><p>Greetings and welcome back to our startup building series with KMM! In our last blog, we talked about the initial ideation and MVP design of <strong>Pocketbook</strong>, our revolutionary finance and budgeting app. Now, it’s time to delve into the technical aspects and explore the backend system design in detail. In this blog, I’ll take you through the UML diagrams and microservices architecture that we’ll use to bring Pocketbook to fruition. Get ready to join us on this exhilarating journey, and let’s kick things off!</p><p><a href="https://medium.com/backyard-programmers/building-startup-with-kmm-2-n-brainstorming-ideas-and-mvp-with-chatgpt-3b5de1b0433c">Building Startup with KMM [2/n]— Brainstorming ideas and MVP with ChatGPT</a></p><blockquote>The ChatGPT only had limited use in this case, but most of its properties were very generic. It is not much autonomus as I expected. Not something out of the box. Though it was really useful during my research. Though the name <strong>PocketBook</strong> given by ChatGPT.</blockquote><h3><strong>Simple System Design</strong></h3><p>Here is what I have an overall idea of the system. I am trying to over-engineer everything, so it is a learning opportunity for me, the comprehensive end-to-end flow.</p><p>The Clients hit the <a href="https://www.redhat.com/en/topics/api/what-does-an-api-gateway-do"><strong>API Gateway,</strong></a><strong> </strong>which will discover the service and pass it to that service. We also have a <a href="https://redis.io/docs/manual/client-side-caching/">caching layer</a> with <a href="https://redis.io/"><strong>Redis Datastore</strong></a><strong>. </strong>Then we have to follow a microservice pattern based on the domain they are divided into. Now for the database part, I will be using <a href="https://www.postgresql.org/"><strong>Postgres</strong></a> and <a href="https://www.elastic.co/elasticsearch/"><strong>Elasticsearch</strong></a><strong> </strong>using Postgres for all the POST/PATCH/DELETE requests. Since this app is expected to have many graphs, so querying data at a large scale would be an issue, so we will be syncing data with Elasticsearch. This will help us to make our queries (for graphs) and text searches faster. We will be later some other use cases where Elasticsearch will be beneficial. We are using <a href="https://grpc.io/"><strong>gRPC</strong></a><strong> </strong>for inter-service and overall communication to have a more unified and resilient contact, smaller payload size and faster functionality over<strong> REST.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*PbK3pQkJCrpaA1zutPcZQA.png" /></figure><p><strong>Some References for what I did and why I did</strong></p><ul><li><a href="https://medium.com/building-aasaanjobs/how-we-optimized-django-apis-using-elasticsearch-postgresql-functions-748b552d1048">How we optimized Django APIs using Elasticsearch &amp; PostgreSQL Functions</a></li><li><a href="https://microservices.io/">What are microservices?</a></li><li><a href="https://microservices.io/patterns/apigateway.html">Microservices Pattern: Pattern: API Gateway / Backends for Frontends</a></li><li><a href="https://marutitech.com/api-gateway-in-microservices-architecture/">How To Configure API Gateway in Microservices Architecture</a></li><li><a href="https://redis.io/docs/manual/client-side-caching/">Client-side caching in Redis</a></li></ul><h3>Postgres Database Design</h3><p>The next step was to plan a basic database schema. So It took me a while to decide what to consider and want not to do. Initially, I intended to make a <a href="https://microservices.io/patterns/data/database-per-service.html"><strong>Database per service</strong></a><strong>; </strong>however<strong>,</strong> it was really complicated stuff that made it easier for me to make a monolithic database to handle all the foreign keys and cascading things for the MVP.</p><p><em>Trying to reduce the monolithic database by design, making sure that only a specific service can access the specific table so that it is easier to separate in the long run.</em></p><p>You check the DB schema and commands here: <a href="https://dbdiagram.io/d/63a9b6ea7d39e42284e791dd">https://dbdiagram.io/d/63a9b6ea7d39e42284e791dd</a></p><p>I added <a href="https://www.tutorialspoint.com/postgresql/postgresql_indexes.htm#:~:text=PostgreSQL%20provides%20several%20index%20types,fit%20the%20most%20common%20situations."><strong>Postgres Indexes</strong></a><strong> </strong>and tried to <a href="https://www.guru99.com/database-normalization.html"><strong>normalize</strong></a> the tables as much as possible, it follows the basics of designing the database. Have a look at the detailed explanation of the design. Do comment if you have some views.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/870a19e7d58f5057d0281c05761802f6/href">https://medium.com/media/870a19e7d58f5057d0281c05761802f6/href</a></iframe><ul><li><a href="https://www.guru99.com/database-normalization.html">DBMS Normalization: 1NF, 2NF, 3NF Database Example</a></li><li><a href="https://www.tutorialspoint.com/postgresql/postgresql_indexes.htm">PostgreSQL - INDEXES</a></li></ul><p>Will be using a managed service, for now, <a href="https://planetscale.com/"><strong>PlanetScale</strong></a> really great free tier. For the authentication layer, I will be using <a href="https://auth0.com/"><strong>Auth0</strong></a><strong> </strong>and some managed service for the Redis Layer from <a href="https://upstash.com/"><strong>Upstash</strong></a><strong> </strong>(Not Sure presently).</p><h3>Elasticsearch Design</h3><p>Keeping this section simple, I will be doing one-to-one mapping tables in Postgres with Elasticsearch. Have a look at this article it is really great, have a look at why I jumped into Elasticsearch.</p><p><a href="https://www.alibabacloud.com/blog/combining-elasticsearch-with-dbs-application-system-scenarios_597112">Combining Elasticsearch with DBs: Application System Scenarios</a></p><p>Here is an example of how you might create a mapping for the users table from your database schema:</p><pre>PUT users<br>{<br>  &quot;mappings&quot;: {<br>    &quot;properties&quot;: {<br>      &quot;id&quot;: {<br>        &quot;type&quot;: &quot;integer&quot;<br>      },<br>      &quot;email&quot;: {<br>        &quot;type&quot;: &quot;text&quot;<br>      },<br>      &quot;password_hash&quot;: {<br>        &quot;type&quot;: &quot;text&quot;<br>      },<br>      &quot;first_name&quot;: {<br>        &quot;type&quot;: &quot;text&quot;<br>      },<br>      &quot;last_name&quot;: {<br>        &quot;type&quot;: &quot;text&quot;<br>      },<br>      &quot;date_of_birth&quot;: {<br>        &quot;type&quot;: &quot;date&quot;<br>      },<br>      &quot;gender&quot;: {<br>        &quot;type&quot;: &quot;keyword&quot;<br>      },<br>      &quot;phone&quot;: {<br>        &quot;type&quot;: &quot;text&quot;<br>      },<br>      &quot;profile_picture_url&quot;: {<br>        &quot;type&quot;: &quot;text&quot;<br>      },<br>      &quot;created_at&quot;: {<br>        &quot;type&quot;: &quot;date&quot;<br>      },<br>      &quot;updated_at&quot;: {<br>        &quot;type&quot;: &quot;date&quot;<br>      }<br>    }<br>  }<br>}</pre><p>You can repeat this process for each of the other tables in your database schema, defining the fields and their data types in the Elasticsearch mapping as needed.</p><p>It’s worth noting that you should choose data types for your Elasticsearch mapping based on the types of queries you will be running against your data. For example, if you want to be able to search for exact values in a field, you might want to use the keyword data type, while if you want to be able to perform full-text searches on a field, you might want to use the text data type.</p><p>I’ve covered the essential steps of basic system design and database structure in creating an MVP. In the next blog, we’ll continue our journey by diving into the development of our MVP. Who knows where this journey will take us? Stay tuned as we turn our side project into a potentially successful startup (or at least have a bit of fun along the way).</p><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Follow me for Kotlin content and more. Happy Coding!</p><p>I will well appreciate one of these 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92775dbd74d6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/building-startup-pocketbook-with-kmm-3-n-database-and-system-design-92775dbd74d6">Building Startup (Pocketbook) with KMM [3/n] — Database and System Design</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Startup with KMM [2/n]— Brainstorming ideas and MVP with ChatGPT]]></title>
            <link>https://medium.com/backyard-programmers/building-startup-with-kmm-2-n-brainstorming-ideas-and-mvp-with-chatgpt-3b5de1b0433c?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/3b5de1b0433c</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 23:08:50 GMT</pubDate>
            <atom:updated>2022-12-20T23:10:24.217Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IITq465nDRzOxR7GjHxPyA.gif" /><figcaption>James Yang</figcaption></figure><p>As a mobile developer, I’m excited to see what we can accomplish with ChatGPT and a little bit of determination. If you don’t know about <a href="https://en.wikipedia.org/wiki/ChatGPT"><strong>ChatGPT</strong></a>, which stands for <strong>Chat Generative Pre-trained Transformer</strong>, is a <a href="https://en.wikipedia.org/wiki/Chatbot">chatbot</a> developed by <a href="https://en.wikipedia.org/wiki/OpenAI">OpenAI</a>. This has taken the world by storm with its detailed responses and articulate answers across many domains of knowledge. You can find more details here.</p><p><a href="https://openai.com/blog/chatgpt/">Introducing ChatGPT</a></p><p>In my previous blog, we already discussed Kotlin Multiplatform Mobile(KMM)</p><p><a href="https://medium.com/backyard-programmers/will-kotlin-multiplatform-mobile-change-the-way-we-make-mobile-applications-c71dd98aa31e">Will Kotlin Multiplatform Mobile change the way we make mobile applications? [1/n]</a></p><p>Just combining two trending topics to make good use of my Wellness Holidays from my company❤️.</p><p><strong>Note: I am planning to develop and publish the app end to end and my journey. Do add your ideas and thoughts in the comments 🙏. I will add the next blog link to this when I post next.</strong></p><p>Building a startup can be a challenging and rewarding experience, but it doesn’t have to be all work and no play. With the right tools and a little bit of creativity, it’s possible to turn a side project into a fun and successful venture. Join me on this journey as I document the process of building a startup from scratch, all while keeping things light and enjoyable. Let’s get started!</p><h3>Ideation</h3><p>Initially, I had no idea in particular so I blankly asked for</p><blockquote>Android and ios app ideas which are easy to build but really creative.</blockquote><p>The ideas from ChatGPT were,</p><ol><li><strong>A social networking app for people with common hobbies or interests</strong>. This could be a platform for people to connect with others who have similar hobbies, such as cooking, gardening, or playing a particular sport.</li><li><strong>A language learning app that gamifies the learning process</strong>. This app could include interactive quizzes, challenges, and rewards to make learning a new language more engaging.</li><li><strong>A recipe app that suggests meals based on the ingredients you have available</strong>. Users could input the ingredients they have on hand, and the app would suggest recipes that use those ingredients.</li><li><strong>A budgeting and finance tracking app that helps users keep track of their spending and set financial goals.</strong> The app could include features like budgeting templates, spending tracking, and alerts when users approach their budget limits.</li><li><strong>A fitness tracking app that uses machine learning to suggest personalized workouts based on the user’s fitness level and goals. </strong>The app could include exercises and workouts for a variety of fitness levels, as well as progress tracking and motivation tools.</li><li><strong>A mental health and self-care app</strong> that offers guided meditation, journaling prompts, and other self-care activities to help users manage stress and improve their overall well-being.</li><li><strong>A travel planning app</strong> that helps users plan and organizes their trips. The app could include features like itinerary planning, travel budgeting, and destination recommendations based on the user’s preferences.</li></ol><p>Nothing new or creative as such but let’s play along with this and see where it takes us. I continued with the <strong>budgeting and finance tracking app.</strong></p><h3>Dissecting and BrainStorming</h3><p>Then I asked</p><blockquote>Can you expand on the <strong>budgeting and finance tracking app</strong> and dissect idea into features based on market research?</blockquote><p>And wah-lah you have a great list of features. Great!</p><ol><li><strong>Budgeting templates:</strong> Users can choose from pre-designed budget templates or create their own custom budget.</li><li><strong>Spending tracking:</strong> Users can input their daily or monthly expenses to track their spending and see how it compares to their budget.</li><li><strong>Bill reminders:</strong> Users can set up alerts to remind them when bills are due, helping them avoid late fees and maintain a good credit score.</li><li><strong>Savings goals:</strong> Users can set savings goals and track their progress towards achieving them. The app could also provide recommendations on how to save more money, such as by cutting unnecessary expenses or finding ways to earn additional income.</li><li><strong>Investment tracking:</strong> Users can track their investments and see how they are performing over time. The app could also provide recommendations on investment opportunities based on the user’s risk tolerance and financial goals.</li><li><strong>Credit score monitoring:</strong> Users can track their credit score and get alerts when it changes. The app could also provide tips on how to improve their credit score, such as by paying bills on time and reducing credit card balances.</li><li><strong>Debt management:</strong> Users can track their debt and create a plan to pay it off. The app could provide recommendations on the best repayment strategies, such as prioritizing high-interest debt or using the snowball method.</li><li><strong>Shared budgets:</strong> Users can invite other people, such as their spouse or family members, to join their budget and track their combined spending.</li><li><strong>Integration with financial accounts:</strong> Users can connect their bank, credit card, and other financial accounts to the app, allowing them to see all their financial information in one place.</li><li><strong>Security:</strong> The app should prioritize the security and privacy of user data, including using strong encryption and secure servers to protect against data breaches.</li></ol><p>I had a follow-up question regarding <strong>Budgeting templates </strong>like what it is referring to?</p><blockquote>Budgeting templates are pre-designed budget plans from which users can choose to assist them in managing their finances. These templates usually include categories for common expenses like housing, transportation, food, and entertainment, as well as estimates for how much should be spent in each category based on the user’s income and financial goals. By providing budgeting templates, the app can provide a starting point for users who are new to budgeting or who want to quickly set up a budget without having to start from scratch. The templates can also be used as a reference for users who want to compare their own budget to a recommended plan.</blockquote><h3>Competition and Product Market Fit</h3><p>When I asked regarding</p><blockquote>Which of these features is unique to the market and not done by already existing apps? and secondly, do you have any creative suggestions for better product market fit?</blockquote><p>The answer was quite intuitive and explanative,</p><p>It’s difficult to say which specific features are unique to the market, as new financial apps are constantly being developed and released. However, here are a few potential ideas for unique features that could differentiate a budgeting and finance tracking app from existing ones:</p><ol><li><strong>Personalized budget recommendations</strong>: The app could use machine learning algorithms to analyze the user’s spending and income patterns and provide recommendations on how to optimize their budget for their specific financial situation.</li><li><strong>Gamification</strong>: The app could use gamification techniques, such as rewards and challenges, to make budgeting and financial management more engaging and motivating for users.</li><li><strong>Integration with financial advisors</strong>: Users could connect with financial advisors through the app to get personalized financial advice and guidance.</li><li><strong>Collaboration with financial institutions</strong>: The app could partner with banks and other financial institutions to offer users exclusive discounts and perks, such as reduced fees or higher interest rates on savings accounts.</li><li><strong>Customized financial planning</strong>: The app could offer personalized financial planning services, such as helping users create a retirement plan or a budget for a major life event, such as a wedding or the birth of a child.</li><li><strong>Social networking for finance</strong>: The app could include a social networking component, allowing users to connect with and learn from others in the financial community. Users could share budgeting and saving tips, share their financial goals, and offer support and encouragement to each other.</li></ol><p>To better fit the product to the market, you could consider conducting market research to understand the needs and preferences of your target users. This could involve surveying potential users, analyzing data on existing financial apps, and conducting focus groups to gather feedback on your product ideas. Based on this research, you can tailor the features of your app to better meet the needs and desires of your target audience.</p><p>Quite an impressive answer!</p><h3>Minimal Viable Product (MVP)</h3><p>After a solid back-and-forth discussion with ChatGPT, I concluded the following as the basic features required for an MVP.</p><ol><li><strong>Budgeting templates: </strong>Users can choose from pre-designed budget templates or create their own custom budget.</li><li><strong>Spending tracking:</strong> Users can input their daily or monthly expenses to track their spending and see how it compares to their budget.</li><li><strong>Bill reminders:</strong> Users can set up alerts to remind them when bills are due.</li><li><strong>Savings goals:</strong> Users can set savings goals and track their progress towards achieving them.</li><li><strong>Security:</strong> The app should prioritize the security and privacy of user data, including using strong encryption and secure servers to protect against data breaches.</li></ol><p>This MVP includes the core features of a budgeting and finance tracking app, including the ability to create a budget, track spending, and set up bill reminders. It also includes security measures to protect user data.</p><p>I’ve covered the essential steps of brainstorming ideas and creating an MVP using ChatGPT. In the next blog, we’ll continue our journey by diving into the development of our MVP. Who knows where this journey will take us? Stay tuned as we turn our side project into a potentially successful startup (or at least have a little bit of fun along the way).</p><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Follow me for Kotlin content and more. Happy Coding!</p><p>I will well appreciate one of these 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b5de1b0433c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/building-startup-with-kmm-2-n-brainstorming-ideas-and-mvp-with-chatgpt-3b5de1b0433c">Building Startup with KMM [2/n]— Brainstorming ideas and MVP with ChatGPT</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Will Kotlin Multiplatform Mobile change the way we make mobile applications? [1/n]]]></title>
            <link>https://medium.com/backyard-programmers/will-kotlin-multiplatform-mobile-change-the-way-we-make-mobile-applications-c71dd98aa31e?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/c71dd98aa31e</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Sun, 20 Nov 2022 09:06:01 GMT</pubDate>
            <atom:updated>2022-11-29T17:17:35.994Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*im3vjSax9_P_B-rCQoO_Zg.jpeg" /></figure><p>If you are a mobile developer and not living under a rock, you should have heard about Kotlin Multiplatform and how it revolutionizes the mobile development industry.</p><p>Let me first explain it to you <a href="https://kotlinlang.org/lp/mobile/"><strong>Kotlin Multiplatform Mobile (KMM)</strong></a> is an SDK designed to simplify the development of cross-platform mobile applications. You can share common code between iOS and Android apps and write platform-specific code only where it’s necessary. Common use cases for Kotlin Multiplatform Mobile include implementing a native UI or working with platform-specific APIs.</p><h3>What is Kotlin Multiplatform Mobile (KMM)?</h3><p>Kotlin Multiplatform Mobile is an SDK for iOS and Android app development. It offers all the combined benefits of creating cross-platform and native apps. Maintain a single codebase for networking, data storage, analytics, and the other logic of your Android and iOS apps. Implement native UIs and leverage other features specific to Android and iOS devices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Bt3Ms_aOWMUgEWBwCjmQA.jpeg" /></figure><p>It is trusted in production by many of the world’s leading companies, including <a href="https://kotlinlang.org/lp/mobile/case-studies/philips"><strong>Philips</strong></a>, <a href="https://netflixtechblog.com/netflix-android-and-ios-studio-apps-kotlin-multiplatform-d6d4d8d25d23?gi=caba8959a8b6"><strong>Netflix</strong></a>, <a href="https://kotlinlang.org/lp/mobile/case-studies/leroy-merlin"><strong>Leroy</strong> <strong>Merlin</strong></a>, and <a href="https://kotlinlang.org/lp/mobile/case-studies/vmware/"><strong>VMWare</strong></a>.</p><h3>Problems that KMM is trying to solve?</h3><ul><li><strong>Time and efforts saved by sharing code — </strong>In mobile development, it is always an issue that the same code has to be written in both android and iOS with KMM it is really easy that the business logic can easily be shared between in turn will rescue the time taken to rewrite the same business logic.</li><li><strong>Native Performance — </strong>With cross-platform solutions performance has always been an issue. Since the introduction of KMM separated out only the business logic, the UI remains the same native, with easier access to hardware like Camara, etc. Unlike cross-platform options like Flutter, Ionic, etc.</li><li><strong>Connect to platform-specific APIs without overhead — </strong>KMM is not overlapped with your native device usage. If you want to access your device camera you natively access it with native Swift code for iOS and Kotlin for Android. This approach is very much better than the approach that Flutter or React Native takes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YaFlTKeozkel5sf-q2TGKg.jpeg" /></figure><h3>How is KMM solving problems?</h3><h4>Share code on platforms</h4><p>If you have common business logic for all platforms, you don’t need to write the same code for each platform — share it in the common source set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*unTRmYwMOh7vaH4UavM5Qg.png" /></figure><h4>One language for cross-platform and native apps</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zWGEvlTSSTHTTW-UUrclA.jpeg" /></figure><p>There’s no need to introduce any new programming languages to your codebase to make your app cross-platform. <a href="https://kotlinlang.org/docs/mobile/integrate-in-existing-app.html">Make your existing Android app work on iOS devices</a> without changing much of your existing code.</p><p>Kotlin syntax follows the same concepts used for iOS development and is easy for iOS developers to learn.</p><h4>Connect to platform-specific APIs</h4><p>If you’re developing a multiplatform application that needs to access platform-specific APIs that implement the required functionality (for example, <a href="https://kotlinlang.org/docs/multiplatform-connect-to-apis.html#generate-a-uuid">generating a UUID</a>), use the Kotlin mechanism of <em>expected and actual declarations</em>.</p><p>With this mechanism, a common source set defines an <em>expected declaration</em>, and platform source sets must provide the <em>actual declaration</em> that corresponds to the expected declaration. This works for most Kotlin declarations, such as functions, classes, interfaces, enumerations, properties, and annotations.</p><p>The compiler ensures that every declaration marked with the <strong>expect</strong> keyword in the common module has the corresponding declarations marked with the <strong>actual</strong> keyword in all platform modules. The IDE provides tools that help you create the missing actual declarations.</p><h4>Familiar with tooling and ecosystem</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0IjOVhwXJJnGot8NwHBmCA.jpeg" /></figure><p>Multiplatform Mobile leverages the multiplatform capabilities of Kotlin and provides tooling for cross-platform mobile development in Android Studio. The <a href="https://github.com/terrakok/kmm-awesome">multiplatform library ecosystem</a> is growing. A number of big libraries such as Ktor, SQLDelight, Apollo, and Koin have already adopted Kotlin Multiplatform.</p><h3>How Kotlin Multiplatform works</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*WJu1I9PO_oyu1E6Zx-MOPA.png" /></figure><ul><li><strong>Common Kotlin</strong> includes the language, core libraries, and basic tools. Code written in common Kotlin works everywhere on all platforms.</li><li>With Kotlin Multiplatform libraries, you can reuse the multiplatform logic in common and platform-specific code. Common code can rely on libraries that cover tasks such as <a href="https://ktor.io/clients/http-client/multiplatform.html">HTTP</a>, <a href="https://github.com/Kotlin/kotlinx.serialization">serialization</a>, and <a href="https://github.com/Kotlin/kotlinx.coroutines">managing coroutines</a>.</li><li>To interop with platforms, use platform-specific versions of Kotlin. <strong>Platform-specific versions of Kotlin</strong> (Kotlin/JVM, Kotlin/JS, Kotlin/Native) include extensions to the Kotlin language, and platform-specific libraries and tools.</li><li>Through these platforms, you can access the <strong>platform&#39;s native code</strong> (JVM, JS, and Native) and leverage all native capabilities.</li></ul><p>These are all the reasons why I feel Kotlin Multiplatform will change the way we think of approaches to building a mobile application. It provides the best of both worlds by providing the power to share business logic between platforms with the speed of native approaches.</p><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Follow me for Kotlin content and more. Happy Coding!</p><p>I will well appreciate one of these 👏</p><h3>Recent Post</h3><ul><li><a href="https://medium.com/backyard-programmers/build-ktor-project-with-docker-and-add-nginx-for-load-balancing-reverse-proxy-2143bb1969cf">Build Ktor Project with Docker and Add Nginx for Load Balancing &amp; Reverse Proxy</a></li><li><a href="https://medium.com/backyard-programmers/media3-exoplayer-in-jetpack-compose-to-make-snapchat-spotlight-75e384e2ef56">Media3 ExoPlayer in Jetpack Compose to make Snapchat Spotlight</a></li><li><a href="https://medium.com/backyard-programmers/adding-google-map-in-jetpack-compose-using-androidview-and-android-maps-compose-23378520523d">Adding Google Map in Jetpack Compose 🗺📌- Using AndroidView And android-maps-compose</a></li><li><a href="https://medium.com/backyard-programmers/replacing-retrofit-with-ktor-client-and-kotlin-serialization-for-android-5ca6bfc60648">Replacing Retrofit with Ktor Client and Kotlin Serialization for Android🐱‍🏍</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c71dd98aa31e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/will-kotlin-multiplatform-mobile-change-the-way-we-make-mobile-applications-c71dd98aa31e">Will Kotlin Multiplatform Mobile change the way we make mobile applications? [1/n]</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blockchain For Dummies]]></title>
            <link>https://medium.com/backyard-programmers/blockchain-for-dummies-8407bfd35af1?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/8407bfd35af1</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain-technology]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Thu, 03 Nov 2022 04:09:38 GMT</pubDate>
            <atom:updated>2022-11-03T04:09:22.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WCVyW2kD3-7nMcBzpqibMg.jpeg" /><figcaption>Source: Matrix Movie</figcaption></figure><p>Blockchain and Cryptocurrency are the new buzzwords of Genz. I think knowledge without understanding is meaningless because it is information, not knowledge. The information doesn’t have meaning on its own, does it?</p><p>This scene from the movie “<a href="https://en.wikipedia.org/wiki/The_Matrix">The Matrix</a>” always intrigues me to know more and have a deeper understanding. The <strong>blue pil</strong>l describes a continuity of the current state of life i.e. living life without knowing its meaning or running away from the truth in order to stay as is. The <strong>red pill</strong> is described as the solution to knowing the real truth in life.</p><p>So today here is your <strong>red pill</strong> for blockchain, to you understand this in the most simple way I can.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*VshjWiwYWdCjHogLxanH1A.jpeg" /><figcaption>Source: MemeFactory</figcaption></figure><p>Assume that there are two individuals: Bob and Alice. Bob lends Alice some money, and Bob records it on a document that Alice has signed. After a few days, Alice disputes the existence of such a document and asserts that Bob faked it. It would now be challenging for Bob to demonstrate that Alice genuinely owed him money.</p><p>In this example, Alice and Bob are two nodes.</p><p>Consider the same situation now, but this time it’s a society. As a result, “k” pairs of people are interacting with one another. And that piece of paper is the only evidence each duo has. Kate offers a remedy after considering this situation. She advises that the entire society keep a shared journal of transactions. She chooses town hall as the location for all conversations. Every couple records their transactions in the shared notebook, which is subsequently stored securely. People are happy with Kate as their leader and accept her.</p><p>That notebook can be called a <strong>database</strong>.</p><p>But the notebook gets wine on it one day. The notebook is now impossible to read. Alice takes advantage of this circumstance and refutes taking money from Bob once more.</p><p>This is the problem databases face: a <a href="https://www.techtarget.com/searchdatacenter/definition/Single-point-of-failure-SPOF#:~:text=What%20is%20a%20single%20point%20of%20failure%20(SPOF)%3F,entire%20system%20to%20stop%20operating."><strong>single point of failure</strong></a>.</p><p>Angered by this issue, Kate finds a different remedy. She advises keeping several notebooks. She selects a few reliable people from the community and gives them each a notebook. Now Kate tells some of those reliable people to record every transaction or exchange that occurs between two people in their notebooks. The information is therefore repeated in the notebooks. Now, even if one notebook is lost or destroyed, it’s likely that the collection of other notebooks will still include all the transactional data.</p><p>This is a <a href="https://www.tutorialspoint.com/distributed_dbms/distributed_dbms_databases.htm"><strong>distributed database</strong></a><strong>,</strong> and multiple notebooks are numerous nodes.</p><p>But the following day, a new issue appears. Bert, a friend of Kate’s, owes a lot of money to various members of society. When he asks Kate for assistance, she grants it. She tells everyone who has a notepad to cross out the lines where Bert received the cash. Based on the notebooks, Bert is now debt-free.</p><p>This is the <strong>problem with distributed databases — they are centralized</strong>. That means one single entity owns all the nodes and resources and can make changes as they deem fit.</p><p>When the members of the society know of it, they remove Kate from the leadership.</p><ul><li>They choose to each keep a notebook. Every time there is a transaction between any two individuals, all the residents of the town gather and record it in their individual notebooks. There are therefore n notebooks in the community if there are n people, and no one person has authority over how the transactions are represented overall.<strong> </strong><a href="https://aws.amazon.com/blockchain/decentralization-in-blockchain/#:~:text=In%20blockchain%2C%20decentralization%20refers%20to,thereof)%20to%20a%20distributed%20network."><strong>This is</strong> <strong>decentralization.</strong></a></li><li>They also decide to never remove or delete an already mentioned transaction from the notebook. <a href="https://medium.com/fluree/immutability-and-the-enterprise-an-immense-value-proposition-98cd3bf900b1#:~:text=Immutability%20%E2%80%94%20the%20ability%20for%20a,highlight%20as%20a%20key%20benefit."><strong>This is immutability</strong>.</a></li><li>Now, every person in society must make the same adjustment when members of a different group, let’s call them group CHO, attempt to alter a record in their notebooks (as mentioned in the first point above, all the people write all the transactions in their notebooks). All of the other participants see that the transaction proposed by group CHO is incorrect before it is written. They thus recognize that CHO is attempting to engage in fraud. They consequently dispute that transaction and omit to record it in their notes. Additionally, they resolve to bar Group CHO from participation in the group going forward. <strong>This is how consensus is formed, and voting is done to decide the validity of a transaction on the blockchain</strong>.</li><li>A very enthusiastic kid suggested that the transactions form a chain, so they decided to call the collective set of fully replicated, decentralized, immutable notebooks Blockchain.</li></ul><p>then, okay. The simplest illustration of blockchain I can think of is this.</p><blockquote>Blockchain is a decentralized, peer-to-peer, immutable storage network that is free from censorship and regulation due to the lack of a central authority. A majority of nodes vote on each written transaction, and it is computationally very challenging to change something that has already been recorded in the chain.</blockquote><p>Hope this is helpful in making you understand the terminologies and concepts. If this encourages you to know more about the blockchain, these links will be helpful.</p><ul><li><a href="https://en.wikipedia.org/wiki/Blockchain">https://en.wikipedia.org/wiki/Blockchain</a></li><li><a href="https://www.ibm.com/id-en/topics/what-is-blockchain">https://www.ibm.com/id-en/topics/what-is-blockchain</a></li><li><a href="https://www.pwc.com/us/en/industries/financial-services/fintech/bitcoin-blockchain-cryptocurrency.html">https://www.pwc.com/us/en/industries/financial-services/fintech/bitcoin-blockchain-cryptocurrency.html</a></li></ul><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Happy Coding!</p><p>I will well appreciate one of these 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8407bfd35af1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/blockchain-for-dummies-8407bfd35af1">Blockchain For Dummies</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secrets Of Strings in Dart]]></title>
            <link>https://medium.com/backyard-programmers/secrets-of-strings-in-dart-4ae03ca3967e?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/4ae03ca3967e</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Mon, 13 Jun 2022 19:03:17 GMT</pubDate>
            <atom:updated>2022-06-13T19:03:16.851Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*78OL1HKqMBJpJXB_" /><figcaption>Photo by <a href="https://unsplash.com/@sysengineer?utm_source=medium&amp;utm_medium=referral">Nicolas Horn</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s dive right into it we will start by understanding what are Runes in Dart,</p><p>Runes are a collection formed out of a String&#39;s Unicode decimal code points. A <strong><em>Code Point</em></strong> is an integer value that uniquely identifies a given Unicode Character from inside the String</p><p>A Dart String is a sequence of <strong><em>UTF-16</em></strong> code. A <strong><em>Code Unit</em></strong> is the unit of an <strong><em>Encoded Code Point</em></strong> .</p><p><strong><em>UTF-16</em></strong> means the code point of a <strong><em>Unicode Character</em></strong> that has been <strong>Encoded</strong> to <strong>16-bit Code Unit (Hexadecimal Code Point). </strong>Then the code point is a hexadecimal number, which means in dart every string is split between characters and each of these characters has a hexadecimal code point, behind the scenes in Dart, a string is no more than a list of hexadecimal code points.</p><pre><strong>String s=&#39;Helloooo&#39; ---&gt; &#39;H&#39;,&#39;e&#39;,&#39;l&#39;,&#39;l&#39;,&#39;o&#39;,&#39;o&#39;,&#39;o&#39;,&#39;o&#39;<br>                       0048,0065,006C,006C,006F,006F,006F,006F</strong></pre><h3>Let’s See Some Examples</h3><p>We make variable runes, we can actually see a list of<strong>utf-16 </strong>code points for that string</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tgiKlld5meHrmdnXrzO6hA.png" /></figure><p>now, let&#39;s convert it into decimal code points in order to see its hexadecimal values, we can call <strong>toRedixSting() </strong>and set 16 bit as the base, then pad it to the left so that it will always be 4 characters long, we are using a map to call it to all characters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9PZrxifdCB_sxoVygK_7Q.png" /></figure><p>By the way, Dart is amazing in providing interpolation of this Unicode to characters with the <strong>/u{} </strong>delimiter i.e, any hexadecimal Unicode can be converted including emojis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wryFUL8TBl69ThLptZu-ag.png" /></figure><p>For a character outside the <strong>Basic Multilingual Plane</strong> (plane 0) that is composed of a surrogate pair, <a href="https://api.flutter.dev/flutter/dart-core/String/runes.html">runes</a> combine the pair and return a single integer. For example, the Unicode character for a musical G-clef (‘𝄞’) with rune value <strong>0x1D11E </strong>consists of a UTF-16 surrogate pair: <strong>0xD834 </strong>and <strong>0xDD1E</strong>. Using <a href="https://api.flutter.dev/flutter/dart-core/String/codeUnits.html">codeUnits</a> returns the surrogate pair, and using <strong>runes </strong>returns their combined value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GH19-6wynWO9kcPYpKhdtg.png" /></figure><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Follow me for Dart &amp; Kotlin content and more. Happy Coding!</p><p>I will well appreciate one of these 👏</p><h4><strong>Recent Post</strong></h4><ul><li><a href="https://medium.com/backyard-programmers/advanced-dart-generator-stream-extension-mixins-generics-f8a6e8b48f67">Advanced Dart — Generator, Stream, Extension, Mixins, Generics…</a></li><li><a href="https://medium.com/backyard-programmers/build-ktor-project-with-docker-and-add-nginx-for-load-balancing-reverse-proxy-2143bb1969cf">Build Ktor Project with Docker and Add Nginx for Load Balancing &amp; Reverse Proxy</a></li><li><a href="https://medium.com/backyard-programmers/replacing-retrofit-with-ktor-client-and-kotlin-serialization-for-android-5ca6bfc60648">Replacing Retrofit with Ktor Client and Kotlin Serialization for Android🐱‍🏍</a></li><li><a href="https://medium.com/backyard-programmers/media3-exoplayer-in-jetpack-compose-to-make-snapchat-spotlight-75e384e2ef56">Media3 ExoPlayer in Jetpack Compose to make Snapchat Spotlight</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ae03ca3967e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/secrets-of-strings-in-dart-4ae03ca3967e">Secrets Of Strings in Dart</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Dart — Generator, Stream, Extension, Mixins, Generics…]]></title>
            <link>https://medium.com/backyard-programmers/advanced-dart-generator-stream-extension-mixins-generics-f8a6e8b48f67?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/f8a6e8b48f67</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Wed, 08 Jun 2022 21:01:46 GMT</pubDate>
            <atom:updated>2022-06-14T17:07:56.837Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced Dart — Generator, Stream, Extension, Mixins, Generics…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*de4SDUc1WoQy5pY2" /><figcaption>Photo by <a href="https://unsplash.com/@macroman?utm_source=medium&amp;utm_medium=referral">Immo Wegmann</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I was revisiting, Flutter after some time so, I thought it will be great to put up my understanding with examples and summarise it here. These are some of the topics that people tend to ignore this gives us a wide understanding of the Dart as a language. This is important, let&#39;s start with the explanation ✨</p><p><a href="https://medium.com/backyard-programmers/secrets-of-strings-in-dart-4ae03ca3967e">Secrets Of Strings in Dart</a></p><h3>1. Extension🔗</h3><p>It is a simple term, you can think of it as the ability of a programmer to add functions to an existing class. It’s understood with an example.</p><p>Suppose you have a class called <strong>Dog</strong>, you need to add a function <strong>train() </strong>you can directly add to the class <strong>Dog</strong>. Now suppose you don’t have the access to the <strong>Dog</strong> class or you want to segregate the function based on some use-case and based on the use-case you want to import a set of functions. Now you can do that with an extension on the class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wkmS02_AUvOFJkLAYNH8tA.jpeg" /></figure><p>You can see in the example we have added the extension function, the name <strong>Train , </strong>there is no specific reason to understand the use of the name it is generally used in case you only want to include a specific extension.</p><h3>2. Async/Await &amp; Future🔮</h3><p>Before everything, you need to know about an <strong><em>asynchronous computation. </em></strong><em>It is when a program</em><strong><em> </em></strong>cannot provide a result immediately when it is started, unlike a synchronous computation which does compute a result immediately by either returning a value or by throwing. An asynchronous computation may need to wait for something external to the program (reading a file, querying a database, fetching a web page) which takes time. <em>Instead of blocking all computation until the result is available, the asynchronous computation immediately returns a </em><strong><em>Future</em></strong><em> which will eventually &quot;complete&quot; the result.</em></p><p>To perform an asynchronous computation, you use a <strong><em>async</em></strong> function which always produces a future. Inside such an asynchronous function, you can use the <strong><em>await</em></strong> operation to delay execution until another asynchronous computation has a result. While the execution of the awaiting function is delayed, the program is not blocked and can continue doing other things.</p><p>See the below code this will help you to understand it in greater detail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2aHW9hBOIlOeOTPC46eNZw.png" /></figure><h3>3. Stream🚝</h3><p>The stream you can think of as a stream of data is <strong><em>asynchronous </em></strong>however it is continuous. You can think of it as a pipe of data it either <strong>completes successfully</strong> or <strong>never completes</strong> or <strong>errors out</strong>. A stream is a sequence of asynchronous events. It is like an asynchronous Iterable — where, instead of getting the next event when you ask for it, the stream tells you that there is an event when it is ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BA_doegYnUKRZ-uO1-fqjA.png" /></figure><h4>Receiving stream events</h4><p>Streams can be created in many ways, which is a topic for another article. Still, they can all be used in the same way: the <em>asynchronous for loop</em> (commonly just called <strong>await for</strong>) iterates over the events of a stream like the <strong>for loop</strong> iterates over an <a href="https://api.dart.dev/stable/dart-core/Iterable-class.html">Iterable</a>. For example:</p><pre>Future&lt;int&gt; sumStream(Stream&lt;int&gt; stream) async {<br>  var sum = 0;<br>  await for (final value in stream) {<br>    sum += value;<br>  }<br>  return sum;<br>}</pre><h3>4. Generator✈</h3><p>Dart Generator is a unique function that allows us to produce a sequence of values. Generators return values on demand; the value is generated when we try to iterate over the iterators. Dart provides built-in support for two types of generator functions.</p><ul><li>Synchronous Generators</li><li>Asynchronous Generators</li></ul><pre>Let&#39;s first understand the difference between <strong>LIST &amp; ITERABLE.</strong> You can think of <strong>Iterable </strong>as a list of things which is not completely calculated when it begins, it is basically <strong>lazy </strong>collection. While <strong>List </strong>in Dart is <strong>egar </strong>i.e, it is already ready then it is being called.</pre><pre><strong>yeild</strong>: The yield returns the single value to the sequence at a time but does not stop the execution of the generator function completely. It returns a value for each execution of the generator function.<br><strong>sync*: </strong>The sync* keyword is used to declare the synchronize generator function. It returns the value when we try to iterator the value not when it was created.<br><strong>async*</strong>: The async keyword is used to declare the asynchronous generators. It returns the stream object.</pre><h4>Synchronous Generator</h4><p>It returns an iterable object which carries value synchronously. The <strong>yeild</strong> keyword is used along with marking the synchronous generator function body as <strong>sync*</strong> to generator values.</p><p><strong>What is the benefit? </strong>You might think why complicating things, suppose each value you yield has heavy computation. You can break out of the while loop any time, and any values after that will not be computed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K5hqROoxWJh6lxWusCdsIQ.png" /></figure><h4>Asynchronous Generators</h4><p>It returns a stream object which carries value asynchronously. The <strong>yeild</strong> keyword is used along with marking the asynchronous generator function body as <strong>async*</strong> to generator values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Ot2q9n4DAwUXzLOf8Y1UA.png" /></figure><h3>5. Mixins🛰</h3><p>In OOPs, we have classes, Interfaces, Abstract Classes, etc. Dart provides one more option of <strong>Mixins.</strong></p><blockquote>Mixins are a way of reusing a class’s code in multiple class hierarchies.</blockquote><p>Mixins allow you to <strong>plug in code blocks <em>without </em>needing to create subclasses</strong>. Mixins are a very useful way of avoiding code duplication without inheritance. You can see the two vertical images on the left and the right as the outcome with mixins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LMvwKPR-dlF1LwKsSLK1AA.jpeg" /></figure><h3>6. Generics🚀</h3><p>In Dart by default, collections are <strong>heterogeneous</strong>. However, by the use of generics, we can make a collection to hold <strong>homogeneous </strong>values. The use of Generics makes the use of a single compulsory data type to be held inside the collection. Such collections are called <strong>type-safe collections</strong>.</p><p>Generics are often required for type safety, but they have more benefits than just allowing your code to run:</p><ul><li>Properly specifying generic types results in better-generated code.</li><li>You can use generics to reduce code duplication.</li></ul><pre>var names = &lt;String&gt;[];<br>names.addAll([&#39;Seth&#39;, &#39;Kathy&#39;, &#39;Lars&#39;]);<br>names.add(42); <strong>// Error</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JWRPKHU6Dk0tcMoWGiygOQ.png" /></figure><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Follow me for Dart &amp; Kotlin content and more. Happy Coding!</p><p>I will well appreciate one of these 👏</p><h4>Recent Post</h4><ul><li><a href="https://medium.com/backyard-programmers/deploy-your-ktor-project-anywhere-d42c61c8e7a6">Deploy Your Ktor Project Anywhere!</a></li><li><a href="https://medium.com/backyard-programmers/build-ktor-project-with-docker-and-add-nginx-for-load-balancing-reverse-proxy-2143bb1969cf">Build Ktor Project with Docker and Add Nginx for Load Balancing &amp; Reverse Proxy</a></li><li><a href="https://medium.com/backyard-programmers/replacing-retrofit-with-ktor-client-and-kotlin-serialization-for-android-5ca6bfc60648">Replacing Retrofit with Ktor Client and Kotlin Serialization for Android🐱‍🏍</a></li><li><a href="https://medium.com/backyard-programmers/media3-exoplayer-in-jetpack-compose-to-make-snapchat-spotlight-75e384e2ef56">Media3 ExoPlayer in Jetpack Compose to make Snapchat Spotlight</a></li><li><a href="https://medium.com/backyard-programmers/adding-google-map-in-jetpack-compose-using-androidview-and-android-maps-compose-23378520523d">Adding Google Map in Jetpack Compose 🗺📌- Using AndroidView And android-maps-compose</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8a6e8b48f67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/advanced-dart-generator-stream-extension-mixins-generics-f8a6e8b48f67">Advanced Dart — Generator, Stream, Extension, Mixins, Generics…</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Your Ktor Project Anywhere!]]></title>
            <link>https://medium.com/backyard-programmers/deploy-your-ktor-project-anywhere-d42c61c8e7a6?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/d42c61c8e7a6</guid>
            <category><![CDATA[ktor]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kotlin-backend]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Tue, 31 May 2022 16:08:56 GMT</pubDate>
            <atom:updated>2022-05-31T16:08:56.583Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c3BptRWnDWOpC5aL" /><figcaption>Photo by <a href="https://unsplash.com/@mattgyver?utm_source=medium&amp;utm_medium=referral">Matt Benson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Ktor backend is becoming more and more common since it is easy to build and lighter to run. But the main problem you may face is deploying it on your Linux server, or anywhere in general, you can do it in two ways:</p><ul><li>Getting everything building a jar out of the Ktor project, pushing it to the server, and running it on a JVM environment.</li><li>Using Docker to do all the heavy lifting</li></ul><p>We will do the Docker way here. No need to worry it is really simple and you can reuse it every time it is straightforward.</p><h3>Project Setup</h3><p>We will not do much on the Ktor side, we will use the <a href="https://start.ktor.io/#/settings?name=ktor-sample&amp;website=example.com&amp;artifact=com.example.ktor-sample&amp;kotlinVersion=1.6.21&amp;ktorVersion=2.0.1&amp;buildSystem=GRADLE_KTS&amp;engine=NETTY&amp;configurationIn=CODE&amp;addSampleCode=true&amp;plugins=">Ktor Project generator</a> to build a simple minimal project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TfR9zbopbbRStoZC.jpeg" /></figure><p>This is the basic structure of the Ktor Project, we will add a simple String here, in return. If you start the application it will run and return the string when we hit this endpoint <a href="http://localhost:8080/api"><strong>http://localhost:8080/api</strong></a></p><h3>Build a Jar from Ktor Project</h3><p>We will app a plugin in <strong>build.gradle.kt </strong>the<strong> </strong><strong>plugins{} </strong>block</p><pre><strong>id(&quot;com.github.johnrengelman.shadow&quot;) <em>version </em>&quot;7.1.2&quot;</strong></pre><p>when we make the Gradle sync, will get a new task added to our list of Gradle tasks. We will run this task and this will create a jar for us.</p><pre><strong>gradlew shadowJar</strong></pre><p>this will create a jar inside <strong>builds/libs </strong>and you can simply run this particular jar directly it has all the requirements inside so it can run anywhere. <strong>You can see the folder structure below. </strong>You can run it will the command after you navigate inside <strong>builds/libs</strong></p><pre><strong>java -jar com.example.docker-ktor-sample-0.0.1-all.jar</strong></pre><p>This will run on our localhost on port <strong>8080</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QkHEGoYG1COHitKi.jpeg" /></figure><h3>Deploy Ktor with Docker</h3><p>Docker is really simple to use and <a href="https://www.docker.com/"><em>install</em></a>, install<em> </em><a href="https://www.docker.com/products/docker-desktop/"><em>Docker Desktop</em></a> will really help us to visualise the images and containers. <strong>You can see the folder structure below.</strong></p><p>You can directly copy this, and make a file with the name <strong>Dockerfile </strong>at the base of the project. These consist of really simple setting Java 11, moving into a directory, downloading and setting up <strong>gradlew , </strong>run the<strong> </strong><strong>gradlw shadowJar </strong>to build the jar, we the expose like open<strong>8080, </strong>we make a <strong>run </strong>folder and then copy from the<strong> </strong><strong>build/libs </strong>to the<strong> </strong><strong>run </strong>folder rename to <strong>server.jar , </strong>finally, we will run the<strong> </strong><strong>java -jar /run/server.jar </strong>.</p><p>Now how to run this file? you can simply do to run this to run the servers</p><pre>/*<br>This command at the base of project where Dockerfile is present,which build from the above Dockerfile with the name <strong>ktor-docker</strong>. &#39;.&#39; signifies find the Dockerfile here<br>*/<br><strong><em>docker build -t ktor-docker .</em></strong></pre><pre><br>/*<br>This command will have to run the above &#39;<strong>ktor-docker</strong>&#39; with the name <strong>docker-ktor1 </strong>on port<strong> 8080<br></strong>*/<br><strong><em>docker run --name docker-ktor1 -p 8080:8080 ktor-docker</em></strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_2vybb2rxp6ay7L5.jpeg" /></figure><p>The server will start at port 8080 and it will be visible on the Docker Desktop</p><h4>Wow, we were able to run our Ktor app with Docker!!🎉</h4><p>Since docker gives you the flexibility to run the backend irrespective of the system preferences you can now deploy to any popular Infrastructure as a Service like GCP, AWS, Azure etc.</p><ul><li><a href="https://devcenter.heroku.com/articles/deploying-executable-jar-files">Deploying Executable JAR Files</a></li><li><a href="https://www.amazonaws.cn/en/getting-started/tutorials/deploy-docker-containers/">How to Deploy Docker Containers - Amazon Web Services</a></li><li><a href="https://docs.docker.com/cloud/aci-integration/">Deploying Docker containers on Azure</a></li><li><a href="https://www.infiproton.com/post/multiple-services-to-deploy-spring-boot-app-in-gcp">3 ways to deploy and run the Spring Boot app on GCP</a></li></ul><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Follow me for Kotlin content and more. Happy Coding!</p><p>I will well appreciate one of these 👏</p><h4>Recent Post</h4><ul><li><a href="https://medium.com/backyard-programmers/build-ktor-project-with-docker-and-add-nginx-for-load-balancing-reverse-proxy-2143bb1969cf">Build Ktor Project with Docker and Add Nginx for Load Balancing &amp; Reverse Proxy</a></li><li><a href="https://medium.com/backyard-programmers/media3-exoplayer-in-jetpack-compose-to-make-snapchat-spotlight-75e384e2ef56">Media3 ExoPlayer in Jetpack Compose to make Snapchat Spotlight</a></li><li><a href="https://medium.com/backyard-programmers/adding-google-map-in-jetpack-compose-using-androidview-and-android-maps-compose-23378520523d">Adding Google Map in Jetpack Compose 🗺📌- Using AndroidView And android-maps-compose</a></li><li><a href="https://medium.com/backyard-programmers/replacing-retrofit-with-ktor-client-and-kotlin-serialization-for-android-5ca6bfc60648">Replacing Retrofit with Ktor Client and Kotlin Serialization for Android🐱‍🏍</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d42c61c8e7a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/deploy-your-ktor-project-anywhere-d42c61c8e7a6">Deploy Your Ktor Project Anywhere!</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K-Means Clustering]]></title>
            <link>https://medium.com/backyard-programmers/k-means-clustering-6e672a3f77aa?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/6e672a3f77aa</guid>
            <dc:creator><![CDATA[AKASH RANJAN]]></dc:creator>
            <pubDate>Fri, 20 May 2022 19:04:10 GMT</pubDate>
            <atom:updated>2022-05-20T19:03:39.632Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*TefNfrbptSWMWtqemxVXig.png" /></figure><h3>Introduction</h3><h4>What is Clustering?</h4><p><strong><em>Clustering</em></strong><em> is basically a type of </em><a href="https://en.wikipedia.org/wiki/Unsupervised_learning"><strong><em>Unsupervised learning method</em></strong></a><em>. It is the process of dividing the population into groups consisting of similar data points. Points lying in the same group are as similar as possible and points in different groups are as dissimilar as possible.</em></p><h4>Why Clustering?</h4><p><strong><em>Clustering</em></strong><em> </em><strong><em>helps in understanding the natural grouping in a dataset</em></strong><em>. Their purpose is to make sense to partition the data into some group of logical groupings. The main advantage of a clustered solution is </em><strong><em>automatic recovery from failure</em></strong><em>, that is, recovery without user intervention.</em></p><h4>Types Of Clustering:</h4><ol><li><strong><em>Exclusive Clustering</em></strong><em>: It is considered </em><strong><em>hard clustering</em></strong><em>. Here data points/items belong exclusively to one cluster. Example: </em><strong><em>K-Means Clustering.</em></strong></li><li><strong><em>Over Lapping Clustering</em></strong><em>: It is considered </em><strong><em>soft clustering</em></strong><em>. Here data points/items belong to multiple clusters. Example: </em><strong><em>Fuzzy/C-Means Clustering.</em></strong></li></ol><h3>K-Means Clustering</h3><h4>Introduction</h4><p><strong><em>K-Means Clustering</em></strong><em> is </em><strong><em>a type of unsupervised learning, which is used when you have unlabeled data (i.e., data without a Target Column)</em></strong><em>. The goal of this algorithm is to find groups in the data, with the number of groups represented by the variable K.</em></p><h4>Working</h4><p><em>Before applying any algorithm on datasets it’s necessary to understand it’s working so, let’s deep dive into the working of </em><strong><em>K-Means Clustering</em></strong><em>:</em></p><ol><li><em>At very first we need to choose the </em><strong><em>number K of Clusters</em></strong><em> (Let’s take K=2).</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*4H-B67JFsmRV1dSauMfR9g.png" /></figure><p>2. <em>Then selecting at</em><strong><em> random K points</em></strong><em>, the</em><strong><em> </em></strong><a href="https://en.wikipedia.org/wiki/Centroid"><strong><em>centroids</em></strong></a><strong><em> (not necessary from the dataset)</em></strong><em>.</em></p><p>3. <em>Then assign each data point to the </em><strong><em>closest centroid → that forms K Cluster</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*ME52drMDE3Km_abuLV_4lQ.png" /><figcaption><strong>Finding the Euclidean distance</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*HopXNXQvI-wWJgJZsR2tww.png" /><figcaption><strong>Separating both centroids by Red and Blue color.</strong></figcaption></figure><p>4. <em>Then it computes and </em><strong><em>places the new centroid of each cluster</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*H75ItnUQzUGZ0L05X1v0_w.png" /><figcaption><strong>Computing and shifting centroid</strong></figcaption></figure><p>5. <em>Reassigning each data point to the new closest centroid. If any reassignment took place, then we</em><strong><em> go to step 4, otherwise, our model is ready</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*XvzSwTBbfvTxGD1J1OC_1Q.png" /><figcaption><strong>Wrong data points</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*jtiXNZNkvlKSgm9w9yBLlg.png" /><figcaption><strong>Data Points correctly marked to the nearest centroids</strong></figcaption></figure><p><strong><em>Note:</em></strong><em> The Above Process continues until the best cluster is formed</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*7-zYvq56EdR8Kv5sKBUwUw.png" /><figcaption><strong>Final Model is Ready</strong></figcaption></figure><h4>How to Choose the Right Number of Clusters?</h4><p><em>Finding the right number of clusters is the most difficult and important part of the Algorithm. So, Let’s understand how to choose the right number of clusters in </em><strong><em>K-Means Clustering</em></strong><em>.</em></p><p><strong><em>WCSS</em></strong><em>: Also known as </em><strong><em>Within-Cluster-Sum of Squared. </em></strong><em>It is the</em><strong><em> sum of the squared distance between each point and the centroid in a cluster.</em></strong></p><p><em>I will try to show step by step what actually happens to the value of WCSS when the number of Clusters increases, Then I will show the best optimal method to find the right Cluster.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8d2duVQw7AEBwBgvolMkgQ.jpeg" /><figcaption><strong>WCSS(8000) is high when there is only one cluster</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g5_gbA1kt-ZfzjHIu12Iyw.jpeg" /><figcaption><strong>WCSS(3000) here decreases from the second one</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZ3F7vFPotmyTR0d0US3lw.jpeg" /><figcaption><strong>WCSS(1000) is the least here</strong></figcaption></figure><p><em>As we are able to find that </em><strong><em>WCSS is decreasing</em></strong><em> as we are trying to</em><strong><em> increase the clusters</em></strong><em>. Our main </em><strong><em>aim is to decrease the WCSS.</em></strong><em> The main task of knowing the right number of clusters is the point after which the </em><strong><em>WCSS decrease becomes almost constant.</em></strong><em> So instead of using plots, we will analyze it using the </em><strong><em>Elbow Method</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*TfMeJ5FGYnEdjBgen9bahA.png" /></figure><p><em>From the Above Elbow curve, we found that After 3 Clusters the value of WCSS becomes almost constant so the right number of clusters for this set of data points is 3.</em></p><h4>What would happen if we had a bad random initialization?</h4><p><em>Traditional k-means utilize a randomization process for initializing these centroids, poor initialization can lead to </em><strong><em>increased numbers of required clustering iterations to reach convergence, a greater overall runtime, and a less-efficient algorithm overall</em></strong><em>.</em></p><p><em>To solve this issue we have a solution that is the same as K-Means but has an advantage over bad random initialization called</em><strong><em> K-Means++</em></strong><em>. </em><strong><em>K-Means++</em></strong><em> is a </em><strong><em>smart centroid initialization technique</em></strong><em> and the rest of the algorithm is the same as that of </em><strong><em>K-Means</em></strong><em>. The steps to follow for centroid initialization are:</em></p><ul><li><em>Pick the first centroid point (C_1) randomly.</em></li><li><em>Compute the distance of all points in the dataset from the selected centroid. The distance of x_i point from the farthest centroid can be computed by</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/0*gco2ladwXr0033Dk.png" /></figure><pre>d_i: Distance of x_i point from the farthest centroid<br>m: number of centroids already picked</pre><ul><li><em>Make the point x_i as the new centroid that is having maximum probability proportional to d_i.</em></li><li><em>Repeat the above two steps till you find k-centroids.</em></li></ul><h4>Implementation:</h4><p><em>As of now, we have a rough idea of how </em><strong><em>K-Means Clustering</em></strong><em> works. So, Let’s implement it.</em></p><ol><li><em>Importing the Libraries:</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dxinImpEA83_BjzwpYTmGA.png" /></figure><p>2.<em> Importing, Reading DataSet, And Creating the Feature Matrix:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVVybNICzCqNKBs5U7warg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*7XtgTXtFDtaJXv-X8kSG5Q.png" /></figure><p><strong><em>CustomerID </em></strong><em>is 100% Unique so will never contribute to Model Predictions.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UoSEMA4H5UdqF_QgeVnIWg.png" /></figure><blockquote>We are using just the last two features(<strong>Annual Income (k$)</strong>and <strong>Spending Score (1–100) </strong>) for clustering because I wanted to show you guys how clusters actually look if I will use all the features then it will become difficult for visualizing the clusters in a 2D plot.</blockquote><p>3. <em>Using the Elbow method to find the optimal number of clusters:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVtGbBzdtc25RxHxDNnlMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*INL_lcZIc0ObJ_cMgE9MKQ.png" /><figcaption><strong>From the Elbow Method, we can say that 5 is the optimal number of Clusters</strong></figcaption></figure><p>4. <em>Training the </em><strong><em>K-Means model</em></strong><em> on the dataset:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SfxU7NKPrKDiKkr8k8KW-g.png" /></figure><p>5. Visualising the clusters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4gg26PB-1cIGfOFCyBOpPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*orEcYTDIpdeG5eM2Hy4dtA.png" /></figure><p><em>The source code of this is available on my </em><a href="https://github.com/akash-ranjan8/MACHINE_LEARNING_MODELS_IN_PYTHON/blob/master/K_Means_Clustering.ipynb"><strong><em>GitHub repository.</em></strong></a></p><h3>Summary:</h3><p><em>With this, we came to the end of our article on </em><strong><em>K-Means Clustering</em></strong><em>. I hope this article will help you in learning </em><strong><em>K-Means Clustering </em></strong><em>in a better manner.</em></p><p><em>For any queries contact me on </em><a href="https://www.linkedin.com/in/akash-ranjan-183018159"><strong><em>LinkedIn</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e672a3f77aa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/k-means-clustering-6e672a3f77aa">K-Means Clustering</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build Ktor Project with Docker and Add Nginx for Load Balancing & Reverse Proxy]]></title>
            <link>https://medium.com/backyard-programmers/build-ktor-project-with-docker-and-add-nginx-for-load-balancing-reverse-proxy-2143bb1969cf?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/2143bb1969cf</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[kotlin-backend]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ktor]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Wed, 18 May 2022 22:45:06 GMT</pubDate>
            <atom:updated>2022-05-18T22:45:05.987Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KPmIJdMA-S_PQpdu" /><figcaption>Photo by <a href="https://unsplash.com/@yuliamatvienko?utm_source=medium&amp;utm_medium=referral">Yulia Matvienko</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Kotlin is wide having a wide scale adoption both for Android and Backend. I primarily used Kotlin with SpringBoot but I feel for a simple backend and with a minimum requirement you should give Ktor a try it is worth it. Being a mobile developer I think it is a great way to enter backend development.</p><p>In this blog, we will try to deploy our Ktor app using <strong>Docker </strong>and later we will use <strong>Nginx </strong>as a load balancer. If you don’t know much about <a href="https://www.youtube.com/watch?v=3c-iBn73dDE"><em>Docker </em></a>or <a href="https://www.youtube.com/watch?v=7VAI73roXaY"><em>Ngnix </em></a>you can get a good idea here.</p><p>The final project is here, you can check it out here:</p><p><a href="https://github.com/Debanshu777/docker-ktor-nginx-sample">GitHub - Debanshu777/docker-ktor-nginx-sample: Simple Example using Nginx Docker with Ktor</a></p><h3>Project Setup</h3><p>We will not do much on the Ktor side, we will use the <a href="https://start.ktor.io/#/settings?name=ktor-sample&amp;website=example.com&amp;artifact=com.example.ktor-sample&amp;kotlinVersion=1.6.21&amp;ktorVersion=2.0.1&amp;buildSystem=GRADLE_KTS&amp;engine=NETTY&amp;configurationIn=CODE&amp;addSampleCode=true&amp;plugins=">Ktor Project generator</a> to build a simple minimal project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dt2vye_QoDUMQ2I61_rewQ.jpeg" /></figure><p>This is the basic structure of the Ktor Project, we will add a simple String here, in return. If you start the application it will run and return the string when we hit this endpoint <strong>http://localhost:8080/api</strong></p><h3>Build a Jar from Ktor Project</h3><p>We will app a plugin in <strong>build.gradle.kt </strong>the<strong> </strong><strong>plugins{} </strong>block</p><pre><strong>id(&quot;com.github.johnrengelman.shadow&quot;) <em>version </em>&quot;7.1.2&quot;</strong></pre><p>when we make the Gradle sync, will get a new task added to our list of Gradle tasks. We will run this task and this will create a jar for us.</p><pre><strong>gradlew shadowJar</strong></pre><p>this will create a jar inside <strong>builds/libs </strong>and you can simply run this particular jar directly it has all the requirements inside so it can run anywhere. <strong>You can see the folder structure below. </strong>You can run it will the command after you navigate inside <strong>builds/libs</strong></p><pre><strong>java -jar com.example.docker-ktor-sample-0.0.1-all.jar</strong></pre><p>This will run on our localhost on port <strong>8080</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bDsURydM7Xwtp-hkPxe4Mg.jpeg" /></figure><h3>Deploy Ktor with Docker</h3><p>Docker is really simple to use and <a href="https://www.docker.com/"><em>install</em></a>, install<em> </em><a href="https://www.docker.com/products/docker-desktop/"><em>Docker Desktop</em></a> will really help us to visualize the images and containers. <strong>You can see the folder structure below.</strong></p><p>You can directly copy this, and make a file with the name <strong>Dockerfile </strong>at the base of the project. These consist of really simple setting Java 11, moving into a directory, downloading and setting up <strong>gradlew , </strong>run the<strong> </strong><strong>gradlw shadowJar </strong>to build the jar, we the expose like open<strong>8080, </strong>we make a <strong>run </strong>folder and then copy from the<strong> </strong><strong>build/libs </strong>to the<strong> </strong><strong>run </strong>folder rename to <strong>server.jar , </strong>finally, we will run the<strong> </strong><strong>java -jar /run/server.jar </strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d8ca806999e8fd7b95572acadcb4b07/href">https://medium.com/media/6d8ca806999e8fd7b95572acadcb4b07/href</a></iframe><p>Now how to run this file? you can simply do to run this to run the servers</p><pre>/*<br>This command at the base of project where Dockerfile is present,which build from the above Dockerfile with the name <strong>ktor-docker</strong>. &#39;.&#39; signifies find the Dockerfile here<br>*/</pre><pre><strong><em>docker build -t ktor-docker .</em></strong></pre><pre>/*<br>This command will have to run the above &#39;<strong>ktor-docker</strong>&#39; with the name <strong>docker-ktor1 </strong>on port<strong> 8080<br></strong>*/</pre><pre><strong><em>docker run --name docker-ktor1 -p 8080:8080 ktor-docker</em></strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wMM9wRDhBC0VXszToPrW3g.jpeg" /><figcaption>The server will start at port 8080 and it will be visible on the Docker Desktop</figcaption></figure><h4>Wow, we were able to run our Ktor app with Docker!!🎉</h4><h3>Adding Nginx for Load Balancing and Reverse Proxy With Docker</h3><p><a href="https://www.nginx.com/">Nginx</a>, pronounced like “engine-ex”, is an open-source web server that, since its initial success as a web server, is now also used as a <a href="https://kinsta.com/blog/reverse-proxy/">reverse proxy</a>, HTTP cache, and load balancer.</p><p>We will make a folder <strong>nginx </strong>outside<strong> </strong><strong>src</strong>. <strong>You can see the folder structure below.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GwWBbBf_4rFXyfbd039KJg.png" /></figure><p>Create a file with the name<strong>nginx.conf </strong>and write it with the below code. In the <strong>server{} </strong>block, we are porting it to 9090 and we are basically using <strong>location{} </strong>block, we are routing it to all the list of servers with the <a href="https://www.geeksforgeeks.org/program-round-robin-scheduling-set-1/"><em>Round Robin Algorithm </em></a><strong>we are assuming having two instances of our Ktor server running at port </strong><strong>8181 and </strong><strong>8282</strong> . Hence working as load balancing and also hiding the actual server location since the user will hit the link with <strong>9090 </strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24945c5222e97076974429b2fc3a92f5/href">https://medium.com/media/24945c5222e97076974429b2fc3a92f5/href</a></iframe><p>Let&#39;s add Docker to help us set up our Nginx server, we will create a new <strong>Dockerfile </strong>inside the<strong> </strong><strong>nginx </strong>folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ade14fb4f023222dce040337cd80ebc5/href">https://medium.com/media/ade14fb4f023222dce040337cd80ebc5/href</a></iframe><p>use these commands to run, as explained above in the Ktor section to build and run inside <strong>./nginx </strong>. After running this you will find a new server running in your Docker Desktop on port <strong>9090</strong></p><pre><strong><em>docker build -t nginx-docker .</em></strong></pre><pre><strong><em>docker run --name docker-nginx1 -p 9090:9090 nginx-docker</em></strong></pre><h4>Yes, we were able to run our Nginx server with Docker, ie if you hi port `9090` you will get data from `8181` and `8282`🎉</h4><h3>Combine Server and Nginx together to docker-compose.yml</h3><p>You can think of this as a script to run our servers in a proper way. Here we will try to run two servers running on ports <strong>8181</strong> &amp; <strong>8282</strong> , Nginx running <strong>9090</strong> which will help in reverse proxy and load balancing.</p><p>We will have to add a file <strong>docker-compose.ymal </strong>at the base of the project. <strong>You can see the folder structure below.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CDPqO-RTpYd1Xmq77Y8uAw.png" /></figure><p>We have added this <strong>docker-compose.yml , </strong>this file is easy to understand we are starting <strong>nginx-server:9090 </strong>which depends on 2 instances of our Ktor server <strong>service1</strong> &amp; <strong>service2 </strong>which is mapped to port<strong> </strong><strong>8181 </strong>&amp; <strong>8282 .</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6827cca47baddc61225a94cac729de15/href">https://medium.com/media/6827cca47baddc61225a94cac729de15/href</a></iframe><p>make a small change in <strong>nginx.conf </strong>we have to specify the <strong>service1</strong> &amp; <strong>service2 </strong>it is a small change.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81602a700eb6c0e0bf28732b038270b1/href">https://medium.com/media/81602a700eb6c0e0bf28732b038270b1/href</a></iframe><p>We can finally get all of these syncs and start our servers together with two commands</p><pre><strong>docker-compose build</strong></pre><pre><strong>docker-compose up</strong></pre><h4>Finally, we are able to start our servers and all synced if you open your Docker Desktop and your Browser you will see this.🎊</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Gr9iwNnwDr3QvhRLlFEEg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*sk4upSvcaPHNV1Hd0acpmQ.png" /></figure><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Follow me for Kotlin content and more. Happy Coding!</p><p>I will well appreciate one of these 👏</p><h4>Recent Post</h4><ul><li><a href="https://medium.com/backyard-programmers/replacing-retrofit-with-ktor-client-and-kotlin-serialization-for-android-5ca6bfc60648">Replacing Retrofit with Ktor Client and Kotlin Serialization for Android🐱‍🏍</a></li><li><a href="https://medium.com/backyard-programmers/detect-swipe-direction-on-jetpack-compose-to-trigger-bottomsheetscaffold-8d9116c8107c">Detect Swipe Direction on Jetpack Compose to trigger BottomSheetScaffold</a></li><li><a href="https://medium.com/backyard-programmers/media3-exoplayer-in-jetpack-compose-to-make-snapchat-spotlight-75e384e2ef56">Media3 ExoPlayer in Jetpack Compose to make Snapchat Spotlight</a></li><li><a href="https://medium.com/backyard-programmers/adding-google-map-in-jetpack-compose-using-androidview-and-android-maps-compose-23378520523d">Adding Google Map in Jetpack Compose 🗺📌- Using AndroidView And android-maps-compose</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2143bb1969cf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/build-ktor-project-with-docker-and-add-nginx-for-load-balancing-reverse-proxy-2143bb1969cf">Build Ktor Project with Docker and Add Nginx for Load Balancing &amp; Reverse Proxy</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detect Swipe Direction on Jetpack Compose to trigger BottomSheetScaffold]]></title>
            <link>https://medium.com/backyard-programmers/detect-swipe-direction-on-jetpack-compose-to-trigger-bottomsheetscaffold-8d9116c8107c?source=rss----164a34fe7068---4</link>
            <guid isPermaLink="false">https://medium.com/p/8d9116c8107c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[snapchat]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Debanshu Datta]]></dc:creator>
            <pubDate>Mon, 16 May 2022 07:11:57 GMT</pubDate>
            <atom:updated>2022-05-16T07:13:22.025Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AnVDfloki7ih1RYe" /><figcaption>Photo by <a href="https://unsplash.com/@reinis_birznieks?utm_source=medium&amp;utm_medium=referral">Reinis Birznieks</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my recent project, I was trying to add BottomSheet which gets triggered when the user creates a gesture of upwards swipe as you see in Snapchat Memories, where the camera works in the background and on upwards swipe we open the bottom sheet. Here is the outcome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*aBiM6VBlVa6_JsQuOUPb8w.gif" /></figure><p>We will be using BottomSheetScaffold here which is ideal for this use case.</p><pre>In Jetpack Compose, we have two types of bottom sheets, the <strong>BottomSheetScaffold</strong> and the <strong>ModalBottomSheetLayout</strong>.</pre><pre><strong>- BottomSheetScaffold</strong> doesn’t block the screen’s main UI when it appears, and you can view and interact with both (main UI and bottom sheet) simultaneously. Also, you can set a peak height to show part of the bottom sheet all the time.</pre><pre><strong>- ModalBottomSheetLayout </strong>acts like a popup view. It shows up when you press a button and blocks any interaction with the rest of the screen.</pre><h3><strong>Adding BottomSheetScaffold to Compose✨</strong></h3><p>I will show you how I used it, Initially, I had a <strong>Scaffold </strong>which I wrapped with <strong>BottomSheetScaffold . </strong>We have to pass two crucial <strong>bottomSheetScoffoldState </strong>and <strong>scope</strong>which is used to manage the sheet&#39;s state and give the coroutine scope respectively. These are passed around to collapse or expand the bottom sheet. You can see in the image below that I have passed it to the <strong>Naviagtion </strong>composable and which in turn is passed to the <strong>CamaraScreen .</strong></p><pre><strong>BottomSheetScafflod parameters</strong></pre><pre><strong>sheetContent - </strong>as the name suggests they provides with the content for the bottomsheet. In my case it was the MemoriesScreen.<br><strong>scaffoldState -</strong> takes the <strong>bottomSheetScaffoldState </strong>defined above.<br><strong>sheetShape - </strong>It is used to provide shape to the bottom sheet<br><strong>sheetBackgroundColor - </strong> as the name suggests<br><strong>sheetPeekHeight - </strong>It is added to make the sheet invisible initally, since BottomSHeetScaffold have a default peek value. </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlEzv6UpK3KSZ9L5Yde0dw.png" /></figure><h3>Gesture Detection In Compose✨</h3><p>Now coming to the important part is how to detect the swipe and trigger the bottom sheet to expand. We have already passed the <strong>bottomSheetScaffoldState</strong> and <strong>scope </strong>to the <strong>CamaraScreen </strong>.</p><p>We have to add a new modifier to the <strong>Surface </strong>which is <strong>pointerInput() </strong>inside it we will set the <strong>detectDragGesture{} </strong>in which we get the directions based on the <strong>x </strong>and <strong>y </strong>locations which helps us to detect the direction of the swipe. Based on these inputs we will trigger the bottom sheet open and close in the main screen by changing the state.</p><pre><strong>pointerInput - </strong>Create a modifier for processing pointer input within the region of the modified element.</pre><pre><strong>detectDragGestures -</strong> Gesture detector that waits for pointer down and touch slop in any direction and then calls <strong>onDrag </strong>for each drag event. It follows the touch slop detection of awaitTouchSlopOrCancellation but will consume the position change automatically once the touch slop has been crossed.</pre><pre><strong>onDrag: (PointerInputChange, Offset) → Unit<br></strong>OnDrag have two parameter which i have changed to <strong>change </strong>and <strong>dragAmount. </strong>This <strong>dragAmount </strong> gives us the <strong>x</strong> and <strong>y </strong>which helps us to detect the swipe. <strong>change.comsume()</strong> consumes change event, claiming all the corresponding change info to the caller. This is usually needed when, button, when being clicked, consumed the &quot;up&quot; event so no other parents of this button could consume this &quot;up&quot; again.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hKhU59QRenvqXz0XqIPp6g.png" /></figure><p>If you want to video the whole code of the project you can refer here</p><p><a href="https://github.com/Debanshu777/Compose-Snapchat-Clone">GitHub - Debanshu777/Compose-Snapchat-Clone: Snapchat Clone with Jetpack Compose and Clean Architecture - Navigation Components, CamaraX, android-maps-compose, Exoplayer, Detekt, Coil, Gradle Secrets, Permission Handling.</a></p><h4>Finally, you have done it wow added a swipe gesture bottom Sheet in your Compose App like Snapchat Memories!!🎉</h4><p>For any doubts and suggestions, you can reach out on my <a href="https://www.instagram.com/debanshu.datta/">Instagram</a>, or <a href="https://www.linkedin.com/in/debanshu-datta-483376169/">LinkedIn</a>. Follow me for Kotlin content and more. Happy Coding!</p><p>I will well appreciate one of these 👏</p><h4>Recent Post</h4><ul><li><a href="https://medium.com/backyard-programmers/media3-exoplayer-in-jetpack-compose-to-make-snapchat-spotlight-75e384e2ef56">Media3 ExoPlayer in Jetpack Compose to make Snapchat Spotlight</a></li><li><a href="https://medium.com/backyard-programmers/adding-google-map-in-jetpack-compose-using-androidview-and-android-maps-compose-23378520523d">Adding Google Map in Jetpack Compose 🗺📌- Using AndroidView And android-maps-compose</a></li><li><a href="https://medium.com/backyard-programmers/using-webview-in-jetpack-compose-and-enforce-dark-mode-313bca06b5e4">Using Webview in Jetpack Compose and enforce Dark Mode</a></li><li><a href="https://medium.com/backyard-programmers/replacing-retrofit-with-ktor-client-and-kotlin-serialization-for-android-5ca6bfc60648">Replacing Retrofit with Ktor Client and Kotlin Serialization for Android🐱‍🏍</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d9116c8107c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backyard-programmers/detect-swipe-direction-on-jetpack-compose-to-trigger-bottomsheetscaffold-8d9116c8107c">Detect Swipe Direction on Jetpack Compose to trigger BottomSheetScaffold</a> was originally published in <a href="https://medium.com/backyard-programmers">Backyard Programmers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>