<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kodefyi on Medium]]></title>
        <description><![CDATA[Stories by Kodefyi on Medium]]></description>
        <link>https://medium.com/@kodefyi?source=rss-88c22c206fad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mFiUrLYOL7WTwvT7fJDKTg.jpeg</url>
            <title>Stories by Kodefyi on Medium</title>
            <link>https://medium.com/@kodefyi?source=rss-88c22c206fad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:16:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kodefyi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Spring Boot Excercise: Custom JSON Response with ResponseEntity]]></title>
            <link>https://medium.com/@kodefyi/spring-boot-excercise-custom-json-response-with-responseentity-2fd183514b64?source=rss-88c22c206fad------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fd183514b64</guid>
            <category><![CDATA[responses]]></category>
            <category><![CDATA[custom-response]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[jpa]]></category>
            <dc:creator><![CDATA[Kodefyi]]></dc:creator>
            <pubDate>Fri, 04 Nov 2022 04:47:47 GMT</pubDate>
            <atom:updated>2022-11-07T05:41:43.560Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*Re2FDDvcYzMYY7T4.png" /></figure><blockquote><strong>In </strong>this article, I will show you how to modify the JSON response with ResponseEntity in Spring Boot for handling response.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z0XmoMjwiC61rdAROwZZ1A.jpeg" /><figcaption>difference between default response and custom response</figcaption></figure><p>Here in the above screenshot as we can see that with the default response we can’t return the message, total character count of city name and response status. But in the custom response we have returned the message for user, total character count and also response status code by creating “ResponseHandler”.</p><p>Tech Stack:</p><p>Spring Boot</p><p>Spring Data JPA</p><p>Java 8</p><p>MySQL Database</p><p>Maven</p><p>Spring Tool Suit</p><h3>What are we Building?</h3><p>We are building a simple spring boot application which is basically a application to store cityname and its pincode into the database.</p><h3>Problem statement:</h3><blockquote>1. Implementation of a simple REST API in spring boot that accepts a list of city names and pincodes in the HTTP request body, and persist the data in a database (either in memory or a traditional one).</blockquote><blockquote>2. The API should also have an endpoint that receives the pincode range and returns in the response body the list of city names belonging to that pincode range, sorted alphabetically as well as the total number of characters of all names combined.</blockquote><h3>Project Creation</h3><p>First, let’s use the Spring initializer page to initialize our project with the dependencies listed below.</p><ol><li>Go to → <a href="https://start.spring.io/">https://start.spring.io/</a></li><li>Leave everything as it is and select the following dependencies: Spring Web, JPA, MySQL and DevTools.</li><li>Extract the generated project and Open spring tool suit and Go to File → Open Projects From File System.. → Choose the directory of your project and click on Finish.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*tabt4Yh459aHi3jPZSDtUw.png" /><figcaption>Initialized and downloaded project from spring initializer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*QaScM5P3uHSH7Ca6.png" /><figcaption>File → Open Projects From File System</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FPXUD8tPYALX1-x4iLeZig.png" /><figcaption>Selecting the project directory</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1jSaE20jU8xbssxTteXdVA.png" /><figcaption>Finishing the project import</figcaption></figure><h3>Entity Creation</h3><p>Now let´s create our entity class called City(Entity class).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b49a7d58294f098bb7a463b558d3b73/href">https://medium.com/media/1b49a7d58294f098bb7a463b558d3b73/href</a></iframe><p>Creating the class named CityName.java to use the comparator to sort the data based on the city name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7605986b65a625a86bba4dc4486d8207/href">https://medium.com/media/7605986b65a625a86bba4dc4486d8207/href</a></iframe><h3>Data Layer (JPA Repositories)</h3><p>The repositories allow us to access the information stored in the database.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a3f0401959a94cc9cdf9d2ae6efeb44/href">https://medium.com/media/0a3f0401959a94cc9cdf9d2ae6efeb44/href</a></iframe><h3>Service Layer</h3><p>Now let´s create our service layer. We will inject the CityRepository and the CityServiceImpl.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/513b5060833bfa9f1835f2520d038f7c/href">https://medium.com/media/513b5060833bfa9f1835f2520d038f7c/href</a></iframe><p>Here in CityServiceImpl.java class I have create a method called “getCityWithPincodeRange” where I have used some java 8 features like stream API, Lambda expression, filter, predicate and sorted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f907d8b3dad786647713b9389629ab8/href">https://medium.com/media/5f907d8b3dad786647713b9389629ab8/href</a></iframe><h3>MySQL Database configuration in application.properties file</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cf0462a7fe38f94ab4a14f652a562d3/href">https://medium.com/media/2cf0462a7fe38f94ab4a14f652a562d3/href</a></iframe><h3>Response Handler</h3><p>let’s create a new package with the name ‘<em>handler</em>’ in which we will create a class with the name “<em>ResponseHandler</em>”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ac020aef05e35b3d05aea12e757d1d4/href">https://medium.com/media/9ac020aef05e35b3d05aea12e757d1d4/href</a></iframe><h3>Controller Layer</h3><p>Now let´s create our controller layer to handle the coming web requests. We will inject the CityService.</p><blockquote>In CityController.java class we have a method called “getCityWithPinCode” and that API should also have an endpoint that receives the pincode range and returns in the response body the list of city names belonging to that pincode range, sorted alphabetically as well as the total number of characters of all names combined. So here we are using our custom “ResponseHandler” to get the desired output.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54b8693f3d53ea9742cf7db5f3881ed5/href">https://medium.com/media/54b8693f3d53ea9742cf7db5f3881ed5/href</a></iframe><p>Note: By default Spring Boot will create the database structure and tables if you have provided in the right way your MySQL credentials in the application.properties file.</p><p>Now, Run the spring boot application from right clicking on CityprojectApplication.java class and choose RunAs → SpringBoot Application.</p><p>To access the API I have used postman tool:</p><p>URL : <a href="http://localhost:8080/">http://localhost:8080</a></p><p>Post API: <a href="http://localhost:8080/city/addcity">http://localhost:8080/city/addcity</a></p><p>Payload to be used in post method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5203be51518dfcc2ecce1d1a3e5f991/href">https://medium.com/media/a5203be51518dfcc2ecce1d1a3e5f991/href</a></iframe><p>Get API: http://localhost:8080/city/getcitywithpincode?startpostcoderange=&lt;your_start_range&gt;&amp;endpostcoderange=&lt;your_end_range&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*si3uOvy_NEYNkSsxPnGIHg.png" /><figcaption>Get API Response</figcaption></figure><p>That’s all folks, as you can see we have implemented spring boot application to get custom JSON response with ResponseEntity.</p><p>If you have any questions or feedback don’t hesitate to write your thoughts in the comments/responses section.</p><p>Kindly visit <a href="https://github.com/kodefyi/springboot_custom_response_excercise.git">https://github.com/kodefyi/springboot_custom_response_excercise.git</a></p><p>~Amit Sharma</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fd183514b64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform 0.12: How to Upgrade]]></title>
            <link>https://medium.com/@kodefyi/how-to-upgrade-to-terraform-0-12-3180868c2b2a?source=rss-88c22c206fad------2</link>
            <guid isPermaLink="false">https://medium.com/p/3180868c2b2a</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Kodefyi]]></dc:creator>
            <pubDate>Sun, 23 Oct 2022 08:04:17 GMT</pubDate>
            <atom:updated>2022-10-23T09:01:14.442Z</atom:updated>
            <content:encoded><![CDATA[<p>A popular IAC tool, <strong><em>Terraform</em></strong>, allows DevOps Engineers to automate and manage the entire infrastructure from a single place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4zHahDD5liFy05gr_qgOHQ.png" /></figure><p>As we all know, managing infrastructure was a tough task until the arrival of Terraform, which has tons of features, making DevOps Engineers’ lives easier. To dramatically improve our software delivery process, Terraform offers a variety of Software Engineering practices, including Self-Service, Speed, Safety, Documentation, Version Control, Validation, Reuse, and Happiness. :)</p><p>In this article, I would take you through the entire process of upgrading a Terraform code currently running on 0.11 version to 0.12 version.</p><h3><strong>Let’s Play:</strong></h3><p>The code has 2 configuration and modules named EC2 and VPC each.<br>Just like Java functions, modules are reusable pieces of code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*88S6Lxla5EzLDan2G4LHhA.png" /><figcaption>Depicts the structure of repository</figcaption></figure><blockquote>Kindly visit the below repository to access the whole configuration.</blockquote><p><a href="https://github.com/kodefyi/terraform-upgradation.git">GitHub - kodefyi/terraform-upgradation</a></p><p>Below is the code snippet of the resources.</p><h4>EC2:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/462ca07aec4ea879f9bd38ec1daf1b00/href">https://medium.com/media/462ca07aec4ea879f9bd38ec1daf1b00/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0d08c6358be223e5ec9fcf8148d2bb8/href">https://medium.com/media/b0d08c6358be223e5ec9fcf8148d2bb8/href</a></iframe><h4>VPC:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e868434bce6fdfc30b1378a8c095e45/href">https://medium.com/media/3e868434bce6fdfc30b1378a8c095e45/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc57e4d21f0b3a2547e69321be4b0fc4/href">https://medium.com/media/cc57e4d21f0b3a2547e69321be4b0fc4/href</a></iframe><p>Cloud: AWS</p><p>Workstation: Ubuntu Machine</p><p>During this exercise, we will attempt to create a dedicated VPC for a EC2 instance. Since a VPC is required to spin up resources, we would deploy a VPC first.</p><h4>Deploying VPC:</h4><pre>The configuration of VPC is located in configuration/vpc/ directory and the below TF commands should be performed there.</pre><p><strong>Terraform init:</strong> The terraform init command initializes a working directory containing Terraform configuration files. This is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*dYvaavpd7qg4-NYc5GsU9w.png" /><figcaption>TF init Output</figcaption></figure><p><strong>Terraform plan:</strong>The terraform plan command lets us to preview the<strong> </strong>actions Terraform would take to modify your infrastructure.This serves to be a sanity check before we create resources onto the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*laYJm3BKRySo3_zyFBd7YQ.png" /><figcaption>TF plan Output</figcaption></figure><p><strong>Terraform apply:</strong>The terraform apply command executes the actions proposed in a Terraform plan.Now the resources are unleashed onto the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*3OMErcYAimi5JRezR4hSHQ.png" /><figcaption>TF apply Output</figcaption></figure><h4>Deploying EC2:</h4><p>As we have our VPC in place now , we would move ahead and spin up an EC2 instance.</p><pre>The configuration of EC2 is located in configuration/ec2/ directory and the below TF commands should be performed there.</pre><p><strong>Terraform init:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*USRlvDI0ZDk2MsAe_cMrkQ.png" /><figcaption>TF init Output</figcaption></figure><p><strong>Terraform plan :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*FPoduv5o-ZlgRykTzn_pVQ.png" /><figcaption>TF plan Output</figcaption></figure><p><strong>Terraform apply :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*P_uRMSVTUWAzXagymcVihA.png" /><figcaption>TF apply Output</figcaption></figure><h4>How to Upgrade:</h4><p>Now we have our resources running on real world. Prior performing any upgrade activity ensure to have clean plan of the infrastructure.<br>As we have just created the resources , we have clean TF plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*2RBVquole-PSz1QEbFGryg.png" /><figcaption>TF clean plan for VPC</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*IYuRG3MpSrRvakafyM8Gvw.png" /><figcaption>TF clean plan for EC2</figcaption></figure><p>Having Terraform 0.12 installed on our system, we will switch to Terraform 0.12 version now .</p><p>Now that we are on Terraform 0.12, we are ready to convert. Luckily, Terraform has a built-in command for this, which would automatically rewrite the whole configuration files from 0.11 to 0.12.<br>Just fire up below command having terraform init and terraform 0.12 checklist run on each configuration.</p><pre>terraform0.12 upgrade</pre><h4>Terraform Upgradation on EC2 config:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*8VSB8Ch9U8HiTpAn8TJLpw.png" /><figcaption>TF Upgrade on EC2</figcaption></figure><h4>Terraform Upgradation on VPC config:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*UoAfcwTRrsRSLKqnBT8NcA.png" /><figcaption>TF Upgrade on VPC</figcaption></figure><p>Don’t forget we have a module in our configuration :)</p><p>In same way, the modules must be upgraded as the config files are already upgraded to 0.12 version.</p><p>Just get the path of modules files and fire up the terraform 0.12upgrade command from base configuration.</p><h4>Terraform Upgradation of VPC modules:</h4><pre>terraform 0.12upgrade /root/terraform-upgradation/modules/vpc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*xjmfAJknsd_Iqrfl_X_xgQ.png" /><figcaption>VPC Modules Upgraded To TF0.12</figcaption></figure><h4>Terraform Upgradation of EC2 modules:</h4><pre>terraform 0.12upgrade /root/terraform-upgradation/modules/ec2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*rd7z8I9r9GlOdmUjP1UxAg.png" /><figcaption>EC2 Modules Upgraded To TF0.12</figcaption></figure><p>Kudos!! Here we complete our exercise.</p><p>Note: If state files are managed remotely ensure to perform terraform state push.</p><p>If you have any questions or feedback don’t hesitate to write your thoughts in the comments/responses section.</p><blockquote>Kindly visit the below repository in order to access the whole configuration.</blockquote><blockquote><a href="https://github.com/kodefyi/terraform-upgradation.git">https://github.com/kodefyi/terraform-upgradation.git</a></blockquote><blockquote>Kindly visit the below repository in order to access the whole configuration. upgraded to 0.12 TF version.</blockquote><blockquote><a href="https://github.com/kodefyi/terraform-upgradation0.12.git">https://github.com/kodefyi/terraform-upgradation0.12.git</a></blockquote><p>~Dev Shah</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3180868c2b2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Remember Me Excercise]]></title>
            <link>https://medium.com/@kodefyi/javascript-remember-me-excercise-8371c339462d?source=rss-88c22c206fad------2</link>
            <guid isPermaLink="false">https://medium.com/p/8371c339462d</guid>
            <category><![CDATA[google-chrome]]></category>
            <category><![CDATA[chrome-cookie]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[js-localstorage]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Kodefyi]]></dc:creator>
            <pubDate>Thu, 20 Oct 2022 07:13:19 GMT</pubDate>
            <atom:updated>2022-10-20T08:22:42.209Z</atom:updated>
            <content:encoded><![CDATA[<h4>The purpose of this tutorial is to demonstrate how to use Javascript to implement a remember me feature.</h4><p>For the login and logout process, I will use PHP and MySQL as the backend, and HTML, CSS, and Bootstrap as the frontend.</p><h3>How does Remember Me work?</h3><p>By checking the “Remember Me” box, your browser will save a cookie so that the next time you go back to the site, you will automatically be logged in if you close out the window without signing out.</p><h4><strong>Getting Started</strong></h4><p>My project directory structure is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*B2l82_hkQaZAGgj9cMGaKA.png" /><figcaption>project directory structure</figcaption></figure><h4>First of all we will create database connection file to communicate and store registered users.</h4><p>As you can see in the above screenshot I have created a dbconnection folder inside that my connection logic is present.</p><p>Below code snippet will help you in writing database connection using PHP.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0bd93b2fd9ab5958762f01b2756f56bd/href">https://medium.com/media/0bd93b2fd9ab5958762f01b2756f56bd/href</a></iframe><p>Now we will create a user registration page so that if a user is not present he can register for himself.</p><p>Below screenshot is how our registration page will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*6kvPz04UEeo73FjRpJXl6w.png" /><figcaption>User registration page</figcaption></figure><p>Below code snippet will help you in creating registration page and also how to save registered user into our MySQL database.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf19d2845419b7246e8110ae58443879/href">https://medium.com/media/cf19d2845419b7246e8110ae58443879/href</a></iframe><p>When we click on submit the action will start from line number 42 and it will check for null values.</p><p>Suppose if we won’t enter the email or password then it will not allow you to register.</p><p>Now we will create a user login page so that a user can login and if email and password is correct he will be redirected to welcome page.</p><p>Below screenshot is how our login page will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*CWD4dJC57c3NEtt3qkvzmQ.png" /><figcaption>User Login Page</figcaption></figure><p>Now we will see how to implement remember me function using javascript.</p><p>In our project directory we have created a folder called “js” inside that folder we will create a file called “script.js” file.</p><p>Below code snippet will help you in creating remember me functionality uing javascript:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92af1db9011a2d0474380e3395415060/href">https://medium.com/media/92af1db9011a2d0474380e3395415060/href</a></iframe><p>Now in our login page which is “index.php” file we have to include this “script.js” file so that the function will be called whenever we use remember me checkbox.</p><p>let create “index.php” file and implement the login page and logic to validate user and login.</p><p>Below code snippet will help you in checking &amp; validating user and login.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf9c4a5a671601e8fe11e931323373d0/href">https://medium.com/media/cf9c4a5a671601e8fe11e931323373d0/href</a></iframe><p>As we all can see that in line number 14 I have added the “script.js” file to use the remember me function.</p><p>And after entering username and password when a user will click on login first it will check email and password both are entered or not.</p><p>Also from line 61 to line 69 that contains the logic to check that user has entered correct email and password or not if it is wrong then it will simply pop-up an alert that password is incorrect and if everything is correct then we will create a session and it will be redirected to welcome page and will print email of the user whoever has logged in.</p><p>Below code snippet will help you creating welcome page:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e2eda978f4f2485da1de9f2c16e58b1/href">https://medium.com/media/3e2eda978f4f2485da1de9f2c16e58b1/href</a></iframe><p>And at last we will implement the logic to destroy the session and let user to logout.</p><p>Below code snippet will help you in implementing logout functionality:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27b475bf96906c9ee7f5c0821d54e430/href">https://medium.com/media/27b475bf96906c9ee7f5c0821d54e430/href</a></iframe><p>Below screenshots will help in understanding the flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*OozrztKBJiJqHGMdi6vGQw.png" /><figcaption>registering the user</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*yi60-ol6-g0dPyhuhJOE9A.png" /><figcaption>login the user</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*ePiJ51KoQqVYNH4ATbi_Jw.png" /><figcaption>welcome page</figcaption></figure><p>Now here once we click on log out the input fields for email and password in login page will be filled automatically using browser cookies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*TSALLChmurK58F6qmiRVyg.png" /><figcaption>page after logout</figcaption></figure><p>That’s all folks, as you can see we have implemented a login, logout &amp; remeember me funcnationality using PHP, MySQL &amp; JavaScript.</p><p>If you have any questions or feedback don’t hesitate to write your thoughts in the comments/responses section.</p><p>Kindly visit <a href="https://github.com/kodefyi/Remember_me.git">https://github.com/kodefyi/Remember_me.git</a></p><p>~Amit Sharma</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8371c339462d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DATA STRUCTURE & ALGO PROBLEM STATEMEMNT SERIES]]></title>
            <link>https://medium.com/@kodefyi/data-structure-algo-problem-statememnt-series-4aa79767f46f?source=rss-88c22c206fad------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aa79767f46f</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[google-interview]]></category>
            <dc:creator><![CDATA[Kodefyi]]></dc:creator>
            <pubDate>Mon, 26 Sep 2022 16:44:02 GMT</pubDate>
            <atom:updated>2022-09-26T16:44:02.601Z</atom:updated>
            <content:encoded><![CDATA[<h3>Shifted Binary Search</h3><p><strong>Write a function that takes input in a sorted array of distinct integer as well as target integer.The Caveat is that the integer in the array have been shifted by some amount i.e they have been rotated left or right by one or more position. For instance, [21,22,23,24] might be turned into [23,24,21,22].</strong></p><p><strong>The function should return the index of the target integer ,if the target integer is not present the function should return -1.</strong></p><p><strong>Sample Input:</strong></p><p>array=[45, 61, 71, 72, 73, 0, 1, 21, 33, 37]</p><p>target =33</p><p><strong>Sample Output:</strong></p><p>8</p><p>Indexing start with 0.</p><p>Solution:</p><p>The question will be solved with the help of binary search.But first let us discuss what is binary search .</p><p><strong>Binary Search is a searching algorithm for finding an element’s position in a sorted array.</strong></p><p>But we can see that when the sorted array is rotated ,it will go against the binary search property.</p><p>So ,how we can solve that ?</p><p>From our sample input [45, 61, 71, 72, 73, 0, 1, 21, 33, 37] , we can observe that the elements [45,…,73] and [0,..37] are sorted in ascending order and from there we will take the advantage of binary search.</p><p>Algorithim:</p><ol><li>From the Sorted rotated array ,take left index with value as 0 and right index with value as length of the array-1.</li><li>Check left index is less than equal to right index in a while loop.</li><li>Inside the while loop ,find the middle index as (left index + right index)/2</li><li>check if middle index element is equal to target value . If “YES” return the position of the middle index.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*MYNCs55MzB9vug49wGcpmw.png" /></figure><p>5. If the middle index element is not equal to target ,check if left index element is less than equal to middle index element. If “YES” again check the condition that target value is less than middle index value and target value is greater than equal to left index value .IF “Yes” we will explore the left half of the array by shifting the right index to middle index-1 else we will explore the right half of the array the shifting the left index to middle index+1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*xbzKTQJfd1M0jpw3U-hxLA.png" /></figure><p>6. If the step 4 and step 5 fails . We will check if left index element is greater than middle index element. If “YES” again check the condition that target value is greater than middle index value and target value is less than equal to right index value .IF “Yes” we will explore the right half of the array by shifting the left index to middle index+1 else we will explore the left half of the array the shifting the right index to middle index-1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*tnIJ97EKNFTnzqmz7mmJnA.png" /></figure><p>7. Iterate through Step 3 to Step 6 until the condition become false.</p><p><strong>Dry Run:</strong></p><p>Sample Input:</p><p>[45, 61, 71, 72, 73, 0, 1, 21, 33, 37]</p><p>Target: 33</p><p>left index=0</p><p>right index=9 (i.e length of array-1)</p><p>left index &lt; right index , condition is true . middle index=(0+9)/2=4</p><p>middle_value=array[middle index]=73</p><ol><li>From Basic Binary Search:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*z_yad8YJ6v0uk4ZftOFcmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*7_hjIMhrIXR7YlwcHfE-hQ.png" /></figure><p>First IF condition fails ,second IF condition will execute and we will only explore the left half of the array .In the basic binary search ,we will explore the left half of the array and we will never find the target value.</p><p>2. From extended binary search</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*W6kTCPk2WT_XiOMRNCmW-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZ862mtUjFwblz-sQoIsvg.png" /></figure><p>First IF condition fails ,second IF condition will become true. Inside the elif condition it will again check condition and will explore the left or right part.</p><p>Time Complexity — O(log n)</p><p>Space Complexity — O(1)</p><p>You can find the source code on our github repo:</p><p><a href="https://github.com/kodefyi/DS-ALGO-Question-Series/blob/main/Shifted_Binary_Search/ShiftedBinarySearchSolution.py">DS-ALGO-Question-Series/ShiftedBinarySearchSolution.py at main · kodefyi/DS-ALGO-Question-Series</a></p><p>~Rohit Singh</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aa79767f46f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Tier Application Using Spring Boot + MySQL + JPA + HTML & Maven]]></title>
            <link>https://medium.com/@kodefyi/two-tier-application-using-spring-boot-mysql-jpa-html-maven-5f79b95c7912?source=rss-88c22c206fad------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f79b95c7912</guid>
            <dc:creator><![CDATA[Kodefyi]]></dc:creator>
            <pubDate>Fri, 23 Sep 2022 08:25:14 GMT</pubDate>
            <atom:updated>2022-09-26T16:56:28.241Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>In</strong> this article, we intend to develop an <strong>Employee management </strong>application using following tech stack:</p><p>Spring Boot (2.7.4)</p><p>Spring MVC</p><p>JPA</p><p>Java 8</p><p>MySQL Database</p><p>Thymeleaf</p><p>Bootstrap &amp; HTML (For UI)</p><p>Maven</p><p>Spring Tool Suit</p><h3>What are we Building?</h3><p>We are building a <strong>Employee Management System</strong>. In our application, we can create, update, view and delete various Employee records.</p><h3>Project Creation</h3><p>First, let’s use the Spring initializer page to initialize our project with the dependencies listed below.</p><ol><li>Go to → <a href="https://start.spring.io/">https://start.spring.io/</a></li><li>Leave everything as it is and select the following dependencies: <strong>Spring Web, JPA, MySQL, Thymeleaf </strong>and <strong>DevTools</strong>.</li><li>Extract the generated project and Open spring tool suit and Go to <strong>File → Open Projects From File System.</strong>. <strong>→ Choose the directory of your project</strong> and click on Finish.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*EommVO5ia3bFWwrkC8QWBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFmBHZ_N3QlwU1ocdBUr4w.png" /><figcaption>In spring tool suit click on file -&gt; open projects from file system..</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KfRlU1UVV2CKD4mVWJYGpA.png" /><figcaption>selecting the project directory and click finish.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*zP3th-V5n2EXR7SJT-_Ssw.png" /><figcaption>once finish will done it will come in spring tool suit</figcaption></figure><h3><strong>Note: Below I will be attaching the link of the classes been used. You may directly view them.</strong></h3><h3>Entity Creation</h3><p>Now let´s create our entity class called Employee(Entity class).</p><p><strong>Employee.java</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/java/com/kodefyi/employee/entity/Employee.java">employee_management/Employee.java at main · kodefyi/employee_management</a></p><h3>Data Layer (JPA Repositories)</h3><p>The repositories allow us to access the information stored in the database.</p><p><strong>EmployeeRepository.java</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/java/com/kodefyi/employee/repository/EmployeeRepository.java">employee_management/EmployeeRepository.java at main · kodefyi/employee_management</a></p><h3>Service Layer</h3><p>Now let´s create our service layer. We will inject the EmployeeRepository and the EmployeeServiceImpl.</p><p><strong>EmployeeService.java &amp; EmployeeServiceImpl.java</strong></p><ul><li><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/java/com/kodefyi/employee/service/EmployeeService.java">employee_management/EmployeeService.java at main · kodefyi/employee_management</a></li><li><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/java/com/kodefyi/employee/service/impl/EmployeeServiceImpl.java">employee_management/EmployeeServiceImpl.java at main · kodefyi/employee_management</a></li></ul><h3>MySQL Database configuration in application.properties file</h3><p><strong>application.properties</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/resources/application.properties">employee_management/application.properties at main · kodefyi/employee_management</a></p><h3>Controller Layer</h3><p>Now let´s create our controller layer to handle the coming web requests. We will inject the EmployeeService.</p><p><strong>EmployeeController.java</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/java/com/kodefyi/employee/controller/EmployeeController.java">employee_management/EmployeeController.java at main · kodefyi/employee_management</a></p><h3>Main Spring Boot Application</h3><p><strong>EmployeeApplication.java</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/java/com/kodefyi/employee/EmployeeApplication.java">employee_management/EmployeeApplication.java at main · kodefyi/employee_management</a></p><h3>Frontend layers</h3><p><strong>index.html</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/resources/templates/index.html">employee_management/index.html at main · kodefyi/employee_management</a></p><p><strong>add_employee.html</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/resources/templates/add_employee.html">employee_management/add_employee.html at main · kodefyi/employee_management</a></p><p><strong>edit_employee.html</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/resources/templates/edit_employee.html">employee_management/edit_employee.html at main · kodefyi/employee_management</a></p><p><strong>list_employee.html</strong></p><p><a href="https://github.com/kodefyi/employee_management/blob/main/src/main/resources/templates/list_employee.html">employee_management/list_employee.html at main · kodefyi/employee_management</a></p><p><strong>Note:</strong> By default Spring Boot will create the database structure and tables if you have provided in the right way your MySQL credentials in the application.properties file.</p><p>Now, Run the spring boot application from right clicking on EmployeeApplication.java class and choose RunAs → SpringBoot Application.</p><p>To access the application on the browser type below URL:</p><p>URL : <a href="http://localhost:8080/">http://localhost:8080</a></p><p>And you will find the welcome page like below:</p><p><strong>Home Page</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EtZkRzHnRGYcshQFOr03xA.png" /></figure><p><strong>Add employee page</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XXWQBJrjObIBavo-zOBYiQ.png" /></figure><p><strong>Show All Employee Records Page</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3mg2fwRSlUDX7tDl8RVSQ.png" /></figure><p>That’s all folks, as you can see we have implemented a two tier spring boot application from scratch including MySQL, HTML &amp; bootstrap.</p><p>If you have any questions or feedback don’t hesitate to write your thoughts in the comments/responses section.</p><p>Kindly visit <a href="https://github.com/kodefyi/employee_management">https://github.com/kodefyi/employee_management</a></p><p>~Amit Sharma</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f79b95c7912" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>