<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abhishek Kulshrestha on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Kulshrestha on Medium]]></description>
        <link>https://medium.com/@abhikulshrestha22?source=rss-822b126bb776------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Ml5mFS_j1vC2MtUsFjAD_w.jpeg</url>
            <title>Stories by Abhishek Kulshrestha on Medium</title>
            <link>https://medium.com/@abhikulshrestha22?source=rss-822b126bb776------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 20:08:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhikulshrestha22/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kafka producer and consumer using Spring Boot in Kotlin]]></title>
            <link>https://medium.com/@abhikulshrestha22/kafka-producer-and-consumer-using-spring-boot-in-kotlin-100ce2a52fbd?source=rss-822b126bb776------2</link>
            <guid isPermaLink="false">https://medium.com/p/100ce2a52fbd</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kafka-streams]]></category>
            <category><![CDATA[kafka-consumer]]></category>
            <dc:creator><![CDATA[Abhishek Kulshrestha]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 18:41:37 GMT</pubDate>
            <atom:updated>2023-02-01T14:39:55.369Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28tw9_Eaj-UA3AWgOFK54Q.jpeg" /></figure><h3>Introduction</h3><p>Apache Kafka is an open-source distributed event streaming platform used to build real-time data pipelines and streaming applications. It is horizontally scalable, fault-tolerant, and fast, making it a popular choice for building real-time streaming applications.</p><p>In this tutorial, we will show see how to use Spring Boot to create a simple Kafka application.</p><h3>Setting up Spring boot application</h3><p>Use <a href="https://start.spring.io/">https://start.spring.io</a>/ to create the basic spring boot project.</p><p>Make sure to include these two dependencies</p><ul><li>Spring web</li><li>Spring for Apache Kafka</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMRZxmpWw-eUENbYJLK44w.png" /></figure><p>Download and extract the project. Open in your favourite IDE ( I am using IntelliJ IDEA).</p><h3>Setting up Kafka and Zookeeper</h3><p>You need to go to the link <a href="https://kafka.apache.org/downloads">https://kafka.apache.org/downloads</a> to download the latest kafka. I downloaded the latest binary scala 2.13 version here.</p><p>Unzip the package and go the the extracted kafka folder</p><p>If you feel stuck with setting up kafka and zookeeper, you can follow <a href="https://medium.com/@abhikulshrestha22/understanding-kafka-components-using-cli-436f7d494644">https://medium.com/@abhikulshrestha22/understanding-kafka-components-using-cli-436f7d494644</a> for a better understanding.</p><ol><li><strong>Run the following command to start the zookeeper in windows and mac respectively</strong></li></ol><pre>.\\bin\\windows\\zookeeper-server-start.bat .\\config\\zookeeper.properties</pre><pre>bin/zookeeper-server-start config/zookeeper.properties</pre><p>2. <strong>To start kafka broker in windows and mac run these commands respectively</strong></p><pre>.\\bin\\windows\\kafka-server-start.bat .\\config\\server.properties</pre><pre>bin/kafka-server-start config/server.properties</pre><h3>Configuring kafka properties in the application</h3><p>Open <em>application.properties</em> and add the following properties</p><pre>spring.kafka.bootstrap-servers=localhost:9092<br>spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer<br>spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer<br>spring.kafka.consumer.group-id=myGroup<br>spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer<br>spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer</pre><p>The <strong>bootstrap-servers</strong> property specifies the connection details for our Kafka cluster.</p><p>The <strong>key-serializer</strong> and <strong>value-serializer</strong> properties specify the serializers to use when sending messages to Kafka. In this case, we are using the default <strong>StringSerializer</strong> for both the key and value.</p><p>The <strong>group-id</strong> property specifies the consumer group that our application will be a part of, and the <strong>key-deserializer</strong> and <strong>value-deserializer</strong> properties specify the deserializers to use for the key and value of the message.</p><h3>Create Topic</h3><p>To keep using the same topic name everywhere, create a static variable.</p><pre>class AppConstants {<br>    companion object {<br>        const val TOPIC_NAME = &quot;KAFKA-TOPIC&quot;<br>    }<br>}</pre><p>Create KafkaConfig file to create the topic using TopicBuilder</p><pre>@Configuration<br>class KafkaConfig {<br>    @Bean<br>    fun topicCreate(): NewTopic {<br>        return TopicBuilder.name(AppConstants.TOPIC_NAME).build()<br>    }<br>}</pre><h3>Create KafkaProducer</h3><p>Create a service KafkaProducer used to call out kafkaTemplate to send the data.</p><p>The KafkaTemplate wraps a producer and provides convenience methods to send data to Kafka topics.</p><pre>@Service<br>class KafkaProducer(val kafkaTemplate: KafkaTemplate&lt;String, String&gt;) {<br>fun sendEvent(message: String) {<br>        kafkaTemplate.send(AppConstants.TOPIC_NAME,message)<br>    }<br>}</pre><h3>Create Controller to use service KafkaProducer</h3><p>This controller is basically used to trigger the sendEvent function of KafkaProducer. We inject the kafkaProducer form the constructor.</p><pre>@RestController<br>class KafkaController(val kafkaProducer: KafkaProducer){<br>@GetMapping(&quot;/event&quot;)<br>    fun sendKafkaEvent(@RequestParam(&quot;msg&quot;) msg: String): ResponseEntity&lt;String&gt; {<br>        kafkaProducer.sendEvent(msg)<br>        return ResponseEntity(&quot;Message sent by kafka&quot;, HttpStatus.OK)<br>    }<br>}</pre><p>On sending GET request in form of</p><pre>http://localhost:8080/event?msg=abc</pre><p>where “abc” is the desired message. The Producer will send the message to kafka</p><h3>Create KafkaConsumer</h3><p>The @KafkaListenerannotation is used to designate a bean method as a listener for a listener container. We can set different configuration like topics, groupid with this.</p><pre>@Service<br>class KafkaConsumer {<br>@KafkaListener(topics = [AppConstants.TOPIC_NAME])<br>    fun listen(msg:String){<br>        print(&quot;Message Received - $msg&quot;)<br>    }<br>}</pre><p>That’s it. Now when you use GET request http://localhost:8080/event?msg=abc, you can see the log appearing from the KafkaConsumer listen method.</p><p>This was originally posted at <a href="https://www.abhikul.com/blog/kafka-producer-and-consumer-using-spring-boot-in-kotlin/">https://www.abhikul.com/blog/kafka-producer-and-consumer-using-spring-boot-in-kotlin/</a>.</p><p>I hope you find this article helpful. For more such articles please follow, upvote and share this with friends. 😁✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=100ce2a52fbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Will ChatGPT replace software development jobs?]]></title>
            <link>https://medium.com/@abhikulshrestha22/will-chatgpt-replace-software-development-jobs-2e136a18cfa1?source=rss-822b126bb776------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e136a18cfa1</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Abhishek Kulshrestha]]></dc:creator>
            <pubDate>Wed, 28 Dec 2022 09:05:26 GMT</pubDate>
            <atom:updated>2022-12-28T09:36:24.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niOJ2tw5NNHgum9S0CPUbg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@santesson89?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Andrea De Santis</a> on <a href="https://unsplash.com/photos/zwd435-ewb4?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I am sure that most of you have heard about ChatGPT being this cool kid on the internet and doing amazing things. Just ask any question and you have the relevant answer.</p><p>If you are new, here is how ChatGPT describes itself</p><blockquote>GPT (Generative Pre-trained Transformer) is an artificial intelligence model that is trained to generate human-like text. It processes large amounts of text data and uses this information to generate new text that is similar in style and content to the input text. GPT has been used in a variety of applications, including language translation, chatbots, and text generation, and has achieved impressive results in various language tasks. However, it is not a replacement for human intelligence and does not have the ability to understand the meaning or context of the text it generates.</blockquote><p>People are using it to generate articles, software and a lot more. And it gives correct output (most of the times).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*oqGH0jUiD7_B3_6g1Z_R_A.gif" /><figcaption>Maybe, maybe not?</figcaption></figure><h3>Should we be scared?</h3><p>I don’t think that software development is going to fade away or the jobs will be gone coz of ChatGPT.</p><p>ChatGPT is gooood, but still it is not the complete answer. Software development involves a wide range of complex tasks that require a deep understanding of programming concepts and the ability to design and build software systems that meet specific needs. It also requires the ability to troubleshoot and debug code, as well as the ability to work effectively in a team and communicate with clients or stakeholders. These are skills that chatbots and other forms of artificial intelligence do not possess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYIu6PY9b_Kt-rRO_hV9Yg.png" /></figure><p>That being said, chatbots and other forms of artificial intelligence can be useful tools for software developers, as they can assist with tasks such as code completion, bug detection, and error correction. However, they are not a replacement for human software developers and will not be able to fully replace the roles that these professionals play in the software development process.</p><h3>Conclusion</h3><p>ChatGPT won’t finish software development jobs, but it will accelerate the developer productivity.</p><p>Do not be scared about ChatGPT, instead make it a part of your development capabilities. Also think about software development more than just programming. Be aware about how softwares are designed, gain experience about how to handle scale, how software systems interact with each other. These are not replaceable by AI yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*BYTSRgiW_rYdGdUr2jkDvA.gif" /></figure><p>I hope you find this article helpful. For more such articles please follow, upvote and share this with friends. 😁✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e136a18cfa1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run kafka using CLI]]></title>
            <link>https://medium.com/@abhikulshrestha22/understanding-kafka-components-using-cli-436f7d494644?source=rss-822b126bb776------2</link>
            <guid isPermaLink="false">https://medium.com/p/436f7d494644</guid>
            <category><![CDATA[kafka-producer]]></category>
            <category><![CDATA[kafka-streams]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[kafka-consumer]]></category>
            <dc:creator><![CDATA[Abhishek Kulshrestha]]></dc:creator>
            <pubDate>Mon, 26 Dec 2022 18:16:01 GMT</pubDate>
            <atom:updated>2022-12-26T18:17:13.151Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28tw9_Eaj-UA3AWgOFK54Q.jpeg" /></figure><h3>Introduction</h3><p>Kafka is a publish/subscribe messaging system which allows publishing generic types of data which can be consumed by the consumers even after a period of time.</p><p>In this post, we will see how to setup kafka topic, consumer and producer using the kafka cli and pass the message.</p><p>If you are just beginning with the kafka, I would suggest you to go through below link as well.</p><p><a href="https://medium.com/@abhikulshrestha22/introduction-to-kafka-and-its-vocabulary-in-5-minutes-4b48a7800401">Introduction to Kafka and it’s vocabulary in 5 minutes</a></p><h3>Setup</h3><ul><li>You need to go to the link <a href="https://kafka.apache.org/downloads">https://kafka.apache.org/downloads</a> to download the latest kafka. I downloaded the latest binary scala 2.13 version here.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fjbOLbUp_diU7LfOBp-o8Q.png" /><figcaption>Screenshot showing the different available versions of kafka</figcaption></figure><ul><li>Unzip the package and go the the extracted kafka folder</li></ul><h3>Run Zookeeper and kafka broker</h3><p>Apache Zookeeper is a centralized service for maintaining configuration information, naming, and providing distributed synchronization.</p><p>In the context of Kafka, Zookeeper is used to store metadata about the Kafka cluster and its topics, such as the location of the Kafka brokers that make up the cluster, the number of partitions for each topic, and the location of the replicas for each partition. Zookeeper helps to coordinate the Kafka brokers and allows them to come to a consensus on leadership and data distribution.</p><p><strong>If you are using windows,</strong> make sure to edit these two files,</p><ul><li><em>./config/server.properties —</em> change the log.dirs path to something like “<em>C:/kafka/kafka-logs</em>” instead of the temp folder</li><li><em>./config/zookeeper.properties — </em>change the dataDir path to something like “<em>C:/kafka/kafka-data</em>“ instead of the temp folder</li></ul><ol><li><strong>Run the following command to start the zookeeper in windows and mac respectively</strong></li></ol><pre>.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties</pre><pre>bin/zookeeper-server-start config/zookeeper.properties</pre><p>2.<strong> To start kafka broker in windows and mac run these commands respectively</strong></p><pre>.\bin\windows\kafka-server-start.bat .\config\server.properties</pre><pre>bin/kafka-server-start config/server.properties</pre><h3>Create topic</h3><p>Now as the kafka broker and zookeeper have started, let’s create a topic named quickstart on which we will transport the message.</p><pre>.\bin\windows\kafka-topics --create --topic quickstart --bootstrap-server localhost:9092</pre><pre>bin/kafka-topics.sh --create --topic quickstart --bootstrap-server localhost:9092</pre><p>Here localhost:9092 is the address of kafka broker we created.</p><h3>Create Kafka Producer</h3><pre>.\bin\windows\kafka-console-producer.bat --topic quickstart --bootstrap-server localhost:9092</pre><pre> bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092</pre><p>You will see a new line created after you pressed enter. Add the message you want to be sent to kafka</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfHKEXS8f3hc_ZAXFSdpdw.png" /></figure><h3>Create kafka consumer</h3><pre>bin\windows\kafka-console-consumer --topic quickstart --bootstrap-server localhost:9092 --from-beginning</pre><pre>bin/kafka-console-consumer.sh --topic quickstart --from-beginning --bootstrap-server localhost:9092</pre><p>We can see receiving messages here from the beginning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yW4FtUMT_AzS9BI6YqLQPQ.png" /></figure><p>This is a very basic example of how kafka works using Kafka CLI.</p><p>I hope you find this article helpful. For more such articles please follow, upvote and share this with friends.</p><p>Happy Learning … 😁✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=436f7d494644" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Kafka and it’s vocabulary in 5 minutes]]></title>
            <link>https://medium.com/@abhikulshrestha22/introduction-to-kafka-and-its-vocabulary-in-5-minutes-4b48a7800401?source=rss-822b126bb776------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b48a7800401</guid>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Abhishek Kulshrestha]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 16:11:08 GMT</pubDate>
            <atom:updated>2022-12-14T16:11:08.048Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28tw9_Eaj-UA3AWgOFK54Q.jpeg" /></figure><h3>What is publish/subscribe Messaging?</h3><ul><li>Its a pattern where sender (publisher) does not specifically directs the data (message) to receiver. Instead, the publisher classifies the message somehow and receiver (subscriber) subscribe to receive certain kind of message</li><li>Often, there is a common point called as broker where messages are published.</li></ul><h3>Kafka</h3><p>Kafka is a publish/subscribe messaging system which allows publishing generic types of data which can be consumed by the consumers even after a period of time. It is also known as “distributed commit log” so that all logs can be replayed back to build the state of the system. The data stays distributed to provide additional protections against failures, as well as for scaling performance.</p><h4>Message</h4><p>Unit of data within Kafka. Simply an array of bytes.</p><ul><li>Message can have key (also byte array)</li><li>Keys are used when messages are written in partitions in a more controlled manner. like calculating hash and storing the same key messages in a same partition</li><li>Messages are written in kafka in batches.</li><li>Batch is group of messages, which are produced to the same topic and partition</li><li>Batches are typically compressed to be more efficient</li></ul><h4>Schemas</h4><ul><li>Schema is used so that msg can be understood better and messges are just byte array</li><li>Can be json, avro, protobuf</li></ul><h4>Topics</h4><ul><li>Messages in kafka are categorized in topics</li><li>Closest analogy is like table or folder in filesystem</li><li>Topics are broken down in <strong>partition</strong></li><li>Partition is single log</li><li>Messages are written in an append only fashion and read in order from beginning to end</li><li>Topic ordering guarantee is in partition only, not in the topic</li></ul><h4>Partition</h4><ul><li>Kafka provides redundancy and scalability using partitions</li><li>Each partition can be hosted on a different server</li><li>This means that single topic can be scaled horizontally across multiple servers</li><li>Partition can also be replicated such that different servers hold the copy of the same partition in case one server fails</li></ul><h4>Stream</h4><ul><li>Stream is most often considered as single topic of data moving from producer to consumer</li><li>Stream processing frameworks are kafka streams, apache samza , storm</li></ul><h4>Producers</h4><ul><li>Producers creates new messages, in other publish/subscribe systems, these may be called as publishers or writers</li><li>Message is produced to specific topic</li><li>By default, producer will balance messages over all partitions of a topic evenly</li><li>Producer can direct messages to specific paritions based on the hash of the key</li><li>It can also use custom partitioner based on the business requirements to map message to partitions</li></ul><h4>Consumers</h4><ul><li>Consumers read messages, also referred as subscriber or readers</li><li>Subscribes to one or more topics and reads the message in order in which they were produced to each partition</li><li>Keeps track of messages already consumed using Offset of message</li><li>By storing offset for each parotion, a consumer can stop and restart from the same place</li></ul><h4>Offset</h4><ul><li>Integer value which continually increases</li><li>This is metadata that kafka adds whenever message is produced</li><li>Each message in a given partition has a unique offset</li></ul><h4>Consumer Group</h4><ul><li>Group or one or more consumer that work together to consume a topic</li><li>Group ensures that one partition is consumed by one member</li><li>One consumer can consume from multiple partitions</li><li>Helps to scale horizontally to consume topics of large messages</li><li>If single consume fails, remaining members of the group will reassign the partitions being consumed to take over for the missing member</li></ul><h4>Brokers</h4><ul><li>Single kafka server is called broker</li><li>Receives message from producer and assigns offset and write the message to storage on disk</li><li>Services to consumers by responding to fetch requests for partitions and responding with the messages that have been published.</li><li>Depending on hardware and its performance characteristics , single broker can handler thousands of partitions and millions of messages per second</li></ul><h4>Clusters</h4><ul><li>Kafka brokers operate as part of cluster</li><li>Within a cluster of broker, one broker will function as cluster <strong>controller</strong> (elected automatically from live members of the cluster)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORQM3a7GC3LLb115zxZExQ.png" /></figure><h4>Controller</h4><ul><li>Responsible for admin operations like assigning partitions to brokers, monitoring broker failures</li></ul><h4>Leader</h4><ul><li>A partition is owned by a single broker in the cluster, and that broker is called the leader of that partition</li><li>All producers must connect to the leader in order to publish message</li></ul><h4>Follower</h4><ul><li>If Broker A is the leader of partition p1, broker will B can be the <strong>follower</strong> for partition p1.</li><li>Follower basically means here a replicated parition</li><li>Replication helps in case of leader broker failure so that follower can take the leadership</li><li>Consumers may fetch from leader or the followers</li></ul><h3>Good to know</h3><ul><li>Brokers are configured with default retention setting for topics, either retaining messages for some period of time (e.g., 7 days) or untill partition reaches a certain size in bytes (e.g 1 GB). Once these limit is reached messages are expired and deleted</li><li>Individual topics can also be configured with their own retention settings</li></ul><h3>References</h3><p><a href="https://www.amazon.in/Kafka-Definitive-Real-Time-Processing-Grayscale/dp/9355420587/ref=sr_1_1?keywords=kafka+definitive+guide&amp;qid=1671033112&amp;sprefix=kafka+defini%2Caps%2C270&amp;sr=8-1">Kafka, The Definitive Guide</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b48a7800401" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference between bind, call and apply]]></title>
            <link>https://medium.com/@abhikulshrestha22/difference-between-bind-call-and-apply-ffe768bbc307?source=rss-822b126bb776------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffe768bbc307</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Abhishek Kulshrestha]]></dc:creator>
            <pubDate>Thu, 25 Jul 2019 18:01:58 GMT</pubDate>
            <atom:updated>2019-07-25T18:01:58.956Z</atom:updated>
            <content:encoded><![CDATA[<p>You must have heard about these functions in javascript, but may not know much . Or dont know the difference between these. So let’s dive into knowing them a little more…</p><p>All these functions are related to <strong><em>this </em></strong>keyword.</p><blockquote><strong><em>this </em></strong>is used inside function and it refers to the object which calls that function.</blockquote><p>For example,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd280e743dd60554af06fa1a8ab51840/href">https://medium.com/media/dd280e743dd60554af06fa1a8ab51840/href</a></iframe><p>In the above example, <strong><em>this </em></strong>is used to refer to the object fruit1. And so, this.quantity is 2 and this.name is ‘Apple’.</p><p>What if we have another similiar function, and we need to have the same function <strong><em>getString()</em> </strong>for it? Something like the example below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/556e1764712bb910923c2e536c6e3a8f/href">https://medium.com/media/556e1764712bb910923c2e536c6e3a8f/href</a></iframe><p>Should we write <strong><em>getString()</em> </strong>function inside every objects? Thats a lot of work, right?</p><p>Instead, we can write <strong><em>getString() </em></strong>function once and use it with different objects.</p><p>Let’s see how to do this.</p><h3>Call( )</h3><p>According to mozilla ,</p><blockquote><strong>call()</strong> method calls a function with a given <strong>this</strong> value and arguments provided individually.</blockquote><p>So what call() method does is,<strong> it helps us to invoke a function where we can specify the context in which it is invoked.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c0943b865d636925fc51fb08a53dd30/href">https://medium.com/media/7c0943b865d636925fc51fb08a53dd30/href</a></iframe><p>Here the context of <strong><em>getString()</em></strong> function is set to fruit1 first, and this points to the fruit1. Hence the output is ‘2 Apple remaining’.</p><p>Second time, the <strong><em>getString() </em></strong>function is set to fruit2 and the output is “4 Mango remaining”.</p><p>There is more to the <strong><em>call()</em> </strong>function, after the first parameter as context, we can <strong>also pass other parameters</strong> to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40d1ba836e9e75f70c81d53b6b878a05/href">https://medium.com/media/40d1ba836e9e75f70c81d53b6b878a05/href</a></iframe><p>So , we can pass the parameters one by one to the call function and it would work. But what if we have many parameters to pass. Wouldn’t it be better if we would pass the parameters at once. So to handle such case, we have <strong><em>apply() </em></strong>function</p><h3>Apply( )</h3><p>To avoid having too many parameters inside call function. We have another approach i.e using <strong>apply( )</strong> function.</p><blockquote>Here we can pass all the parameters as an array.</blockquote><p>And it would work. That’s the only difference between <strong>call( )</strong> &amp; <strong>apply( )</strong></p><p>Let’s see an example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6154024c92ddd8046ec5d60b6630e1ea/href">https://medium.com/media/6154024c92ddd8046ec5d60b6630e1ea/href</a></iframe><h3>Bind( )</h3><p>As we have seen , call( ) and apply( ) are used to invoke the function while providing the context to the function.</p><blockquote>Bind( ) is same as call( ) except that instead of invoking the function , bind( ) is used to return a function while providing the context to that function.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61f3c68b500dbebedd3131bb32199e1a/href">https://medium.com/media/61f3c68b500dbebedd3131bb32199e1a/href</a></iframe><p>This can be very useful where we want to create a new function and use it later. Its good to know about these functions, as these can be used to write better code.</p><p>Hope this helps you clear your concepts about these functions. Please <strong><em>share </em></strong>if you like the blog post.</p><p>Have any thoughts about this post or this topic? Please reach out in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffe768bbc307" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bootbox- Confirmation Modal in react]]></title>
            <link>https://medium.com/@abhikulshrestha22/bootbox-confirmation-modal-in-react-6310f1958f75?source=rss-822b126bb776------2</link>
            <guid isPermaLink="false">https://medium.com/p/6310f1958f75</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Abhishek Kulshrestha]]></dc:creator>
            <pubDate>Sun, 05 May 2019 04:21:31 GMT</pubDate>
            <atom:updated>2019-05-05T04:21:31.549Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DoRiMdg1PE4hlgQfvtqHBw.jpeg" /><figcaption>Source — <a href="https://unsplash.com/photos/FGXqbqbGt5o">https://unsplash.com/photos/FGXqbqbGt5o</a></figcaption></figure><p>Many times while designing the web app, we come across a point where we need to ask the user whether he wants to proceed or not.</p><p>For example, while submitting a form, we can ask the user to confirm submitting it. In such situations , we need a confirmation modal.</p><p>For this example, let’s simply install a new react project, using create-react-app.</p><p>If you have not installed create-react-app globally, install it using the following command below.</p><pre>npm i create-react-app -g </pre><p>Now create the project repo, go inside the folder.</p><pre>create-react-app testProject<br>cd testProject</pre><p>Install the following packages (bootstrap and react-bootbox) to use react-bootbox to implement confirmation modal.</p><pre>npm i bootstrap react-bootbox --save</pre><p>In the index.js file, import the bootstrap css</p><pre>import ‘bootstrap/dist/css/bootstrap.css’;</pre><p>Replace the code in App.js with the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9663a08005349f2853dc8fdb4682921/href">https://medium.com/media/d9663a08005349f2853dc8fdb4682921/href</a></iframe><p>Here we imported the Bootbox , which is shown on the screen on the basis on props <strong>show. </strong>The message as well as the action on the buttons can be changed from the props.</p><p>Lets run the app and see it its working fine.</p><pre>npm start</pre><p>We get the bootbox like below with the above code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*1d3LTqw4EgmRCoGDT9eGKg.png" /></figure><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6310f1958f75" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>