<?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 Tarun Khare on Medium]]></title>
        <description><![CDATA[Stories by Tarun Khare on Medium]]></description>
        <link>https://medium.com/@tarunkhare54321?source=rss-2a0aeef49414------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Ws1FWuFkr2EGPTCFGFuQNQ.jpeg</url>
            <title>Stories by Tarun Khare on Medium</title>
            <link>https://medium.com/@tarunkhare54321?source=rss-2a0aeef49414------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 00:51:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tarunkhare54321/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[The most perfect setup you could have for React and Node in VS Code. -]]></title>
            <link>https://medium.com/@tarunkhare54321/the-most-perfect-setup-you-could-have-for-react-and-node-in-vs-code-c82478f34bd6?source=rss-2a0aeef49414------2</link>
            <guid isPermaLink="false">https://medium.com/p/c82478f34bd6</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tarun Khare]]></dc:creator>
            <pubDate>Tue, 24 Sep 2019 06:27:50 GMT</pubDate>
            <atom:updated>2019-10-06T10:54:19.930Z</atom:updated>
            <content:encoded><![CDATA[<h3>The most perfect setup you could have for React and Node in VS Code.</h3><p>As web developers working with multiple technologies and frameworks like React, Node, Express, Redux, we all have to deal with multiple files, directories, libraries, packages etc. It becomes overwhelming when the code bases are very large and it is difficult to keep track of things. So to make your lives easier, I will help you setup Visual Studio Code in such a way that will help you save a lot of time and effort.</p><h4>Must have VS Code extensions.</h4><p>There are a few extensions available in Visual Studio Code which will greatly enhance your experience and productivity while developing web apps. I will list some of them.</p><p>1) <strong>Auto Rename Tag</strong>: This extension automatically renames paired HTML/XML tags, For example, you have an HTML document which looks like: &lt;div&gt; ... &lt;/div&gt; and we want to change this tag to &lt;body&gt;....&lt;/body&gt;. For this, we have to edit both the opening and closing tag. But with this extension, the closing tag gets automatically renamed whenever you edit any opening tag. This will save your time specially when you have to edit huge html documents.</p><p>2) <strong>Prettier — Code formatter</strong>: This extension will help you format your code files with all the proper spacing, newlines etc. to make it more readable and easier to debug. Once you install this extension, go to settings, in the search box, type <strong>format on save</strong> and set it to true. This will automatically format your code whenever you will save your files (Ctrl + S).</p><p>3) <strong>Bracket pair colorizer</strong>: This extension colors the opening and closing pairs of brackets used in the code (curly, square and normal) using multiple colors. This improves the aesthetics of your code and helps you identify opening and closing bracket pairs with a glance of eye.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/0*NAoKjTFm9kSsMAyu" /><figcaption>Notice that the opening and closing pairs of brackets have been colored appropriately.</figcaption></figure><p>4) <strong>ES7 React/Redux/GraphQL/React-Native snippets</strong>: Many times you have to write repetitive code for boilerplate which consumes a lot of time. This extension gives multiple shortcut codes to write such repetitive code. For example, if you have created a file called <strong>Login.js</strong> and you want to write the following code in it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/075bb890634daefad9b349c101827f01/href">https://medium.com/media/075bb890634daefad9b349c101827f01/href</a></iframe><p>Instead of typing it, all you have to do is type rafc and press Enter. This extension will already write the above code with const name according to your file name.</p><h4>Chrome extensions for React/ Redux.</h4><p>1) <strong>React Develper Tools</strong>: For React developers, Facebook offers a cool extension called React Developer Tools on Chrome webstore. This extension can show you the root React components that were rendered on the page, as well as the subcomponents that they ended up rendering. By selecting one of the components in the tree, you can inspect and edit its current props and state as well. This tool comes in handy to keep track of state, props and loaded components in your application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/0*w9jV1PJxVzSpAizc" /><figcaption>Using React Developer Tools to view components and their props.</figcaption></figure><p>2) <strong>Redux DevTools</strong>: This chrome extension is made for developers who are using Redux for state management. To use it, download it from webstore, and in the <strong>store.js</strong> file of your application (where you define your createStore() method), you have to make few changes as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a142f0b619275fcaf0f545b6110ffb4/href">https://medium.com/media/7a142f0b619275fcaf0f545b6110ffb4/href</a></iframe><p>Also in your <strong>package.json</strong> file, under the “dependencies” tree, add the following line:</p><pre>&quot;redux-devtools-extension&quot;: &quot;^2.13.8&quot;,</pre><p>This will allow the Redux DevTools extension to access your app state. Now open your chrome developer tools (Ctrl + Shift + J) and select Redux to access it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/0*dPfAh-eY45g-fmCS" /><figcaption>Using Redux DevTools to check action types and states.</figcaption></figure><h4>Server management tools.</h4><p>1) <strong>Nodemon</strong>: Are you tired of restarting your server every time you make changes in your code in order to test it live? With nodemon, you can auto restart your server without typing any command on your terminal whenever you make file changes. Here is a post I found which explains how to setup and use nodemon: <a href="https://alligator.io/workflow/nodemon/">Restart Your Node.js Apps Automatically Using nodemon </a>. Now whenever you will save your files after making changes, server will restart automatically and quickly as well, thus saving your time.</p><p>2) <strong>Concurrently</strong>: Concurrently is a tool to run multiple servers using a single command. Suppose you are building a fullstack web app using Node, Express as backend and React as frontend. So, to run your application, you have to open two terminals, run backend in one and frontend in other one. But with concurrently, you can use a single command to run both servers at the same time. This single command will trigger both servers in the background, thus saving you from the pain of doing so. Here is the <a href="https://www.npmjs.com/package/concurrently">official npm page</a> of concurrently which tells you how to install and use it.</p><p>That’s it folks! With this setup, you will be coding your web apps more efficiently like a pro! Hope you liked the article. Comment in case of any doubts. Also check out my articles on <a href="https://medium.com/@tarunkhare54321">medium</a> and follow me on <a href="https://twitter.com/codeharvestio">twitter</a>. Also check out my other articles on this <a href="http://www.codeharvest.io/">blog</a> as well!</p><p><em>Originally published at </em><a href="http://www.codeharvest.io/web-dev/the-most-perfect-setup-you-could-have-for-react-and-node-in-vs-code/"><em>http://www.codeharvest.io</em></a><em> on September 24, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c82478f34bd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Track website browsing time using python.]]></title>
            <link>https://medium.com/@tarunkhare54321/track-website-browsing-time-using-python-838552fc0ede?source=rss-2a0aeef49414------2</link>
            <guid isPermaLink="false">https://medium.com/p/838552fc0ede</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Tarun Khare]]></dc:creator>
            <pubDate>Thu, 11 Jul 2019 11:07:31 GMT</pubDate>
            <atom:updated>2019-08-08T14:04:55.002Z</atom:updated>
            <content:encoded><![CDATA[<p>We, as programmers, have to constantly be in front of our computers. A big part of our work life is spent online. Whether it be searching for solutions on stackoverflow, or keeping up with coworkers through slack, reading documentation etc. But internet comes with a lot of distractions. At the same time, we may end up with multiple tabs of Stackoverflow, Instagram, gmail, python docs, YouTube etc. We might not feel it, but this indeed wastes a lot of time. Thus it becomes necessary to track your website browsing time so that you have an idea of how productive your day is going.</p><p>I will teach you how to build a <strong>python script which can track what websites you are browsing, and how much time you spend on them</strong>.</p><h4>How will we do this?</h4><p>This project will have two components,</p><ol><li>A chrome extension which will monitor the current website you are viewing.</li><li>A flask server which will use this data to calculate time spent on a particular website.</li></ol><p>The chrome extension will have a background script which will monitor any change in the current active tab or URL. Whenever any change occurs, it will send the new current active URL to the flask server using an HTTP request. Meanwhile, the flask server will calculate the time passed since the previous request and the new request. This will be the time spent on previous URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*6IRgzvBmfhBgJSuRj0KsmQ.png" /><figcaption>Store the timestamps of each new URL whenever it is opened, Also update the timestamp when a URL is re-opened.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*WzEPKFABfMmlGti-GouoQw.png" /><figcaption>subtract the timestamps of current URL and previous URL to get the time spent on previous URL.</figcaption></figure><p>First we will make a chrome extension which will send an HTTP request to flask server as soon as the active URL changes.</p><p>Don’t worry, making such chrome extension is not hard. You just need basic JavaScript knowledge to do so. I will guide you through the steps:</p><h4>Making the chrome extension.</h4><p>Note that we do not need to make a front end for our extension as our extension serves only a simple purpose. We will just write a background script which will run in the background of the browser while the extension is active. Here is the file structure of our extension:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/142/1*YQP99yA5hVkeB-sFxaM42A.png" /></figure><p>As shown, our extension has 3 files:</p><ul><li>background.js: This file will contain the code which will run in the background of browser.</li><li>icon.png: our extension icon file. You can download any icon file in PNG format from the internet and use it.</li><li>manifest.json: This file contains basic configurations related to our extension.</li></ul><p>First of all, let us start coding our background.js file.</p><p>The work of this file is simple. Just watch whenever a person switches between tabs or opens a new tab. As soon as this happens, send a HTTP request to server with the new current URL as the data. In order to detect when a new tab is opened, chrome API has an inbuilt listener which is invoked every time</p><pre>chrome.tabs.onActivated.addListener(function (activeInfo) {<br>    chrome.tabs.get(activeInfo.tabId, function (tab) {<br>        y = tab.url;<br>        var xhttp = new XMLHttpRequest();<br>        xhttp.onreadystatechange = function () {<br>            if (this.readyState == 4 &amp;&amp; this.status == 200) {<br>                console.log(this.responseText);<br>            }<br>        };<br>        xhttp.open(&quot;POST&quot;, &quot;http://127.0.0.1:5000/send_url&quot;);<br>        xhttp.send(&quot;url=&quot; + y);<br><br>    });<br>});</pre><p>In above code, onActivated.addListener() is invoked whenever a new tab is activated in the browser window. Inside this function, we can access the Id of this tab using tabId and URL using tab.url. Then we send an HTTP request using XMLHttpRequest() to /send_url endpoint with URL as the data.</p><p>Now we have to create a listener whenever the user switches between tabs. We use onUpdated.addListener() for this. This function invokes whenever tabs are updated.</p><pre>chrome.tabs.onUpdated.addListener((tabId, change, tab) =&gt; {<br>    if (tab.active &amp;&amp; change.url) {<br><br>        var xhttp = new XMLHttpRequest();<br>        xhttp.onreadystatechange = function () {<br>            if (this.readyState == 4 &amp;&amp; this.status == 200) {<br>                console.log(this.responseText);<br>            }<br>        };<br>        xhttp.open(&quot;POST&quot;, &quot;http://127.0.0.1:5000/send_url&quot;);<br>        xhttp.send(&quot;url=&quot; + change.url);<br><br>    }<br>});</pre><p>In onUpdated.addListener() , change object can be used to access the new URL. We again send this changed URL to server using XMLHttpRequest() .</p><p>Now we have to also detect whenever a tab is closed, so that we can update its timestamp and viewtime in the server code. For this, we use a combination of onUpdated() and onRemoved() listeners. This is done because whenever a tab is removed, it is also considered as an update in chrome. Also we cannot access the removed tab URL from onRemoved() function, so we have to use it in combination with onUpdated().</p><pre>// define a mapping between tabId and url:<br>var tabToUrl = {};<br><br>chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {<br>    //store tabId and tab url as key value pair:<br>    tabToUrl[tabId] = tab.url;<br>});<br><br>chrome.tabs.onRemoved.addListener(function (tabId, removeInfo) {<br>    //since tab is not available inside onRemoved,<br>    //we have to use the mapping we created above to get the removed tab url:<br>    console.log(tabToUrl[tabId]);<br><br>    var xhttp2 = new XMLHttpRequest();<br>    xhttp2.onreadystatechange = function () {<br>        if (this.readyState == 4 &amp;&amp; this.status == 200) {<br>            console.log(this.responseText);<br>        }<br>    };<br>    xhttp2.open(&quot;POST&quot;, &quot;http://127.0.0.1:5000/quit_url&quot;);<br>    xhttp2.send(&quot;url=&quot; + tabToUrl[tabId]);<br><br>    // Remove information for non-existent tab<br>    delete tabToUrl[tabId];<br><br>});</pre><p>With this, we have completed background.js code. Now lets create manifest.json and add the following code to it:</p><pre>{<br>	&quot;manifest_version&quot;: 2,<br>	&quot;name&quot;: &quot;Currenturl&quot;,<br>	&quot;description&quot;: &quot;Fetches current tab url.&quot;,<br>	&quot;version&quot;: &quot;0.1&quot;,<br>	&quot;author&quot;: &quot;Tarun Khare&quot;,<br>	&quot;browser_action&quot;: {<br>		&quot;default_icon&quot;: &quot;icon.png&quot;,<br>		&quot;default_title&quot;: &quot;Just observing your current url.&quot;<br>	},<br>	&quot;permissions&quot;: [&quot;tabs&quot;, &quot;activeTab&quot;, &quot;http://127.0.0.1:5000/*&quot;, &quot;storage&quot;],<br>	&quot;background&quot;: {<br>		&quot;scripts&quot;: [&quot;background.js&quot;],<br>		&quot;persistent&quot;: false<br>	}<br>}</pre><p>In this file, we define things like extension name, version, icon file etc. We have to allow some permissions to our extension. So in “permissions” we define “tabs”, “activeTab”, storage and the server URL, which is 127.0.0.1:5000 in my case. In “background”, we define our background script name i.e “background.js”.</p><p>Now our chrome extension is complete. We can start writing our python script. In our python code, first we will import the required flask modules and define some global variables.</p><pre>from flask import Flask, jsonify, request<br>import time<br><br>app = Flask(__name__)<br>url_timestamp = {}<br>url_viewtime = {}<br>prev_url = &quot;&quot;</pre><p>In the above code, we will use url_timestamp to store the latest unix timestamp when a URL became active. For example, if &quot;google.com&quot; becomes active, then our extension will send a request to our server with &quot;google.com&quot; as data. As soon as this request reaches the server, we will find the unix time at that particular moment, and store this timestamp as a value to url_timestamp[&quot;google.com&quot;].</p><p>Similarly, url_viewtime will store the total time a URL has been viewed in seconds.</p><p>Since URLs are often long, So let us create a function which will strip URLs to their parent only. For example, “<a href="https://twitter.com/codeharvestio">https:twitter.com/codeharvestio</a>”should be shortened to “www.twitter.com&quot;.</p><pre>def url_strip(url):<br>    if &quot;http://&quot; in url or &quot;https://&quot; in url:<br>        url = url.replace(&quot;https://&quot;, &#39;&#39;).replace(&quot;http://&quot;, &#39;&#39;) <br>            .replace(&#39;\&quot;&#39;, &#39;&#39;)<br>    if &quot;/&quot; in url:<br>        url = url.split(&#39;/&#39;, 1)[0]<br>    return url</pre><p>Now we will write the function for ‘send_url/’ endpoint. In this function, whenever we will recieve a new URL from our extension, we will find the current unix timestamp using time.time() function. Them we will find the timestamp of the previous URL from the url_timestamp dictionary. On subtracting these two timestamps, we will get the time spent on the previous url. We will then add on this time to the total viewtime of previous URL. Here is the code for &#39;send_url/&#39; endpoint.</p><pre>@app.route(&#39;/send_url&#39;, methods=[&#39;POST&#39;])<br>def send_url():<br>    resp_json = request.get_data()<br>    params = resp_json.decode()<br>    url = params.replace(&quot;url=&quot;, &quot;&quot;)<br>    print(&quot;currently viewing: &quot; + url_strip(url))<br>    parent_url = url_strip(url)<br><br>    global url_timestamp<br>    global url_viewtime<br>    global prev_url<br><br>    print(&quot;initial db prev tab: &quot;, prev_url)<br>    print(&quot;initial db timestamp: &quot;, url_timestamp)<br>    print(&quot;initial db viewtime: &quot;, url_viewtime)<br><br>    if parent_url not in url_timestamp.keys():<br>        url_viewtime[parent_url] = 0<br><br>    if prev_url != &#39;&#39;:<br>        time_spent = int(time.time() - url_timestamp[prev_url])<br>        url_viewtime[prev_url] = url_viewtime[prev_url] + time_spent<br><br>    x = int(time.time())<br>    url_timestamp[parent_url] = x<br>    prev_url = parent_url<br>    print(&quot;final timestamps: &quot;, url_timestamp)<br>    print(&quot;final viewtimes: &quot;, url_viewtime)<br><br>    return jsonify({&#39;message&#39;: &#39;success!&#39;}), 200</pre><p>For ‘quit_url/’ endpoint, we don’t have to write much code. The reason is that, as soon as a tab is closed in chrome, it is also considered as an update, so onUpdated.addListener() function in the second code snippet automatically runs. Thus running the send_url() function in our python script. This takes care of everything. But we will create this function just for printing purposes.</p><pre>@app.route(&#39;/quit_url&#39;, methods=[&#39;POST&#39;])<br>def quit_url():<br>    resp_json = request.get_data()<br>    print(&quot;Url closed: &quot; + resp_json.decode())<br>    return jsonify({&#39;message&#39;: &#39;quit success!&#39;}), 200</pre><p>Finally, add the following line to complete the server code:</p><p>app.run(host=&#39;0.0.0.0&#39;, port=5000)</p><p><strong>Run your python code</strong>. Then open chrome. Click on three dot symbol at top right corner, then ‘more tools’, then ‘extensions’. Turn on the developer mode from top right corner of this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*05IzJwU1lk7id_Hg2mqdFQ.png" /></figure><p>Now click on ‘Load unpacked’ to load your extension. Select the folder where your three extension files are present. (Please don’t keep your python file in this folder to avoid problems).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*N0ocuFRZXo-0slQ5AqYUTA.png" /></figure><p>Now as soon as your extension starts running, you can open new tabs, or switch between open tabs. Spend some time on them. Now Open your running python server. You will see the URL time being printed in python console as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*CnTJ2JBCx5rHRSC4" /></figure><p>As you will switch between tabs or open new tab or URL, the updated outputs will re-printed on console.</p><p>That’s It. Hope you liked the article. Comment in case of any doubts. Also check out my articles on <a href="https://medium.com/@tarunkhare54321">medium</a> and follow me on <a href="https://twitter.com/codeharvestio">twitter</a>. Also check out my other articles on this <a href="http://www.codeharvest.io/">blog</a> as well!</p><p><em>Originally published at </em><a href="http://www.codeharvest.io/python/track-website-browsing-time-using-python/"><em>http://www.codeharvest.io</em></a><em> on July 11, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=838552fc0ede" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to break out of tutorial loop and finally start real coding? — The Code Harvest]]></title>
            <link>https://medium.com/@tarunkhare54321/how-to-break-out-of-tutorial-loop-and-finally-start-real-coding-the-code-harvest-80b353e14a8f?source=rss-2a0aeef49414------2</link>
            <guid isPermaLink="false">https://medium.com/p/80b353e14a8f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[motivation]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Tarun Khare]]></dc:creator>
            <pubDate>Wed, 26 Jun 2019 17:02:16 GMT</pubDate>
            <atom:updated>2019-06-27T08:15:44.624Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to break out of tutorial loop and finally start real coding?</h3><p>Many people keep on learning new programming languages, frameworks etc whenever they get time. They refer to online tutorials, udemy courses and what not. While doing this, they feel good about how finally they have managed to create a website or a program after watching hours of videos. But in reality, all they did was, copy each and every piece of code exactly as the instructor told them. They are basically stuck in what we call tutorial loop.</p><p>By doing this, though you may be able to create a decent portfolio of projects which are basically copies of the instructor’s code, but in reality, you didn’t learn much.</p><p>Now some people might argue that they didn’t exactly ‘copy’ the code, but they slogged through the videos and listened carefully what each piece of code does. And then they hand-typed the code themselves on their editors.</p><p>But try asking yourselves, after doing the course, are you now able to create something similar of your own, from scratch? This new project might be similar to the one you made during your course. Your answer, most probably would be a ‘no’.</p><p>Even I did this mistake of falling into the tutorial loop for a large period of time. If I wanted to learn some new language or framework, I would browse youtube videos, purchase udemy courses, and religiously follow them. But as the course ended, I had this same feeling everytime of not knowing enough. All I did was, create a clone of what instructor made during the course.</p><p>I tried to learn various skills this way, like Ethereum, Django, React etc. But I didn’t feel like actually knowing any of them.</p><h4>So, what is the correct way to learn programming?</h4><p>The answer is simple. Don’t trap yourself too much in the tutorial loop. If something is completely new to you, then search some basic tutorials and follow them. This will teach you basic syntax and other necessary stuff.</p><p>After that, think of a project idea related to what you have just learnt. It doesn’t need to be fancy, just anything with some decent complexity. For example, if you just completed some basic tutorial on web scraping using python, then you could make a python script which can fetch imdb ratings of all the movies released in 2019, and sort them in decreasing order.</p><p>Then open a blank editor page, and start typing. Initially you will not be able to think how to start. At this stage, the tutorial you completed just some time ago will help you. It will help you remember what libraries to import, and what basic functions would be used to create your project.</p><p>But after that, it will be you, who decides the inner intricacies of the project, how it would open, what it would look like etc. So if you want to scrape imdb website, then open it, inspect the page source and start drawing parallels between what you just learnt in the tutorial and what would you like to do now.</p><h4>What to do if you get stuck?</h4><p>If you feel that you have to use something other than what was taught in the tutorial, then just google how to do it. In this way you will keep on learning new things. For example if your tutorial didn’t teach you how to open Chrome browser using python code, and you need to use it in your project, then just google it. There will be hundreds of <a href="http://www.stackoverflow.com/">stackoverflow</a> answers, blogposts and docs to help you out.</p><p>This method will help you learn programming in a better way. You will remember what you learnt, and be able to further use it in other projects as well.</p><p>After You complete your project, you will be more proud of yourself. And moreover, you will be able to use this learning while further creating new, and more complex projects.</p><p>Hope you liked the article, please leave comments if you have any doubts, I would be glad to help you out! Please do check out my other articles on <a href="https://medium.com/@tarunkhare54321">medium</a> and my blog <a href="http://www.codeharvest.io/">codeharvest</a>.</p><p><em>Originally published at </em><a href="http://www.codeharvest.io/productivity/how-to-break-out-of-tutorial-loop-and-finally-start-real-coding/"><em>http://www.codeharvest.io</em></a><em> on June 26, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80b353e14a8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[But how does blockchain actually work?]]></title>
            <link>https://medium.com/@tarunkhare54321/but-how-does-blockchain-actually-work-2a5186bb1d1d?source=rss-2a0aeef49414------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a5186bb1d1d</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bitcoin-mining]]></category>
            <dc:creator><![CDATA[Tarun Khare]]></dc:creator>
            <pubDate>Thu, 20 Jun 2019 17:07:21 GMT</pubDate>
            <atom:updated>2019-06-28T11:22:41.067Z</atom:updated>
            <content:encoded><![CDATA[<p>There is a lot of information available online on blockchains, crytocurrencies, etc. But only a few manage to explain what is happening behind the scenes of these technologies on a basic level. This article attempts to answer such queries and explain what actually is blockchain, how it works and what is its use. So lets dive in!</p><p>Suppose there are few friends who go out a lot and thus many times they pay for each other. After some time, they settle up the amounts they owe to each other and this goes on. But they can’t solely depend on their memories as it might deceive them. So how do they approach this problem? Simple. They will make a common ledger on a paper where everyone can add the amount others owe them. This ledger might look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/0*5SM39icmK8bFFwZr" /></figure><p>Now how will you ensure that no one adds any fake line in the legder, or changes the amount in order to cheat?</p><p>We can simply add signature of person who owes the amount at the end of each line. This will ensure no one else can add a fake entry on behalf of the person who owes money.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/0*ZybdQIG4-l6M6Buk" /></figure><p>But people can copy each other’s signatures, right? To prevent that, we can use digital signatures. In this system, everyone will have their public key and private key. The public key of people are known to everyone while private keys of a person are secret, like a password. The digital signature is usually a very long binary number which is generated using a combination of the input statement, and the private key. These two parameters, when passed on to a hash function give us the digital signature.</p><p>To understand this we need to know what are hash functions. Hash functions are special functions, which always produce a unique output for a given input.</p><p>Hash_function (inputs) = 010010010… (unique binary number)</p><p>The property of hash functions is that it will never produce the same output, unless the input is same. The length and type of the number generated (binary, decimal, hexadecimal) depends on the type of hash function used. There are multiple types of hash function like MD5, SHA256 etc. Bitcoin, in particular uses SHA256 hash. Also, just a small change in hash input completely changes the output of the hash function. For example:</p><p><strong><em>Hash_function(“hello world”) = 010010011101001…</em></strong> <strong><em>Hash_function(“helo world”) = 1011010110010011..</em></strong></p><p>Note that for a given combination of inputs, the hash function will always generate a unique signature. This ensures that signature of a person is unique as the secret key is known to that person only.</p><p>For example, in the first line of ledger, Suppose <strong>Alice has a private key: 1423 </strong>(which only she knows), Alice can add her signatures in the following way:</p><p><strong><em>Hash_function (“Alice owes Bob $10”, 1423) = 011000100111</em></strong>.</p><p>Thus <strong><em>011000100111 </em></strong>is the digital signature of Alice. This signature can be generated by Alice only as she only knows her private key.</p><p>To verify if the signature is correct, the hash function has a corresponding verification function as well. The verification function returns True or False if the signature is correct or not. It works as follows:</p><p><strong><em>Verification_function (message, signature, public key) = True/ False</em></strong></p><p>So anyone can check if a particular signature is real or fraudulent by simply putting the message, the signature which has to be checked, and public key of person who signed (which is known to everyone). If the function returns True, then the signature is authentic, else fraudulent.</p><p>So currently our ledger looks like this after implementation of digital signatures:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/0*xnXHjUYo8_pTfhML" /></figure><p>Though now it can be checked if an entry in ledger is legit or not by simply checking its signature, but one thing can still be done to add fake entries in the ledger. What if someone copies one of the previous entry multiple times in the ledger, thus forcing the borrower to pay multiple times. The entry and signature combination would still hold true, thus the borrower would have no way to claim that it is a fake entry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/0*fE-Jbj4iEkJI1tPx" /></figure><p>To solve this problem, we can simply add a unique ID (eg. serial no.) before each line. Now if someone will try to copy same entry multiple times, the ID will be same in both, thus they will become invalid. Now with this implementation, our ledger looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/0*iYf041jt7cOfZgrp" /></figure><p>Also instead of writing “owes” or “pays” every time in ledger, we can standardize our entries. For example if Alice has to give Bob $10, we can simply write:</p><p>Now we have solved few problems in our ledger and made it more secure. With this ledger, we can do one more thing, i.e stop relying on actual currency to perform transactions. What everyone can do is, bank some initial amount, and then use it for transactions. For example if Alice banks in $80, Bob banks in $70 and so on, then Alice can not overspend this amount, and if any transaction leads to overspending, it won’t be added to ledger as Alice doesn’t have that much money to pay. Now since the deposit money remains in this ledger system, It can be called anything, like <strong>ledgercoin (LC), </strong>and this ledgercoin can be used for transactions within this system consisting of friends.</p><p>Cryptocurrencies, like bitcoin are quite similar to these hypothetical ledgercoins which we invented. But instead of our few friends, they have ecosystem of millions of users, who can exchange these bitcoins with each others for various services like buying pizza, downloading apps, and even buying/ selling illegal items on dark web. Now since initial no. of ledgercoins for each person is limited, they can’t overspend this amount. And if they want to spend more, they will have to add more ledgercoins in their balance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/0*U9eXDMfeWzp6Ovqy" /></figure><p>Now our ledger works fine, but we need to still find some common place like a bulletin board, or a website to post our ledger so that people can add their entries. In a way we are still dependent on a 3rd party to host our ledger, this 3rd party like a website might become down, or get hacked, thus preventing us from transacting. In order to finish our dependence on a 3rd party, we can create multiple copies of the ledger and distribute it to all our friends. But now we have to find a way of maintaining consistency between these copies. That’s where the things get interesting!</p><p>The way we can ensure consistency between everyone’s ledger is by broadcasting the transactions whenever they happen. For example, if <strong>Alice-&gt;Bob LC 10 </strong>is signed and updated in Alice’s ledger, then it should get automatically broadcast to everyone else in the system, including Bob, so that they all can add this entry in their ledgers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/0*yqU_2SjxDaHYw5NT" /></figure><p>After the broadcast reaches others, their respective ledgers will be updated. Now Bob will update his ledger quickly as he is receiving money, but how will he ensure others have updated their ledgers as well? After all, Bob might need to use these 10 LC he just received to further pay others, and if others are not aware of Bob owning these 10 LC, then Bob won’t be able to perform transactions using these 10 LC.</p><p>To solve this problem, Satoshi Nakamoto, the inventor of Bitcoin proposed an algorithm called “Proof of work”. This algorithm requires people to compete while solving a cryptographic puzzle whenever some new transactions are added. But before learning proof of work, we need to get ourselves familiar with blocks.</p><p><strong>What is the ‘block’ in blockchain?</strong></p><p>A block consists of a set of transaction entries along with some additional parameters. In a way, it is simply a piece of ledger with some additional entries. The number of transaction entries inside a block if usually fixed. Below is the basic structure of block:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/0*BHBX1AYdJi0riYSA" /></figure><p>Let us understand the constituents of a block one by one:</p><ol><li>Serial No: pretty self explanatory, it denotes the serial in which a particular block comes in the blockchain (we will know what blockchain is in a minute).</li><li>Previous Hash: It denotes the hash value of the block preceding a particular block.</li><li>Data: It contains the transaction information like sender, reciever, amount, digital signatures and other details.</li><li>Nonce: It is a special number which we have to find out in order to mine a block. We will learn about mining in a minute.</li><li>Hash: It is the value generated by the hash function when all the above constituents of the block are passed through it. <strong>hash = hash_function(s.no, prev hash, data, nonce)</strong></li></ol><p>As you might have noticed above, each block also contains the hash of the previous block, so in a way. these blocks are connected as the ‘hash’ value of a block points to the ‘previous hash’ value of next block. This chain of connected blocks is called a <strong>blockchain</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/0*KjNQIKQkLalupQUX" /></figure><p>Notice that hash of a block is same as the previous hash of the next block.</p><p>Whenever a user broadcasts a block to everyone, then we already have the S.no, previous hash and data. In order to find block hash, we need to find the nonce.</p><p>Nonce is such a number, so that when inserted in the hash function along with data, S.no, prev. hash, It produces a hash which is less than a given number.</p><p>For example, if we need the hash to be less than 999999 then we have to find a nonce such that it satisfies:</p><p>Hash_function (nonce, S.no, Data, Prev. hash) &lt; 999999</p><p>There is no fixed way to find nonce as the hash produced are truly random in nature. So basically all the users try out many numbers one by one until one of them finds the nonce. The person who finds the nonce first then broadcasts it to other nodes and everyone updates this value in their blockchain. Note that this process of finding the correct nonce is called <strong>mining</strong>.</p><p>Once a block gets mined, only then it gets added in the blockchain. So the above process can be summarized with the illustrations below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/0*FecmFnwWQfu1us-u" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*WZmCQ5gWkuhkUWYn" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*WLzshgGHalQizrqB" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*QFY01WXMmIWK9jy6" /></figure><p>But how does this process make blockchain secure? The answer is simple. If someone will try to change the transaction entries in a mined block, then the data of the block will change. This in turn, will change the hash of this block and the hash won’t remain lesser than the required value. Also, in the next block, the ‘previous hash’ value will change, this will in turn change hash of this next block as well as the hash depends on all the constituent values in a block. This will keep on happening until all the blocks following the tampered block will become un-mined again, thus the tampering will be caught and the changes will be reverted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*pkerbpjq4kzgmXl2" /></figure><p>There are other mechanisms which prevent fraud transactions from appearing in blockchain like forking, key management etc. We will cover these topics later as this blog post has become too long! Hope you understood the basics of blockchain, please feel free to ask doubts in the comments section! Also please do check out my blog <a href="http://www.codeharvest.io/">codeharvest</a>.</p><p><em>Originally published at </em><a href="http://www.codeharvest.io/blockchain/how-does-blockchain-actually-work/"><em>http://www.codeharvest.io</em></a><em> on June 20, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a5186bb1d1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GUI Automation Using Python]]></title>
            <link>https://medium.com/@tarunkhare54321/gui-automation-using-python-d07c4bbbd263?source=rss-2a0aeef49414------2</link>
            <guid isPermaLink="false">https://medium.com/p/d07c4bbbd263</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gui-automation]]></category>
            <category><![CDATA[pyautogui]]></category>
            <dc:creator><![CDATA[Tarun Khare]]></dc:creator>
            <pubDate>Fri, 22 Feb 2019 13:34:32 GMT</pubDate>
            <atom:updated>2019-02-22T13:34:32.955Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fCoVurbiB_Ib36PMY3kk5A.jpeg" /></figure><p>Python is popularly known as the language of the future. It is a powerful, high level language which can perform complex tasks with few lines of code.</p><p>In this article, I will show how to automate movements of mouse using pyautogui module in python. It does not come preloaded with python. So to install it, open cmd (type cmd in windows search and click first result). It shows C:/Users/yourname as the current directory. You need to change the current directory to the ‘Scripts’ folder at the place where you have installed python (something like C:/Python/Scripts in my PC). To change the current directory, type the following in cmd:</p><pre>cd C:\Python\Scripts</pre><p>Now to install pyautogui, type the following in cmd:</p><pre>pip install pyautogui</pre><p>Wait until the package is installed. Now it can be used to write python code.</p><p>Open a text editor and type:</p><pre>import pyautogui</pre><p>to import all its functions.</p><p><strong><em>Controlling mouse movements using pyautogui</em>:</strong></p><p>Python tracks and controls mouse using coordinate system of screen. Suppose the resolution of your screen is 1023×767, then your screen’s coordinate system looks like :</p><p>to know your screen resolution, type the following in a text editor:</p><pre>import pyautogui</pre><pre>print(pyautogui.size())</pre><p>Save this file with .py extension, and then run the file.</p><p>This python code use size() function to output your screen resolution in x,y format:</p><p><strong>output: (1023, 768)</strong></p><p>To move the mouse, use function moveTo() in pyautogui module. Type:</p><pre>import pyautogui</pre><pre>pyautogui.moveTo(100, 100, duration= 1)</pre><p>This code uses moveTo() function, which takes x and y coordinates, and an optional duration argument. This function moves your mouse pointer from it’s current location to x,y coordinate, and takes time as specified by duration argument to do so.</p><p>Save and run this python script to see your mouse pointer magically moving from its current location to coordinates (100, 100) , taking 1 second in this process.</p><p><strong><em>Using moveRel() function:</em></strong></p><p>moveRel() function moves the mouse pointer relative to its previous position. Type:</p><pre>import pyautogui</pre><pre>pyautogui.moveRel(0, 50, duration=1)</pre><p>This code will move mouse pointer at (0, 50) relative to its original position. For example, if mouse position before running the code was (1000, 1000), then this code will move the pointer to coordinates (1000, 1050) in duration 1 second.</p><p><strong><em>Getting current mouse position:</em></strong></p><p>use position() function to get current position of the mouse pointer. Type:</p><pre>import pyautogui</pre><pre>print(pyautogui.position())</pre><p><strong>output: (500, 600)</strong></p><p>or wherever your mouse was residing at the time of executing the program.</p><p><strong><em>Clicking and dragging the mouse:</em></strong></p><p>type:</p><pre>import pyautogui</pre><pre>pyautogui.click(100, 100)</pre><p>This code performs a typical mouse click at the location (100, 100).</p><p>We have two functions associated with drag operation of mouse, dragTo and dragRel. they perform similar to moveTo and moveRel functions, except they hold the left mouse button while moving, thus initiating a drag. This functionality can be used at various places, like moving a dialog box, or drawing something automatically using pencil tool in MS Paint. For example to draw a square in paint, type the following code:</p><pre>import time  #a module which has functions related to time. It can be installed using cmd command: pip install time, in the same way as pyautogui.</pre><pre>import pyautogui</pre><pre>time.sleep(10)   //makes program execution pause for 10 sec</pre><pre>pyautogui.moveTo(1000, 1000, duration=1) //moves mouse to 1000, 1000.</pre><pre>pyautogui.dragRel(100, 0, duration=1)/*drags mouse 100, 0 relative to its previous position, thus dragging it to 1100, 1000*/</pre><pre>pyautogui.dragRel(0, 100, duration=1)</pre><pre>pyautogui.dragRel(-100, 0, duration=1)</pre><pre>pyautogui.dragRel(0, -100, duration=1)</pre><p>before running the code, open MS paint in background with pencil tool selected. Now run the code, quickly switch to MS paint before 10 seconds (since we have given 10 second pause time using sleep() function before running the program).</p><p>After 10 seconds, you will see a square being drawn in MS paint, with its top left edge at 1000,1000 and edge length 100 pixels.</p><p><strong><em>Using scroll() function:</em></strong></p><p>scroll function takes no. of pixels as argument, and scrolls the screen up to given number of pixels.</p><pre>import pyautogui</pre><pre>pyautogui.scroll(200)</pre><p>This code scrolls the active screen up to 200 pixels.</p><p><strong><em>Controlling the keyboard:</em></strong></p><p><strong><em>Automate typing of a string:</em></strong></p><p>You can automate typing of string by using typewrite() function. just pass the string which you want to type as argument of this function. Ex:</p><pre>import pyautogui</pre><pre>pyautogui.click(100, 100)</pre><pre>pyautogui.typewrite(“hello Geeks!”)</pre><p>suppose a text field was present at coordinates 100, 100 on screen, then this code will click the text field to make it active and type “hello Geeks!” in it.</p><p><strong><em>Passing key names:</em></strong></p><p>You can pass key names separately through typewrite() function. For example:</p><pre>import pyautogui</pre><pre>pyautogui.typewrite([“a”, “left”, “ctrlleft”])</pre><p>This code is automatic equivalent of typing “a”, pressing left arrow key, and pressing left control key.</p><p><strong><em>Pressing hotkey combinations:</em></strong></p><p>Use hotkey() function to press combination of keys like ctrl-c, ctrl-a etc. Ex:</p><pre>import pyautogui</pre><pre>pyautogui.hotkey(“ctrlleft”, “a”)</pre><p>This code is automatic equivalent of pressing left ctrl and “a”simultaneously. Thus in windows, this will result in selection of all text present on screen.</p><p>Hence we finish with the basic introduction of GUI automation using python. If you want to read more about it, read the Pyautogui documentation <a href="https://pyautogui.readthedocs.io/">here</a>. For more cool articles, stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d07c4bbbd263" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>