<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Awdesh</title>
    <description>The latest articles on DEV Community by Awdesh (@s_awdesh).</description>
    <link>https://dev.to/s_awdesh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F83627%2F29aac2ba-ef3f-4ca0-a721-271ee8720138.jpg</url>
      <title>DEV Community: Awdesh</title>
      <link>https://dev.to/s_awdesh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/s_awdesh"/>
    <language>en</language>
    <item>
      <title>Step by step guide to create an analytics application with AWS Redshift using AWS Lambda and S3</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Tue, 13 Apr 2021 13:41:24 +0000</pubDate>
      <link>https://dev.to/s_awdesh/step-by-step-guide-to-create-an-analytics-application-with-aws-redshift-using-aws-lambda-and-s3-3i82</link>
      <guid>https://dev.to/s_awdesh/step-by-step-guide-to-create-an-analytics-application-with-aws-redshift-using-aws-lambda-and-s3-3i82</guid>
      <description>&lt;p&gt;AWS Redshift is a data warehouse service where you can run analytics and make smart product decisions. Redshift can easily scale on petabytes of data with blazing fast querying speed. &lt;/p&gt;

&lt;p&gt;Its query engine is powered by PostgreSQL which means that PostgreSQL drivers for every language will work just fine to connect to the Redshift cluster. You can query data inside Redshift just like you'd query the data in Postgres.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why not use a regular RDBMS solution to run data analytics?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Regular databases are meant for OLTP purposes i.e. they are good for transactions over the database. A standard application writes and reads into the database a lot and that's where a regular OLTP solution shines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For an analytics application we feed the data into the database once and then read it many times where OLTP solutions aren't the perfect fit. An OLAP solution like Redshift fits perfect and gives great performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OLAP solutions store data in column-based storage for fast table scans. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Amazon Redshift, Google's Big Query, and Snowflake are some examples of the OLAP database.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How can we populate Redshift database&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;There are a couple of ways by which we can unload data from S3 to Redshift. Let's explore them in details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#1 AWS Glue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can hand over the work of offloading the data from S3 to Redshift by using another AWS service "AWS Glue". As the name suggests it'll work as a Glue between the two services by dynamically creating schema from the uploaded file inside S3. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1618318978025%2F0yMt-75a5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1618318978025%2F0yMt-75a5.png" alt="Untitled Diagram(2)(2)(2).png"&gt;&lt;/a&gt;&lt;br&gt;
AWS Glue which can run crawler on the uploaded file inside S3 and accordingly create a schema for us for Redshift database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#2 AWS Lambda&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another option is to take the matter into our hand :P and create tables manually inside Redshift, trigger AWS Lambda from S3 upload operation and let Lambda COPY data from JSON to Redshift.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1618318915332%2FwiJZgBuQH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1618318915332%2FwiJZgBuQH.png" alt="Untitled Diagram(1)(2)(3).png"&gt;&lt;/a&gt;&lt;br&gt;
I have experimented with both the options and I prefer the latter because I don’t want the dependency on another AWS service(AWS Glue) when I can manually create the schema which doesn't change too often. Also, it is an optimized option from a cost perspective.&lt;/p&gt;

&lt;p&gt;Let's get started. &lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;Create Redshift cluster using AWS console.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;First and foremost we need to create a Redshift cluster from the AWS console. You can choose "free trial" which is more than enough for POC purposes. The free trial gives 1 node of "db2-large" with 160GB storage. Creating a cluster is pretty fast and doesn't require any custom configuration. You can choose default settings and provide your master username and password to have your cluster ready in few mins.&lt;/p&gt;

&lt;p&gt;2) &lt;strong&gt;Create a new table inside Redshift.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using the Query Editor connect to the database using the credentials that you have supplied while creating the Redshift cluster.&lt;br&gt;
Once you are connected to the database you can use the Query Editor to run the regular SQL commands. &lt;br&gt;
To create a new table simply run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;Create&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will create a new table with the given table name in the database that you are on under the public schema category. Query Editor left pane will allow you to choose the database, schema category.&lt;/p&gt;

&lt;p&gt;If you prefer video tutorial, I have a video on YT of above steps. You can find it here. &lt;br&gt;
&lt;a href="http://www.youtube.com/watch?feature=player_embedded&amp;amp;v=r0Ekfn-Uads&amp;lt;br&amp;gt;%0A" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy05u18bf3j9c9ciltlwv.png" alt="Intro to AWS Redshift"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3) &lt;strong&gt;Create a Lambda function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lambda function is going to be quite simple and straightforward. We are just going to pass a file location inside S3, connect to Redshift and unload the file in it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;psycopg2&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_handler&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;file.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;loc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"'&lt;/span&gt;&lt;span class="s"&gt;s3://mybucket-awdeshcodes/%s&lt;/span&gt;&lt;span class="sh"&gt;'"&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;unload_to_redshift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;output: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;statusCode&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello from Lambda!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;unload_to_redshift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;psycopg2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dbname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;snippets&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;redshift_endpoint&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;5439&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;master_username&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;****&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="c1"&gt;# Begin your transaction
&lt;/span&gt;    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;begin;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;COPY public.&amp;lt;table_name&amp;gt; FROM&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;loc&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CREDENTIALS &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;aws_iam_role=arn:aws:iam::1234567:role/lamda-s3-rd-full-access&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; json &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;auto&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Commit your transaction
&lt;/span&gt;    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;commit;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Commit your transaction
&lt;/span&gt;    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;commit;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am using psycopg2 python driver to connect to the Redshift cluster from lambda. The connection line is most important.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;psycopg2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dbname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;snippets&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;redshift_endpoint&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;5439&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;master_username&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;****&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;dbname&lt;/strong&gt;: Name of the Redshift database used when we created the cluster and where our table exists.&lt;br&gt;
&lt;strong&gt;host&lt;/strong&gt;: Redshift endpoint. You can find that by clicking on the cluster link. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617950993951%2Fy-DcigDpz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617950993951%2Fy-DcigDpz.png" alt="Screenshot from 2021-04-09 08-49-13.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you copy the entire endpoint from the console, it'll come up with the database name and port at the end, make sure to remove them since we are going to use port and database name in a separate param.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;user&lt;/strong&gt;: This is the master username for the Redshift cluster.&lt;br&gt;
password: password used for the master username.&lt;/p&gt;

&lt;p&gt;Another important command in the above snippet is the COPY command that is going to COPY the file from S3 to RS. Let's take a look at it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;COPY&lt;/span&gt; &lt;span class="n"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;table_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;FROM&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; + loc + &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;CREDENTIALS&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;aws_iam_role=arn:aws:iam::1234567:role/lamda-s3-rd-full-access&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;auto&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;table_name&lt;/strong&gt;: use the name of the table that you created in the previous step inside the Redshift cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;CREDENTIALS&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;aws_iam_role=arn:aws:iam::1234567:role/lamda-s3-rd-full-access
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the command as is. YES, you have to write "CREDENTIALS" as is followed by a whitespace and ARN of the IAM role.&lt;/p&gt;

&lt;p&gt;This brings us to the IAM role which we haven't discussed yet.&lt;/p&gt;

&lt;p&gt;4) &lt;strong&gt;Create an IAM Role.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to IAM service and create a new role with access to S3 and Redshift service. At the moment I have given this role FullAccess to both services but I believe certain actions like writing to S3, deletion can be revoked.&lt;/p&gt;

&lt;p&gt;Now in the second tab of "Trusted relationships", press Edit and Add below policy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Service"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"redshift.amazonaws.com"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sts:AssumeRole"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By doing this we are allowing this new role to take action on the Redshift cluster. Action in our scenario is a COPY operation inside the table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617951673763%2Fu6mCTGQbj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617951673763%2Fu6mCTGQbj.png" alt="Screenshot from 2021-04-09 09-00-47.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have to associate this new role with the Redshift cluster as well. So switch to the Redshift cluster tab and open the Properties tab inside the cluster.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617951764840%2Fw-NQet5ku.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617951764840%2Fw-NQet5ku.png" alt="Screenshot from 2021-04-09 09-02-22.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617951803140%2F9vOh5sAik.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617951803140%2F9vOh5sAik.png" alt="Screenshot from 2021-04-09 09-03-00.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we scroll down a bit inside Properties we see "Cluster Permission" where we have to click on "Manage IAM roles" and add the ARN of the newly added IAM role from the above step. Click Associate and give the cluster couple of minutes to take in the effect of changes.&lt;/p&gt;

&lt;p&gt;At this point, we have associated the newly IAM role with the Redshift cluster and we can use the same IAM role inside our Lambda function as well.&lt;/p&gt;

&lt;p&gt;So let's get back to step#3 where we left it and copy the arn of IAM role like below.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
CREDENTIALS aws_iam_role=&amp;lt;arn_of_the_newly_created_role&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;At this point we can upload a json file in S3 with three fields&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
     &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"AWS Redshift"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"description"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The upload operation will trigger the Lambda which is going to run the &lt;code&gt;COPY&lt;/code&gt; command to copy the fields inside JSON into Redshift table.&lt;/p&gt;

&lt;p&gt;Open Redshift query editor and run the select command, you should see new records getting populated there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1618283558523%2FhKkEzdqOb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1618283558523%2FhKkEzdqOb.png" alt="Screenshot from 2021-04-13 05-11-03.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Connect to cluster from outside the VPC
&lt;/h4&gt;

&lt;p&gt;If you are looking to use a SQL client instead of AWS's Redshift console to query the data you can use SQLWorkbench. &lt;/p&gt;

&lt;p&gt;Download SQLWorkbench from this location&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.sql-workbench.eu/download-archive.html" rel="noopener noreferrer"&gt;https://www.sql-workbench.eu/download-archive.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once downloaded, uncompress it and it will have &lt;em&gt;sqlworkbench.exe&lt;/em&gt;* and ''SQL workbench.sh** which can be used for running workbench on windows and Unix platforms. Make sure Redshift cluster is accessible from outside the VPC, you can enable it from Properties-&amp;gt; Network settings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1618271908109%2F2gOpNlpbO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1618271908109%2F2gOpNlpbO.png" alt="Screenshot from 2021-04-12 16-57-00.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From File -&amp;gt; Connection Windows you can create a new connection. Below is a screenshot of my sql workbench connection config to Redshift.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617990233911%2FSrWHlLAYB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1617990233911%2FSrWHlLAYB.png" alt="Screenshot from 2021-04-09 10-43-42.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/redshift/latest/dg/copy-usage_notes-copy-from-json.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/redshift/latest/dg/copy-usage_notes-copy-from-json.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking for a video to learn about Redshift? I have one on my YT channel &lt;a href="https://youtu.be/r0Ekfn-Uads" rel="noopener noreferrer"&gt;Introduction to Redshift&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I post daily about programming. You can find me 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://studio.youtube.com/channel/UC7Ze67ISJCgtHZBXCYcBLIg" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt; | &lt;a href="https://twitter.com/S_AWDESH" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; | &lt;a href="https://www.instagram.com/awdeshcodes/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s learn together 💪💪&lt;/p&gt;

&lt;p&gt;Happy Coding 💻&lt;/p&gt;

</description>
      <category>aws</category>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Setup Java development environment and create your first program with IntelliJ</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Fri, 26 Mar 2021 06:16:46 +0000</pubDate>
      <link>https://dev.to/s_awdesh/create-your-first-program-in-java-with-intellij-4jf9</link>
      <guid>https://dev.to/s_awdesh/create-your-first-program-in-java-with-intellij-4jf9</guid>
      <description>&lt;p&gt;Setup JAVA development environment on your machine and start coding in JAVA.&lt;br&gt;
I have worked with Java on and off for the last 6-7 years but I still had a few fundamental questions/concerns like-:&lt;/p&gt;

&lt;p&gt;1.) Why do I need JDK to write a Java Program?&lt;br&gt;
2.) Should I install JDK vs JRE?&lt;br&gt;
3.) Is Java 1.8 and Java 8 the same?&lt;br&gt;
4.) Where should I install Java from?&lt;/p&gt;

&lt;p&gt;and many more.&lt;/p&gt;

&lt;p&gt;In this video, I am discussing answers to all of the above questions plus capturing how to install IntelliJ and setup Java from scratch.&lt;/p&gt;

&lt;p&gt;TL;DR&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary of the video&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JDK contains Java compiler, java doc, java debugger, etc. All of them are integral to code and compile a java program.&lt;/p&gt;

&lt;p&gt;A couple of years ago JRE and JDK used to come as a separate distribution but now JRE comes with JDK. Although JRE can also be downloaded separately.&lt;/p&gt;

&lt;p&gt;Java versioning scheme has changed after Java 8 and there is no more 1.x in the versions anymore. With each new version we get Java x and Jdk x e.g. March 2021, Java 16 got released with Jdk 16. I am covering this topic in detail in the video.&lt;/p&gt;

&lt;p&gt;I write and record videos on various platforms about programming. These days I am writing mostly about JAVA.&lt;/p&gt;

&lt;p&gt;You can find me at &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UC7Ze67ISJCgtHZBXCYcBLIg?sub_confirmation=1"&gt;Youtube&lt;/a&gt;  |  &lt;a href="https://twitter.com/S_AWDESH"&gt;Twitter&lt;/a&gt;  |  &lt;a href="https://instagram.com/awdeshcodes"&gt;Instagram&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Let’s learn together 💪💪&lt;/p&gt;

&lt;p&gt;Happy Coding 💻&lt;/p&gt;

&lt;p&gt;reference: &lt;a href="https://stackoverflow.com/questions/1906445/what-is-the-difference-between-jdk-and-jre"&gt;https://stackoverflow.com/questions/1906445/what-is-the-difference-between-jdk-and-jre&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Database access in Spring.</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Thu, 25 Mar 2021 05:40:52 +0000</pubDate>
      <link>https://dev.to/s_awdesh/database-access-in-spring-384c</link>
      <guid>https://dev.to/s_awdesh/database-access-in-spring-384c</guid>
      <description>&lt;p&gt;JPA is a standard for ORM. It is an API layer that maps Java objects to the database tables. All you need is to annotate your Domain object with @Entity. &lt;/p&gt;

&lt;p&gt;In Spring Boot, Spring Data JPA brings the goodness of Spring Data and JPA together. &lt;/p&gt;

&lt;p&gt;In the JDBC world we have to embed sql queries inside the codebase to access the database, JPA hides all that complexity by providing many CRUD related methods via JpaRepository.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let's take a look&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614642552926%2Fvqae0Mb9C.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614642552926%2Fvqae0Mb9C.png" alt="carbon(2).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above code is mapping User Object to User table in the database. User table consists two columns "first_name" and "last_name".  @Column annotation is defining the column inside the User table.&lt;/p&gt;

&lt;p&gt;JPA supports many annotations e.g. @Table annotation can define the indexes on the table. Take a look at the sample code below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614644104258%2FjBZ1KFZKp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614644104258%2FjBZ1KFZKp.png" alt="carbon(3).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above we are creating an index name “name_index” on the first_name column.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data access layer without JPA:
&lt;/h3&gt;

&lt;p&gt;JDBC is the prominent method to access the database. JDBC requires one to write sql queries to communicate with the database, it makes use of Statement, ResultSet etc. to prepare a sql statement and gets the result out of database respectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's take a look below&lt;/strong&gt;-:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT first_name FROM Customers WHERE last_name = 'Doe'");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we create a statement object and call executeQuery on it with supplying the SQL query. ResultSet object will contain all the returned result from the query. We can now use an iterator to iterate over items inside result set.&lt;/p&gt;

&lt;p&gt;Similarly an insert statement could look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Statement stmt = connection.createStatement();
stmt.execute("INSERT INTO user (FIRST_NAME,LAST_NAME) VALUES (1,'John','Dow')");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Data access layer with JPA
&lt;/h3&gt;

&lt;p&gt;Let's see how JPA does above two database operations.&lt;/p&gt;

&lt;p&gt;Spring Data Jpa expose JpaRepository which is comprises on all the CRUD methods. Once we define a repository for the domain object we are ready to call these methods.&lt;/p&gt;

&lt;p&gt;Let's create a repository interface for User.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614644818460%2FfmRbLKzye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614644818460%2FfmRbLKzye.png" alt="carbon(5).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;@Repository annotation tells Spring Boot to scan interface and make it available at startup. You'll notice that we haven't create any method inside our interface because we don't need to, atleast for the simple CRUD use cases. &lt;br&gt;
All those operations are supported by JpaRepository out of the box and we are extending it.&lt;/p&gt;

&lt;p&gt;Now let's compare same select and insert operation of Jdbc here in Jpa.&lt;/p&gt;

&lt;p&gt;Like Select if we have to retrieve all the objects we can do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User user = userRepository.findAll();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like Insert if we have to insert a user we can do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userRepository.save(user);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much simpler than the JDBC implementation. &lt;/p&gt;

&lt;p&gt;Let's take a look at another example. &lt;/p&gt;

&lt;p&gt;Finding all the users with the given first name. &lt;/p&gt;

&lt;p&gt;Use “findBy” to search on a particular column.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// find rows by the first name.
userRepository.findByFirstName(String firstName);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// find rows by the last name.
userRepository.findByLastName(String lastName);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'll stop here for this post. In the next post I'll write how to handle more complex sql queries using JPA.&lt;/p&gt;

&lt;p&gt;If you like to walk through video tutorial rather I have a Spring Boot playlist on YouTube 👉 &lt;a href="https://youtu.be/fiKYlmTdG2g" rel="noopener noreferrer"&gt;Spring Boot Tutorial Series&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I post daily about programming on different platforms with the intention of writing good tech content and keep them less spammy.&lt;/p&gt;

&lt;p&gt;You can also find me 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/fiKYlmTdG2g" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt;  |  &lt;a href="https://twitter.com/S_AWDESH" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;  |  &lt;a href="https://instagram.com/awdeshcodes" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Let’s learn together 💪💪&lt;/p&gt;

&lt;p&gt;Happy Coding 💻&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Quick walk through of creating an API with Spring Boot.</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Wed, 24 Mar 2021 00:10:28 +0000</pubDate>
      <link>https://dev.to/s_awdesh/quick-walk-through-of-creating-an-api-with-spring-boot-2dm5</link>
      <guid>https://dev.to/s_awdesh/quick-walk-through-of-creating-an-api-with-spring-boot-2dm5</guid>
      <description>&lt;p&gt;In this post, I am discussing how we can create a simple API with Spring Boot. This post discusses about Repository, Controller/Resource and Model layer.&lt;/p&gt;

&lt;p&gt;Let's get to it. 🚀&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisite&lt;/strong&gt;: Make sure you have Java 11 and maven installed.&lt;/p&gt;

&lt;p&gt;Head over to &lt;em&gt;start.spring.io&lt;/em&gt; from your favourite browser and create a starter project. Add these three dependency from the Add Dependency tab on right pane.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JPA&lt;/strong&gt; : JAVA Persistence API. Provides lot of methods to interact with database.&lt;br&gt;
&lt;strong&gt;H2&lt;/strong&gt; : In memory relational database. &lt;br&gt;
&lt;strong&gt;Spring Web&lt;/strong&gt; : Uses Apache Tomcat as default embedded container.&lt;/p&gt;

&lt;p&gt;Click on Generate at the bottom to download the zipped folder. Extract it and open it in IntelliJ or any other favourite editor of your choice.&lt;/p&gt;

&lt;p&gt;Your pom.xml with dependencies should look like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wQXiCVhK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49iof8y308haovzmkwav.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wQXiCVhK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49iof8y308haovzmkwav.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just three dependencies that we added from the website. Simple and clean.&lt;/p&gt;

&lt;p&gt;At this point we can run the service and it'll start the tomcat but it won't be very useful to us since we haven't defined any endpoints.&lt;/p&gt;

&lt;p&gt;So let’s jump into the action and start creating classes. I'll start from bottom-up i.e. creating classes that are closer to the database and then move up to utilize those classes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Model layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first thing I like to think about is the object that I want to store in the database. In this post I am using &lt;strong&gt;Video&lt;/strong&gt; object. A video can contain a title and a description.&lt;/p&gt;

&lt;p&gt;Let's create a class named Video.java.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YoaHR-Z_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0i0u5u5g7g2p8ehvv1d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YoaHR-Z_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0i0u5u5g7g2p8ehvv1d.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the quick summary of the annotations used in the class.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a class="comment-mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;
&lt;/em&gt; : Annotation tells that the field is a primary key.&lt;br&gt;
&lt;em&gt;@GeneratedValue&lt;/em&gt; : JPA will take care of auto generating this value for us. We don't need to manually send it with the object.&lt;br&gt;
&lt;em&gt;@Entity&lt;/em&gt; : Represents that the POJO can be persisted in the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Repository layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remember JPA that we added while generating the project. It exposes many methods that can be utilized to interact with the database. Methods like save(), findAll(), delete for regular CRUD operations.&lt;/p&gt;

&lt;p&gt;No more hassle of constructing JDBC queries.👍&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YEsILVBJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/047a0a26c1h2qqkx935j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YEsILVBJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/047a0a26c1h2qqkx935j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;@Repository : Helps Spring Boot to scan the repository layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Controller/ Resource layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Layer that expose object from data to the outside world and brings days from outside world.&lt;/p&gt;

&lt;p&gt;In other words, it is where we define GET, POST and other REST mappings to create API endpoints.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AiE6VMpZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ctycpukv7vzhny452pih.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AiE6VMpZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ctycpukv7vzhny452pih.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;@RestController : Signifies that the class is a controller class and contains REST endpoints. &lt;/p&gt;

&lt;p&gt;That's it. 🎉🎉&lt;/p&gt;

&lt;p&gt;Now you are ready to run the service. Look for the class ending with Application in your project. It should contain main method. &lt;/p&gt;

&lt;p&gt;You can simply run the main method that will scan all the components based on the annotations that we have supplied and bootup the service.&lt;/p&gt;

&lt;p&gt;If everything went well, you should be able to see tomcat running at port 8080. Fireup postman and go to &lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt; and GET, POST a Video object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="http://localhost:8080/h2-console"&gt;http://localhost:8080/h2-console&lt;/a&gt;&lt;/strong&gt; will open the window to connect to in memory database. You don't need to change anything other than Jdbc_url which can be find from the logs inside the terminal window.&lt;/p&gt;

&lt;p&gt;This is a very basic and simple implementation of creating an API with Spring Boot. There are many features of SB that comes out of the box which I will write about in the next few posts.&lt;/p&gt;

&lt;p&gt;If you like to walk through video tutorial rather I have a Spring Boot playlist on YouTube 👉 &lt;a href="https://www.youtube.com/channel/UC7Ze67ISJCgtHZBXCYcBLIg"&gt;Spring Boot Tutorial Series&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I post daily about programming. You can find me 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://studio.youtube.com/channel/UC7Ze67ISJCgtHZBXCYcBLIg"&gt;Youtube&lt;/a&gt; | &lt;a href="https://twitter.com/S_AWDESH"&gt;Twitter&lt;/a&gt; | &lt;a href="https://www.instagram.com/awdeshcodes/"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s learn together 💪💪&lt;/p&gt;

&lt;p&gt;Happy Coding 💻&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>java</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>My programmer friends, How are you drinking your coffee?</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Sat, 11 Jul 2020 03:22:14 +0000</pubDate>
      <link>https://dev.to/s_awdesh/to-my-programmer-friends-how-are-you-drinking-your-coffee-1122</link>
      <guid>https://dev.to/s_awdesh/to-my-programmer-friends-how-are-you-drinking-your-coffee-1122</guid>
      <description>&lt;p&gt;Coffee and software engineers match made in heaven, right? Well, that might be an overstatement but we have to agree that nothing beats a good cup of coffee to kick start your morning.&lt;/p&gt;

&lt;p&gt;We have all read, watched, and talked about our office setup with a cool keyboard, mouse, and expensive headsets but coffee. I feel coffee deserves an article as well since it is an integral part of our dev space, at least for most of us.&lt;/p&gt;

&lt;p&gt;I live in Coffee capital, Seattle where rain consumes most of the year. It's the coffee that helps you to get through the gloomy part of the season.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhjyggxaiiqjzwfv8spvt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhjyggxaiiqjzwfv8spvt.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Being from an Indian background I always used to drink coffee with milk and sugar. Black Coffee isn't quite common back at home. When I started working in the US, I somehow picked up the black coffee and since then we are living happily together.&lt;/p&gt;

&lt;p&gt;My journey with black coffee started with the basic drip coffee, you know the one that’s already brewed and boiled. Although I must admit that I always tend to put cream and sugar in my drip coffee mostly because I see cream, sugar, and cinnamon within the proximity of the drip coffee and it’s tough to resist sugar once you see it :P&lt;/p&gt;

&lt;p&gt;From drip coffee, I moved to K-Cups, the one where you have crushed beans inside the cup which you throw in a K-cup machine. Machine poke a hole in the cup and pours the hot water through it and ”voila”, your hot cup of coffee is ready. &lt;/p&gt;

&lt;p&gt;I remember the day 4-5 years back when after work on Friday, I rushed to Target to get a k-cup brewing machine and walked over 2 miles with rather uncomfortable to carry brewer 📦. All I wanted, coffee the next morning at home instead of going out to a nearby coffee house. &lt;/p&gt;

&lt;p&gt;Everything has a journey and so did my K-cup brewer not because it broke but the coffee after a point was just hot brown water. Now, I was longing for a better option something fresh, like coffee beans which I can grind at home.&lt;/p&gt;

&lt;p&gt;I decided to move on to an old-style where I can get powdered coffee and pour hot water over it to have a perfect cup of hot coffee.&lt;/p&gt;

&lt;p&gt;The problem was: I didn’t have a coffee filter, pour-over mug, kettle, etc. and I didn’t want to spend more money especially when I am in the experimentation phase and more importantly when K-cup brewing machine is witnessing me ignoring her.&lt;/p&gt;

&lt;p&gt;But I had a measuring cup that I can use to boil water in a microwave, a strainer that I could use to filter coffee grounds. So I started with that, zero investment other than buying a powdered filtered coffee. My technique was simple, boil the water in the microwave for 2 and half minutes, let it sit for 10 seconds, put coffee grounds on the strainer and pour the hot water over the coffee grounds, and through the strainer, you’ll have the hot cup of coffee into the mug.&lt;/p&gt;

&lt;p&gt;Using a bare metal filter is not a good idea. For one, it doesn’t filter out all the coffee and some of the grounds can slip through it. You don’t want to taste the coffee grounds unless you are drinking the ‘Turkish coffee’. Secondly, the taste isn't great unless you use it with a paper filter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frsubs76e4oqzganzlw1b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frsubs76e4oqzganzlw1b.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚠️ Another problem using the metal filter.
&lt;/h3&gt;

&lt;p&gt;Unlike paper filters, metal filters are incapable of absorbing everything from the coffee grounds. Coffee contains the cafestol which is made up of a chemical compound ‘diterpenes’. Diterpenes are fundamentally an oily compound, Wikipedia says “Diterpenes is the base compound in Retinol”.  No wonder all the skin creams contain retinol in them, claim to get rid of skin dryness. &lt;/p&gt;

&lt;p&gt;Based on some more research online I found out that cafestol in your coffee can increase your LDL levels. I suffer from high LDL and have been told to stay away from oily food. Well, I didn’t know the oil was sneaking through coffee. If I am drinking a 2-3 cup of coffee daily I want to make sure I am not drinking something unwanted in it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is it just the problem with metal filters?
&lt;/h3&gt;

&lt;p&gt;Yes, wherever we use it. Not just pour over but all other means of coffee filtering like the most popular french press which uses metal filter has the most amount of cafestol. To make the matter worse, the process of letting your coffee sit inside the french press jar increases the cafestol further.&lt;/p&gt;

&lt;p&gt;If you drink 5 cups of french press a day it can increase your LDL levels from 6% to 8%.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1a7epjrnmla0tnwyoc1j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1a7epjrnmla0tnwyoc1j.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
I have finally switched to using the paper filter and a pour-over mug. The paper filter absorbs the diterpene, the oily compound just because of the nature of paper. The paper absorbs oil, metal doesn’t, makes sense.&lt;/p&gt;

&lt;p&gt;Well, this is just my observation. At this point I would ask the ultimate question, How do you take your coffee? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyor8whyifwuzfyfsdhna.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyor8whyifwuzfyfsdhna.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the images are taken from Pexels and Unsplash.&lt;/p&gt;

&lt;p&gt;TIP: Use a pinch of salt in your coffee. Salt cuts the bitterness in the Coffee and enhances the flavor.&lt;/p&gt;

</description>
      <category>watercooler</category>
      <category>discuss</category>
      <category>writing</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Money poor Time rich or vice versa</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Thu, 20 Jun 2019 22:57:26 +0000</pubDate>
      <link>https://dev.to/s_awdesh/money-poor-but-time-rich-or-vice-versa-1nb5</link>
      <guid>https://dev.to/s_awdesh/money-poor-but-time-rich-or-vice-versa-1nb5</guid>
      <description>&lt;p&gt;What kind of a job would you prefer?&lt;/p&gt;

&lt;p&gt;Job-1 -: Working for one of the big tech company, aggressive work culture. Good base salary + bonus + stock. &lt;/p&gt;

&lt;p&gt;Job-2 -: Working for a smaller company, not so aggressive work culture or deadlines, working from home. Ownership and decision making on projects. Competitive base, no bonus or stocks.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Summary of dev talks from the Dev conference I attended last week.</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Wed, 05 Jun 2019 06:13:18 +0000</pubDate>
      <link>https://dev.to/s_awdesh/things-i-learned-from-dev-conference-18nd</link>
      <guid>https://dev.to/s_awdesh/things-i-learned-from-dev-conference-18nd</guid>
      <description>&lt;p&gt;It’s been a while since I have posted an article. I thought this might be a nice article to share while stuff from the conference is still fresh in my memory. The conference was heavily focused on microservices, Kubernetes and cloud platforms. &lt;/p&gt;

&lt;p&gt;I want to share some of the highlights from different sessions so to have a note for myself for the future reference :P&lt;/p&gt;

&lt;p&gt;There were a lot of sessions around microservices. I’ll try to summarize my understanding from a lot of different talks on the same topic. The common theme of different talks was to focus on the evaluation of the need for microservices in your architecture. &lt;/p&gt;

&lt;p&gt;Some of the things to consider before choosing microservices architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt; -: Different services need to talk to each other and communicate by sending data over the network. Data in motion between services needs to be encrypted which is something you don’t need to worry in a monolith service architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Network latency&lt;/strong&gt; -: In Microservices architecture services are going to be spread around the network. Calling one service from another over the network could be slow because of network slowness.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Observability&lt;/strong&gt; -: Adding centralized telemetry data around different services can be a challenging task.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Team dynamics&lt;/strong&gt; -: Team dynamics can be tricky with each team working in the silo on their own small piece of service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Versioning can be a pain&lt;/strong&gt; -: Different microservices can have different versions based on the feature implementations. It is vital to keep track of which version is compatible with which version of other microservices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some interesting mentions of the tool for microservices in another talk&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Istio&lt;/strong&gt; -: Service mesh to manage micro services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Envoy&lt;/strong&gt; -: Side car proxy to enable communication between services in a microservice architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mixer&lt;/strong&gt; -: Gather telemetry data from different services.&lt;/p&gt;

&lt;p&gt;Another talk was around going from Monolithic architecture to Microservices via mini services. I quickly wrote down the comparison chart in the talk. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mini service&lt;/strong&gt; architecture as I understood is an intermediate between the monolith and microservices architecture in which you neither have a bulky codebase with every possible implementation nor you go crazy by splitting every possible feature into a microservice. &lt;/p&gt;

&lt;p&gt;In mini service, you only split features that require more work/ maintenance or whatever matrix you choose to split.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web assembly talk&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I really found this talk very interesting. I have read about web assembly before but never cared to understand it thoroughly. I found the talk to be a quick and good intro to web assembly.&lt;/p&gt;

&lt;p&gt;Write code in different languages like C, C++, Go, Rust and have it compile into web assembly directly into the browser. The idea of web assembly is to get native desktop app performance on the browser with the same code base that you have used to write a desktop app thus bypassing rewriting the application in JavaScript.&lt;/p&gt;

&lt;p&gt;Think about desktop games, Java applet applications running in the browser without asking the client to download runtime and without developer to port desktop app code to JavaScript.&lt;/p&gt;

&lt;p&gt;You do not write code in web assembly rather you compile code in web assembly by using the language compilers.&lt;/p&gt;

&lt;p&gt;Node Js 8 or higher supports web assembly.&lt;/p&gt;

&lt;p&gt;80% of the browser supports web assembly.&lt;/p&gt;

&lt;p&gt;Compiled web assembly is called .wasm which can be imported as an ES6 module.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chaos Engineering&lt;/strong&gt; was another term that I really found very interesting. Netflix uses it and the idea is to take servers offline from the architecture to see if other servers are able to take load successfully.&lt;/p&gt;

&lt;p&gt;There was another interesting talk about &lt;strong&gt;Outcome driven development&lt;/strong&gt; which focused on how to achieve efficiency within the engineering team by focusing on the outcome rather than the output.&lt;/p&gt;

&lt;p&gt;I got introduced to &lt;strong&gt;Dev SecOps&lt;/strong&gt; term in a cloud security talk. The talk was focused on using the security policies in the development environment so to not get surprised eventually when software doesn’t go through validation afterward.&lt;br&gt;
Have a baseline of cloud infrastructure that can be agreed upon by Devs and Security team.&lt;/p&gt;

&lt;p&gt;The closing talk was very informative from the director of AWS. The topic of the talk was how to create MLP (most loved product) not MVP. How we create MVP first and then keep adding features into it rather than improving MVP.&lt;/p&gt;

&lt;p&gt;There were a lot of great insights about great UI from the work of Dieter Rams, the chief designer of Braun. His Wikipedia page talks about all the good design principles. &lt;a href="https://en.wikipedia.org/wiki/Dieter_Rams"&gt;https://en.wikipedia.org/wiki/Dieter_Rams&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is it. &lt;/p&gt;

&lt;p&gt;Please feel free to send your feedback and comments to add further on the topics or correct me if I went wrong in some of my understanding from the talk.&lt;/p&gt;

</description>
      <category>webassembly</category>
      <category>devops</category>
      <category>webservices</category>
      <category>cloud</category>
    </item>
    <item>
      <title>My first week of learning Swift.</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Fri, 14 Sep 2018 05:15:25 +0000</pubDate>
      <link>https://dev.to/s_awdesh/my-first-week-of-learning-swift-hne</link>
      <guid>https://dev.to/s_awdesh/my-first-week-of-learning-swift-hne</guid>
      <description>&lt;h3&gt;
  
  
  1.) Declaring constants and variables.
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Variables&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fj30gzph8h08vnshfg6ib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fj30gzph8h08vnshfg6ib.png" alt="var"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Constants&lt;/code&gt;: Once declared their value can't be changed. Swift will throw compile time error when trying to update the value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0czj40r38b68uvy85pwa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0czj40r38b68uvy85pwa.png" alt="let"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2.) Declaring a function
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fa7xk2qy0dg795fmbwmkp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fa7xk2qy0dg795fmbwmkp.png" alt="func"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Java's syntax of a regular function looks like below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz1lkguxfj9wxwvxrjy8n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz1lkguxfj9wxwvxrjy8n.png" alt="method"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3.) Class function
&lt;/h3&gt;

&lt;p&gt;Like python, swift has class functions. Class functions are bound to a class rather than an instance of a class. Honestly, &lt;code&gt;function&lt;/code&gt; followed by &lt;code&gt;class&lt;/code&gt; in the syntax threw me off a bit when I first encountered it in the source code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1oafqmyxd1wy5ik98wpp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1oafqmyxd1wy5ik98wpp.png" alt="class functions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python's syntax of a class function&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbitdtez1x7g1k6ckwgrd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbitdtez1x7g1k6ckwgrd.png" alt="python class"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4.) Using underscore &lt;code&gt;_&lt;/code&gt;.
&lt;/h3&gt;

&lt;p&gt;In my very short experience with Swift, I have seen the use of &lt;code&gt;_&lt;/code&gt; inside function calls. &lt;code&gt;_&lt;/code&gt; is used to define an unnamed parameter inside the function. Swift uses a name for each parameter so when we call a function we need to provide the name of the parameter. &lt;/p&gt;

&lt;p&gt;Use of &lt;code&gt;_&lt;/code&gt; can bypass passing of the name altogether. Let's walk through an example-:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fe8huvrtk19shv64kr2ut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fe8huvrtk19shv64kr2ut.png" alt="underscore"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In general, when &lt;code&gt;_&lt;/code&gt; in front we can to ignore value. Another use case of &lt;code&gt;_&lt;/code&gt; would be something like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzv8817iurxim6bchrzc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzv8817iurxim6bchrzc1.png" alt="return"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5.) Type Alias
&lt;/h3&gt;

&lt;p&gt;As the name suggests, type alias allows giving aliases to existing types. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fev86b2bi4o2fiocq7lbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fev86b2bi4o2fiocq7lbg.png" alt="alias"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is certainly not the best use case of using type aliases. The better use case is by aliasing closures inside the function. Functions and closures in swift have a parameter type and a return type which can be aliased.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8x93lvorzyajh6pjmhg6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8x93lvorzyajh6pjmhg6.png" alt="alias"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6.) Closures
&lt;/h3&gt;

&lt;p&gt;As per Apple docs&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Closures are self-contained blocks of functionality that can be passed around and used in your code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcnn5n4jrh34up45e1kcx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcnn5n4jrh34up45e1kcx.png" alt="closures"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7.) &lt;code&gt;?&lt;/code&gt; and &lt;code&gt;!&lt;/code&gt;.
&lt;/h3&gt;

&lt;p&gt;Both &lt;code&gt;?&lt;/code&gt; and &lt;code&gt;!&lt;/code&gt; is used for Optionals in swift. Use of optionals can make variable to have a value or nil.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;?&lt;/code&gt; is used after the variable type indicate that the variable is optional.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4p134d6dmh4go5oh31v7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4p134d6dmh4go5oh31v7.png" alt="Optional"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;!&lt;/code&gt; is used to unwrap the value of optional so to use it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fio9a2pikn4vs0xorvqmu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fio9a2pikn4vs0xorvqmu.png" alt="unwrap"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We could check for non-nil before unwrapping optional to get rid of runtime error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0lortmj1krhaeqz5riia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0lortmj1krhaeqz5riia.png" alt="force-unwrap"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As pointed out by Nuno Vieira in the comment section, force unwrapping is not a good practice rather we can use (if..let) which is called &lt;strong&gt;Optional binding&lt;/strong&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxg7v2d9w42otdxjwkjaq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxg7v2d9w42otdxjwkjaq.png" alt="optional-binding"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8.) Dictionary and Array
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcd6wxoa03b3r5ty6qza3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcd6wxoa03b3r5ty6qza3.png" alt="array"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is it for this post. Stay tuned for articles like this.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Offical swift tutorial from Apple-: &lt;a href="https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html" rel="noopener noreferrer"&gt;https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Great read about Optionals-: &lt;a href="https://stackoverflow.com/questions/24003642/what-is-an-optional-value-in-swift" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/24003642/what-is-an-optional-value-in-swift&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you want me to write on a specific topic, please feel free to post them in the comment section. &lt;/p&gt;

&lt;p&gt;You can support my work by buying me a coffee below. 💚💚💚💚💚💚 !!&lt;br&gt;
&lt;a href="https://ko-fi.com/F1F0J8U1" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcc1nn30p8xi1ub53ae5a.png" alt="Buy me a ko-fi"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>programming</category>
      <category>beginners</category>
      <category>ios</category>
    </item>
    <item>
      <title>Shuffling algorithms and randomization to improve algorithm‘s runtime.</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Sat, 04 Aug 2018 09:50:26 +0000</pubDate>
      <link>https://dev.to/s_awdesh/everyday-im-shuffling-im-a-card--fire-1f8b</link>
      <guid>https://dev.to/s_awdesh/everyday-im-shuffling-im-a-card--fire-1f8b</guid>
      <description>&lt;p&gt;Shuffling card is an essential part of every card game. There are many techniques for shuffling cards but overhand and riffle are the most popular ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overhand shuffle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this shuffle, a set of cards are transferred from bottom of the deck to the top of the deck and the same process gets executed recursively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fazilazcmdufmet87m5fn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fazilazcmdufmet87m5fn.jpg" alt="overhand shuffle"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;A deck of cards is essentially a fixed sized array of length 52. Overhand shuffle puts set of cards from the end of the array to the beginning of an array. This process gets repeated to get a good shuffle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Riffle shuffle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotncj2nsn1kq4s3si6ov.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotncj2nsn1kq4s3si6ov.gif" alt="riffle shuffle"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This involves cutting the deck into 2 halves so we get two sets of cards and riffle them such that at the end both halves gets interleaved.&lt;/p&gt;

&lt;p&gt;A quick implementation of riffle shuffle would be something like following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4u1c439scjtw6fr3thht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4u1c439scjtw6fr3thht.png" alt="kata"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are shuffling algorithms in existence that runs faster and gives consistent results. These algorithms rely on randomization to generate a unique random number on each iteration.&lt;/p&gt;

&lt;p&gt;As per Wikipedia&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If a computer has access to purely random numbers, it is capable of generating a "perfect shuffle".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Fisher-Yates&lt;/strong&gt; shuffle is one such algorithm for achieving a perfect shuffle using a random number generator. The algorithm is named after Ronald Fisher and Frank Yates who first described this algorithm in their book in 1938. Later Donal Knuth and Richard Durstenfeld introduced an improved version of the algorithm in 1964. &lt;/p&gt;

&lt;p&gt;Unlike swapping items at two different indexes, algorithm generates a random number k between range of the elements inside an array. Every iteration updates the last element in the range thus random generator works on the new range on every iteration and generates a unique number every time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuffslfdyodcanm8jj80r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuffslfdyodcanm8jj80r.png" alt="kata"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above algorithm works in linear time and faster than riffle shuffle. Putting some timing around both shuffle algorithm for an array of 100 integers produces below result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn3e0ivridzlbhz4u6ysk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn3e0ivridzlbhz4u6ysk.png" alt="kata"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Programming languages use a similar algorithm in their inbuilt implementation of shuffle method. Java's implementation of shuffle method could be used by invoking&lt;/p&gt;

&lt;p&gt;&lt;code&gt;collections.shuffle()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To shuffle a linked list which doesn't allow access of object by their index, Java converts it back to array first so to have random access, shuffles it and converts it back to list.&lt;/p&gt;

&lt;p&gt;Shuffle method's implementation From Java docs&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj63i384kpg206iog102w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj63i384kpg206iog102w.png" alt="kata"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Can randomization improve the runtime of an algorithm.
&lt;/h3&gt;

&lt;p&gt;A good shuffling algorithm has a function which generates a unique random number consistently. Quicksort which gives quadratic time performance on a sorted array can generate consistent O(nlogn) result by randomizing sorted array first and then fed it into quicksort algorithm. &lt;/p&gt;

&lt;p&gt;There are two different types of randomization algorithms namely &lt;strong&gt;Las Vegas&lt;/strong&gt; and &lt;strong&gt;Monte Carlo&lt;/strong&gt; algorithms. IMHO, one can't get a better name than Las Vegas for a shuffling algorithm :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Las Vegas&lt;/strong&gt; algorithm guarantees to give result in an expense of the time complexity whereas &lt;strong&gt;Monte Carlo&lt;/strong&gt; compromises guarantee of the result by exiting early if it doesn’t find the desired output. If we have to search an item inside an array Las Vegas algorithm will execute until it finds the expected item whereas Monte Carlo will execute for a couple of cycles and stops if it doesn't find the item. Rabin Karp algorithm for string searching uses Las Vegas algorithm to find all matching sub-string inside input string.&lt;/p&gt;

&lt;h3&gt;
  
  
  Applications
&lt;/h3&gt;

&lt;p&gt;Randomized algorithms are useful in applications that require good results consistently irrespective of input to the algorithms. Software in rockets, satellites, airplane, cryptography utilizes randomization to get a high probability of good result on algorithm&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/randomized-algorithms-set-2-classification-and-applications/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/randomized-algorithms-set-2-classification-and-applications/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Images are taken from Google.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;There is so much to learn and write about shuffling algorithms and randomization. In my next post, we'll sort back cards after shuffling them in here using inbuilt sort function in language. &lt;/p&gt;




&lt;p&gt;If you want me to write on a specific topic, please feel free to post them in the comment section below. &lt;/p&gt;

&lt;p&gt;You can support my work by buying me a coffee below. 💚💚💚💚💚💚 !!&lt;br&gt;
&lt;a href="https://ko-fi.com/F1F0J8U1" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcc1nn30p8xi1ub53ae5a.png" alt="Buy me a ko-fi"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>java</category>
    </item>
    <item>
      <title>Dual Pivot Quick Sort: Java’s default sorting algorithm for primitive data types.</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Sun, 29 Jul 2018 07:00:09 +0000</pubDate>
      <link>https://dev.to/s_awdesh/double-pivot-quick-sort--javas-default-sorting-algorithm-1m4</link>
      <guid>https://dev.to/s_awdesh/double-pivot-quick-sort--javas-default-sorting-algorithm-1m4</guid>
      <description>&lt;p&gt;What happens when we do Arrays.sort() in Java? which sorting algorithm does Java use in the background? &lt;/p&gt;

&lt;p&gt;Since Java 7 release back in 2011, default sorting algorithm used is DualPivotQuickSort which is an enhancement over classic quicksort algorithm. &lt;/p&gt;

&lt;p&gt;Dual pivot quicksort is a combination of insertion sort and quick sort. Insertion sort has faster runtime when the number of elements to be sorted is small,  Double pivot quicksort uses this fact thus when the number of elements is &amp;lt;= 47 Java performs insertion sort under the hood. &lt;/p&gt;

&lt;p&gt;When input size array is larger than 47 Java uses Double pivot quicksort. As the name suggests DualPivotQuickSort algorithm picks 2 pivots instead of 1. Unlike quicksort in which we partition the array around 1 pivot, we partition the array in three parts around 2 pivots. &lt;/p&gt;

&lt;p&gt;1st sub array  :  items &amp;lt; LP&lt;br&gt;
2nd sub array  :  LP &amp;lt;= items &amp;lt;= RP&lt;br&gt;
3rd sub array  =:  items &amp;gt;= RP&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithm&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LP: Left Pivot &lt;br&gt;
RP: Right Pivot&lt;/p&gt;

&lt;p&gt;1.) Left most item in an array is taken as the left pivot and Rightmost item as the right pivot. &lt;br&gt;
2.) Swap Left pivot with Right Pivot if LP &amp;gt; RP&lt;br&gt;
3.) Partition array in three sub-arrays around left and right pivot.&lt;/p&gt;

&lt;p&gt;Once a partition is done we perform above 3 steps recursively on three sub-array.&lt;/p&gt;

&lt;p&gt;Let’s walk through an example-:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90uxo1dntf3ceygnbbds.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90uxo1dntf3ceygnbbds.jpg" alt="Alt text of image" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No need to swap pivots in above image since LP &amp;lt; RP. &lt;br&gt;
Now we partition the array following below schemes.&lt;/p&gt;

&lt;p&gt;1st sub array  :  items &amp;lt; LP&lt;br&gt;
2nd sub array  :  LP &amp;lt;= items &amp;lt;= RP&lt;br&gt;
3rd sub array  =:  items &amp;gt;= RP&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3ze1ccpxzqrm9emdpcr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3ze1ccpxzqrm9emdpcr.jpg" alt="Alt text of image" width="800" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have 3 sub-array over which we'll perform the same steps as above. Since the first two arrays have only 2 items, one will become left pivot and other will become right pivot. We'll swap left pivot with right pivot if the left pivot is greater than right pivot which is not the case for first two sub-arrays.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbv1q6ro25qhdukkwibei.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbv1q6ro25qhdukkwibei.jpg" alt="Alt text of image" width="800" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the third sub-array as we can see in below image left pivot is greater than right pivot thus we'll swap them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7n2kif9lp8kuwnnlpt4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7n2kif9lp8kuwnnlpt4.jpg" alt="Alt text of image" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Swapping pivots.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqjmpcqswzjyzum0gq8b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqjmpcqswzjyzum0gq8b.jpg" alt="Alt text of image" width="800" height="599"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We don't have any more elements in the array that we can partition further.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F13zl7hgjyjuz0tkpilhr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F13zl7hgjyjuz0tkpilhr.jpg" alt="Alt text of image" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnwl0r1opeozphmvzzwby.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnwl0r1opeozphmvzzwby.jpg" alt="Alt text of image" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/dual-pivot-quicksort/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/dual-pivot-quicksort/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/20917617/whats-the-difference-of-dual-pivot-quick-sort-and-quick-sort" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/20917617/whats-the-difference-of-dual-pivot-quick-sort-and-quick-sort&lt;/a&gt;&lt;br&gt;
&lt;a href="http://codeblab.com/wp-content/uploads/2009/09/DualPivotQuicksort.pdf" rel="noopener noreferrer"&gt;http://codeblab.com/wp-content/uploads/2009/09/DualPivotQuicksort.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Similarly, Python uses Timsort which is a combination of insertion sort and merge sort. I’d like to read and write about different other variation of quicksort in the next few days. &lt;/p&gt;




&lt;p&gt;If you want me to write on a specific topic, please feel free to post them in the comment section below. &lt;/p&gt;

&lt;p&gt;You can support my work by buying me a coffee below. 💚💚💚💚💚💚 !!&lt;br&gt;
&lt;a href="https://ko-fi.com/F1F0J8U1" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcc1nn30p8xi1ub53ae5a.png" alt="Buy me a ko-fi" width="200" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sorting</category>
      <category>java</category>
      <category>programming</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Reverse a Word.</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Wed, 25 Jul 2018 02:02:03 +0000</pubDate>
      <link>https://dev.to/s_awdesh/reverse-a-word-352m</link>
      <guid>https://dev.to/s_awdesh/reverse-a-word-352m</guid>
      <description>

&lt;p&gt;I wrote couple of posts previously &lt;a href="https://dev.to/s_awdesh/finding-duplicates-in-a-given-range-of-elements-d60"&gt;here&lt;/a&gt; and &lt;a href="https://dev.to/s_awdesh/check-if-duplicate-exists-inside-a-sorted-array-3aa5"&gt;here&lt;/a&gt; on how to find duplicates in an array and we saw different variety of that problem. I want to switch gear now to string related problems. Previous posts on arrays built a good foundation for us to solve string related problem because string is an essentially an array of characters.&lt;/p&gt;

&lt;p&gt;We are given a word which contains only alphabetical characters. Considering string is an array of characters and one of the biggest advantage and vital key to solve certain array problems is to iterate an array from forwards and backwards at the same time. &lt;/p&gt;

&lt;p&gt;We can use two pointers where one pointer start from beginning and other pointer move inwards from end of the array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mIssU1k1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/j5sns0ihrcrrrxwz2lvl.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mIssU1k1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/j5sns0ihrcrrrxwz2lvl.jpeg" alt="palindrome"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This information is vital to solve this problem. Let’s use that algorithm and write down code.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
      &lt;iframe height="550px" src="https://repl.it/@AwdeshSharma1/SickJumpyMinimalsystem?lite=true"&gt;&lt;/iframe&gt;
    &lt;/div&gt;

&lt;p&gt;Could we use the same algorithm to reverse words inside a sentence? e.g. "This is a word" should change into "word a is This" by the algorithm.&lt;br&gt;
If we split the string by a whitespace we'll get an array of strings and then we can use above algorithm to reverse a sentence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Aj5-FM53--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wj3xsxkcvwmlzj9wg9h3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Aj5-FM53--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wj3xsxkcvwmlzj9wg9h3.png" alt="palindrome"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another problem where we could utilize same algorithm is to solve string palindrome problem. A word is a palindrome when it reads same from backwards as forward e.g. kayak, noon etc.&lt;/p&gt;

&lt;p&gt;Now we know that we can traverse a string from forwards and backwards, we can use that knowledge to solve palindrome problem. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GW6OM9DS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rw0jr5odxx6jjx5k2ykr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GW6OM9DS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rw0jr5odxx6jjx5k2ykr.png" alt="palindrome"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is it for this post. I plan to write more on string related problems in my next posts. &lt;/p&gt;

&lt;p&gt;Stay tuned. :)&lt;/p&gt;


</description>
      <category>string</category>
      <category>array</category>
      <category>twopointers</category>
      <category>algorithm</category>
    </item>
    <item>
      <title>Finding duplicates algorithm series-  A given range of elements as an input.</title>
      <dc:creator>Awdesh</dc:creator>
      <pubDate>Sun, 22 Jul 2018 05:09:15 +0000</pubDate>
      <link>https://dev.to/s_awdesh/finding-duplicates-in-a-given-range-of-elements-d60</link>
      <guid>https://dev.to/s_awdesh/finding-duplicates-in-a-given-range-of-elements-d60</guid>
      <description>&lt;p&gt;In my previous posts in &lt;strong&gt;finding duplicates&lt;/strong&gt; series &lt;a href="https://dev.to/s_awdesh/check-if-duplicate-exists-inside-a-sorted-array-3aa5"&gt;here&lt;/a&gt; and &lt;a href="https://dev.to/s_awdesh/finding-duplicates-inside-an-array---easy-version-37la"&gt;here&lt;/a&gt; we have seen different variation of this problem. This is another interesting twist in the problem as now we have given input which falls in a given range.&lt;/p&gt;

&lt;p&gt;Let's walk through an example-:&lt;/p&gt;

&lt;p&gt;Below we are given an example where an array given contains elements that are in range 1-10. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s3Zpv_fT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/sz769vzu3mhnu58q2xqp.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s3Zpv_fT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/sz769vzu3mhnu58q2xqp.jpeg" alt="problem"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1hlGxk63--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ov23mr6kllun9x2dxlzu.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1hlGxk63--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ov23mr6kllun9x2dxlzu.jpeg" alt="hint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we have given input in a range, &lt;strong&gt;counting sort&lt;/strong&gt; like algorithm is the best we can implement. More on counting sort is &lt;a href="https://www.geeksforgeeks.org/counting-sort/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inspired from counting sort algo, to solve this algorithm we’ll create another count array in which we store count of each item at the index i.e. at index 2 we’ll store item 2 in the count array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o-TIf1XE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gpq0js3dt96en4ytqqcx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o-TIf1XE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gpq0js3dt96en4ytqqcx.jpeg" alt="Algo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is repl in Java.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@AwdeshSharma1/OutrageousDirectModem?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;We have learnt another variation of &lt;strong&gt;finding duplicate&lt;/strong&gt; problem plus we also learnt about counting sort. In coming posts I want to work on String related problems.&lt;/p&gt;

&lt;p&gt;Happy coding. Cheers.&lt;/p&gt;

</description>
      <category>array</category>
      <category>algorithms</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
