<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6103469486614880434</id><updated>2026-03-21T18:42:18.011+00:00</updated><category term="Tutorials"/><category term="How To"/><category term="C Programming Stuff"/><category term="Vim"/><category term="Linux"/><category term="Programming"/><category term="Gvim"/><category term="Java"/><category term="General Awareness"/><category term="Python"/><category term="Blogging tips"/><category term="Apache Spark"/><category term="Hadoop"/><category term="Mathema&#39;tricks&#39;"/><category term="Terminal"/><category term="windows tips"/><category term="Git"/><category term="HTML 5"/><category term="Regular Expression"/><category term="VimFirstLesson"/><category term="grep"/><category term="regex"/><category term="Analytics"/><category term="Bash"/><category term="Big Data"/><category term="Data Science"/><category term="Linux Tips"/><category term="Machine Learning"/><category term="Scala"/><category term="API"/><category term="Automation"/><category term="Bernie Sanders"/><category term="CSS"/><category term="Cryptography"/><category term="Daily wisdom dosage"/><category term="Hillary Clinton"/><category term="JSON"/><category term="Java script"/><category term="Merge Conflicts"/><category term="Politics"/><category term="Presidential Elections"/><category term="Speed Cubing"/><category term="Tech"/><category term="Tweepy"/><category term="US Elections"/><category term="sed"/><category term="vim tabs"/><category term="Aliases"/><category term="Arrays"/><category term="Blogging"/><category term="CSV"/><category term="Chess"/><category term="Compression"/><category term="Computer Security"/><category term="Data"/><category term="Encryption"/><category term="Flask"/><category term="Flatmap"/><category term="Geography"/><category term="Git merge"/><category term="Google"/><category term="Images"/><category term="Interview"/><category term="Maven"/><category term="Medium"/><category term="Nerdtree"/><category term="Octopus"/><category term="Openings"/><category term="Parquet"/><category term="Parsing"/><category term="Petrov"/><category term="Philosophy"/><category term="Pip"/><category term="Readline"/><category term="Rebase"/><category term="Scraping"/><category term="Size reduction"/><category term="Solar"/><category term="Source Control"/><category term="Spyware"/><category term="Strings"/><category term="TIL"/><category term="Tinypng"/><category term="Trump"/><category term="Twiiter"/><category term="Twitter"/><category term="US2016"/><category term="VCS"/><category term="VLC"/><category term="Version control"/><category term="Web Application"/><category term="Web Framework"/><category term="Web Server"/><category term="Wordcount"/><category term="Xargs"/><category term="awk"/><category term="branch"/><category term="cherrypick"/><category term="functions"/><category term="plugins"/><category term="sessions"/><category term="software"/><category term="tab pages"/><category term="top 5&#39;s and 10&#39;s"/><category term="vim splits"/><title type='text'>FreBlogg</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/'/><link rel='next' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>97</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-9132846057529531465</id><published>2018-01-12T18:24:00.000+00:00</published><updated>2018-01-12T18:24:59.540+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Flask"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Application"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Framework"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Server"/><title type='text'>Build A Web Application With Flask In Python Part I</title><content type='html'>&lt;!--
Title : Build A Web Application With Flask In Python Part I
Labels: Flask, Web Application, Python, Web Server, Web Framework
PostId: 
Destination: Blogger
--&gt;
&lt;p&gt;Flask is a popular micro web application framework for Python using which you can create web apps. Unlike another popular framework like Django, Flask keeps its foot print to a minimum providing only the basic functionality required instead of picking out the entire stack for you the way Django does. And we call it a micro framework for this very reason. Using flask&#39;s extensibility at the core, you can build any type of applications by picking the components you want to use. Several big name companies like LinkedIn, Pinterest use Flask for their products.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://avatars1.githubusercontent.com/u/18305767&quot; alt=&quot;Flask Logo&quot; class=&quot;aligncenter&quot; height=&quot;300&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;In this tutorial we will get started with using &lt;code&gt;Flask&lt;/code&gt; and create a simple web application with it.&lt;/p&gt;
&lt;h3 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;
&lt;p&gt;To follow along with this series you should have some knowledge of Python language. I&#39;m using &lt;code&gt;3.6&lt;/code&gt; for these tutorials and if you would like to follow along without any issues, I would suggest you to use the same version. For any of the previous versions, there might be a couple of changes in the syntax but the ideas and concepts will remain same.&lt;/p&gt;
&lt;p&gt;You will also need to install &lt;code&gt;Flask&lt;/code&gt;. You can do that with &lt;code&gt;pip&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;pip install -U flask&lt;/pre&gt;
&lt;p&gt;This will install flask if you don&#39;t already have it and update the version to latest if you have a previous version installed.&lt;/p&gt;
&lt;p&gt;With those two things, you are good to go.&lt;/p&gt;
&lt;h3 id=&quot;getting-started&quot;&gt;Getting Started&lt;/h3&gt;
&lt;p&gt;Just like with anything else you start by importing the stuff you want.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;from flask import Flask&lt;/pre&gt;
&lt;p&gt;And this will make &lt;code&gt;Flask&lt;/code&gt; ready for you to use. After this you have to create an &lt;code&gt;app&lt;/code&gt; object by calling the &lt;code&gt;Flask&lt;/code&gt; constructor like this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;app = Flask(&amp;quot;hello&amp;quot;)&lt;/pre&gt;
&lt;p&gt;This will create our &lt;code&gt;app&lt;/code&gt; object. The name &lt;code&gt;hello&lt;/code&gt; I&#39;ve specified in the constructor can be anything. But the usual convention is to keep it &lt;code&gt;__main__&lt;/code&gt;. Also, the app is just a variable. So, you can name it anything you want.&lt;/p&gt;
&lt;p&gt;Next you have to define the routes. Using routes you configure your server to do different actions. Let&#39;s say when you type in some website URL in to your browser, you will be taken to its home page. Now if you do a &lt;code&gt;&amp;lt;website&amp;gt;/info&lt;/code&gt; it will take you to the info page. So, this mapping of the call to &lt;code&gt;/info&lt;/code&gt; URL to the &lt;code&gt;info&lt;/code&gt; page is what we call as a route. For the home page the route is simply &lt;code&gt;/&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Let&#39;s say we want our server&#39;s homepage to display &lt;code&gt;Hello World&lt;/code&gt;. You can configure that with a method like this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;@app.route(&amp;#39;/&amp;#39;)
def index():
    return &amp;quot;Hello World&amp;quot;&lt;/pre&gt;
&lt;p&gt;With the &lt;code&gt;@app.route(&#39;/&#39;)&lt;/code&gt;, we are defining a route on our server. So, when ever somebody opens that route, which for us i the homepage, the &lt;code&gt;index()&lt;/code&gt; method associated with that route annotation will be called. And when the &lt;code&gt;index()&lt;/code&gt; method is called it will return &lt;code&gt;Hello World&lt;/code&gt; just as we expect it to.&lt;/p&gt;
&lt;p&gt;And there is one final command to start and run our server which is:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;app.run(debug=True)&lt;/pre&gt;
&lt;p&gt;And that&#39;s it. This will run the app that we have created when you run the python file. The &lt;code&gt;debug=True&lt;/code&gt; option is useful while developing and testing applications. So, we&#39;ll keep that for now.&lt;/p&gt;
&lt;p&gt;Just run your python script and you should output like this on the console:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;* Debugger is active!
* Debugger PIN: 127-398-124
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)&lt;/pre&gt;
&lt;p&gt;Now If you go to &lt;a href=&quot;http://localhost:5000&quot; class=&quot;uri bodyclass&quot;&gt;http://localhost:5000&lt;/a&gt;, you can see &lt;code&gt;Hello World&lt;/code&gt; displayed.&lt;/p&gt;
&lt;p&gt;That&#39;s it. You have successfully created your first web application with flask in just 3 lines of code. Now, that is awesome. Stay tuned for the next part.&lt;/p&gt;
&lt;p&gt;That is all for this article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more programming articles, checkout &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Freblogg&lt;/a&gt; &lt;a href=&quot;http://www.freblogg.com/search/label/Python&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some articles on automation:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/web-scraping-with-python-introduction-7b3c0bbb6053&quot; class=&quot;bodyclass&quot;&gt;Web Scraping For Beginners with Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/my-semi-automated-blogging-workflow-62cba2827986&quot; class=&quot;bodyclass&quot;&gt;My semi automated workflow for blogging&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/publish-articles-on-blogger-in-just-one-second-2ef45586901&quot; class=&quot;bodyclass&quot;&gt;Publish articles to Blogger automatically&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2017/12/publish-articles-to-your-medium-blog-in_83.html&quot; class=&quot;bodyclass&quot;&gt;Publish articles to Medium automatically&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the 21st article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot; class=&quot;bodyclass&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Nine more articles on various topics, including but not limited to, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot; class=&quot;bodyclass&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot; class=&quot;bodyclass&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot; class=&quot;bodyclass&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot; class=&quot;bodyclass&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you&#39;re at it, Go ahead and subscribe &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;here on medium&lt;/a&gt; and my &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;other blog&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven&#39;t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot; class=&quot;bodyclass&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in its functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/9132846057529531465/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/webapp-with-flask-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/9132846057529531465'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/9132846057529531465'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/webapp-with-flask-1.html' title='Build A Web Application With Flask In Python Part I'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-7015235245835350349</id><published>2018-01-10T18:26:00.000+00:00</published><updated>2018-01-10T18:26:34.496+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data"/><category scheme="http://www.blogger.com/atom/ns#" term="How To"/><category scheme="http://www.blogger.com/atom/ns#" term="JSON"/><category scheme="http://www.blogger.com/atom/ns#" term="Parsing"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Json Parsing With Python</title><content type='html'>&lt;!--
Title : Json Parsing With Python
Labels: Json, Python, Parsing, Programming, How To, Data
PostId: 
Destination: Blogger
--&gt;
&lt;p&gt;JSON has become an ubiquitous data exchange format everywhere. Pretty much every service has a JSON API. And since it is so popular, most of the programming languages have built-in JSON parsers. And Of course, Python is no exception. In this article, I&#39;ll show you how you can parse JSON with Python&#39;s &lt;code&gt;json&lt;/code&gt; library.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.python.org/static/community_logos/python-logo-master-v3-TM.png&quot; alt=&quot;Python Logo&quot; class=&quot;aligncenter&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;JSON parsing in Python is quite straight forward and easy unlike in some languages, where it is unnecessarily cumbersome. Like everything else in Python, You start by importing the library you want.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;import json&lt;/pre&gt;
&lt;p&gt;In this article, I am going to use the following JSON I got from &lt;a href=&quot;http://json.org/example.html&quot; class=&quot;bodyclass&quot;&gt;json.org&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;{
  &amp;quot;menu&amp;quot;: {
    &amp;quot;id&amp;quot;: &amp;quot;file&amp;quot;,
    &amp;quot;value&amp;quot;: &amp;quot;File&amp;quot;,
    &amp;quot;popup&amp;quot;: {
      &amp;quot;menuitem&amp;quot;: [
        {&amp;quot;value&amp;quot;: &amp;quot;New&amp;quot;, &amp;quot;onclick&amp;quot;: &amp;quot;CreateNewDoc()&amp;quot;},
        {&amp;quot;value&amp;quot;: &amp;quot;Open&amp;quot;, &amp;quot;onclick&amp;quot;: &amp;quot;OpenDoc()&amp;quot;},
        {&amp;quot;value&amp;quot;: &amp;quot;Close&amp;quot;, &amp;quot;onclick&amp;quot;: &amp;quot;CloseDoc()&amp;quot;}
      ]
    }
  }
}&lt;/pre&gt;
&lt;p&gt;We have got a good set of dictionaries and arrays to work with in this data. If you want to follow along, you can use the same JSON or you can use anything else as well.&lt;/p&gt;
&lt;p&gt;The first thing to do is to get this json string into a variable.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;json_string = &amp;quot;&amp;quot;&amp;quot;{&amp;quot;menu&amp;quot;: {
  &amp;quot;id&amp;quot;: &amp;quot;file&amp;quot;,
  &amp;quot;value&amp;quot;: &amp;quot;File&amp;quot;,
  &amp;quot;popup&amp;quot;: {
    &amp;quot;menuitem&amp;quot;: [
      {&amp;quot;value&amp;quot;: &amp;quot;New&amp;quot;, &amp;quot;onclick&amp;quot;: &amp;quot;CreateNewDoc()&amp;quot;},
      {&amp;quot;value&amp;quot;: &amp;quot;Open&amp;quot;, &amp;quot;onclick&amp;quot;: &amp;quot;OpenDoc()&amp;quot;},
      {&amp;quot;value&amp;quot;: &amp;quot;Close&amp;quot;, &amp;quot;onclick&amp;quot;: &amp;quot;CloseDoc()&amp;quot;}
    ]
  }
}}&amp;quot;&amp;quot;&amp;quot;&lt;/pre&gt;
&lt;p&gt;And now we parse this string into a &lt;code&gt;dictionary&lt;/code&gt; object with the help of the &lt;code&gt;json&lt;/code&gt; library&#39;s &lt;code&gt;loads()&lt;/code&gt; method.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;json_dict = json.loads(json_string)&lt;/pre&gt;
&lt;p&gt;And you&#39;re done. The JSON is parsed and is stored in the &lt;code&gt;json_dict&lt;/code&gt; object. The &lt;code&gt;json_dict&lt;/code&gt; here is a python dictionary object. If you want to verify, you can do that by calling the &lt;code&gt;type()&lt;/code&gt; on it with&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;print(type(json_dict))&lt;/pre&gt;
&lt;p&gt;And it will show that it is &lt;code&gt;&amp;lt;class &#39;dict&#39;&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Getting back, We have the entire json object as a dictionary in &lt;code&gt;json_dict&lt;/code&gt; object and you can just drill down into the dictionary with the keys. On the top level, We just have one key in the dictionary which is &lt;code&gt;menu&lt;/code&gt;. We get can get that by indexing the dictionary with that key.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;menu = json_dict[&amp;#39;menu&amp;#39;]&lt;/pre&gt;
&lt;p&gt;And of course &lt;code&gt;menu&lt;/code&gt; is a dictionary too with the keys &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;value&lt;/code&gt;, and &lt;code&gt;popup&lt;/code&gt;. We can access them and print them as well.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;print(menu[&amp;#39;id&amp;#39;])            ## =&amp;gt; &amp;#39;file&amp;#39;
print(menu[&amp;#39;value&amp;#39;])         ## =&amp;gt; &amp;#39;File&amp;#39;&lt;/pre&gt;
&lt;p&gt;And then finally we&#39;ve got &lt;code&gt;popup&lt;/code&gt; which is another dictionary as well with the key &lt;code&gt;menuitem&lt;/code&gt; which is a list. We can verify this by checking the types of these objects.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;popup = menu[&amp;#39;popup&amp;#39;]
print(type(popup))           ## =&amp;gt; &amp;lt;class &amp;#39;dict&amp;#39;&amp;gt;

menuitem = popup[&amp;#39;menuitem&amp;#39;]
print(type(menuitem))        ## =&amp;gt; &amp;lt;class &amp;#39;list&amp;#39;&amp;gt;&lt;/pre&gt;
&lt;p&gt;And Since &lt;code&gt;menuitem&lt;/code&gt; is a list, we can iterate on it and print the values.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;for item in menuitem:
    print(item)&lt;/pre&gt;
&lt;p&gt;And the output is&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;{&amp;#39;value&amp;#39;: &amp;#39;New&amp;#39;, &amp;#39;onclick&amp;#39;: &amp;#39;CreateNewDoc()&amp;#39;}
{&amp;#39;value&amp;#39;: &amp;#39;Open&amp;#39;, &amp;#39;onclick&amp;#39;: &amp;#39;OpenDoc()&amp;#39;}
{&amp;#39;value&amp;#39;: &amp;#39;Close&amp;#39;, &amp;#39;onclick&amp;#39;: &amp;#39;CloseDoc()&amp;#39;}&lt;/pre&gt;
&lt;p&gt;And of course each of these elements are dictionaries and so you can go further inside and access those keys and values.&lt;/p&gt;
&lt;p&gt;For example, If you want to access &lt;code&gt;New&lt;/code&gt; from the above output, you can do this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;print(menuitem[0][&amp;#39;value&amp;#39;])  ## =&amp;gt; New&lt;/pre&gt;
&lt;p&gt;And so on and so forth to get any value in the JSON.&lt;/p&gt;
&lt;p&gt;And not only that, &lt;code&gt;json&lt;/code&gt; library can also accept JSON responses from web services. One cool thing here is that, web server responses are &lt;code&gt;byte&lt;/code&gt; strings which means that if you want to use them in your program you&#39;d have convert them to regular strings by using the &lt;code&gt;decode()&lt;/code&gt; method. But for &lt;code&gt;json&lt;/code&gt; you don&#39;t have to do that. You can directly feed in the &lt;code&gt;byte&lt;/code&gt; string and it will give you a parsed object. That&#39;s pretty cool!&lt;/p&gt;
&lt;p&gt;That is all for this article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more programming articles, checkout &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Freblogg&lt;/a&gt; &lt;a href=&quot;http://www.freblogg.com/search/label/Python&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some articles on automation:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/web-scraping-with-python-introduction-7b3c0bbb6053&quot; class=&quot;bodyclass&quot;&gt;Web Scraping For Beginners with Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/my-semi-automated-blogging-workflow-62cba2827986&quot; class=&quot;bodyclass&quot;&gt;My semi automated workflow for blogging&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/publish-articles-on-blogger-in-just-one-second-2ef45586901&quot; class=&quot;bodyclass&quot;&gt;Publish articles to Blogger automatically&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2017/12/publish-articles-to-your-medium-blog-in_83.html&quot; class=&quot;bodyclass&quot;&gt;Publish articles to Medium automatically&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the 19th article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot; class=&quot;bodyclass&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Eleven more articles on various topics, including but not limited to, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot; class=&quot;bodyclass&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot; class=&quot;bodyclass&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot; class=&quot;bodyclass&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot; class=&quot;bodyclass&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you&#39;re at it, Go ahead and subscribe &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;on medium&lt;/a&gt; and my &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;blog&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven&#39;t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot; class=&quot;bodyclass&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in its functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/7015235245835350349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/json-parsing-with-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/7015235245835350349'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/7015235245835350349'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/json-parsing-with-python.html' title='Json Parsing With Python'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-401722815539045231</id><published>2018-01-08T16:16:00.001+00:00</published><updated>2018-01-08T16:16:45.971+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Analytics"/><category scheme="http://www.blogger.com/atom/ns#" term="Apache Spark"/><category scheme="http://www.blogger.com/atom/ns#" term="CSV"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Science"/><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="JSON"/><category scheme="http://www.blogger.com/atom/ns#" term="Machine Learning"/><category scheme="http://www.blogger.com/atom/ns#" term="Parquet"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorials"/><title type='text'>Datasets In Apache Spark - Part 3 | Writing Datasets to Disk</title><content type='html'>&lt;!--
Title : Datasets In Apache Spark - Part 3 | Writing Datasets to Disk
Labels: Apache Spark, Java, Programming, Machine Learning, Scala, Data Science, Tutorials, Hadoop, Analytics, Parquet, CSV, JSON
PostId: 
Destination: Blogger
--&gt;
&lt;p&gt;In the &lt;a href=&quot;http://www.freblogg.com/2018/01/apache-spark-datasets-2.html&quot; class=&quot;bodyclass&quot;&gt;last tutorial&lt;/a&gt; we&#39;ve seen how to create parametrized datasets. Once you create datasets and perform &lt;a href=&quot;http://www.freblogg.com/2017/12/apache-spark-datasets-1.html#operations-on-datasets&quot; class=&quot;bodyclass&quot;&gt;some operations&lt;/a&gt; on them, you would like to save those results back into storage. This is what we&#39;ll try to do in this article - Saving Datasets to storage.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://redislabs.com/wp-content/uploads/2016/12/spark.png&quot; alt=&quot;Spark Logo&quot; class=&quot;aligncenter&quot; width=&quot;500&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;The first thing we&#39;ll do as always is to create the spark-session variable.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;// Initialize Sparksession
SparkSession spark = SparkSession.builder().appName(&amp;quot;Freblogg-Spark&amp;quot;).master(&amp;quot;local&amp;quot;).getOrCreate();&lt;/pre&gt;
&lt;p&gt;Using that session variable, we read the &lt;code&gt;fake-people.csv&lt;/code&gt; file which has data like this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;id,first_name,last_name,email,gender,ip_address
1,Netti,McKirdy,nmckirdy0@slideshare.net,Female,148.3.248.193
2,Nickey,Curreen,ncurreen1@tripadvisor.com,Male,206.9.48.216
3,Allayne,Chatainier,achatainier2@trellian.com,Male,191.118.4.217
...&lt;/pre&gt;
&lt;p&gt;We read this file into a dataset as following:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;// Read csv file
Dataset&amp;lt;Row&amp;gt; peopleDs = spark.read().option(&amp;quot;header&amp;quot;, &amp;quot;true&amp;quot;).csv(&amp;quot;fake-people.csv&amp;quot;);&lt;/pre&gt;
&lt;p&gt;After we have the dataset, Let&#39;s assume you&#39;ve performed some operations on it. Some &lt;a href=&quot;http://www.freblogg.com/2017/12/apache-spark-datasets-1.html#column-selection&quot; class=&quot;bodyclass&quot;&gt;column selections&lt;/a&gt;, some &lt;a href=&quot;http://www.freblogg.com/2017/12/apache-spark-datasets-1.html#filtering-on-columns&quot; class=&quot;bodyclass&quot;&gt;filtering&lt;/a&gt;, some &lt;a href=&quot;http://www.freblogg.com/2017/12/apache-spark-datasets-1.html#sorting-on-columns&quot; class=&quot;bodyclass&quot;&gt;sorting&lt;/a&gt; etc. And we have a new dataset after all those operations.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;// After performing several awesome operations
Dataset&amp;lt;Row&amp;gt; newDs = ....&lt;/pre&gt;
&lt;p&gt;We want to store this dataset back on the disk. We can do that with the &lt;code&gt;write()&lt;/code&gt; on spark session variable, just like &lt;code&gt;read()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;newDs.write().csv(&amp;quot;processed-data&amp;quot;);&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;processed-data&lt;/code&gt; in the above command is not the name for the output CSV file but instead for the output directory. When you write a Dataset to a file, it will store the data in the format you asked for, &lt;code&gt;CSV&lt;/code&gt; in this case, along with adding some check files and status flags as well creating a directory with that name.&lt;/p&gt;
&lt;p&gt;These are the files that get created in the &lt;code&gt;processed-data&lt;/code&gt; folder.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ ls ../../apache-spark/processed-data
_SUCCESS  part-00000-311049cf-3e48-4286-b93c-7d2096a18678-c000.csv&lt;/pre&gt;
&lt;p&gt;There are two more hidden CRC files that I&#39;m not showing here. The &lt;code&gt;part-00000-31hxxxxxxxxx.csv&lt;/code&gt; is the actual data file which has the data from the new dataset.&lt;/p&gt;
&lt;p&gt;You can also create a &lt;code&gt;json&lt;/code&gt; file by running&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;newDs.write().json(&amp;quot;processed-data&amp;quot;)&lt;/pre&gt;
&lt;p&gt;And that will create another folder with json file and the &lt;code&gt;_SUCCESS&lt;/code&gt; file inside it.&lt;/p&gt;
&lt;p&gt;You can also save this data to an external Database if you want to. You&#39;ll use the &lt;code&gt;jdbc()&lt;/code&gt; method along with the connection string and the table name. And Spark will write it to the DB.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sdtimes.com/wp-content/uploads/2015/04/OGYr_m6J.jpeg&quot; alt=&quot;Parquet Logo&quot; class=&quot;aligncenter&quot; width=&quot;300&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Apart from the CSV and JSON formats, there is one more popular data format in the Data Science and Big Data world. That is &lt;a href=&quot;https://parquet.apache.org/&quot; class=&quot;bodyclass&quot;&gt;Parquet&lt;/a&gt;. Parquet is a data format that is highly optimized and well suited for column-wise operations. It is widely used in a lot of projects in the Big Data ecosystem as a data serialization format. And In Spark, Parquet is the default file storage format. Of course one main difference between Parquet and formats like CSV, JSON is that Parquet is not meant to be used for humans. It can only be read by a parquet reader. A sample file looks something like this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;PAR1   ï¿½k ï¿½&amp;gt;, ï¿½          999  1     ï¿½5,   ï¿½      1   2   3   4   5   6   7   8   9  - 0   1   2   3   4   5   6   7   8   &amp;lt; 2 &amp;lt; 2 &amp;lt; 2 &amp;lt; 2 &amp;lt; 2 &amp;lt; 2 &amp;lt; 2 &amp;lt;
.....&lt;/pre&gt;
&lt;p&gt;Utterly gibberish. But spark can read and understand it. In fact, As Parquet is designed for speed and throughput, it can be 10-100 times faster than reading/writing from an ordinary data format like CSV or JSON, depending on the type of data.&lt;/p&gt;
&lt;p&gt;You save dataset to Parquet as follows:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;newDs.write().parquet(&amp;quot;processed&amp;quot;);&lt;/pre&gt;
&lt;p&gt;And this will save the dataset as a parquet file along with the &lt;code&gt;_SUCCESS&lt;/code&gt; status file.&lt;/p&gt;
&lt;p&gt;That is all for this article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more programming articles, checkout &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Freblogg&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Apache%20Spark&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Spark&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Articles on Apache Spark:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2016/06/apache-spark-map-vs-flatmap.html&quot; class=&quot;bodyclass&quot;&gt;Map Vs Flat map&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2016/06/spark-word-count-with-java.html&quot; class=&quot;bodyclass&quot;&gt;Spark Word count with Java&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2017/12/apache-spark-datasets-1.html&quot; class=&quot;bodyclass&quot;&gt;Datasets in Spark | Part I&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2018/01/apache-spark-datasets-2.html&quot; class=&quot;bodyclass&quot;&gt;Datasets in Spark | Part II&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the 17th article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot; class=&quot;bodyclass&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Thirteen more articles on various topics, including but not limited to, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot; class=&quot;bodyclass&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot; class=&quot;bodyclass&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot; class=&quot;bodyclass&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot; class=&quot;bodyclass&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you&#39;re at it, Go ahead and subscribe &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;here on medium&lt;/a&gt; and my &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;other blog&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven&#39;t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot; class=&quot;bodyclass&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in its functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/401722815539045231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/apache-spark-datasets-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/401722815539045231'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/401722815539045231'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/apache-spark-datasets-3.html' title='Datasets In Apache Spark - Part 3 | Writing Datasets to Disk'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-6628116640599446942</id><published>2018-01-06T18:05:00.000+00:00</published><updated>2018-01-06T18:09:20.189+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arrays"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>Remove Duplicate Elements From An Array</title><content type='html'>&lt;!--
Title : Remove Duplicate Elements From An Array
Labels: Arrays, Java, Programming, Interview
PostId: 
Destination: Blogger
--&gt;
&lt;p&gt;Interviews are a great place to learn about your strengths and weaknesses, which makes them a great way to improve oneself. In one of my interviews, I was asked to &lt;code&gt;Remove duplicate elements from an array&lt;/code&gt;. So, given the array &lt;code&gt;a&lt;/code&gt; as below, I&#39;ve to produce &lt;code&gt;b&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;text&quot;&gt;a = {1, -2, 3, 1, 0, 9, 5, 6, 4, 5, 3, 1, 0}
b = {1, -2, 3, 0, 9, 5, 6, 4}&lt;/pre&gt;
&lt;p&gt;Here &lt;code&gt;b&lt;/code&gt; has the same order of elements as &lt;code&gt;a&lt;/code&gt; but per the problem statement, It is not necessary to do that.&lt;/p&gt;
&lt;p&gt;I was flustered for a bit after getting the question. It took me a while to get to a proper solution, not before getting my first solution rejected for using &lt;code&gt;HashMap&lt;/code&gt; which apparently, I was not supposed to. I am attributing this mainly to the fact that I was told to write Java code on a piece of paper and not an IDE. Anyway, I came home after that and decided to try it out and find what other&#39;s have done online. That is what this article is about.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://echmondprojects.com/wp-content/uploads/2016/04/two-arrays-700x525.png&quot; alt=&quot;Array of Donuts&quot; class=&quot;aligncenter&quot; width=&quot;450&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Since that particular interview was in Java, It is only fair that I use Java for the solution here, although I really wanted to do it in Python. Maybe some other time.&lt;/p&gt;
&lt;p&gt;Approaches for solving the problem:&lt;/p&gt;
&lt;h3 id=&quot;approach1&quot;&gt;Approach #1&lt;/h3&gt;
&lt;p&gt;The most naive approach would be to just look through the entire array and compare each element to every other element to see if there&#39;s a duplicate. Of course, this is useless as its time complexity is &lt;code&gt;O(n^2)&lt;/code&gt;. So, Let&#39;s skip this one and go to the next one.&lt;/p&gt;
&lt;h3 id=&quot;approach2&quot;&gt;Approach #2&lt;/h3&gt;
&lt;p&gt;Another approach is using a HashMap to keep track of elements. This is what I&#39;ve tried initially but was rejected because I&#39;ve used HashMap when I wasn&#39;t supposed to. The pseudo code would be:&lt;/p&gt;
&lt;pre class=&quot;text&quot;&gt;map = new Map // Create map
new_arrray = []

for number in numbers_array
  if not map.contains(number)
  map += number
  new_array += number

print(new_array)&lt;/pre&gt;
&lt;p&gt;Of course, Since I wrote my implementation of this in Java, I had to make a few modifications to this as you need to first define the size of the array and only then can you add elements to it. So, I&#39;ve added a count variable to count unique elements and then created a new array after the iteration with that size. This would require two loop iterations, but it is still &lt;code&gt;O(n)&lt;/code&gt; which is fine. But Alas I couldn&#39;t use this.&lt;/p&gt;
&lt;p&gt;And so, then comes my final approach.&lt;/p&gt;
&lt;h3 id=&quot;approach3&quot;&gt;Approach #3&lt;/h3&gt;
&lt;p&gt;The third solution is to first sort the array and then from the sorted array, remove duplicates. We can do this because the problem didn&#39;t want us to maintain the given input order. Otherwise, we wouldn&#39;t have been able to sort the array.&lt;/p&gt;
&lt;p&gt;Sorting is easy enough. We just use the built-in sort method, which will sort the array in place.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Arrays.sort(numbers);&lt;/pre&gt;
&lt;p&gt;Then comes the major part which is removing the duplicates in that sorted array. We can accomplish that by using two pointers &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;j&lt;/code&gt; on our array. &lt;code&gt;i&lt;/code&gt; goes through the entire loop while &lt;code&gt;j&lt;/code&gt; is the slow-moving pointer that only changes based on a condition.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt; int j = 0; // Slow moving index

// i is the fast moving index that loops through the entire array
for (int i = 1; i &amp;lt; numbers.length; i++) {
    if (numbers[i] != numbers[j]) {
        j++;
        numbers[j] = numbers[i];
    }
}&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;j&lt;/code&gt; index is basically playing catch up with &lt;code&gt;i&lt;/code&gt;. When there is a duplicate element, &lt;code&gt;i&lt;/code&gt; moves ahead while &lt;code&gt;j&lt;/code&gt; stays back at the first duplicate element and then with &lt;code&gt;numbers[j] = numbers[i]&lt;/code&gt;, we assign the next unique value to the &lt;code&gt;j&lt;/code&gt; location. After this, our original array has unique elements till index &lt;code&gt;j&lt;/code&gt; but after that, we&#39;ll have leftover elements. To take care of that, we can create a new array from the numbers array.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;int[] result = Arrays.copyOf(numbers, j + 1);
System.out.println(Arrays.toString(result));&lt;/pre&gt;
&lt;p&gt;And that&#39;s it. This will remove all the duplicated elements from the array. To test it, let me run the code:&lt;/p&gt;
&lt;pre class=&quot;text&quot;&gt;Input array: [1, -2, 3, 1, 0, 9, 5, 6, 4, 5]
Final result after removing duplicates: [-2, 0, 1, 3, 4, 5, 6, 9]&lt;/pre&gt;
&lt;p&gt;The sorting of the array can be assumed to be done in &lt;code&gt;O(nlogn)&lt;/code&gt;. And then the iteration after that is &lt;code&gt;O(n)&lt;/code&gt;. Put together you still technically get &lt;code&gt;O(n)&lt;/code&gt;, which is the same as the previous case. Of course depending on a more specific kind of array, the sort might take less time as well. &lt;code&gt;O(n)&lt;/code&gt; for the average case is what you finally get.&lt;/p&gt;
&lt;p&gt;The full code is present as a gist:&lt;/p&gt;
&lt;script src=&quot;https://gist.github.com/durgaswaroop/a3b4ce78d4a1626b14ade072ea941cd2.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;Let me know if you have any more questions that need answers. That is all for this article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more programming articles, checkout &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Freblogg&lt;/a&gt; &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Java&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the 15th article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot; class=&quot;bodyclass&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Fifteen more articles on various topics, including but not limited to, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot; class=&quot;bodyclass&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot; class=&quot;bodyclass&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot; class=&quot;bodyclass&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot; class=&quot;bodyclass&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you&#39;re at it, Go ahead and subscribe &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;here on medium&lt;/a&gt; and my &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;other blog&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven&#39;t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot; class=&quot;bodyclass&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code but also with usage documentation and also by identifying any bugs in its functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Image of Donuts: http://echmondprojects.com/wp-content/uploads/2016/04/two-arrays-700x525.png&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/6628116640599446942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/remove-duplicate-elements-from-array_6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/6628116640599446942'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/6628116640599446942'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/remove-duplicate-elements-from-array_6.html' title='Remove Duplicate Elements From An Array'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-5757295685226771698</id><published>2018-01-04T17:41:00.003+00:00</published><updated>2018-01-05T17:40:49.861+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Automation"/><category scheme="http://www.blogger.com/atom/ns#" term="Compression"/><category scheme="http://www.blogger.com/atom/ns#" term="Images"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Size reduction"/><category scheme="http://www.blogger.com/atom/ns#" term="Tinypng"/><title type='text'>Reduce Image Size With Python And Tinypng</title><content type='html'>&lt;!--
Title : Reduce Image Size With Python And Tinypng
Labels: Python, Images, Tinypng, Compression, Size reduction, Automation
PostId:5757295685226771698
Destination: Blogger
--&gt;
&lt;p&gt;Whenever I want to upload images with my articles, I make sure they are of the right size first and then I have to check the file sizes and if they are too big, I will have to compress them. For this compression, I use &lt;a href=&quot;https://tinypng.com/&quot; class=&quot;bodyclass&quot;&gt;Tinypng&lt;/a&gt;. They compress your images to a small size all the while keeping the image looking the same. I&#39;ve tried some other services as well, but TinyPNG is definitely the best as their compression ratio is quite impressive.&lt;/p&gt;
&lt;p&gt;In this article I&#39;ll show you how I&#39;m planning to automate the image compression process using TinyPNG&#39;s &lt;a href=&quot;https://tinypng.com/developers&quot; class=&quot;bodyclass&quot;&gt;developer API&lt;/a&gt;. And of-course we are going to using &lt;a href=&quot;http://www.freblogg.com/search/label/Python&quot; class=&quot;bodyclass&quot;&gt;python&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;setup&quot;&gt;Setting up&lt;/h3&gt;
&lt;p&gt;First of all, you need to have a developer key to connect to TinyPNG and use their services. So, go to &lt;a href=&quot;https://tinypng.com/developers&quot; class=&quot;bodyclass&quot;&gt;Developer&#39;s API&lt;/a&gt; and enter your name and email.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/Reduce-Image-Size-With-Python-And-TinyPNG/13.tinypng-email-name-form.png&quot; alt=&quot;TinyPNG API registration&quot; class=&quot;aligncenter&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Once you&#39;ve registered, you&#39;ll get a mail from TinyPNG with a link and once you click on that, you&#39;ll go to your developers page which also has your API key and your usage information. Do keep it mind that for the free account, you can only compress 500 images per month. For someone like me, that&#39;s a number I won&#39;t really be reaching in a month anytime soon. But if do, you should probably check out their paid plans.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/Reduce-Image-Size-With-Python-And-TinyPNG/13.tinypng-api-key.png&quot; alt=&quot;Developers API key page&quot; class=&quot;aligncenter&quot; width=&quot;600&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;PS: That&#39;s not my real key :D&lt;/p&gt;
&lt;h3 id=&quot;start&quot;&gt;Get started&lt;/h3&gt;
&lt;p&gt;Once you&#39;ve the developer key, you can start compressing images using their service. The full documentation for Python is &lt;a href=&quot;https://tinypng.com/developers/reference/python&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You start by installing &lt;a href=&quot;https://pypi.python.org/pypi/tinify&quot; class=&quot;bodyclass&quot;&gt;Tinify&lt;/a&gt;, which is TinyPNG&#39;s library for compression.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;pip install --upgrade tinify&lt;/pre&gt;
&lt;p&gt;Then we can start using tinify in code by importing it and setting the API key from your developer&#39;s page.&lt;/p&gt;
&lt;div class=&quot;sourceCode&quot; id=&quot;cb2&quot;&gt;&lt;pre class=&quot;sourceCode python&quot;&gt;&lt;code class=&quot;sourceCode python&quot;&gt;&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-1&quot; data-line-number=&quot;1&quot;&gt;&lt;span class=&quot;im&quot;&gt;import&lt;/span&gt; tinify&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-2&quot; data-line-number=&quot;2&quot;&gt;tinify.key &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;API_Key&amp;#39;&lt;/span&gt;&lt;/a&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you&#39;ve to send your requests over a proxy, you can set that as well.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;tinify.proxy = &amp;quot;http://user:pass@192.168.0.1:8080&amp;quot;&lt;/pre&gt;
&lt;p&gt;Then, you can start compressing your image files. You can upload either PNG or JPEG files and tinify will compress it for you.&lt;/p&gt;
&lt;p&gt;For the purpose of this article, I&#39;m going to use the following &lt;code&gt;delorean.jpeg&lt;/code&gt; image.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/Reduce-Image-Size-With-Python-And-TinyPNG/delorean.jpeg&quot; alt=&quot;Delorean uncompressed&quot; class=&quot;aligncenter&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;And I&#39;ll compress this to &lt;code&gt;delorean-compressed.jpeg&lt;/code&gt;. For that we&#39;ll use the following code:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;source = &amp;quot;delorean.jpeg&amp;quot;
destination = &amp;quot;delorean-compressed.jpeg&amp;quot;

original = tinify.from_file(source)
original.to_file(destination)&lt;/pre&gt;
&lt;p&gt;And that gives me this file:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/Reduce-Image-Size-With-Python-And-TinyPNG/delorean-compressed.jpeg&quot; alt=&quot;Delorean compressed&quot; class=&quot;aligncenter&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;If they both look the same, then that is the magic of TinyPNG&#39;s compression algorithm. It looks pretty much identical but it did compress it. To verify that, let&#39;s print the file sizes.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;import os.path as path

original_size = path.getsize(source)
compressed_size = path.getsize(destination)
print(original_size/1024, compressed_size/1024)&lt;/pre&gt;
&lt;p&gt;And this prints,&lt;/p&gt;
&lt;pre class=&quot;text&quot;&gt;29.0029296875 25.3466796875 1.144249662878058&lt;/pre&gt;
&lt;p&gt;The file was original 29 KB and now after compression it is 25.3 KB which is a fairly good compression for such a small file. If the original file was bigger, you will be able to see an even tighter compression.&lt;/p&gt;
&lt;p&gt;And since this is the free version, there&#39;s a limit on the number of requests we can make. We can keep track of that with a built-in variable &lt;code&gt;compression_count&lt;/code&gt;. You can print that after every requests to make sure you don&#39;t go over that.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;compressions_this_month = tinify.compression_count
print(compressions_this_month)&lt;/pre&gt;
&lt;p&gt;You can also compress images from their URL&#39;s and store it locally. You will just do:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;original = tinify.from_url(&amp;quot;https://raw.githubusercontent.com/durgaswaroop/delorean/master/delorean.jpeg&amp;quot;)&lt;/pre&gt;
&lt;p&gt;And then you can store the compressed file locally just like before.&lt;/p&gt;
&lt;p&gt;Apart from just compressing the images, you can also resize them with TinyPNG&#39;s API. We&#39;ll cover that in the tomorrow&#39;s article &lt;a href=&quot;&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So, That is all for this article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more programming articles, checkout &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Freblogg&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Python&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some articles on automation:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/web-scraping-with-python-introduction-7b3c0bbb6053&quot; class=&quot;bodyclass&quot;&gt;Web Scraping For Beginners with Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/my-semi-automated-blogging-workflow-62cba2827986&quot; class=&quot;bodyclass&quot;&gt;My semi automated workflow for blogging&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/publish-articles-on-blogger-in-just-one-second-2ef45586901&quot; class=&quot;bodyclass&quot;&gt;Publish articles to Blogger automatically&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2017/12/publish-articles-to-your-medium-blog-in_83.html&quot; class=&quot;bodyclass&quot;&gt;Publish articles to Medium automatically&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the 13th article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot; class=&quot;bodyclass&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Seventeen more articles on various topics, including but not limited to, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot; class=&quot;bodyclass&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot; class=&quot;bodyclass&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot; class=&quot;bodyclass&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot; class=&quot;bodyclass&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you&#39;re at it, Go ahead and subscribe &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;here on medium&lt;/a&gt; and my &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;other blog&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven&#39;t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot; class=&quot;bodyclass&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in its functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/5757295685226771698/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/resize-compress-images-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/5757295685226771698'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/5757295685226771698'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/resize-compress-images-in-python.html' title='Reduce Image Size With Python And Tinypng'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-5499065943074593951</id><published>2018-01-02T13:13:00.000+00:00</published><updated>2018-01-02T13:13:36.858+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Analytics"/><category scheme="http://www.blogger.com/atom/ns#" term="Apache Spark"/><category scheme="http://www.blogger.com/atom/ns#" term="Big Data"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Science"/><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="How To"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Machine Learning"/><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorials"/><title type='text'>Datasets In Apache Spark | Part 2</title><content type='html'>&lt;!--
Title : Datasets In Apache Spark | Part 2
Labels: Apache Spark, Java, Analytics, Big Data, Data Science, Hadoop, How To, Machine Learning, Tutorials, Scala
PostId: 
Destination: Blogger
--&gt;
&lt;p&gt;In the two last tutorials we have covered &lt;a href=&quot;http://www.freblogg.com/2016/06/spark-word-count-with-java.html&quot; class=&quot;bodyclass&quot;&gt;what Apache Spark&lt;/a&gt; is and also got ourselves familiar with &lt;a href=&quot;http://www.freblogg.com/2017/12/apache-spark-datasets-1.html&quot; class=&quot;bodyclass&quot;&gt;Datasets in Apache Spark&lt;/a&gt;, which is the primary data abstraction in Spark. In this tutorial we will see how to read a data file as a parametrized Bean object Dataset using Encoders.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://redislabs.com/wp-content/uploads/2016/12/spark.png&quot; alt=&quot;Spark Image Logo&quot; class=&quot;aligncenter&quot; width=&quot;450&quot; /&gt; &lt;/p&gt;
&lt;p&gt;This tutorial is going to be short, but this is very important as you would find yourself doing this frequently. In the last article you&#39;ve seen how to read a CSV or JSON file as a &lt;code&gt;Dataset&lt;/code&gt;. You might have noticed that we were using &lt;code&gt;Dataset&amp;lt;Row&amp;gt;&lt;/code&gt; for everything. If you&#39;re not familiar with &lt;a href=&quot;https://docs.oracle.com/javase/tutorial/java/generics/why.html&quot; class=&quot;bodyclass&quot;&gt;Generics&lt;/a&gt; in Java, &lt;code&gt;Dataset&amp;lt;Row&amp;gt;&lt;/code&gt; can be thought of as a Dataset consisting of Row objects. The Row object is a spark sql class and is the default when creating a Dataset.&lt;/p&gt;
&lt;p&gt;Although the &lt;code&gt;Row&lt;/code&gt; class has some useful methods, as a generic object suitable for all types, it is not suitable for everything. Since Datasets usually store data that usually corresponds to a Bean class, it is better to create a Dataset of that bean class instead of Row. With this, you&#39;ll have access to all your usual getters and setters of the bean class. That&#39;s what We&#39;ll do in this article. We&#39;ll create a Dataset of POJO&#39;s instead of Row objects.&lt;/p&gt;
&lt;p&gt;I&#39;m using the same &lt;code&gt;fake-people.csv&lt;/code&gt; file that I used in the last article that looks like this:&lt;/p&gt;
&lt;pre class=&quot;text&quot;&gt;id,first_name,last_name,email,gender,ip_address
1,Netti,McKirdy,nmckirdy0@slideshare.net,Female,148.3.248.193
2,Nickey,Curreen,ncurreen1@tripadvisor.com,Male,206.9.48.216
3,Allayne,Chatainier,achatainier2@trellian.com,Male,191.118.4.217
...&lt;/pre&gt;
&lt;p&gt;To represent this data, I&#39;ve created a POJO called &lt;code&gt;FakePeople.java&lt;/code&gt;, which looks like this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;import lombok.Data;
public @Data class FakePeople {
    final int id;
    final private String firstName;
    final private String lastName;
    final private String email;
    final private String gender;
    final private String ipAddress;
}

&lt;/pre&gt;
&lt;p&gt;I&#39;m using &lt;a href=&quot;https://projectlombok.org/&quot; class=&quot;bodyclass&quot;&gt;Project Lombok&lt;/a&gt; here, to generate the required Getters, Setters and other POJO methods. (If you don&#39;t know about Lombok, you should definitely check that out. It is quite handy).&lt;/p&gt;
&lt;p&gt;We have our POJO now, Let&#39;s get a parametrized Dataset. To achieve this we first need to create an &lt;code&gt;Encoder&lt;/code&gt;. We do that for the &lt;code&gt;FakePeople&lt;/code&gt; class as following:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Encoder&amp;lt;FakePeople&amp;gt; fakePeopleEncoder = Encoders.bean(FakePeople.class);&lt;/pre&gt;
&lt;p&gt;This will register our encoder which will help us parse our CSV data.&lt;/p&gt;
&lt;p&gt;Of course we need our spark session variable as well.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;// Initialize Sparksession
SparkSession spark = SparkSession.builder().appName(&amp;quot;Freblogg-Spark&amp;quot;).master(&amp;quot;local&amp;quot;).getOrCreate();&lt;/pre&gt;
&lt;p&gt;Now we can go ahead and read the CSV file, very much like the way we did before with just one addition.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;// Without Encoder
Dataset&amp;lt;Row&amp;gt; people = spark.read().option(&amp;quot;header&amp;quot;, &amp;quot;true&amp;quot;).csv(&amp;quot;fake-people.csv&amp;quot;);

// With Encoder
Dataset&amp;lt;FakePeople&amp;gt; people = spark.read().option(&amp;quot;header&amp;quot;, &amp;quot;true&amp;quot;).csv(&amp;quot;fake-people.csv&amp;quot;).as(fakePeopleEncoder);&lt;/pre&gt;
&lt;p&gt;And the output of &lt;code&gt;people.show(5)&lt;/code&gt; is the same as what you&#39;d expect.&lt;/p&gt;
&lt;pre class=&quot;text&quot;&gt;&lt;span style=&quot;font-size: 85%&quot;&gt;+---+----------+----------+--------------------+------+--------------+
| id|first_name| last_name|               email|gender|    ip_address|
+---+----------+----------+--------------------+------+--------------+
|  1|     Netti|   McKirdy|nmckirdy0@slidesh...|Female| 148.3.248.193|
|  2|    Nickey|   Curreen|ncurreen1@tripadv...|  Male|  206.9.48.216|
|  3|   Allayne|Chatainier|achatainier2@trel...|  Male| 191.118.4.217|
|  4|     Tades|    Emmett|temmett3@barnesan...|  Male|153.113.87.195|
|  5|     Shawn|    McGenn|smcgenn4@shop-pro.jp|  Male|  247.45.80.68|
+---+----------+----------+--------------------+------+--------------+&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As you can see the only difference in creating the Dataset is &lt;code&gt;.as(fakePeopleEncoder)&lt;/code&gt; and that gets us &lt;code&gt;Dataset&amp;lt;FakePeople&amp;gt;&lt;/code&gt; instead of &lt;code&gt;Dataset&amp;lt;Row&amp;gt;&lt;/code&gt;. And with that, we now have access to all the getters, setters of &lt;code&gt;FakePeople&lt;/code&gt; class which we wouldn&#39;t otherwise have with a &lt;code&gt;Row&lt;/code&gt; object. We&#39;ll explore more about how this is useful in a future tutorial.&lt;/p&gt;
&lt;p&gt;For more information on Datasets: &lt;a href=&quot;https://spark.apache.org/docs/latest/sql-programming-guide.html&quot; class=&quot;bodyclass&quot;&gt;Spark SQL, DataFrames and Datasets Guide&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That is all for this article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more programming articles, checkout &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Freblogg&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Apache%20Spark&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Spark&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Apache Spark articles:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2016/06/spark-word-count-with-java.html&quot; class=&quot;bodyclass&quot;&gt;Word count with Apache Spark and Java&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2017/12/apache-spark-datasets-1.html&quot; class=&quot;bodyclass&quot;&gt;Datasets in Apache Spark | Part 1&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2017/12/apache-spark-datasets-2.html&quot; class=&quot;bodyclass&quot;&gt;Datasets in Apache Spark | Part 2&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the 11th article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot; class=&quot;bodyclass&quot;&gt;#31DaysOfBlogging&lt;/a&gt;. Nineteen more articles on various topics, including but not limited to, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot; class=&quot;bodyclass&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot; class=&quot;bodyclass&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot; class=&quot;bodyclass&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot; class=&quot;bodyclass&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you&#39;re at it, Go ahead and subscribe &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;here on medium&lt;/a&gt; and my &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;other blog&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven&#39;t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot; class=&quot;bodyclass&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in its functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/5499065943074593951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/apache-spark-datasets-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/5499065943074593951'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/5499065943074593951'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2018/01/apache-spark-datasets-2.html' title='Datasets In Apache Spark | Part 2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-1236771032443243229</id><published>2017-12-31T12:37:00.000+00:00</published><updated>2017-12-31T12:44:57.592+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Automation"/><category scheme="http://www.blogger.com/atom/ns#" term="Blogging"/><category scheme="http://www.blogger.com/atom/ns#" term="How To"/><category scheme="http://www.blogger.com/atom/ns#" term="Medium"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Tweepy"/><category scheme="http://www.blogger.com/atom/ns#" term="Twitter"/><category scheme="http://www.blogger.com/atom/ns#" term="Vim"/><title type='text'>My Almost Fully Automated Blogging Workflow</title><content type='html'>&lt;!--
Title : My Almost Fully Automated Blogging Workflow
Labels: Python, Automation, Blogging, How To, Medium, Twitter, Tweepy, Vim
PostId: 
Destination: Blogger
--&gt;
&lt;p&gt;In the article &lt;a href=&quot;https://medium.com/@durgaswaroop/my-semi-automated-blogging-workflow-62cba2827986&quot; class=&quot;bodyclass&quot;&gt;My semi automated workflow for blogging&lt;/a&gt;, I have outlined what my blogging process is like and how I&#39;ve started to automate it. Ofcourse, at the time of that article, the process was still in early stages and I hadn&#39;t automated everything I do. And, that&#39;s where this article comes in. This is the second attempt at automating my entire Blogging workflow.&lt;/p&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*dUMvQW8ynuO4qw2ceGF0BA.png&quot; alt=&quot;Medium blogger python logo&quot; class=&quot;aligncenter&quot; /&gt;
&lt;p&gt;Just to give you some context, here are the things that I do when I&#39;m blogging.&lt;/p&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Open a markdown file in Vim with the title of the article as the name along with some template text&lt;/li&gt;
&lt;li&gt;Open a browser with the html of the newly created markdown file&lt;/li&gt;
&lt;li&gt;Convert markdown to html with pandoc several times during the writing process&lt;/li&gt;
&lt;li&gt;Once the article is done and html is produced, edit the html to make some changes specific based on whether I&#39;m publishing on &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;Medium&lt;/a&gt; or if I&#39;m publishing on &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Blogger&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Read the tags/labels and other attributes from the file and Publish the code as draft on Medium or Blogger.&lt;/li&gt;
&lt;li&gt;Once it looks good, Schedule or Publish it (This is a manual process. There&#39;s no denying it.)&lt;/li&gt;
&lt;li&gt;Finally tweet about the post with the link to the article&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I have the individual pieces of this process ready. I have already written about them in the following articles.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/my-semi-automated-blogging-workflow-62cba2827986&quot; class=&quot;bodyclass&quot;&gt;Semi Automated Blogging Workflow&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/publish-articles-on-blogger-in-just-one-second-2ef45586901&quot; class=&quot;bodyclass&quot;&gt;Publish Articles To Blogger In One Second&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2017/12/publish-articles-to-your-medium-blog-in_83.html&quot; class=&quot;bodyclass&quot;&gt;Publish Articles To Medium In One Second&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.freblogg.com/2017/12/tweeting-with-python-and-tweepy.html&quot; class=&quot;bodyclass&quot;&gt;Tweeting With Python &amp;amp; Tweepy&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now, since the individual pieces are ready, it might seem that everything is done. But, as it turns out (unsurprisingly), the integration is of-course a big deal and took a lot more effort than I was expecting. And I am documenting that in this article along with the complete flow.&lt;/p&gt;
&lt;p&gt;It starts with the script &lt;code&gt;blog-it&lt;/code&gt; which opens vim for me, opens chrome and also sets up a process for converting markdown to html, continuously.&lt;/p&gt;
&lt;script src=&quot;https://gist.github.com/durgaswaroop/8ed9a5a55b8629f2180880665866f30e.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;That script calls &lt;code&gt;blog.py&lt;/code&gt; which is what opens the vim along with the default text template. I would like to put the &lt;a href=&quot;https://gist.github.com/durgaswaroop/78c51da2d74944d9e5a936cd18733f85&quot; class=&quot;bodyclass&quot;&gt;complete gist&lt;/a&gt; here, but it is just too long and so instead I&#39;m showing the meat of the script.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;article_title = title.replace(&amp;quot;_&amp;quot;, &amp;quot; &amp;quot;).title()

# Create the markdown file and add the title
f = open(md_file, &amp;quot;w+&amp;quot;)
f.write(generate_comments_header(article_title))
f.write(article_title)  # Replace underscores and title case it
f.write(&amp;quot;\n&amp;quot;)
f.write(&amp;quot;-&amp;quot; * len(title))
f.write(&amp;quot;\n&amp;quot;)
f.write(generate_footer_text())
f.close()

# Now, create the html file
html_file = title + &amp;quot;.html&amp;quot;
open(html_file, &amp;quot;w&amp;quot;).close()

# Start vim with the markdown file open on line #10
subprocess.run([&amp;#39;C:/Program Files (x86)/Vim/vim80/gvim.exe&amp;#39;, &amp;#39;+10&amp;#39;, md_file])&lt;/pre&gt;
&lt;p&gt;Then comes &lt;code&gt;m2h&lt;/code&gt; which continuously converts markdown to html.&lt;/p&gt;
&lt;script src=&quot;https://gist.github.com/durgaswaroop/356c3aac4f8ce8f89501693b4d9bcb27.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;This ends one flow. Next comes, publishing. I have broken this down because publishing is a manual process for me unless I can complete the entire article in one sitting, which is never going to be possible. So, Once I&#39;m doing with writing it, I&#39;ll start the publishing.&lt;/p&gt;
&lt;p&gt;I&#39;ll run &lt;code&gt;publish.py&lt;/code&gt; which depending on the comments in the html publishes it to either &lt;code&gt;Blogger&lt;/code&gt; or &lt;code&gt;Medium&lt;/code&gt;. Again, I&#39;m only showing a part of it. The full gist is available &lt;a href=&quot;https://gist.github.com/durgaswaroop/4a81aabeca3bd91cccb0ceb9bda31663&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;with open(html_file) as file:
    html_file_contents = file.read()

re_comments = re.compile(&amp;#39;\s*&amp;lt;!--(.*)--&amp;gt;&amp;#39;, re.DOTALL)
comments_text = re_comments.search(html_file_contents).group(1).strip()
comments_parser = CommentParser.parse_comments(comments_text)

if comments_parser.destination.lower() == &amp;#39;blogger&amp;#39;:
    blogger_publish.publish(html_file, comments_parser.title, comments_parser.labels, comments_parser.post_id)
elif comments_parser.destination.lower() == &amp;#39;medium&amp;#39;:
    medium_publish.publish(html_file, comments_parser.title, comments_parser.labels)
else:
    print(
        &amp;#39;Unknown destination: &amp;#39; + comments_parser.destination + &amp;#39;. Supported destinations are Blogger and Medium.&amp;#39;)&lt;/pre&gt;
&lt;p&gt;Then comes the individual publishing scripts that publish to blogger and medium.&lt;/p&gt;
&lt;p&gt;For &lt;code&gt;blogger-publish.py&lt;/code&gt; (Gist &lt;a href=&quot;https://gist.github.com/durgaswaroop/20bef02450137907d01f794ba99b965c&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;), I do any required modifications with &lt;code&gt;blogger_modifications.py&lt;/code&gt; (Gist &lt;a href=&quot;https://gist.github.com/durgaswaroop/dd9dcb1e592751c1aced5f0f42aeedc1&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;) which converts some tags as expected my blogger page.&lt;/p&gt;
&lt;p&gt;Then for &lt;code&gt;medium-publish.py&lt;/code&gt; (Gist &lt;a href=&quot;https://gist.github.com/durgaswaroop/f6fbcc910ddcc5b3fa7a0c1cdbd57401&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;), I take the parameters and publish to blogger as html. No, modifications needed to be done here.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;access_token_file = &amp;#39;~/.medium-access-token&amp;#39;
expanded_path = os.path.expanduser(access_token_file)
with open(expanded_path) as file:
  access_token = file.read().strip()

headers = get_headers(access_token)
user_url = get_user_url(headers)

# Publish new post
posts_url = user_url + &amp;#39;posts/&amp;#39;
payload = generate_payload(title, labels, html_file)
response = requests.request(&amp;#39;POST&amp;#39;, posts_url, data=payload, headers=headers)&lt;/pre&gt;
&lt;p&gt;Actually this publishing does send it to the site as a draft instead of actually publishing it. This is a step that I don&#39;t know how to automate as I have to manually take a look at how the article looks in preview. May be I should try doing this with selenium or something like that.&lt;/p&gt;
&lt;p&gt;Once, I&#39;ve verified that the post looks good, I will publish it and take the URL of the published article and call the &lt;code&gt;tweeter.py&lt;/code&gt; (Gist &lt;a href=&quot;https://gist.github.com/durgaswaroop/2169cd8c89cc6a9d89134a414bb49b9c&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;) which then opens a Vim file with some default text for title, and URL already filled in along with some hashtags. I&#39;ll complete the tweet and once, I close it, It gets published on Twitter.&lt;/p&gt;
&lt;p&gt;And that completes the process. Obviously there are still a couple of manual steps. Although I can&#39;t eliminate all of them, I might be able to minimize them as well. But, so far it looks pretty good especially with just the little effort I&#39;ve put into this in just one week. Of course, I&#39;ll keep on tuning it as needed to make it even better and may be I&#39;ll publish one final article for that.&lt;/p&gt;
&lt;p&gt;That is all for this article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more programming articles, checkout &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Freblogg&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Python&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some articles on automation:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/web-scraping-with-python-introduction-7b3c0bbb6053&quot; class=&quot;bodyclass&quot;&gt;Web Scraping For Beginners with Python&lt;/a&gt; &lt;a href=&quot;https://medium.com/@durgaswaroop/my-semi-automated-blogging-workflow-62cba2827986&quot; class=&quot;bodyclass&quot;&gt;My semi automated workflow for blogging&lt;/a&gt; &lt;a href=&quot;https://medium.com/@durgaswaroop/publish-articles-on-blogger-in-just-one-second-2ef45586901&quot; class=&quot;bodyclass&quot;&gt;Publish articles to Blogger automatically&lt;/a&gt; &lt;a href=&quot;http://www.freblogg.com/2017/12/publish-articles-to-your-medium-blog-in_83.html&quot; class=&quot;bodyclass&quot;&gt;Publish articles to Medium automatically&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the 9th article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot; class=&quot;bodyclass&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Twenty one more articles on various topics, including but not limited to, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot; class=&quot;bodyclass&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot; class=&quot;bodyclass&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot; class=&quot;bodyclass&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot; class=&quot;bodyclass&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you&#39;re at it, Go ahead and subscribe &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;here on medium&lt;/a&gt; and my &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;other blog&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven&#39;t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot; class=&quot;bodyclass&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in its functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/1236771032443243229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/my-automated-blogging-workflow.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/1236771032443243229'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/1236771032443243229'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/my-automated-blogging-workflow.html' title='My Almost Fully Automated Blogging Workflow'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-8459371640122855692</id><published>2017-12-29T14:27:00.000+00:00</published><updated>2017-12-29T14:27:36.740+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="API"/><category scheme="http://www.blogger.com/atom/ns#" term="Blogging tips"/><category scheme="http://www.blogger.com/atom/ns#" term="How To"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Publish Articles To Your Medium Blog In One Second With Integration Tokens</title><content type='html'>&lt;!--
Title: Publish Articles To Your Medium Blog In One Second
Labels: Python, API, Blogging tips, How To, Programming
PostId:
--&gt;
&lt;p&gt;In my article &lt;a href=&quot;https://medium.com/@durgaswaroop/my-semi-automated-blogging-workflow-62cba2827986&quot; class=&quot;bodyclass&quot;&gt;My semi automated workflow for blogging&lt;/a&gt;, I have talked about my blogging workflow. There were two main things (actually one thing) in that flow that were not automated. i.e., automatically Uploading to Blogger and automatically Uploading to Medium. I have talked about the first one &lt;a href=&quot;https://medium.com/@durgaswaroop/publish-articles-on-blogger-in-just-one-second-2ef45586901&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;. This article is about uploading posts to Medium automatically.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/w_400,h_300,c_thumb/z6odfvngwx1gp60murhe/1473332149.png&quot; alt=&quot;Medium Logo&quot; class=&quot;aligncenter&quot; /&gt; &lt;/p&gt;
&lt;p&gt;Developer documentation for Medium is a breath of fresh air after the mess that is Google API’s. Of course, Google API’s are complex because they have so many different services, but they could’ve done a better job at organizing all that stuff. Anyway, Let’s see how you can use Medium API’s.&lt;/p&gt;
&lt;h3 id=&quot;setting-up&quot;&gt;Setting Up&lt;/h3&gt;
&lt;p&gt;We don’t really need any specific dependencies for what we’re doing in this article. You can do everything with &lt;code&gt;urllib&lt;/code&gt; which is already part of the python standard library. I’ll be using &lt;code&gt;requests&lt;/code&gt; as well to make it a bit more simpler but you can achieve the same without it.&lt;/p&gt;
&lt;h3 id=&quot;getting-the-access-token&quot;&gt;Getting the access token&lt;/h3&gt;
&lt;p&gt;To authenticate yourself with Medium, you need to get an access token that you’ll pass along to every request. There are two ways to get that token.&lt;/p&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Browser-based authentication&lt;/li&gt;
&lt;li&gt;Self-issues access tokens&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Which one you should go with, depends on what kind of application you’re trying to build. As you can probably guess based on the title, we’ll be covering the second method in this article. The first method needs an authentication server setup which can accept callback from Medium. But, since at this moment, I don’t have that setup, I’m going with the second option.&lt;/p&gt;
&lt;p&gt;The Self-issued access tokens method is quite easy to work with as you directly take the &lt;code&gt;access token&lt;/code&gt; without having to have the user authenticate via the browser.&lt;/p&gt;
&lt;p&gt;To get the access token, Go to &lt;a href=&quot;https://medium.com/me/settings&quot; class=&quot;bodyclass&quot;&gt;Profile Settings&lt;/a&gt; and scroll down till you see &lt;code&gt;Integration tokens&lt;/code&gt; section.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/7.Medium-integration-tokens-section.png&quot; alt=&quot;Medium Integration tokens&quot; class=&quot;aligncenter&quot; /&gt; &lt;/p&gt;
&lt;p&gt;There enter some description for what you’re going to use this token and click on &lt;code&gt;Get integration token&lt;/code&gt;. Copy that generated token which looks something like &lt;code&gt;181d415f34379af07b2c11d144dfbe35d&lt;/code&gt; and save it some where to be used in your program.&lt;/p&gt;
&lt;h3 id=&quot;using-access-token-to-access-medium&quot;&gt;Using Access token to access Medium&lt;/h3&gt;
&lt;p&gt;Once you have the access token, you’ll use that token as your password and send it along with every request to get the required data.&lt;/p&gt;
&lt;p&gt;Let’s get started then. As, I’ve said we’ll be using &lt;code&gt;requests&lt;/code&gt; library for url connections. We’ll also be using the &lt;code&gt;json&lt;/code&gt; libary for parsing the responses. So, Let’s import them.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;import requests
import json&lt;/pre&gt;
&lt;p&gt;Then use &lt;code&gt;access_token&lt;/code&gt; you’ve got and put it in a &lt;code&gt;headers&lt;/code&gt; dictionary.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;access_token = &amp;#39;181d415f34379af07b2c11d144dfbe35d&amp;#39;
headers = {
    &amp;#39;Authorization&amp;#39;: &amp;quot;Bearer &amp;quot; + access_token,
    &amp;#39;User-Agent&amp;#39;: &amp;#39;Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36&amp;#39;
}&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;User-Agent&lt;/code&gt; in the above dictionary is required as Medium won’t accept your request otherwise. You don’t have to have the same value as I did.&lt;/p&gt;
&lt;h4 id=&quot;validating-the-access-token&quot;&gt;Validating the access token&lt;/h4&gt;
&lt;p&gt;First thing to check is if the access_token is valid. You can do that by making a &lt;code&gt;GET&lt;/code&gt; request to &lt;code&gt;https://api.medium.com/v1/me&lt;/code&gt; and checking the response.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;me_url = base_url + &amp;#39;me&amp;#39;
me_req = ureq.Request(me_url, headers=headers)
me_response = ureq.urlopen(me_req).read()
json_me_response = json.loads(me_response)
print(json_me_response)&lt;/pre&gt;
&lt;p&gt;And, when I print the &lt;code&gt;json_me_response&lt;/code&gt;, which is a json object, I get the following:&lt;/p&gt;
&lt;pre&gt;{
&amp;quot;data&amp;quot;: {
  &amp;quot;id&amp;quot;:&amp;quot;5303d74c64f66366f00cb9b2a94f3251bf5adskak7623as&amp;quot;,
  &amp;quot;username&amp;quot;:&amp;quot;durgaswaroop&amp;quot;, 
  &amp;quot;name&amp;quot;:&amp;quot;Durga swaroop Perla&amp;quot;, 
  &amp;quot;url&amp;quot;:&amp;quot;https://medium.com/@durgaswaroop&amp;quot;,
  &amp;quot;imageUrl&amp;quot;:&amp;quot;https://cdn-images-1.medium.com/fit/c/400/400/0*qVDXEHT9DDYUOcrj.&amp;quot;
  }
}&lt;/pre&gt;
&lt;p&gt;If we got that response like above, then we know that the access token we have is valid.&lt;/p&gt;
&lt;p&gt;From there, I extract, the &lt;code&gt;user_id&lt;/code&gt; from the JSON string, with&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;user_id = json_me_response[&amp;#39;data&amp;#39;][&amp;#39;id&amp;#39;]&lt;/pre&gt;
&lt;h4 id=&quot;get-users-publications&quot;&gt;Get User’s Publications&lt;/h4&gt;
&lt;p&gt;From the above request, we’ve validated that the access token is correct and we also have got the &lt;code&gt;user_id&lt;/code&gt;. Using that we can get access to the publications of a user. For that, we’ve to make a &lt;code&gt;GET&lt;/code&gt; to &lt;code&gt;https://api.medium.com/v1/users/{{userId}}/publications&lt;/code&gt; and you’ll see the list of the publications by that user.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;user_url = base_url + &amp;#39;users/&amp;#39; + user_id
publications_url = user_url + &amp;#39;publications/&amp;#39;
publications_req = ureq.Request(publications_url, headers=headers)
publications_response = ureq.urlopen(publications_req).read()
print(publications_response)  &lt;/pre&gt;
&lt;p&gt;I don’t have any publications on my medium account, and so I got an empty array as response. But, if you have some publications, the response will be something like this.&lt;/p&gt;
&lt;pre&gt;{
  &amp;quot;data&amp;quot;: [
    {
      &amp;quot;id&amp;quot;: &amp;quot;b969ac62a46b&amp;quot;,
      &amp;quot;name&amp;quot;: &amp;quot;About Medium&amp;quot;,
      &amp;quot;description&amp;quot;: &amp;quot;What is this thing and how does it work?&amp;quot;,
      &amp;quot;url&amp;quot;: &amp;quot;https://medium.com/about&amp;quot;,
      &amp;quot;imageUrl&amp;quot;: &amp;quot;https://cdn-images-1.medium.com/fit/c/200/200/0*ae1jbP_od0W6EulE.jpeg&amp;quot;
    },
    {
      &amp;quot;id&amp;quot;: &amp;quot;b45573563f5a&amp;quot;,
      &amp;quot;name&amp;quot;: &amp;quot;Developers&amp;quot;,
      &amp;quot;description&amp;quot;: &amp;quot;Medium’s Developer resources&amp;quot;,
      &amp;quot;url&amp;quot;: &amp;quot;https://medium.com/developers&amp;quot;,
      &amp;quot;imageUrl&amp;quot;: &amp;quot;https://cdn-images-1.medium.com/fit/c/200/200/1*ccokMT4VXmDDO1EoQQHkzg@2x.png&amp;quot;
    }
  ]
}&lt;/pre&gt;
&lt;p&gt;Now, one weird thing about Medium’s API is that they don’t have a &lt;code&gt;GET&lt;/code&gt; for posts. From the API’s we can get a list of all the publications but you can’t get a user’s posts. You can only publish a new post. Although, it is odd for that to be missing, It is not something I’m looking for anyway, as I am only interested in publishing an article. But if you need that, you probably should check to see if there are any hacky ways of achieving the same (at your own volition).&lt;/p&gt;
&lt;h4 id=&quot;create-a-new-post&quot;&gt;Create a New Post&lt;/h4&gt;
&lt;p&gt;To create a new post, we have to make a &lt;code&gt;POST&lt;/code&gt; request to &lt;code&gt;https://api.medium.com/v1/users/{{authorId}}/posts&lt;/code&gt;. The &lt;code&gt;authorId&lt;/code&gt; here would be the same as the &lt;code&gt;userId&lt;/code&gt; of the user whose access-token you have.&lt;/p&gt;
&lt;p&gt;I’m using &lt;code&gt;requests&lt;/code&gt; library for this as making a &lt;code&gt;POST&lt;/code&gt; request becomes easy with it. Of course, first you need to create a payload to be uploaded. The payload should look something like the following, as described &lt;a href=&quot;https://github.com/Medium/medium-api-docs#33-posts&quot; class=&quot;bodyclass&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;{
  &amp;quot;title&amp;quot;: &amp;quot;Liverpool FC&amp;quot;,
  &amp;quot;contentFormat&amp;quot;: &amp;quot;html&amp;quot;,
  &amp;quot;content&amp;quot;: &amp;quot;&amp;lt;h1&amp;gt;Liverpool FC&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;You’ll never walk alone.&amp;lt;/p&amp;gt;&amp;quot;,
  &amp;quot;tags&amp;quot;: [&amp;quot;football&amp;quot;, &amp;quot;sport&amp;quot;, &amp;quot;Liverpool&amp;quot;],
  &amp;quot;publishStatus&amp;quot;: &amp;quot;public&amp;quot;
}&lt;/pre&gt;
&lt;p&gt;So, for this, I did the following:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;posts_url = user_url + &amp;#39;posts/&amp;#39;

payload = {
    &amp;#39;title&amp;#39;: &amp;#39;Medium Test Post&amp;#39;,
    &amp;#39;contentFormat&amp;#39;: &amp;#39;markdown&amp;#39;,
    &amp;#39;tags&amp;#39;: [&amp;#39;medium&amp;#39;, &amp;#39;test&amp;#39;, &amp;#39;python&amp;#39;],
    &amp;#39;publishStatus&amp;#39;: &amp;#39;draft&amp;#39;,
    &amp;#39;content&amp;#39;: open(&amp;#39;7.Test_post.md&amp;#39;).read()
}

response = requests.request(&amp;#39;POST&amp;#39;, posts_url, data=payload, headers=headers)
print(response.text)&lt;/pre&gt;
&lt;p&gt;As you see, for &lt;code&gt;contentFormat&lt;/code&gt;, I’ve set &lt;code&gt;markdown&lt;/code&gt; and for &lt;code&gt;content&lt;/code&gt; I read it straight from the file. I didn’t want to publish this as it is just a dummy post and so I’ve set the &lt;code&gt;publishStatus&lt;/code&gt; to &lt;code&gt;draft&lt;/code&gt;. And sure enough, it works as expected and I can see this draft added on my account.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/7.Medium-draft-posts.png&quot; alt=&quot;Draft post&quot; class=&quot;aligncenter&quot; /&gt; &lt;/p&gt;
&lt;p&gt;Do note that the &lt;code&gt;title&lt;/code&gt; in the payload object won’t actually be the title of the article. If you want to have a title, you add it in the &lt;code&gt;content&lt;/code&gt; itself as a &lt;code&gt;&amp;lt;h*&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;
&lt;p&gt;The full code is available as a gist.&lt;/p&gt;
&lt;script src=&quot;https://gist.github.com/durgaswaroop/a0c5e1f772ec231d2254db43e2b26b93.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;That is all for this article.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more programming and Python articles, checkout &lt;a href=&quot;http://freblogg.com&quot;&gt;Freblogg&lt;/a&gt; and &lt;a href=&quot;http://www.freblogg.com/search/label/Python&quot;&gt;Freblogg/Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some articles on automation:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/web-scraping-with-python-introduction-7b3c0bbb6053&quot;&gt;Web Scraping For Beginners with Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@durgaswaroop/my-semi-automated-blogging-workflow-62cba2827986&quot;&gt;My semi automated workflow for blogging&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the seventh article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Twenty-three more articles on various topics including but not limited to &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you’re at it, Go ahead and subscribe to this blog and my &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;blog on Medium&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven’t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in the functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/8459371640122855692/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/publish-articles-to-your-medium-blog-in_83.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/8459371640122855692'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/8459371640122855692'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/publish-articles-to-your-medium-blog-in_83.html' title='Publish Articles To Your Medium Blog In One Second With Integration Tokens'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-4373440216421990005</id><published>2017-12-27T14:30:00.000+00:00</published><updated>2018-01-01T18:22:00.103+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Analytics"/><category scheme="http://www.blogger.com/atom/ns#" term="Apache Spark"/><category scheme="http://www.blogger.com/atom/ns#" term="Big Data"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Science"/><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="How To"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Machine Learning"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorials"/><title type='text'>Datasets in Apache Spark | Part 1</title><content type='html'>&lt;p&gt;In my &lt;a href=&quot;http://www.freblogg.com/2016/06/spark-word-count-with-java.html&quot; class=&quot;bodyclass&quot;&gt;previous post&lt;/a&gt; I have talked about Apache Spark. We have also built an application for counting the number of words in a file, which is the hello world equivalent of the big data world.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://redislabs.com/wp-content/uploads/2016/12/spark.png&quot; alt=&quot;Apache spark Java Logo’s&quot; class=&quot;centeralign&quot; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;It has been over 18 months since that article and spark has changed quite a lot in this time. A new major release of spark, which is spark-2.0 came out and now the latest version is &lt;a href=&quot;https://spark.apache.org/news/spark-2-2-1-released.html&quot; class=&quot;bodyclass&quot;&gt;2.2.1&lt;/a&gt;. And with a new version comes new API’s and improvements. In-fact the first thing you’ll probably notice is that, you don’t need to create &lt;code&gt;SparkContext&lt;/code&gt; or &lt;code&gt;JavaSparkContext&lt;/code&gt; objects anymore. The various context and configurations have been put together into a new class &lt;code&gt;SparkSession&lt;/code&gt;. You can still access the SparkContext or the SqlContext from the &lt;code&gt;SparkSession&lt;/code&gt; object itself. So, you’ll be starting your programs with this now:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;SparkSession spark = SparkSession.builder().appName(&amp;quot;Freblogg-Spark&amp;quot;).master(&amp;quot;local&amp;quot;).getOrCreate();&lt;/pre&gt;
&lt;p&gt;And you can use this &lt;code&gt;spark&lt;/code&gt; variable the way you’d use other context variables.&lt;/p&gt;
&lt;p&gt;Another change in Spark 2.0 is that, there is a heavy emphasis on the usage of &lt;code&gt;Dataset&lt;/code&gt; API’s, and for a good reason. &lt;em&gt;Datasets are more performant and memory efficient than RDD’s&lt;/em&gt;. RDD (Resilient Distributed Datasets) have been pushed to second place now. You can still use RDD’s if you want but Datasets are the preferred API. In fact, datasets have some nice convenience methods that we can use them for even unstructured data like text as well. Let’s generate some cool lipsum from &lt;a href=&quot;http://www.malevole.com/mv/misc/text/&quot; class=&quot;bodyclass&quot;&gt;Malevole&lt;/a&gt;. It looks something like this:&lt;/p&gt;
&lt;pre&gt;Ulysses, Ulysses - Soaring through all the galaxies. In search of Earth, flying in to the night. Ulysses, Ulysses - Fighting evil 
and tyranny, with all his power, and with all of his might. Ulysses - no-one else can do the things you do. Ulysses - like a bolt of
thunder from the blue. Ulysses - always fighting all the evil forces bringing peace and justice to all....&lt;/pre&gt;
&lt;p&gt;Now, you might try to use an RDD to read this, but let’s see what we can do with Datasets.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Dataset&amp;lt;String&amp;gt; lipsumDs = spark.read().textFile(&amp;quot;fake-text.txt&amp;quot;);
lipsumDs.show(5);&lt;/pre&gt;
&lt;p&gt;Here we are reading the text file using the &lt;code&gt;spark&lt;/code&gt; object we created earlier and that gives us a &lt;code&gt;Dataset&amp;lt;String&amp;gt;&lt;/code&gt; &lt;code&gt;lipsumDs&lt;/code&gt;. The &lt;code&gt;show()&lt;/code&gt; method on the dataset object prints the dataset. And we get the following output:&lt;/p&gt;
&lt;pre&gt;
+--------------------+
|               value|
+--------------------+
|Ulysses, Ulysses ...|
|Ulysses, Ulysses ...|
| no-one else can ...|
|  always fighting...|
|                    |
+--------------------+
&lt;/pre&gt;
&lt;p&gt;What we see here are the lines of the text file. Each line in the file is now a row in the Dataset. There are now a rich set of functions available to you in Datasets which weren’t in RDD’s. You can do filters on the rows for certain words, do a count on the table, perform &lt;code&gt;groupBy&lt;/code&gt; operations, etc all like you would on a Database table. For a full list of all the available operations on Dataset, read this: &lt;a href=&quot;https://spark.apache.org/docs/latest/api/java/index.html&quot; class=&quot;bodyclass&quot;&gt;Dataset: Spark Documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I hope that’s enough talk about unstructured data analysis. Let’s get to the main focus of this article, which is using Datasets for structured data. More specifically, &lt;code&gt;csv&lt;/code&gt; and &lt;code&gt;json&lt;/code&gt;. For this tutorial, I am using the data created from &lt;a href=&quot;http://www.mockaroo.com/&quot; class=&quot;bodyclass&quot;&gt;Mockaroo&lt;/a&gt;, an online data generator. I’ve created 1000 csv records that look like this:&lt;/p&gt;
&lt;pre&gt;
id,first_name,last_name,email,gender,ip_address
1,Netti,McKirdy,nmckirdy0@slideshare.net,Female,148.3.248.193
2,Nickey,Curreen,ncurreen1@tripadvisor.com,Male,206.9.48.216
3,Allayne,Chatainier,achatainier2@trellian.com,Male,191.118.4.217
4,Tades,Emmett,temmett3@barnesandnoble.com,Male,153.113.87.195
5,Shawn,McGenn,smcgenn4@shop-pro.jp,Male,247.45.80.68
6,Giuseppe,Scobbie,gscobbie5@twitter.com,Male,123.114.131.200
...
&lt;/pre&gt;
&lt;p&gt;We’ll use this data, which I’ve put in a file named &lt;code&gt;fake-people.csv&lt;/code&gt;, to work with Datasets. Let’s create a Dataset out of this csv data.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Dataset&amp;lt;Row&amp;gt; peopleDs = spark.read().option(&amp;quot;header&amp;quot;, &amp;quot;true&amp;quot;).csv(&amp;quot;fake-people.csv&amp;quot;);
peopleDs.show(5);&lt;/pre&gt;
&lt;p&gt;Since we’ve column headers in our data, we add the &lt;code&gt;.option(&amp;quot;header&amp;quot;, &amp;quot;true&amp;quot;)&lt;/code&gt; and the output is a nicely formatted table of the data with all the columns like this:&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;font-size: 85%&quot;&gt;
+---+----------+----------+--------------------+------+--------------+
| id|first_name| last_name|               email|gender|    ip_address|
+---+----------+----------+--------------------+------+--------------+
|  1|     Netti|   McKirdy|nmckirdy0@slidesh...|Female| 148.3.248.193|
|  2|    Nickey|   Curreen|ncurreen1@tripadv...|  Male|  206.9.48.216|
|  3|   Allayne|Chatainier|achatainier2@trel...|  Male| 191.118.4.217|
|  4|     Tades|    Emmett|temmett3@barnesan...|  Male|153.113.87.195|
|  5|     Shawn|    McGenn|smcgenn4@shop-pro.jp|  Male|  247.45.80.68|
+---+----------+----------+--------------------+------+--------------+
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;You can read in &lt;code&gt;json&lt;/code&gt; data similarly as well. So, I generated some json this time from mockaroo.&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;font-size: 85%&quot;&gt;{&amp;quot;id&amp;quot;:1,&amp;quot;first_name&amp;quot;:&amp;quot;Zenia&amp;quot;,&amp;quot;last_name&amp;quot;:&amp;quot;Joberne&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;zjoberne0@foxnews.com&amp;quot;,&amp;quot;gender&amp;quot;:&amp;quot;Female&amp;quot;,&amp;quot;ip_address&amp;quot;:&amp;quot;214.207.159.43&amp;quot;}
{&amp;quot;id&amp;quot;:2,&amp;quot;first_name&amp;quot;:&amp;quot;Renard&amp;quot;,&amp;quot;last_name&amp;quot;:&amp;quot;Kezor&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;rkezor1@elpais.com&amp;quot;,&amp;quot;gender&amp;quot;:&amp;quot;Male&amp;quot;,&amp;quot;ip_address&amp;quot;:&amp;quot;199.3.18.104&amp;quot;}
{&amp;quot;id&amp;quot;:3,&amp;quot;first_name&amp;quot;:&amp;quot;Briant&amp;quot;,&amp;quot;last_name&amp;quot;:&amp;quot;Patel&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;bpatel2@odnoklassniki.ru&amp;quot;,&amp;quot;gender&amp;quot;:&amp;quot;Male&amp;quot;,&amp;quot;ip_address&amp;quot;:&amp;quot;111.184.217.23&amp;quot;}
{&amp;quot;id&amp;quot;:4,&amp;quot;first_name&amp;quot;:&amp;quot;Robinett&amp;quot;,&amp;quot;last_name&amp;quot;:&amp;quot;Heasley&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;rheasley3@tiny.cc&amp;quot;,&amp;quot;gender&amp;quot;:&amp;quot;Female&amp;quot;,&amp;quot;ip_address&amp;quot;:&amp;quot;21.40.190.226&amp;quot;}
{&amp;quot;id&amp;quot;:5,&amp;quot;first_name&amp;quot;:&amp;quot;Rosalinda&amp;quot;,&amp;quot;last_name&amp;quot;:&amp;quot;Glandfield&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;rglandfield4@indiegogo.com&amp;quot;,&amp;quot;gender&amp;quot;:&amp;quot;Female&amp;quot;,&amp;quot;ip_address&amp;quot;:&amp;quot;26.16.4.132&amp;quot;}
{&amp;quot;id&amp;quot;:6,&amp;quot;first_name&amp;quot;:&amp;quot;Haslett&amp;quot;,&amp;quot;last_name&amp;quot;:&amp;quot;Culligan&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;hculligan5@meetup.com&amp;quot;,&amp;quot;gender&amp;quot;:&amp;quot;Male&amp;quot;,&amp;quot;ip_address&amp;quot;:&amp;quot;201.191.72.10&amp;quot;}
....&lt;/span&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: Spark can read json only of this format where we have one object per row. Otherwise you will see &lt;code&gt;_corrupt_record&lt;/code&gt; when you print your dataset. That’s your cue to make sure the json is formatted as per spark’s need.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And you read json very similar to the way you read csv. Since in json we don’t have headers, we don’t need the header option.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Dataset&amp;lt;Row&amp;gt; peopleJsonDs = spark.read().json(&amp;quot;fake-people.json&amp;quot;);
peopleJsonDs.show(5);&lt;/pre&gt;
&lt;p&gt;And the output is,&lt;/p&gt;
&lt;pre&gt;+--------------------+----------+------+---+--------------+---------+
|               email|first_name|gender| id|    ip_address|last_name|
+--------------------+----------+------+---+--------------+---------+
|psurgison0@istock...|   Prissie|Female|  1| 48.151.89.171| Surgison|
| rsewell1@jalbum.net|    Robena|Female|  2| 184.16.37.210|   Sewell|
|aluxon2@list-mana...| Annamarie|Female|  3| 254.69.187.23|    Luxon|
|sodoherty3@twitpi...|   Shannah|Female|  4| 0.245.101.197|O&amp;#39;Doherty|
| alodford4@jigsy.com|     Alice|Female|  5|70.217.170.182|  Lodford|
+--------------------+----------+------+---+--------------+---------+&lt;/pre&gt;
&lt;p&gt;You can see the order of columns is jumbled. This is because JSON data doesn’t usually keep any specified order and so, when you read JSON data into a dataset, the order might not be same as what you’ve given. Of course if you want to display the columns in a particular order, you can always do a &lt;code&gt;select&lt;/code&gt; operation.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;peopleJsonDs.select(&amp;quot;id&amp;quot;, &amp;quot;first_name&amp;quot;, &amp;quot;last_name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;gender&amp;quot;, &amp;quot;ip_address&amp;quot;).show(5);&lt;/pre&gt;
&lt;p&gt;And that would print it in the right order. This is exactly like the &lt;code&gt;SELECT&lt;/code&gt; query in SQL, if you’re familiar with it.&lt;/p&gt;
&lt;p&gt;Now, that we have seen how to create Datasets, let’s see some of the operations we can perform on them.&lt;/p&gt;
&lt;h3 id=&quot;operations-on-datasets&quot;&gt;Operations on Datasets&lt;/h3&gt;
&lt;p&gt;Datasets are built on top of Dataframes. So, if you’re already familiar with Dataframes in the spark 1.x releases you already know a ton about Datasets. Some of the operations you can perform on Dataset are as follows:&lt;/p&gt;
&lt;h4 id=&quot;column-selection&quot;&gt;Column selection&lt;/h4&gt;
Select one or more columns from the dataset.
&lt;pre class=&quot;prettyprint&quot;&gt;
peopleDs.select(&quot;email&quot;).show(5); // Selecting one column
peopleDs.select(col(&quot;email&quot;), col(&quot;gender&quot;)).show(5); // Selecting multiple columns
&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: &lt;code&gt;col&lt;/code&gt; is a static import of org.apache.spark.sql.functions.col;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;filtering-on-columns&quot;&gt;Filtering on columns&lt;/h4&gt;
Filter a subset of rows in the dataset based on conditions.
&lt;pre class=&quot;prettyprint&quot;&gt;
// Filter rows with id &gt; 5 and \&lt;= 10
peopleDs.filter(col(&quot;id&quot;).$less$eq(10).and(col(&quot;id&quot;).$greater(5))).show();
&lt;/pre&gt;
&lt;h4 id=&quot;dropping-columns&quot;&gt;Dropping columns&lt;/h4&gt;
Remove one or more columns from the dataset
&lt;pre class=&quot;prettyprint&quot;&gt;
peopleDs.drop(&quot;last_name&quot;, &quot;ip_address&quot;).show(5);
&lt;/pre&gt;
&lt;h4 id=&quot;sorting-on-columns&quot;&gt;Sorting on columns&lt;/h4&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
peopleDs.sort(desc(&quot;first_name&quot;)).show(5);
&lt;/pre&gt;
&lt;p&gt;And that sorts the dataset in the reverse order of the column &lt;code&gt;first_name&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;pre&gt;+---+----------+---------+--------------------+------+-------------+
| id|first_name|last_name|               email|gender|   ip_address|
+---+----------+---------+--------------------+------+-------------+
|685|  Zedekiah|  Brockie|zbrockiej0@mozill...|  Male|105.119.18.98|
|308|     Zarla| Bryceson|zbryceson8j@redif...|Female|55.118.168.15|
|636|  Zacherie|   Kermon|zkermonhn@prnewsw...|  Male| 120.36.10.87|&lt;/pre&gt;
&lt;p&gt;Those are some of the functions that you can use with Datasets. There are still several Database table type operations on Datasets, like group By, aggregations, joins, etc. We’ll look at them in the next article on Spark as I think this article already has a lot of information already and I don’t want to overload you with information.&lt;/p&gt;
&lt;p&gt;So, that is all for this article. If you’re someone that has never tried Datasets or Dataframes, I hope this article gave a good introduction on the topic to keep you interested in learning more.&lt;/p&gt;
&lt;p&gt;The full code is available as gist.&lt;/p&gt;
&lt;script src=&quot;https://gist.github.com/durgaswaroop/646ffb6283aa0238277aa16ae0771016.js&quot;&gt;&lt;/script&gt;
&lt;hr /&gt;
&lt;p&gt;For more Java, Apache Spark, Big data and other programming articles, checkout &lt;a href=&quot;http://freblogg.com&quot; class=&quot;bodyclass&quot;&gt;Freblogg&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Apache%20Spark&quot; class=&quot;bodyclass&quot;&gt;Freblogg/Spark&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This is the fifth article as part of my twitter challenge &lt;a href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot; class=&quot;bodyclass&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Twenty-five more articles on various topics including but not limited to &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; class=&quot;bodyclass&quot;&gt;Java&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Git&quot; class=&quot;bodyclass&quot;&gt;Git&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/label/Vim&quot; class=&quot;bodyclass&quot;&gt;Vim&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=software&quot; class=&quot;bodyclass&quot;&gt;Software Development&lt;/a&gt;, &lt;a href=&quot;http://www.freblogg.com/search/?q=python&quot; class=&quot;bodyclass&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a href=&quot;https://twitter.com/durgaswaroop&quot; class=&quot;bodyclass&quot;&gt;@durgaswaroop&lt;/a&gt;. While you’re at it, Go ahead and subscribe to this blog and my &lt;a href=&quot;https://medium.com/@durgaswaroop/&quot; class=&quot;bodyclass&quot;&gt;blog on Medium&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven’t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a href=&quot;https://github.com/durgaswaroop/delorean&quot; class=&quot;bodyclass&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in the functionality.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/4373440216421990005/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/apache-spark-datasets-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/4373440216421990005'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/4373440216421990005'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/apache-spark-datasets-1.html' title='Datasets in Apache Spark | Part 1'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-2269123612198233232</id><published>2017-12-25T13:30:00.000+00:00</published><updated>2017-12-25T18:00:04.524+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="API"/><category scheme="http://www.blogger.com/atom/ns#" term="How To"/><category scheme="http://www.blogger.com/atom/ns#" term="Pip"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Scraping"/><category scheme="http://www.blogger.com/atom/ns#" term="Tweepy"/><category scheme="http://www.blogger.com/atom/ns#" term="Twiiter"/><title type='text'>Tweeting with Python and Tweepy</title><content type='html'>&lt;p&gt;Programmers love to automate things and I&#39;m no exception. I always like automate my common tasks. Whether it is checking for stock prices or checking to see when the next episode of my favorite show is coming, I&#39;ve automated scripts for that. Today I am going to add one more thing in that list i.e., automated tweeting. I tweet quite frequently and I would love to have a way of automating this as well. And that&#39;s exactly what we&#39;re going to do today. We are tweeting using python.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;centeralign&quot; alt=&quot;twitter and python&quot; src=&quot;https://s-media-cache-ak0.pinimg.com/600x315/a8/b5/ae/a8b5aea9cabee52dc57abdc8338fc80c.jpg&quot; width=&quot;450&quot;/&gt;&lt;/p&gt;

&lt;p&gt;We&#39;ll use a python library called &lt;code&gt;tweepy&lt;/code&gt; for this. &lt;code&gt;Tweepy&lt;/code&gt; is a simple, easy to use library for accessing Twitter API.&lt;/p&gt;

&lt;p&gt;Accessing twitter API&#39;s programmatically is not only just an accessibility feature but can be of enormous value too. Mining the twitter verse data is one of the key steps in sentimental analysis. Twitter chat bots have also become quite popular now a days with hundreds and thousands of bot accounts. This article, although, only barely scratches the surface, hopefully will helping in building yourself towards that.&lt;/p&gt;

&lt;h3 id=&quot;settingup&quot;&gt;Setting Up&lt;/h3&gt;

&lt;p&gt;First thing&#39;s first, install tweepy by running &lt;code&gt;pip install tweepy&lt;/code&gt;. The latest version at the time of the writing this article is &lt;code&gt;3.5.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then we need to have our Twitter API credentials. Go to &lt;a class=&quot;bodyclass&quot; href=&quot;https://apps.twitter.com/&quot;&gt;Twitter Apps&lt;/a&gt;. If you don&#39;t have any apps registered already, go ahead and click the &lt;code&gt;Create New App&lt;/code&gt; button. &lt;/p&gt;

&lt;p&gt;To register your app you have to provide the following three things&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Name of your application&lt;/li&gt;

&lt;li&gt;Description&lt;/li&gt;

&lt;li&gt;Your website url&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is one more option which is &lt;code&gt;callback URL&lt;/code&gt;. You can ignore that for now. Then after reading the Twitter developer agreement (wink wink), click on &lt;code&gt;Create your Twitter application&lt;/code&gt; button to create a new app.&lt;/p&gt;

&lt;p&gt;Once the app is created you should see that in your twitter apps page. Click on it and GOTO the &lt;code&gt;Keys and Access Tokens&lt;/code&gt; tab.&lt;/p&gt;

&lt;p&gt;&lt;img class=&quot;centeralign&quot; alt=&quot;twitter apps tabs&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/Twitter-apps-page-tabs.png&quot; width=&quot;600&quot;/&gt;&lt;/p&gt;

&lt;p&gt;There you will see four pieces of information. First you have your app API keys which are &lt;code&gt;consumer key&lt;/code&gt; and &lt;code&gt;consumer secret&lt;/code&gt;. Then you have your &lt;code&gt;access token&lt;/code&gt; and &lt;code&gt;access token secret&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We&#39;ll need all of them to access twitter API&#39;s. So, have them ready.  I have copied all of them and exported them as system variables. You could do the same or if you&#39;d like, you can read them from a file as well. &lt;/p&gt;

&lt;h3 id=&quot;letsgetstarted&quot;&gt;Let&#39;s get started&lt;/h3&gt;

&lt;p&gt;First you have to import &lt;code&gt;tweepy&lt;/code&gt; and &lt;code&gt;os&lt;/code&gt;(only if you are accessing system variables).&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;python language-python&quot;&gt;import tweepy
import os
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then I&#39;ll populate the access variables by reading them environment variables.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;python language-python&quot;&gt;consumer_key = os.environ[&quot;t_consumer_key&quot;]
consumer_secret = os.environ[&quot;t_consumer_secret&quot;]
access_token = os.environ[&quot;t_access_token&quot;]
access_token_secret = os.environ[&quot;t_access_token_secret&quot;]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With the keys ready, we setup the authorization.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;python language-python&quot;&gt;authorization = tweepy.OAuthHandler(consumer_key, consumer_secret)
authorization.set_access_token(access_token, access_token_secret)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After authorization we create an API object &lt;code&gt;twitter&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;python language-python&quot;&gt;twitter = tweepy.API(authorization)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And now you can tweet from python using this &lt;code&gt;twitter&lt;/code&gt; object like this.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;python language-python&quot;&gt;twitter.update_status(&quot;Tweet using #tweepy&quot;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That is all you have to do. Just five lines of code and you can already tweet. You should try it out and check your twitter account. I just ran this command and this is the tweet.&lt;/p&gt;

&lt;blockquote class=&quot;twitter-tweet&quot; data-lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Tweet using &lt;a href=&quot;https://twitter.com/hashtag/tweepy?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#tweepy&lt;/a&gt;&lt;/p&gt;&amp;mdash; Durga Swaroop Perla (@durgaswaroop) &lt;a href=&quot;https://twitter.com/durgaswaroop/status/945047842485280768?ref_src=twsrc%5Etfw&quot;&gt;December 24, 2017&lt;/a&gt;&lt;/blockquote&gt;

&lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;p&gt;Not just this, you can also tweet media. Let&#39;s tweet again, this time with a picture attached.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;python language-python&quot;&gt;image = os.environ[&#39;USERPROFILE&#39;] + &quot;\\Pictures\\cubes.jpg&quot;
twitter.update_with_media(image, &quot;Tweet with media using #tweepy&quot;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And this is the media tweet.&lt;/p&gt;

&lt;blockquote class=&quot;twitter-tweet&quot; data-lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Tweet with media using &lt;a href=&quot;https://twitter.com/hashtag/tweepy?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#tweepy&lt;/a&gt; &lt;a href=&quot;https://t.co/9bDuw9DDJI&quot;&gt;pic.twitter.com/9bDuw9DDJI&lt;/a&gt;&lt;/p&gt;&amp;mdash; Durga Swaroop Perla (@durgaswaroop) &lt;a href=&quot;https://twitter.com/durgaswaroop/status/945049796238118912?ref_src=twsrc%5Etfw&quot;&gt;December 24, 2017&lt;/a&gt;&lt;/blockquote&gt;

&lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;p&gt;When you run the previous commands, you&#39;ll see that there is a lot of output that is printed on the terminal. This is a &lt;code&gt;status&lt;/code&gt; object with a lot of useful data like the number of followers you got, your profile picture URL, your location etc., pretty much everything you get from your twitter page. We can make use of this information, If we are building something more comprehensive.&lt;/p&gt;

&lt;p&gt;Apart from sending regular tweets, you can also reply to existing tweets. To reply to a tweet you&#39;d first need its &lt;code&gt;tweet_id&lt;/code&gt; which you can get from the tweet&#39;s URL. &lt;/p&gt;

&lt;p&gt;For example the URL for previous tweet is &lt;a class=&quot;bodyclass&quot; href=&quot;https://twitter.com/durgaswaroop/status/945049796238118912&quot;&gt;https://twitter.com/durgaswaroop/status/945049796238118912&lt;/a&gt; and the &lt;code&gt;tweet_id&lt;/code&gt; is &lt;code&gt;945049796238118912&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Using that id, we can send another tweet as reply.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;python language-python&quot;&gt;id_of_tweet_to_reply = &quot;945049796238118912&quot;
twitter.update_status(&quot;Reply to a tweet using #tweepy&quot;, in_reply_to_status_id=id_of_tweet_to_reply)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The only change in the syntax is &lt;code&gt;in_reply_to_status_id=id_of_tweet_to_reply&lt;/code&gt; that is passed as the second argument. And with that our new tweet will be added as reply to the original tweet.&lt;/p&gt;

&lt;p&gt;The new reply tweet is this:&lt;/p&gt;

&lt;blockquote class=&quot;twitter-tweet&quot; data-lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Reply to a tweet using &lt;a href=&quot;https://twitter.com/hashtag/tweepy?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#tweepy&lt;/a&gt;&lt;/p&gt;&amp;mdash; Durga Swaroop Perla (@durgaswaroop) &lt;a href=&quot;https://twitter.com/durgaswaroop/status/945053630129881088?ref_src=twsrc%5Etfw&quot;&gt;December 24, 2017&lt;/a&gt;&lt;/blockquote&gt;

&lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;p&gt;That&#39;s how easy it is to access Twitter API with tweepy. We now know how to tweet and how to reply to a tweet. Building up from this knowledge, In a later tutorial, I can show you how to create your own twitter chat-bot and also twitter streaming analysis.&lt;/p&gt;

&lt;p&gt;The full code of things covered in this article is available as gist at 
&lt;script src=&quot;https://gist.github.com/durgaswaroop/d16cad3f4e3f8d1976a124aac602f5d2.js&quot;&gt;&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;For more programming and Python articles, checkout &lt;a class=&quot;bodyclass&quot; href=&quot;http://freblogg.com&quot;&gt;Freblogg&lt;/a&gt; and &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/Python&quot;&gt;Freblogg/Python&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;bodyclass&quot; href=&quot;https://medium.com/@durgaswaroop/web-scraping-with-python-introduction-7b3c0bbb6053&quot;&gt;Web Scraping For Beginner with Python&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;This is the third article as part of my twitter challenge &lt;a class=&quot;bodyclass&quot; href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Twenty-seven more articles on various topics including but not limited to &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/Java&quot;&gt;Java&lt;/a&gt;, &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/Git&quot;&gt;Git&lt;/a&gt;, &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/Vim&quot;&gt;Vim&lt;/a&gt;, &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/?q=software&quot;&gt;Software Development&lt;/a&gt;, &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/?q=python&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;

&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a class=&quot;bodyclass&quot; href=&quot;https://twitter.com/durgaswaroop&quot;&gt;@durgaswaroop&lt;/a&gt;. While you&#39;re at it, Go ahead and subscribe to this blog and my &lt;a class=&quot;bodyclass&quot; href=&quot;https://medium.com/@durgaswaroop/&quot;&gt;blog on Medium&lt;/a&gt; as well.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;If you are interested in contributing to any open source projects and haven&#39;t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a class=&quot;bodyclass&quot; href=&quot;https://github.com/durgaswaroop/delorean&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in the functionality.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/2269123612198233232/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/tweeting-with-python-and-tweepy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/2269123612198233232'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/2269123612198233232'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/tweeting-with-python-and-tweepy.html' title='Tweeting with Python and Tweepy'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-2465913766964925233</id><published>2017-12-23T14:30:00.000+00:00</published><updated>2017-12-23T14:54:58.509+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gvim"/><category scheme="http://www.blogger.com/atom/ns#" term="sessions"/><category scheme="http://www.blogger.com/atom/ns#" term="Vim"/><category scheme="http://www.blogger.com/atom/ns#" term="vim tabs"/><title type='text'>Sessions in Vim</title><content type='html'>&lt;p&gt;I love to have a lot of tabs open at the same time in Vim. Being the deputy Scrum master (Yeah, it is a thing) of our dev-team, I have to keep track of a lot of things going on in the team. I maintain a repository of all the links to product documentation, stories, tasks etc. I also need to keep track of the discussions that happened in various team meetings. On top of this, as a backend engineer I have my own stories and tasks to manage as well. All of this means that, I have a ton of tabs and splits open at any given time in Vim. Something like the following:&lt;/p&gt;
&lt;img alt=&quot;Vim multiple tabs open&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/vim_multiple_tabs.png&quot; class=&quot;aligncenter&quot;&gt;
&lt;p&gt;Now, the problem comes when I have to shutdown and start my computer. All the tabs I have kept open for several days will be gone and I have to open them up all again and put them in the order I want. &lt;em&gt;Oh, the pain!&lt;/em&gt;. There has to a better way!&lt;/p&gt;
&lt;img alt=&quot;There has to be a better way&quot; src=&quot;https://i.imgur.com/m01MZOg.gif&quot; class=&quot;aligncenter&quot;&gt;
&lt;p&gt;Luckily for us Vim always has a better way to do something. There is an inbuilt feature just for this.&lt;/p&gt;
&lt;p&gt;It is called &lt;code&gt;Vim-sessions&lt;/code&gt; and with that you can get back all your tabs with just one command. &lt;em&gt;How nice!&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;how-to-create-a-new-session&quot;&gt;How to create a new session?&lt;/h3&gt;
&lt;p&gt;To create a vim session, run the command &lt;code&gt;:mksession episodes.session&lt;/code&gt;. Here &lt;code&gt;episodes&lt;/code&gt; is the name of the session I want to create.&lt;/p&gt;
&lt;p&gt;In short, &lt;code&gt;:mks &amp;lt;session-name&amp;gt;.session&lt;/code&gt;. And that’s it. Your session is now saved. It saves information about what tabs are currently open, what splits are open and even what buffers are open, all into that session file.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: The &lt;code&gt;.session&lt;/code&gt; suffix is not needed. But it is the preferred way as you can easily identify the session file.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Once this is done, you can go ahead and close your tabs as all of that is stored in the session file.&lt;/p&gt;
&lt;h3 id=&quot;how-to-open-an-existing-session&quot;&gt;How to open an existing session?&lt;/h3&gt;
&lt;p&gt;Now that we have the session saved, the next time you want to open all of those tabs, all you have to do is tell Vim to run that session. You do that by running the command &lt;code&gt;:so &amp;lt;session-file-path&amp;gt;&lt;/code&gt;(&lt;code&gt;:so&lt;/code&gt; is short for &lt;code&gt;:source&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;And boom. All of your windows and tabs are back with just one command. You don’t have to have multiple tmux or screen buffers running anymore. Vim can do all of that with just one command.&lt;/p&gt;
&lt;p&gt;That is all you need to know about sessions in vim to make yourself productive. You can always try the vim help with &lt;code&gt;:help session-file&lt;/code&gt; and find out more.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;For more Vim articles, checkout &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/Vim&quot;&gt;Freblogg/Vim&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Beginner Vim Tutorials - &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/VimFirstLesson&quot;&gt;Your First Lesson In Vim&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Vim Color scheme used: &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.vim.org/scripts/script.php?script_id=1802&quot;&gt;Eclipse&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;This is the first article as part of my twitter challenge &lt;a class=&quot;bodyclass&quot; href=&quot;https://twitter.com/durgaswaroop/status/944503750340702208&quot;&gt;#30DaysOfBlogging&lt;/a&gt;. Twenty-nine more articles on various topics including but not limited to &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/Java&quot;&gt;Java&lt;/a&gt;, &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/Git&quot;&gt;Git&lt;/a&gt;, &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/Vim&quot;&gt;Vim&lt;/a&gt;, &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/?q=software&quot;&gt;Software Development&lt;/a&gt;, &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/?q=python&quot;&gt;Python&lt;/a&gt;, to come.&lt;/p&gt;
&lt;p&gt;If you are interested in this, make sure to follow me on Twitter &lt;a class=&quot;bodyclass&quot; href=&quot;https://twitter.com/durgaswaroop&quot;&gt;@durgaswaroop&lt;/a&gt;. While you’re at it, Go ahead and subscribe to this blog and my &lt;a class=&quot;bodyclass&quot; href=&quot;https://medium.com/@durgaswaroop/&quot;&gt;blog on Medium&lt;/a&gt; as well.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;If you are interested in contributing to any open source projects and haven’t found the right project or if you were unsure on how to begin, I would like to suggest my own project, &lt;a class=&quot;bodyclass&quot; href=&quot;https://github.com/durgaswaroop/delorean&quot;&gt;Delorean&lt;/a&gt; which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in the functionality.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Thanks for reading. See you again in the next article.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/2465913766964925233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/sessions-in-vim.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/2465913766964925233'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/2465913766964925233'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/12/sessions-in-vim.html' title='Sessions in Vim'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-3452353723974130380</id><published>2017-09-11T12:30:00.000+02:00</published><updated>2017-09-11T12:30:11.010+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Git"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Version control"/><title type='text'>How to recover from &#39;git reset --hard&quot; | Git</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Git is an amazingly powerful tool. But, as Uncle Ben said,&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
With great power, comes great responsibility&lt;/blockquote&gt;
And that is true for Git as well. If you are not careful when using it, you could easily burn your a**.&lt;br /&gt;
So, If something like that happened to you, Or If you want to make sure that never happens to you, then watch this video.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/MijDnC4mz9w/0.jpg&quot; frameborder=&quot;0&quot; height=&quot;532&quot; src=&quot;https://www.youtube.com/embed/MijDnC4mz9w?feature=player_embedded&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
Subscribe to the channel for more videos like this.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/3452353723974130380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/09/how-to-recover-from-git-reset-hard-git.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/3452353723974130380'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/3452353723974130380'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/09/how-to-recover-from-git-reset-hard-git.html' title='How to recover from &#39;git reset --hard&quot; | Git'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/MijDnC4mz9w/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-634945285375462708</id><published>2017-08-26T23:30:00.000+02:00</published><updated>2017-08-26T23:42:47.098+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Stuff"/><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java script"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="software"/><title type='text'>Functions in C Programming | Part 1</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot;&gt;
Functions are a very important topic in all of Programming. Functions let you organize your code better and also help in not repeating yourself honoring the DRY (Don&#39;t Repeat Yourself) principle. &lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
This video introduces you to how functions work in C Programming. &lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfu320creen=&quot;&quot; c266s=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/J3OdukUKV_g/0.jpg&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;https://www.youtube.com/embed/J3OdukUKV_g?feature=player_embedded&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/634945285375462708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/08/functions-in-c-programming-part-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/634945285375462708'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/634945285375462708'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/08/functions-in-c-programming-part-1.html' title='Functions in C Programming | Part 1'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/J3OdukUKV_g/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-8577320167962202540</id><published>2017-08-12T05:30:00.000+02:00</published><updated>2017-08-12T05:30:51.642+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C Programming Stuff"/><category scheme="http://www.blogger.com/atom/ns#" term="How To"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathema&#39;tricks&#39;"/><category scheme="http://www.blogger.com/atom/ns#" term="Terminal"/><title type='text'>Matrix Multiplication | C Programming</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
We have discussed about Matrix arithmetic in my recent youtube tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/c8s9Gz_-N5E/0.jpg&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/c8s9Gz_-N5E?feature=player_embedded&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
In that, I have already shown how Matrix addition and subtraction can be done and asked you to try multiplication themselves. Hopefully you have been able to do that Or atleast tried it out before coming here to see my solution.&lt;br /&gt;
&lt;br /&gt;
For this example, I have taken two matrices as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg13_wxrTWlsJo1L2Tpcua5n-mvxhBuiAvuWMMhpWUP2iaEffpU39HL27257QAM9nrYsk6z_AQJE17PzAGQltzGAPEGGPmEegEP4cATaVkmr29R6uF8Kn7Fh3eYgvgVNAZJsFVY_hcZOzk/s1600/Matrix1.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;125&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg13_wxrTWlsJo1L2Tpcua5n-mvxhBuiAvuWMMhpWUP2iaEffpU39HL27257QAM9nrYsk6z_AQJE17PzAGQltzGAPEGGPmEegEP4cATaVkmr29R6uF8Kn7Fh3eYgvgVNAZJsFVY_hcZOzk/s200/Matrix1.png&quot; width=&quot;200&quot; /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVquz25yC006v4gZZQ-L8DTlZvx_eLyzwf-gE_le8qOsJAmeVG1kBpkVxKF-NSpkuNB7bm1wYH5tOTPDuxbLpQnXkJlPK656XFEvCoidHFpd0DsSHFNkCAl4EoO8oReSkYGdhzZljK8KU/s1600/Matrix2.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;125&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVquz25yC006v4gZZQ-L8DTlZvx_eLyzwf-gE_le8qOsJAmeVG1kBpkVxKF-NSpkuNB7bm1wYH5tOTPDuxbLpQnXkJlPK656XFEvCoidHFpd0DsSHFNkCAl4EoO8oReSkYGdhzZljK8KU/s200/Matrix2.png&quot; width=&quot;119&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Matrix1 has 3 rows and 4 columns and Matrix2 has 4 rows and 3 columns. And now, the code to multiply these two matrices.&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;#include &quot;stdio.h&quot;
main() {

    int matrix1[3][4] = { {1,2,3,4}, {3,4,1,2}, {4,1,2,3} };
    int matrix2[4][3] = { {0,1,2}, {1,2,0}, {2,0,1}, {1,0,2} };
    
    // Values from the matrices. No. of columns in matrix1 = No. of rows in matrix2. Matrix Multiplication possible
    int rows1 = 3, cols1 = 4, rows2 = 4, cols2 = 3;        
    
    // Initialize the resultant matrix with all zeroes
    int mult_matrix[3][3] = {0};
    
    // Loop variables
    int i=0, j=0, k=0;
        
    for(i = 0; i &amp;lt; rows1; i++) {
        for(j = 0; j &amp;lt; cols2; j++) {
            for(k = 0; k &amp;lt; cols1; k++) {
                // Since we are initializing with zero, we can add new values to the previous value to get the final value
                mult_matrix[i][j] += matrix1[i][k] * matrix2[k][j];
            }
        }
    }
    
    //  Print the new matrix
    for(i = 0; i &amp;lt; rows1; i++) {
        for(j = 0; j &amp;lt; cols2; j++) {
            printf(&quot;%d &quot;, mult_matrix[i][j]);
        }
        printf(&quot;\n&quot;);
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And when you run this program, you get the following output as one would expect:&lt;br /&gt;
&lt;pre&gt;&lt;b&gt;12 5 13
8 11 11
8 6 16

Press any key to continue . . .&lt;/b&gt;
&lt;/pre&gt;
The comments, along with the explanation in the video should be enough for you to understand this code directly.But, do reach out on social media for any queries.&lt;br /&gt;
&lt;br /&gt;
That&#39;s all for this article.&lt;br /&gt;
As, always, Have a happy reading and Stay Awesome !&lt;br /&gt;
&lt;hr /&gt;
If you have liked this article and would like to see more, subscribe to our Facebook and G+ pages.&lt;br /&gt;
&lt;br /&gt;
Facebook page @&amp;nbsp;&lt;a href=&quot;https://www.facebook.com/freblogg&quot;&gt;Facebook.com/freblogg&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Google Plus Page @&amp;nbsp;&lt;a href=&quot;https://plus.google.com/102904658212987164302&quot;&gt;Google.com/freblogg&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/8577320167962202540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/08/matrix-multiplication-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/8577320167962202540'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/8577320167962202540'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/08/matrix-multiplication-in-c.html' title='Matrix Multiplication | C Programming'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/c8s9Gz_-N5E/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-5928627327876170351</id><published>2017-03-03T19:38:00.001+00:00</published><updated>2017-08-11T21:41:19.363+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Chess"/><category scheme="http://www.blogger.com/atom/ns#" term="Openings"/><category scheme="http://www.blogger.com/atom/ns#" term="Petrov"/><category scheme="http://www.blogger.com/atom/ns#" term="TIL"/><title type='text'>Today I Learned | Petrov&#39;s Defense | Russian Opening</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
As you can probably guess from the title of this article, I am an amateur Chess player and certainly a beginner when it comes to Opening theory. My chess journey has a lot of turns and several starts and stops. Hopefully by sharing things I learn, I can get better.&lt;/div&gt;
So, Today learned about one of the famous chess openings - Petrov&#39;s Defence, named after Russian chess master Alexander Petrov. This opening is also sometimes referred to as Russian Opening. And this is my analysis of the opening. I will try to analyse all the possible combinations I can think of how insignificant they may be just so that this is beginner friendly.&lt;br /&gt;
The play starts quite formally with &lt;code&gt;1. e4 e5 2. Nf3 Nf6&lt;/code&gt;, leading us to this comfortable symmetric position&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 1&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov1.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Here&#39;s how it looks from the Black side.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 2&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov2.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
From here easily the most seen move is White capturing the pawn on e5 with the move &lt;code&gt;3. Nxe5&lt;/code&gt;, giving us&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 3&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov3.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now, If you are a fan of symmetry like me, you might expect black to follow suit as well taking the e4 pawn. But that can prove fatal for Black. Not sure how? Let&#39;s explore. So, if Black side plays &lt;code&gt;3. ... Nxe4&lt;/code&gt;, we get this symmetric position on the board as expected.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 4&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov4.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Here white has an easier move of &lt;code&gt;4. Qe2&lt;/code&gt; threatening the Knight.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 5&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov5.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now, If black wanted to continue symmetry and played &lt;code&gt;4. ... Qe7&lt;/code&gt;, it would be really worse as the next moves would be &lt;code&gt;5. Qxe4 Qxe5&lt;/code&gt; and Wham Bam Thank you Ma&#39;am, because black just lost its Queen.&lt;br /&gt;
Now, another possible line from &lt;code&gt;4. Qe2&lt;/code&gt; is &lt;code&gt;4. ... Nf6&lt;/code&gt; with black retreating its Knight.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 6&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov6.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now, Is this fine for Black? The answer is still No. Notice that the White Queen and the Black King are on the &#39;E&#39; file. So, If the white player just moves his Knight out of the way, you will have a discovered check from the Queen.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 7&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov7.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now, If he can manage to threaten one of your big players with the knight along with the discovered check, that would just be deadly. White has two ways it can proceed from here to try to extract maximum damage.&lt;br /&gt;
One possible line is white playing &lt;code&gt;5. Nxf7+&lt;/code&gt;, forking your Queen and Rook along with the discovered check.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 8&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov8.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
But, this position is actually not good for White as black can just take on f7 with &lt;code&gt;5. ... Kxf7&lt;/code&gt; coming out of the check and getting a piece in return.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 9&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov9.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Here White lost a Knight for just a pawn. Though black has lost the ability to castle, the lead in material should more than make up for it if he/she plays carefully. So, we saw &lt;code&gt;5. Nxf7+&lt;/code&gt; is a bad move.&lt;br /&gt;
What else is there? How about &lt;code&gt;5. Nc6+&lt;/code&gt; ? You have a deadly discovered check along with a direct threat to the black Queen.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 10&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov10.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now, if you are playing with black pieces here, all is not done at. You&#39;re certainly in a grave position but with a bit of thought we can try to come out with the least bit of damage.&lt;br /&gt;
So, after &lt;code&gt;5. Nc6+&lt;/code&gt;, you have to first get your king to safety. You&#39;ve got two ways. With the Bishop or the Queen. Let&#39;s see what happens if we try Bishop. So, you move &lt;code&gt;5. ... Be7&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 11&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov11.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now, the White Knight will just jump at the opportunity and take your Queen with &lt;code&gt;6. Nxd8&lt;/code&gt;. You lost the Queen but you got a Knight while losing your ability to Castle.&lt;br /&gt;
So, How about &lt;code&gt;5. ... Qe7&lt;/code&gt;? Knight will still take on e7 with &lt;code&gt;6. Nxe7&lt;/code&gt; and you take it back with the Bishop, all the while getting ready to castle on the Kingside in the next move. Doesn&#39;t look like a bad move.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 12&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov12.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
So, that is your best move if you managed to get to that position. But, you should never get to that position because you should never take on e4 in &lt;code&gt;3. ... Nxe4&lt;/code&gt;. That&#39;s a bad move.&lt;br /&gt;
Let&#39;s get back to the position of &lt;code&gt;3. Nxe5&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 3&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov3.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s see what the black side can do now. Instead of taking the pawn, black can try to get the white knight away from its base by playing &lt;code&gt;3. ... d6&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 13&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov13.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
White of-course retreats its Knight on to f3 or d3, preferably f3 to avoid blocking the light square bishop.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Petrov Defense picture 14&quot; class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/petrov/petrov14.png&quot; width=&quot;360&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now, black can take on the pawn freely and is better equipped to deal with the subsequent pin from Qe2.&lt;br /&gt;
So, that concludes my little analysis of this famous opening. There are a lot of variations possible around this main line and obviously we can&#39;t cover all of them. So, do setup the board and practice all the variations for yourself to get the hang of it.&lt;br /&gt;
That&#39;s it for this analysis. See you next time.&lt;br /&gt;
&lt;hr /&gt;
Follow &lt;a href=&quot;https://www.facebook.com/FreBlogg/&quot;&gt;FreBlogg on Facebook&lt;/a&gt; for more interesting articles.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/5928627327876170351/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/03/petrovs-defense.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/5928627327876170351'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/5928627327876170351'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/03/petrovs-defense.html' title='Today I Learned | Petrov&#39;s Defense | Russian Opening'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-8161045225037164826</id><published>2017-02-20T08:56:00.000+00:00</published><updated>2017-08-11T21:41:19.439+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="branch"/><category scheme="http://www.blogger.com/atom/ns#" term="cherrypick"/><category scheme="http://www.blogger.com/atom/ns#" term="Git"/><title type='text'>Git Cherrypick </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;Cherrypick &lt;/b&gt;is one of the most useful commands in Git. It is used to apply a commit that is present on another branch, on the current branch. Let&#39;s see an example to understand this better.&lt;br /&gt;
&lt;br /&gt;
Let’s say you have two branches &lt;i&gt;feature1 &lt;/i&gt;and &lt;i&gt;feature2 &lt;/i&gt;as in the following picture.&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;https://qph.ec.quoracdn.net/main-qimg-d7022ab07a79d1c93bb1261cd2bd3bdf-c&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now, the green commit 5 on branch 2, has some interesting code that you want on feature1. How would you get that? You are probably thinking about merge/rebase. But with that you will get all the other green commits from 1–4 as well, which you don’t want.&lt;br /&gt;
Cherrypick for the rescue!.&lt;br /&gt;
&lt;br /&gt;
Assuming you are on feature1, all you have to say is&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;git cherry-pick green5 (Assuming &#39;green5&#39; is the commit id)&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
And that’s it. You will have the green5 commit on your orange4 commit like in this picture as you wanted.&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;https://qph.ec.quoracdn.net/main-qimg-1ef6d0807fd45ec07e23ae6cfcbbbca0-c&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Notice, that the green commit is no longer “5” but has been changed to “5′”. This is to show that, though the changes (change set is the git term) in the commit remain the same, Git will generate a new commit hash for this because hashes take parent node also into account.&lt;br /&gt;
&lt;br /&gt;
And that is all you need to know about Cherry picking. So, Go ahead and pick some cherries!&lt;br /&gt;
&lt;br /&gt;
&lt;hr style=&quot;background-color: white; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 0px; border-top-color: rgb(204, 204, 204); border-top-style: solid; box-sizing: content-box; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px; height: 1px; margin: 1em 0px; padding: 0px;&quot; /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px;&quot;&gt;For more interesting articles,&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px;&quot;&gt;Subscribe to&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;bodyclass&quot; href=&quot;http://feeds.feedburner.com/Freblogg&quot; style=&quot;-webkit-font-smoothing: antialiased; background-color: white; color: #2a2a26; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px; text-shadow: rgba(0, 0, 0, 0.00392157) 1px 1px 1px; transition: all 0.4s ease-out;&quot;&gt;Freblogg&#39;s RSS feed&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px;&quot;&gt;. Its a great way to get all the new articles directly.&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px;&quot;&gt;Follow&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;bodyclass&quot; href=&quot;https://www.facebook.com/FreBlogg/&quot; style=&quot;-webkit-font-smoothing: antialiased; background-color: white; color: #2a2a26; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px; text-shadow: rgba(0, 0, 0, 0.00392157) 1px 1px 1px; transition: all 0.4s ease-out;&quot;&gt;FreBlogg on Facebook&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px;&quot;&gt;&amp;nbsp;and follow&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;bodyclass&quot; href=&quot;https://twitter.com/durgaswaroop&quot; style=&quot;-webkit-font-smoothing: antialiased; background-color: white; color: #2a2a26; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px; text-shadow: rgba(0, 0, 0, 0.00392157) 1px 1px 1px; transition: all 0.4s ease-out;&quot;&gt;@durgaswaroop&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, &amp;quot;Source Sans Pro&amp;quot;, sans-serif; font-size: 18px;&quot;&gt;&amp;nbsp;on Twitter&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/8161045225037164826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/02/git-cherrypick.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/8161045225037164826'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/8161045225037164826'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/02/git-cherrypick.html' title='Git Cherrypick '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-3531458615501859428</id><published>2017-01-31T03:30:00.000+00:00</published><updated>2017-08-11T21:41:19.282+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Git"/><category scheme="http://www.blogger.com/atom/ns#" term="Git merge"/><category scheme="http://www.blogger.com/atom/ns#" term="Merge Conflicts"/><category scheme="http://www.blogger.com/atom/ns#" term="Rebase"/><category scheme="http://www.blogger.com/atom/ns#" term="VCS"/><title type='text'>Git Merge Vs. Git Rebase</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Merge and Rebase are two strategies available in Git to combine two ( or more) branches into one branch.&lt;br /&gt;
Let’s say we have two branches &lt;i&gt;feature1 &lt;/i&gt;and &lt;i&gt;feature2&lt;/i&gt; that have diverged from a common commit “&lt;i&gt;a&lt;/i&gt;” to have four commits each.&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;https://qph.ec.quoracdn.net/main-qimg-27b4c373471ccb22663c3189b051dcc3?convert_to_webp=true&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to combine both the features into a single branch. Merge and Rebase are our options. Let’s see what each of them can do.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Git Merge:&lt;/h3&gt;
Merge will seem like a fairly obvious thing, if you look at the end result. It is pretty much like taking two threads and tying them up in a knot.&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;https://qph.ec.quoracdn.net/main-qimg-5c246cb7872aaed9c1243d3fea96b467?convert_to_webp=true&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Here the commit ‘b’, has the information regarding all the commits in feature1 and feature2. So, Merge preserves the history of the repository.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Git Rebase:&lt;/h3&gt;
&lt;i&gt;Rebase &lt;/i&gt;on the other hand doesn’t preserve the history. It quite literally &lt;i&gt;re-bases&lt;/i&gt; one branch on top of the other i.e., it changes the &lt;i&gt;base &lt;/i&gt;of the branch. Let’s see rebasing with the same example.&lt;br /&gt;
Let’s say I want to &lt;i&gt;rebase feature1 onto feature2, &lt;/i&gt;what that means is that I want all the commits in the branch feature1 on top of the commits of feature2. So, after rebase your commit history would look like the following.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;img align=&quot;middle&quot; src=&quot;https://qph.ec.quoracdn.net/main-qimg-531720271c7a9e5ada9047c751c6ab27?convert_to_webp=true&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
As you see in the picture, the base of feature1 which was previously the commit “a”, has been shifted to the green commit “4”. Hence the name &lt;b&gt;Re-Base. &lt;/b&gt;Here feature1 is sitting on top of feature2 as opposed to being on “a”.&lt;br /&gt;
&lt;br /&gt;
Do note that I have added a &lt;b&gt;&lt;i&gt;‘ &lt;/i&gt;&lt;/b&gt;next to the numbers of feature branch making them 1’, 2′ and so on, to indicate that the &lt;i&gt;orange 1′&lt;/i&gt; commit is different from the &lt;i&gt;orange 1 &lt;/i&gt;commit. This is because each commit, apart from storing the changes to the files, stores the information regarding its parent. So, If a parent to a commit changes, even it has the exact sames modifications to the files, will be treated as a different commit by Git, which means we have changed the Git commit history.&lt;br /&gt;
&lt;br /&gt;
Also Anyone who looks at the commit history now, would think that feature1 was added after feature2 which is not what actually happened. If this is the end result you’re going for, then it’s absolutely fine but if you want to show that feature1 and feature2 both started off simultaneously, then you need to use Merge.&lt;br /&gt;
&lt;br /&gt;
Both Merge and Rebase have their pros and cons. Merge keeps the history of the repository but can make it hard for someone to understand and follow what’s going on at a particular stage when there are multiple merges. Rebase on the other hand ‘rewrites’ history (read - creates new history) but makes the repo look cleaner and is much easier to look at.&lt;br /&gt;
&lt;br /&gt;
What you want to use depends on your need. A lot of companies make merges mandatory when adding stuff to master branch because they want to see the history of all changes. And a few companies/Open source projects mandate rebasing as it keeps the flow simple and easy to follow. Use the one that suits your workflow.&lt;br /&gt;
&lt;br /&gt;
Fun Fact:&lt;br /&gt;
There is a merge strategy called Octopus merge, where you merge multiple branches into one. For more info on this: &lt;a href=&quot;http://www.freblogg.com/2016/12/git-octopus-merge.html&quot;&gt;Understanding Git Octopus Merge | FreBlogg&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
For more interesting articles,&lt;br /&gt;
Subscribe to &lt;a class=&quot;bodyclass&quot; href=&quot;http://feeds.feedburner.com/Freblogg&quot;&gt;Freblogg&#39;s RSS feed&lt;/a&gt;. Its a great way to get all the new articles directly.&lt;br /&gt;
Follow &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.facebook.com/FreBlogg/&quot;&gt;FreBlogg on Facebook&lt;/a&gt; and follow &lt;a class=&quot;bodyclass&quot; href=&quot;https://twitter.com/durgaswaroop&quot;&gt;@durgaswaroop&lt;/a&gt; on Twitter&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/3531458615501859428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2017/01/git-merge-vs-git-rebase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/3531458615501859428'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/3531458615501859428'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2017/01/git-merge-vs-git-rebase.html' title='Git Merge Vs. Git Rebase'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-3048028604687256570</id><published>2016-12-20T23:30:00.000+00:00</published><updated>2017-08-11T21:41:19.266+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Git"/><category scheme="http://www.blogger.com/atom/ns#" term="Merge Conflicts"/><category scheme="http://www.blogger.com/atom/ns#" term="Octopus"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Source Control"/><title type='text'>Understanding Git Octopus Merge</title><content type='html'>&lt;p&gt;The Code for Git merge is one of the most sophisticated pieces of software ever written. There is so much stuff that goes inside during a merge that its just mind boggling. Just for that alone, Linus could be considered a programming genius. Too bad for other geniuses, he has Linux kernel on his resume :-D.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; style=&quot;float:right;&quot; alt=&quot;Git Logo&quot; src=&quot;https://git-scm.com/images/logos/downloads/Git-Icon-1788C.png&quot; width=&quot;200&quot;&gt;&lt;/p&gt;
&lt;p&gt;As the title suggests this article is about &lt;em&gt;Octopus Merge&lt;/em&gt; in Git. For this I hope you know what a basic Git merge is and what it means to merge. If you&#39;re completely unfamiliar with Git, then I&#39;ve no idea what you&#39;re doing here. You better read up on some Git 101 before jumping to this article.&lt;/p&gt;
&lt;p&gt;Anyway, Just to brush up, this is how a simple/familiar Git merge goes ..&lt;/p&gt;
&lt;p&gt;We have a branch called &lt;em&gt;feature&lt;/em&gt; that diverged from &lt;em&gt;master&lt;/em&gt; at the second commit and went to have two commits of its own.&lt;/p&gt; 

&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Master and Feature branches in Git&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/git_branches_master_feature.png&quot; width=&quot;500&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: For the branch pictures in this article I am using a Git GUI tool called &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.gitkraken.com/&quot;&gt;Git Kraken&lt;/a&gt;. I have been trying it a few days now and it looks quite promising. I am a fan of its clean and minimalist UI and have been using it extensively for the beautiful visualization of branches. And above all, It is free for personal non-commercial use. So, you can try it out for free.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now you want to add those cool new changes on the feature branch to master. The way you do it is by merging (Let&#39;s not talk about Rebasing for now. We will look at it another time). So, when you merge this is how it looks like.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Git merge master feature&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/git_merge_master_feature.png&quot; width=&quot;500&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is all the usual stuff that we are all familiar with.&lt;/p&gt;
&lt;p&gt;Now there is another type of merge called the &lt;strong&gt;The Octopus Merge&lt;/strong&gt;. At least some of you must have heard about it either from an online video or from a colleague in your office that seems to know everything. Either way the Octopus merge is a really fun way of Merging. You probably won&#39;t get to do this at your work as a lot of companies think this complicates things and we all know how much Companies hate complexity. Anyway, Let&#39;s see what it looks like. I have a local git repository with three branches &lt;em&gt;branch1&lt;/em&gt;, &lt;em&gt;branch2&lt;/em&gt;, &lt;em&gt;branch3&lt;/em&gt; along with &lt;em&gt;master&lt;/em&gt;. All four of these branches have two extra commits from the point they diverged.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Git octopus pre image&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/git_pre_octopus_merge.png&quot; width=&quot;500&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now if you want to merge them, the usual way would be to merge two branches at a time to finally get to the final combination after three merges like so.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;The usual way to merge branches in Git&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/git_usual_merge.png&quot; width=&quot;500&quot;&gt;&lt;/p&gt;
&lt;p&gt;This may seem fine and might actually be the only way you would think about this if not for the Octopus merge. You have three merge commits here and as we know merge commits are noise. They pollute the history of your repository and interrupt the story told by your Git history. So, how about keeping the noise low by just having one Merge commit instead of three. How you ask? Octopus, My friend. All hail the great and mighty Octopus. So, the way you perform an Octopus is by merging all the branches at once on to the master. To do that you give a command like this&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Git merge octopus&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/git_octopus_merge_output.png&quot; width=&quot;500&quot;&gt;&lt;/p&gt;
&lt;p&gt;This will merge all the three branches to master. The branches will look something like this. Do you see the reference of Octopus now?&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Octopus Git merge&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/blogimages/master/git_post_octopus_merge.png&quot; width=&quot;500&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now, if you know anything about octopuses, you might be wondering that we only have four legs here while an Octopus has 8. Well you are right. Octopuses do have 8 legs (technically 6 as two of them are used as hands) but 4 is good enough. Actually any merge can be called Octopus if you&#39;re merging three or more branches.&lt;/p&gt;
&lt;p&gt;If you are using Git for sometime, you might be wondering, If Octopus is so freaking cool, why haven&#39;t more people heard about it and Why are more people not using it. Well, you are right my friend. Octopus is awesome for sure, but as I said it certainly does complicate things a lot especially when dealing with merge conflicts. Merge is hard enough as it is when dealing with just two branches. But if you are merging 5 or 10 branches together it feels like you&#39;re doing a complex surgery. You have to be really careful in that case and I am not even sure if any modern GUI tools support diffing 10-way. Also a lot of people tend to go overboard with Octopus.&lt;/p&gt;
&lt;p&gt;Look at this &lt;a class=&quot;bodyclass&quot; href=&quot;http://marc.info/?l=linux-kernel&amp;amp;m=139033182525831&quot;&gt;message&lt;/a&gt; where Linus Torvalds yells (pleasantly) at a guy for creating an Octopus with 66 branches. Imagine that for a second. 66 branches! I wouldn&#39;t want to be the guy that handles merge conflicts on that one! Linux aptly says&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;that&#39;s not an octopus, that&#39;s a &lt;strong&gt;Cthulhu&lt;/strong&gt; merge&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; style=&quot;float:right;margin:5px&quot; alt=&quot;Cthulu Image&quot; src=&quot;https://upload.wikimedia.org/wikipedia/commons/6/62/Cthulhu_and_R%27lyeh.jpg&quot; width=&quot;300&quot;&gt;&lt;/p&gt;
&lt;p&gt;So, a lot of companies don&#39;t really use this. A lot of people won&#39;t even consider this for their Merge strategies.&lt;/p&gt;
&lt;p&gt;A rule of thumb to follow with &lt;strong&gt;Octopus&lt;/strong&gt; is to never overdo it. An 8-way octopus merge though borders on crazy hard and insane, is fine but more than that is an overkill. The situations where you have to merge more than 5 or 6 branches tend to be very rare and in those cases may be you can go for an Octopus on a subset of branches at a time and do a Octopus for those. Or may be rethink your merging strategy.&lt;/p&gt;
&lt;p&gt;Either way, I hope this article helped you in understanding something new and gives you some ideas for dealing with complex merges. I hope you will educate your peers and colleagues about this new merge and share this article with them&lt;/p&gt;
&lt;p&gt;Well, That is all for this article folks. See you again in the next one. Until then, Good Bye.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more interesting articles,&lt;/p&gt;
&lt;p&gt;Subscribe to &lt;a class=&quot;bodyclass&quot; href=&quot;http://feeds.feedburner.com/Freblogg&quot;&gt;Freblogg&#39;s RSS feed&lt;/a&gt;. Its a great way to get all the new articles directly.&lt;/p&gt;
&lt;p&gt;Follow &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.facebook.com/FreBlogg/&quot;&gt;FreBlogg on Facebook&lt;/a&gt; and follow &lt;a class=&quot;bodyclass&quot; href=&quot;https://twitter.com/durgaswaroop&quot;&gt;@durgaswaroop&lt;/a&gt; on Twitter&lt;/p&gt;
&lt;p&gt;Special Thanks to &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.gitkraken.com/&quot;&gt;Git Kraken&lt;/a&gt; team at Axosoft for developing a great tool like Kraken.&lt;/p&gt;
&lt;h4 id=&quot;attributions&quot;&gt;Attributions:&lt;/h4&gt;
&lt;p&gt;Cthulhu Image : https://commons.wikimedia.org/wiki/File:Cthulhu_and_R&#39;lyeh.jpg&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/3048028604687256570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2016/12/git-octopus-merge.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/3048028604687256570'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/3048028604687256570'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2016/12/git-octopus-merge.html' title='Understanding Git Octopus Merge'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-833507683783993147</id><published>2016-10-13T08:30:00.000+02:00</published><updated>2017-08-11T21:41:19.448+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gvim"/><category scheme="http://www.blogger.com/atom/ns#" term="Vim"/><category scheme="http://www.blogger.com/atom/ns#" term="VimFirstLesson"/><title type='text'>Navigating In Vim II | Your First Lesson in Vim</title><content type='html'>&lt;p&gt;This is the fourth article in the series titled, &amp;quot;&lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/VimFirstLesson&quot;&gt;Your First Lesson In Vim&lt;/a&gt;&amp;quot;. These articles are written with a goal of helping out new Vim users by teaching the awesomeness of the Vim editor and there by extending the Vim community. Vim though quite powerful, has a bad rep for being hard to learn and hard to get started with. So, even when someone is interested in learning about Vim, that infamous learning curve seem to be scaring them off. This series is going to put an end to all of that.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;http://wolfrosch.com/_img/works/goodies/icon/vim@2x&quot; alt=&quot;Vim Logo&quot; width=&quot;150&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the last article &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-3.html&quot;&gt;Navigating in Vim I&lt;/a&gt;, we have seen a lot of Vim motions. Most of these fall under the category of word-motions (&lt;code&gt;:help word-motions&lt;/code&gt;). We will learn some more motions in this article. And in case you still haven&#39;t tried &lt;a class=&quot;bodyclass&quot; href=&quot;http://vim-adventures.com/&quot;&gt;Vim Adventures&lt;/a&gt; you should do it. It will help you a lot with getting the hang of Vim motions and getting around in vim.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;linemotions&quot;&gt;&lt;/a&gt; Here are the list of Vim motions for this article.&lt;/p&gt;
&lt;table style=&quot;width:88%;&quot;&gt;
&lt;colgroup&gt;
&lt;col width=&quot;23%&quot; /&gt;
&lt;col width=&quot;63%&quot; /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th align=&quot;center&quot;&gt;Motion&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;What it does?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;0&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the &lt;em&gt;STARTING&lt;/em&gt; of the &lt;em&gt;CURRENT LINE&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;^&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the &lt;em&gt;FIRST NBC*&lt;/em&gt; of the &lt;em&gt;CURRENT LINE&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;-&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the &lt;em&gt;FIRST NBC*&lt;/em&gt; of the &lt;em&gt;PREVIOUS LINE&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;+&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the &lt;em&gt;FIRST NBC*&lt;/em&gt; of the &lt;em&gt;NEXT LINE&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;$&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the &lt;em&gt;END&lt;/em&gt; of the &lt;em&gt;CURRENT LINE&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;g_&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the &lt;em&gt;LAST NBC*&lt;/em&gt; of the &lt;em&gt;CURRENT LINE&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;f{char}&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Find a character &lt;em&gt;FORWARD&lt;/em&gt; in the current line (Usage: to go to first occurance of c, you type &lt;code&gt;fc&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;F{char}&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Find a character &lt;em&gt;BACKWARD&lt;/em&gt; in the current line (Usage: to go to first occurance of c to the left of the cursor, you type &lt;code&gt;Fc&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;t{char}&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Like &lt;code&gt;f&lt;/code&gt; but places the cursor before the character (Mnemonic : t - till)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;T{char}&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Like &lt;code&gt;T&lt;/code&gt; but places the cursor after the character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;gg&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the first line (compare this with &lt;code&gt;H&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;G&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the last line (compare this with &lt;code&gt;L&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;* NBC - Non Blank Character&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Line motions Vim picture&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/line_motions.png&quot; width=&quot;600&quot;&gt;&lt;/p&gt;
&lt;p&gt;These motions let you move very fast between lines. You can go to any character you want on the current line with just 2 or at 3 keys, which is insanely fast compared to any other text editor. The last two motions (gg, G) are super useful and are certainly two of my most used commands.&lt;/p&gt;
&lt;p&gt;Now we have one final set of motions to learn called Text Object motions (&lt;code&gt;:help object-motions&lt;/code&gt;). Text objects is an important concept in Vim and we will cover that in depth in a future article. For now let&#39;s look at these motions.&lt;/p&gt;
&lt;h3 id=&quot;text-object-motions&quot;&gt;&lt;a name=&quot;textmotions&quot;&gt;&lt;/a&gt;Text Object Motions&lt;/h3&gt;
&lt;table style=&quot;width:88%;&quot;&gt;
&lt;colgroup&gt;
&lt;col width=&quot;23%&quot; /&gt;
&lt;col width=&quot;63%&quot; /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th align=&quot;center&quot;&gt;Motion&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;What it does?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;(&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the beginning of the &lt;em&gt;PREVIOUS&lt;/em&gt; sentence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;)&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the beginning of the &lt;em&gt;NEXT&lt;/em&gt; sentence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;{&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go one paragraph &lt;em&gt;BACKWARD&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;}&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go one paragraph &lt;em&gt;FORWARD&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;These four motions are very useful too. Especially if you&#39;re a programmer, the &lt;code&gt;{&lt;/code&gt; and &lt;code&gt;}&lt;/code&gt; will make navigating the code base a breeze.&lt;/p&gt;
&lt;p&gt;And with that, we have covered all the basic Vim motions for you to get started. There is just one more important thing you need to know in conjunction with Motions. I haven&#39;t told you about this till now because I wanted you to get a full grasp of Vim motions before I explain this. Anyway, here it goes ..&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Every Vim Motion takes a count before it&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That&#39;s it. It might seem simple and it is simple, but its usefulness is just immeasurable.&lt;/p&gt;
&lt;p&gt;Let&#39;s say you have to move eight lines down. To go eight lines down you don&#39;t have to frantically type &lt;code&gt;jjjjjjjj&lt;/code&gt;. Just simply type &lt;code&gt;*8j*&lt;/code&gt;. Similarly &lt;code&gt;4k&lt;/code&gt; to go four lines above, &lt;code&gt;6w&lt;/code&gt; to go to the sixth word from the cursor and so on. This is just such a useful feature that quite literally &lt;em&gt;Sky is the limit&lt;/em&gt; for what you can do with this. Want to go to the second &lt;code&gt;e&lt;/code&gt; after the cursor? Try &lt;code&gt;2fe&lt;/code&gt; and your cursor lands directly on &lt;code&gt;e&lt;/code&gt;. Similarly to go to the ending of the 5th line below just do &lt;code&gt;5$&lt;/code&gt; and B.A.M!&lt;/p&gt;
&lt;p&gt;This opens up a whole new world of combinations for you to use and I hope you will make use of all of them. With these motions you can move to any place you want in the file with minimal number of keystrokes and your ultimate aim should be to accomplish everything with the minimum possible number of keystrokes. Be a Vim Ninja and conquer the world!&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Vim ninja image&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/vim_text_motions.png&quot; width=&quot;600px&quot;&gt;&lt;/p&gt;
&lt;p&gt;Well, That is all for this article folks. Will see you again in the next one. Until then, Keep practicing and Happy Vimming!&lt;/p&gt;
&lt;p&gt;
&lt;a class=&quot;navlinkleft&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-3.html&quot;&gt; ← Prev&lt;/a&gt; &lt;a class=&quot;navlinkright&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-5.html&quot;&gt;Next → &lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more Vim stuff : &lt;a class=&quot;bodyclass&quot; href=&quot;http://vimtutorials.org/&quot;&gt;vimtutorials.org&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Follow &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.facebook.com/FreBlogg/&quot;&gt;FreBlogg on Facebook&lt;/a&gt; for more interesting articles.&lt;/p&gt;
&lt;h4 id=&quot;attributions&quot;&gt;Attributions:&lt;/h4&gt;
&lt;p&gt;Vim Logo - Vim Replacement Icon http://wolfrosch.com/works/goodies/vim (CC BY-NC-ND 3.0)&lt;/p&gt;
&lt;p&gt;Vim Ninja image - https://goo.gl/QgTrsY (Originally from Practical Vim by Drew Neal)&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/833507683783993147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2016/10/your-first-lesson-in-vim-4.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/833507683783993147'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/833507683783993147'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2016/10/your-first-lesson-in-vim-4.html' title='Navigating In Vim II | Your First Lesson in Vim'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-7352028039649706049</id><published>2016-10-08T20:30:00.000+02:00</published><updated>2017-08-11T21:41:19.414+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gvim"/><category scheme="http://www.blogger.com/atom/ns#" term="Vim"/><category scheme="http://www.blogger.com/atom/ns#" term="VimFirstLesson"/><title type='text'>Navigating in Vim I | Your First Lesson In Vim</title><content type='html'>&lt;p&gt;This is the third article in a series titled, &amp;quot;&lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/VimFirstLesson&quot;&gt;Your First Lesson In Vim&lt;/a&gt;&amp;quot;. These articles are written with a goal of helping out new Vim users by teaching the awesomeness of the Vim editor there by extending the Vim community. Vim though quite powerful, has a bad rep for being hard to learn and hard to get started with. So, even when someone is interested in learning about Vim, that infamous learning curve seem to be scaring them off. Hopefully this series will put those fears to bed.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;http://wolfrosch.com/_img/works/goodies/icon/vim@2x&quot; alt=&quot;Vim Logo&quot; width=&quot;150&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the last article &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-2.html&quot;&gt;How To Exit Vim&lt;/a&gt;, we have seen what Vim modes are and what they do. So, If you know about Visual Mode, Insert Mode, Command Mode and Normal Mode, then continue with this article. Otherwise take a look again at the previous article. Vim modes are really important to understand this article and the upcoming ones.&lt;/p&gt;
&lt;p&gt;I wanted this to be a part of the previous article but since this is really important and has a lot of potential information to discuss, I decided to give this its own full article. We will be spending most of our time in Normal mode here as that is where we will navigate in the file. You have seen how you navigate in Vim using &lt;code&gt;h j k l&lt;/code&gt;. If you haven&#39;t figured out already, Vim&#39;s main philosophy is increasing your productivity and because of this some of the things Vim does might seem different compared to the usual way you are used to in other editors. Using &lt;code&gt;h j k l&lt;/code&gt; is one of those things.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/vim_navigation_hjkl.png&quot; alt=&quot;vim navigation&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;We have covered this in the last article but as promised I will expand about it here. If you look at your keyboard you will see that &lt;code&gt;h j k l&lt;/code&gt; are on your Home Row (unless you are using Dvorak Keyboard, in which case this article probably won&#39;t help you much). Having the navigation keys on the home row is such an advantage as you don&#39;t have to move your fingers at all to access them. Going to the arrow keys for navigating is tiresome and time consuming. Don&#39;t think so? Well try it out yourself. Rest your fingers on their normal positions on the Home row (&lt;code&gt;a s d f - j k l ;&lt;/code&gt;) and try to hit the UP arrow and come back. Did you see the travel involved in that? Do it again and see how you have moved your hand away from the keys and came back. Do it 5 more times and tell me If i am wrong when I say its just unnecessary travel, Especially since you have the navigation keys right on the home row in Vim. This is one of the reasons why Vim users are usually pretty fast. They don&#39;t keep moving their hands on and off the keyboard every time you have to go up or down. And again this could save you from potential RSI injuries.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;qwerty keyboard&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/qwerty_time_waste_small.png&quot; width=&quot;600&quot;&gt;&lt;/p&gt;
&lt;p&gt;So, I strongly advise you to stop using UP and DOWN arrow keys. To use the &lt;code&gt;h j k l&lt;/code&gt; keys more, try playing &lt;a class=&quot;bodyclass&quot; href=&quot;http://vim-adventures.com/&quot;&gt;Vim Adventures&lt;/a&gt;. Its a fun game where you go around the textland collecting characters using Vim&#39;s navigation controls. It will help you use the &lt;code&gt;h j k l&lt;/code&gt; keys and just after a couple of tries it becomes muscle memory.&lt;/p&gt;
&lt;p&gt;One more thing that you won&#39;t see Vim users (#VimRocks) using is Mouse. The argument against using Mouse is the same one as that for the arrow keys. You are taking your hands off your main row which not only breaks your typing flow but also is just plain annoying. Its the same for mouse except you&#39;re moving your hand even further which makes it that much worse.&lt;/p&gt;
&lt;p&gt;Getting rid of Arrow keys and Mouse is not an easy thing. This is cert ainly something that takes time to get used to. But once you do, you will be that much faster in your work flow.&lt;/p&gt;
&lt;h3 id=&quot;vim-motions&quot;&gt;Vim Motions&lt;/h3&gt;
&lt;p&gt;Vim Motions are the amazing things that make Vim users so fast. You already know about &lt;code&gt;h j k l&lt;/code&gt;. Motions are just about anything that moves your cursor from one place to another. Apart from that you also have &lt;code&gt;w W b B e E H M L&lt;/code&gt;. Let&#39;s see what they do.&lt;/p&gt;
&lt;br /&gt;
&lt;table style=&quot;width:79%;&quot;&gt;
&lt;colgroup&gt;
&lt;col width=&quot;15%&quot; /&gt;
&lt;col width=&quot;63%&quot; /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th align=&quot;center&quot;&gt;Command&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;What it does?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;w&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the starting of the next word&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;W&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the starting of the next WORD&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;b&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the starting of the previous word (Mnemonic - &lt;strong&gt;b&lt;/strong&gt;ack)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;B&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the starting of the previous WORD&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;e&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the end of the current word (Mnemonic - &lt;strong&gt;e&lt;/strong&gt;nd)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;E&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the end of the current WORD&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;H&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the First line of the current visible screen (Mnemonic - &lt;strong&gt;H&lt;/strong&gt;igh)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;M&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the Middle line of the current visible screen (Mnemonic - &lt;strong&gt;M&lt;/strong&gt;iddle)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;L&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Move the cursor to the Last line of the current visible screen (Mnemonic - &lt;strong&gt;L&lt;/strong&gt;ow)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
&lt;p&gt;The usage of &lt;code&gt;H M L&lt;/code&gt; commands should be clear with this image below. They move your cursor to first, middle and last line of the screen respectively.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;vim hml motions&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/hml_vim.png&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;To understand about &lt;code&gt;w b e&lt;/code&gt; and their upper case variants we have to understand how &lt;em&gt;word&lt;/em&gt; and &lt;em&gt;WORD&lt;/em&gt; are defined in Vim. From the official documentation (&lt;code&gt;:help word&lt;/code&gt;),&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;word&lt;/strong&gt; consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, &lt;EOL&gt;)&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;WORD&lt;/strong&gt; consists of a sequence of non-blank characters, separated with white space&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In short, a group of characters with out a space between them is a &lt;em&gt;WORD&lt;/em&gt; and there can be multiple &lt;em&gt;words&lt;/em&gt; in that. With that definition let&#39;s take a look at some examples and identify the number of words and the number of WORDS in them.&lt;/p&gt;
&lt;table style=&quot;width:79%;&quot;&gt;
&lt;colgroup&gt;
&lt;col width=&quot;22%&quot; /&gt;
&lt;col width=&quot;37%&quot; /&gt;
&lt;col width=&quot;19%&quot; /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th align=&quot;center&quot;&gt;Word&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;# of words&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;# of WORDS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;hello world&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;2 (hello,world)&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;2 (hello,world)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;hello-world&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;3 (hello,-,world)&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;1 (hello-world)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;hello_world&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;1 (hello_world)&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;1 (hello_world)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
&lt;p&gt;Once you understood the difference between &lt;em&gt;word&lt;/em&gt; and &lt;em&gt;WORD&lt;/em&gt;, all the motions explained in the first table would be clear. Just to make the foundation firm, try them out yourself. Type something in a file and try to see what each of the &lt;code&gt;w b e W B E H M L&lt;/code&gt; commands are doing and how they are moving the cursor. All the motions we have covered in this article are called &lt;em&gt;Word motions&lt;/em&gt; (&lt;code&gt;:help word-motions&lt;/code&gt;). There are some more Vim motion commands that you need to know to quickly navigate with ease. To keep this article simple, we will end this discussion here and will pickup again in the next article where we will discuss about the other motion commands. So, Keep practicing these motions combined with other commands discussed in &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-2.html&quot;&gt;How To Exit Vim&lt;/a&gt; and you would be really fast already. Fast like a Puma!&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;Well, That is all for this article folks. Will see you again in the next one. Until then, Keep practicing and Happy Vimming!&lt;/p&gt;
&lt;p&gt;
&lt;a class=&quot;navlinkleft&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-2.html&quot;&gt; ← Prev&lt;/a&gt; &lt;a class=&quot;navlinkright&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-4.html&quot;&gt;Next → &lt;/a&gt;
&lt;/p&gt;
&lt;br /&gt; &lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;For more Vim stuff : &lt;a class=&quot;bodyclass&quot; href=&quot;http://vimtutorials.org/&quot;&gt;vimtutorials.org&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Follow &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.facebook.com/FreBlogg/&quot;&gt;FreBlogg on Facebook&lt;/a&gt; for more interesting articles.&lt;/p&gt;
&lt;h4 id=&quot;attributions&quot;&gt;Attributions:&lt;/h4&gt;
&lt;p&gt;Vim Logo - Vim Replacement Icon http://wolfrosch.com/works/goodies/vim (CC BY-NC-ND 3.0)&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/7352028039649706049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2016/10/your-first-lesson-in-vim-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/7352028039649706049'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/7352028039649706049'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2016/10/your-first-lesson-in-vim-3.html' title='Navigating in Vim I | Your First Lesson In Vim'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-1163967570624278913</id><published>2016-10-02T13:30:00.000+02:00</published><updated>2017-08-11T21:41:19.216+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gvim"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Vim"/><category scheme="http://www.blogger.com/atom/ns#" term="VimFirstLesson"/><title type='text'>How to Exit Vim? | Your First Lesson In Vim</title><content type='html'>&lt;p&gt;This is the second article in the series titled, &amp;quot;&lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/VimFirstLesson&quot;&gt;Your First Lesson In Vim&lt;/a&gt;&amp;quot;. These articles are written with a goal of helping out new Vim users by teaching the awesomeness of the Vim editor and there by extending the Vim community. Vim though quite powerful, has a bad rep for being hard to learn and hard to get started with. So, even when someone is interested in learning about Vim, that infamous learning curve seem to be scaring them off. This series is going to put an end to all of that.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;http://wolfrosch.com/_img/works/goodies/icon/vim@2x&quot; alt=&quot;Vim Logo&quot; width=&quot;150&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the last article &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/2016/09/your-first-lesson-in-vim-introduction.html&quot;&gt;Introduction &amp;amp; Installation&lt;/a&gt; we have seen why Vim is the best and coolest editor ever. Hopefully after watching Damian Conway&#39;s YouTube video given at the end of that article, you would agree. In this article we will experience Vim for the first time. We will learn about the various modes of operations in Vim. And, most importantly as the title of the article suggests, we will learn &lt;strong&gt;How to Exit Vim&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;First thing&#39;s first, You have to open Vim, duh!. You can do that either by directly searching for &lt;code&gt;Vim&lt;/code&gt; in your Search box or by typing &lt;code&gt;vim&lt;/code&gt; in to your terminal. If you want to start off with &lt;code&gt;gvim&lt;/code&gt; then open that instead. Your Gvim or Mac Vim would look something like this.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/gvim_start.png&quot; alt=&quot;Gvim startup picture&quot;  width=&quot;450&quot; &gt;&lt;/p&gt;
&lt;p&gt;If you have already tried to type something, you would observe that there is something shady going on here. For example, if you type &lt;code&gt;hello world&lt;/code&gt; you might observe that only &lt;code&gt;world&lt;/code&gt; is displayed and &lt;code&gt;hello&lt;/code&gt; is no where to be seen. Try it out for yourself. This happens because of the infamous Vim modes. One of the first things you have to realize while using Vim is that its not like your typical run of the mill text editor. Vim works a bit differently and &lt;em&gt;Modes&lt;/em&gt; is one of the key things that makes vim different. So, let&#39;s take a look at them.&lt;/p&gt;
&lt;p&gt;Broadly speaking Vim has Four major modes of operation. That number keeps changing depending on who you&#39;re talking to because there are a few more modes that can technically be called sub-modes but some people insist on treating them as Seperate modes. But to keep things simple here &lt;strong&gt;4&lt;/strong&gt; is the magic number for you and &lt;strong&gt;4&lt;/strong&gt; is the answer to Life, Universe and Everything. Not &lt;em&gt;42&lt;/em&gt;, &lt;em&gt;4&lt;/em&gt;!&lt;/p&gt;
&lt;p&gt;The modes are :&lt;/p&gt;
&lt;h3 id=&quot;normal-mode&quot;&gt;&lt;a name=&quot;normal&quot;&gt;&lt;/a&gt;Normal Mode&lt;/h3&gt;
&lt;p&gt;Normal mode is the default mode you will be in when you open Vim. Normal mode is used for altering, deleting and formatting text. You won&#39;t be &lt;em&gt;inserting&lt;/em&gt; any new text into the document in this mode. Normal Mode is the mode you will be spending most of your time in. You can get to Normal mode by pressing &lt;code&gt;ESC&lt;/code&gt; from any other mode. One of the main things you will be doing in this mode is moving around your document.&lt;/p&gt;
&lt;p&gt;To move around the file in the window you might usually be using arrow keys. In Vim they will work the way you expect them to, but instead vim advises to use &lt;code&gt;h .. j .. k .. l&lt;/code&gt; for moving the cursor. The reason why this came to be and the advantages of this will be apparent in the &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-3.html&quot;&gt;next article&lt;/a&gt; but for now let&#39;s see how this works.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;h&lt;/code&gt; moves the cursor left, &lt;code&gt;l&lt;/code&gt; moves it right&lt;/p&gt;
&lt;p&gt;&lt;code&gt;j&lt;/code&gt; moves the cursor down, &lt;code&gt;k&lt;/code&gt; moves it up&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This following picture would make the idea clear.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/vim_navigation_hjkl.png&quot; alt=&quot;vim navigation&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you are thinking to stick with the arrow keys instead of &lt;code&gt;h j k l&lt;/code&gt;, it is fine. There are a lot of people who use vim this way. But trust me when I say using &lt;code&gt;h j k l&lt;/code&gt; speeds up you work flow a lot. Once you get used to this you wouldn&#39;t want to use arrow keys anymore. But anyway we will discuss more about the this in the next article.&lt;/p&gt;
&lt;p&gt;Working in Normal mode, you will see how everything you do get&#39;s easy in Vim. For a quick sneak peak of some commands.&lt;/p&gt;
&lt;table style=&quot;width:68%;&quot;&gt;
&lt;colgroup&gt;
&lt;col width=&quot;15%&quot; /&gt;
&lt;col width=&quot;52%&quot; /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th align=&quot;center&quot;&gt;Command&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;What it does?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;dd&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;delete the current line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;yy&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Copy (&lt;em&gt;yank&lt;/em&gt;) the current line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;p&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;paste the copied text below the current line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;u&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Undo your previous change&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;gg&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the beginning of the file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;G&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Go to the end of the file&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;From now on you don&#39;t have to awkwardly select the full line with your mouse to delete it. All you have to do is press &lt;code&gt;dd&lt;/code&gt; and that sucker goes away.&lt;/p&gt;
&lt;p&gt;Didn&#39;t mean to delete it? No problem. Just hit &lt;code&gt;u&lt;/code&gt; and it undoes the delete. No more holding down &lt;code&gt;Ctrl&lt;/code&gt; and &lt;code&gt;z&lt;/code&gt;. Also&lt;code&gt;u&lt;/code&gt; for &lt;code&gt;undo&lt;/code&gt; is so simple to remember. What does &lt;code&gt;Z&lt;/code&gt; even mean in &lt;code&gt;Ctrl + z&lt;/code&gt;? And how did that become synonymous to Undo?&lt;/p&gt;
&lt;p&gt;Similarly no more &lt;code&gt;Ctrl + c&lt;/code&gt; and &lt;code&gt;Ctrl + v&lt;/code&gt; to copy and paste. &lt;code&gt;yy&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt; got you covered.&lt;/p&gt;
&lt;p&gt;So you see, Vim sticks to its philosophy of making you productive. Imagine all the keystrokes you save per day, per year. So, switching to Vim doesn&#39;t just improve your productivity, it take care of your health too. With every Key you saved keeps you a key away from getting Carpel Tunnels and RSI. So, Use Vim - Stay healthy. :]&lt;/p&gt;
&lt;p&gt;You might be happy with using &lt;code&gt;Ctrl+c&lt;/code&gt; to copy and &lt;code&gt;Ctrl+v&lt;/code&gt; to paste in your plain old editor. Its absolutely fine but Vim offers a simple and easy alternative and honestly the choice is pretty clear.&lt;/p&gt;
&lt;p&gt;Anyways, that is about Normal mode for now. We will discuss more later when required. Let&#39;s look at Insert mode.&lt;/p&gt;
&lt;h3 id=&quot;insert-mode&quot;&gt;&lt;a name=&quot;insert&quot;&gt;&lt;/a&gt;Insert Mode&lt;/h3&gt;
&lt;p&gt;As the name suggests Insert mode is where you will inserting text and that is all you will be doing in here. You enter Insert mode by pressing &lt;code&gt;i&lt;/code&gt; in Normal mode . And in almost all Vim distributions you should see a noticeable change in the cursor right away. It would have changed from a block type cursor (&lt;code&gt;█&lt;/code&gt;) to a I-beam (|). That&#39;s your indication that you&#39;re in Insert mode. In another tutorial we will see how you make that even more apparent. Whatever you type in Insert mode would be displayed on the file literally. If you type &lt;code&gt;a b c&lt;/code&gt;, it types in those characters in to the file as you would expected. Contrast this from pressing &lt;code&gt;dd&lt;/code&gt; in Normal mode which doesn&#39;t print them on the file but instead does something to the file (In this case, a delete operation).&lt;/p&gt;
&lt;p&gt;Unlike other editors you wont be spending much time here and Infact I&#39;d advise you to get out of Insert mode once you are done typing. To go out of Insert mode you just have to press &lt;code&gt;Esc&lt;/code&gt; and you will be back in Normal Mode.&lt;/p&gt;
&lt;p&gt;Now, Let&#39;s get to the fun part of insert mode. Remember before when I said you go from Normal mode to Insert mode by pressing &lt;code&gt;i&lt;/code&gt;, well, It turns out it is just one of the ways to get in to Insert mode. There are five more ways in which you can enter Insert mode and you can choose the best one based on what you need. Sounds complicated? Let&#39;s list them down first.&lt;/p&gt;
&lt;table&gt;
&lt;colgroup&gt;
&lt;col width=&quot;13%&quot; /&gt;
&lt;col width=&quot;86%&quot; /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th align=&quot;center&quot;&gt;Command&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;Operation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;i&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Enters Insert mode with the cursor placed before the current character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;a&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Enters Insert mode with the cursor placed after the current character (Remember a - after)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;o&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Enters Insert mode by opening a new line below the current line (Remember o - open)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;I&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Enters Insert mode by placing the cursor at the beginning of the line (Remember big I - bigger version of i)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;A&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Enters Insert mode by placing the cursor at the end of the line (Remember big A - bigger version of a)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;O&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Enters Insert mode by opening a new line above the current line (Remember o - open)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;As explained each one has a specific purpose.&lt;/p&gt;
&lt;p&gt;If you want to quickly create a new line above the current line and start typing - You press &lt;code&gt;O&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you want to insert a new line below the current line - You press &lt;code&gt;o&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To add something quickly at the end of a line - You press &lt;code&gt;A&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To add something at the beginning of a line - You press &lt;code&gt;I&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Could that be any more simpler? Surprisingly none of the other popular text editors do this. I can promise you that you won&#39;t be able to move so quickly in any other editor. This is Vim&#39;s power.&lt;/p&gt;
&lt;p&gt;Let&#39;s look at another easy mode that will help you visualize things better, Enter Visual Mode.&lt;/p&gt;
&lt;h3 id=&quot;visual-mode&quot;&gt;&lt;a name=&quot;visual&quot;&gt;&lt;/a&gt;Visual Mode&lt;/h3&gt;
&lt;p&gt;If you have carefully looked at things till now you might have started to feel that Vim favours Keyboard commands using a mouse. If you thought so, you would be absolutely correct. So, in the spirit of &lt;em&gt;No Mouse&lt;/em&gt;, Visual mode tries to emulate Visual selections of your text similar to the way a mouse selects on Screen but instead with completely with the keyboard.&lt;/p&gt;
&lt;p&gt;To enter in to Visual mode, just press &lt;code&gt;v&lt;/code&gt; and move your cursor with either &lt;code&gt;h j k l&lt;/code&gt; or the arrow keys and you will see that the text is getting highlighted indicating that it has been selected. Now, what can you do on this selected text? You can press &lt;code&gt;d&lt;/code&gt; and delete it completely or you can press &lt;code&gt;y&lt;/code&gt; and copy it. Notice that these are &lt;code&gt;d&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; and not &lt;code&gt;dd&lt;/code&gt; and &lt;code&gt;yy&lt;/code&gt; like in Normal mode. With &lt;code&gt;v&lt;/code&gt;, Visual selection happens character by character. But if you want to select the full line, press &lt;code&gt;V&lt;/code&gt; instead and you have the whole line highlighted and you can delete, copy or run any other command on the highlighted text.&lt;/p&gt;
&lt;p&gt;This is how it looks like when you&#39;ve something selected in Visual mode.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/visual_mode_selection.png&quot; alt=&quot;Vim visual mode selection&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;And to exit out of Visual mode or to cancel the selection, just press &lt;code&gt;ESC&lt;/code&gt;.&lt;/p&gt;
&lt;table style=&quot;width:54%;&quot;&gt;
&lt;colgroup&gt;
&lt;col width=&quot;15%&quot; /&gt;
&lt;col width=&quot;38%&quot; /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th align=&quot;center&quot;&gt;Command&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;Operation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td align=&quot;center&quot;&gt;v&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Visual selection by character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td align=&quot;center&quot;&gt;V&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Visual selection by line&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;We are finally down to the last mode, which is the Command mode &lt;em&gt;(You don&#39;t take Command, Son)&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;command-mode&quot;&gt;&lt;a name=&quot;command&quot;&gt;&lt;/a&gt;Command Mode&lt;/h3&gt;
&lt;p&gt;Vim command mode is very powerful and one of the reasons why Vim is so versatile. Command mode is where you type Vim&#39;s commands, Vim configurations, Plugin settings, Open new files, close existing files and also access Vim&#39;s builtin help documentation. You enter to Command mode by typing &lt;code&gt;:&lt;/code&gt; and then you type in the command you want. After you press &lt;code&gt;:&lt;/code&gt; you will see the cursor at the bottom of the screen (called the &lt;em&gt;last line&lt;/em&gt; appropriately) and you type the command.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/command_mode_vim.png&quot; alt=&quot;vim command mode example&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;To open a file, you type in &lt;code&gt;:e file_name&lt;/code&gt; (&lt;code&gt;:e&lt;/code&gt; is short for &lt;code&gt;:edit&lt;/code&gt;)and hit &lt;code&gt;Enter&lt;/code&gt;. If the file exists Vim will open it for you and if doesn&#39;t exist Vim will open blank file for you and the file will be created when you save it.&lt;/p&gt;
&lt;p&gt;To save or rather to &lt;em&gt;write&lt;/em&gt; the file to disk, you do &lt;code&gt;:w&lt;/code&gt; and hit &lt;code&gt;Enter&lt;/code&gt; for it to be saved. If the file doesn&#39;t yet have a name, You type &lt;code&gt;:w file_name&lt;/code&gt; and it will save the contents of the window with that file name.&lt;/p&gt;
&lt;p&gt;And Now for the most important question in all of Vim&#39;s History and the given title of this article, &lt;strong&gt;How to exit Vim&lt;/strong&gt;! If you are using a Graphical version of Vim, then closing Vim is the same as closing the window and &lt;em&gt;poof&lt;/em&gt;, its gone. But If you&#39;re using a terminal (works in gvim and macvim too) then you quit Vim by typing &lt;code&gt;:q&lt;/code&gt; (short for &lt;code&gt;:quit&lt;/code&gt;) and that closes the current window. If you have unsaved changes in your buffer Vim will give an error saying &lt;code&gt;No Write Since Last Change&lt;/code&gt;. If you don&#39;t mind discarding unsaved changes, you append a &lt;code&gt;!&lt;/code&gt; and so the command becomes &lt;code&gt;:q!&lt;/code&gt;. That is all there is about how you exit Vim. The bang(&lt;code&gt;!&lt;/code&gt;) at the end is similar to &lt;code&gt;-f&lt;/code&gt; or &lt;code&gt;--force&lt;/code&gt; option in a lot of linux commands. It forces Vim to quit even when there are unsaved changes.&lt;/p&gt;
&lt;p&gt;From now on if you ever saw a meme like this, you know what they are talking about.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;https://comic.browserling.com/vim.png&quot; alt=&quot;vim how to exit meme&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;Another important Vim command is &lt;code&gt;:help&lt;/code&gt;. It contains the full help manual for Vim and so should be one of your most used commands in the initial days of learning.&lt;/p&gt;
&lt;p&gt;And similar to other modes, you exit command mode by pressing the &lt;code&gt;Esc&lt;/code&gt; key and you will be back in the Normal mode.&lt;/p&gt;
&lt;p&gt;This image illustrates how you switch from one mode to another&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/vim_modes_small.png&quot; alt=&quot;Vim_modes&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;Okay. That&#39;s a lot of information for one article. Let&#39;s do a quick review.&lt;/p&gt;
&lt;h3 id=&quot;story-recap&quot;&gt;Story Recap&lt;/h3&gt;
&lt;p&gt;There are four modes of operations in Vim.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;bodyclass&quot; href=&quot;#normal&quot;&gt;Normal Mode&lt;/a&gt; : moving around the document, deleting, copying, formatting are some of the common things you do in this mode&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;bodyclass&quot; href=&quot;#insert&quot;&gt;Insert Mode&lt;/a&gt; : Inserts text in to the document. Go into Insert mode by typing any one of &lt;code&gt;a A i I o O&lt;/code&gt; in Normal mode. Come out with &lt;code&gt;Esc&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;bodyclass&quot; href=&quot;#visual&quot;&gt;Visual Mode&lt;/a&gt; : For visually selecting the text. Enter with &lt;code&gt;v&lt;/code&gt; or &lt;code&gt;V&lt;/code&gt; and exit with &lt;code&gt;Esc&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;bodyclass&quot; href=&quot;#command&quot;&gt;Command Mode&lt;/a&gt; : To execute commands. &lt;code&gt;:w&lt;/code&gt; to save, &lt;code&gt;:help&lt;/code&gt; for documentation and &lt;code&gt;:q&lt;/code&gt; to quit.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Well, That is all for this article folks. Will see you again in the next one. Until then, Keep practicing and Happy Vimming!&lt;/p&gt;
&lt;p&gt;
&lt;a class=&quot;navlinkleft&quot; href=&quot;http://www.freblogg.com/2016/09/your-first-lesson-in-vim-introduction.html&quot;&gt; ← Prev&lt;/a&gt; &lt;a class=&quot;navlinkright&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-3.html&quot;&gt;Next → &lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more Vim stuff : &lt;a class=&quot;bodyclass&quot; href=&quot;http://vimtutorials.org/&quot;&gt;vimtutorials.org&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Follow &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.facebook.com/FreBlogg/&quot;&gt;FreBlogg on Facebook&lt;/a&gt; for more interesting articles.&lt;/p&gt;
&lt;h4 id=&quot;attributions&quot;&gt;Attributions:&lt;/h4&gt;
&lt;p&gt;Vim Logo - Vim Replacement Icon http://wolfrosch.com/works/goodies/vim (CC BY-NC-ND 3.0)&lt;/p&gt;
&lt;p&gt;Vim Ninja image - https://goo.gl/QgTrsY (Originally from Practical Vim by Drew Neal)&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/1163967570624278913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2016/10/your-first-lesson-in-vim-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/1163967570624278913'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/1163967570624278913'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2016/10/your-first-lesson-in-vim-2.html' title='How to Exit Vim? | Your First Lesson In Vim'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-8582332682163926968</id><published>2016-09-24T17:50:00.003+02:00</published><updated>2017-08-11T21:41:19.464+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gvim"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Vim"/><category scheme="http://www.blogger.com/atom/ns#" term="VimFirstLesson"/><title type='text'>Introduction &amp; Installation | Your First Lesson In Vim</title><content type='html'>&lt;p&gt;This is the first article in a series of articles titled, &amp;quot;&lt;a class=&quot;bodyclass&quot; href=&quot;http://www.freblogg.com/search/label/VimFirstLesson&quot;&gt;Your First Lesson In Vim&lt;/a&gt;&amp;quot;. These articles are written with a goal of helping out new Vim users by teaching the awesomeness of the Vim editor and there by extending the Vim community. Vim though quite powerful, has a bad rep for being hard to learn and hard to get started with. So, even when someone is interested in learning about Vim, that infamous learning curve seem to be scaring them off. This series is going to put an end to all of that.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot;  src=&quot;http://wolfrosch.com/_img/works/goodies/icon/vim@2x&quot; alt=&quot;Vim Logo&quot; width=&quot;150&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Warning&lt;/strong&gt; : After going through all the articles in this series you will love Vim so much that you would like to have Vim style keyboard bindings everywhere, in your browser, in your mail client, in your shell and every other place which has a text input, which might not always be possible. So, Continue further at your own risk. YOU HAVE BEEN WARNED!&lt;/p&gt;
&lt;p&gt;Vim is one of the best text editors available out there in the market. In fact it is one of the two best editors, the other being Emacs (This would be the last you&#39;ll see its name. From here on, it will be referred to as, &lt;em&gt;The Editor which shall not be named&lt;/em&gt; ). Now you might be wondering, what about Sublime Text ? or Atom ? or some other flashy editor that&#39;s getting attention. My answer to that is very simple - East or West, Vim is the best. Don&#39;t get me wrong, editors like Sublime, Atom are good and I was a fan of Sublime myself. But to be called the best, a Text Editor needs to customizable, extensible and most importantly should have a huge community of users helping out each other. None of these editors can beat Vim in those areas. Apart from that Vim is really fast and robust. It can open huge files that makes other editors crash. It has builtin syntax support for hundred&#39;s of file types. It has a huge plugin base that both extend vim&#39;s functionality and add more functionality to do pretty much any thing you want. And that&#39;s just a few reasons why its the best.&lt;/p&gt;
&lt;p&gt;Since you are reading this article, I assume that you&#39;re interested in learning about what Vim is and about what Vim does. So, Let&#39;s start with some brief history of how the Vim editor came to be.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In 1970&#39;s, Bill Joy developed &lt;strong&gt;ex&lt;/strong&gt; editor for Unix which later came to be known as the &lt;em&gt;Vi&lt;/em&gt; editor for having a &lt;em&gt;Vi&lt;/em&gt;sual interface for editing.&lt;/li&gt;
&lt;li&gt;1987 - &lt;strong&gt;Stevie&lt;/strong&gt; was developed as a clone of Vi for Atari ST systems. Stevie stands for &#39;ST Editor for Vi Enthusiasts&#39;. The name might be a mouthful but the editor itself is quite popular.&lt;/li&gt;
&lt;li&gt;1988 - Vim (Vi IMitation) was created by Bram Moolenaar (Remember the name ..) as a port of Stevie for AmigaOS. Though started as an imitation, Vim quickly started to add several new features with support for multiple operating systems.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;1993 - Vim 2.0 released with name changed to &#39;Vi IMproved&#39; because, by then Vim had a lot more features than original Vi.&lt;/p&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;p&gt;. Fast forwarding history&lt;/p&gt;
&lt;p&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;2006 - Vim 7.0 released with support for tabs, code completion, undo branching and a lot more&lt;/li&gt;
&lt;li&gt;&lt;p&gt;2016 - Vim 8.0 released with a lot of exciting features like Asynchronous I/O, channels, Jobs, Timers, Packages and a lot more&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;(Shout out to &lt;a class=&quot;bodyclass&quot; href=&quot;https://buildingvts.com/a-brief-history-of-vim-1476ec4a6eb8#.dyvv00erx&quot;&gt;buildingvts.com&lt;/a&gt; for putting this history together)&lt;/p&gt;
&lt;p&gt;So, as you can see from our brief Time travel, Vim has been around for almost 30 years. Now you might be asking yourself, why the heck is this editor still used today after almost 30 years. That&#39;s a good question and one that needs to answered right now.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Floppy disks&quot; src=&quot;https://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Floppy_disk_2009_G1.jpg/800px-Floppy_disk_2009_G1.jpg&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;Technology sure changes a lot and old things usually tend to get lost with all the new things that keep coming. But in the case of Vim or &lt;em&gt;The Editor which shall not be named&lt;/em&gt;, that is simply not the case. They fall in to the category of &amp;quot;Old is Gold&amp;quot;. These editors are written during the days when floppy disks and magnetic tapes were all the rage and hence are written to be memory efficient. Though Vim has changed a lot over the years to add countless new features, the fundamental idea of being light weight and memory efficient is still one of its big selling points. That is the reason why Vim managed to stay relevant through three decades and that is also the reason why it will continue to be relevant for more decades to come.&lt;/p&gt;
&lt;p&gt;So, If that answer convinced you to stay the course and explore the exciting and enticing world of Vim, then Welcome aboard! Make sure to remember that this is the day you have decided to take your text editing to the next level by learning Vim.&lt;/p&gt;
&lt;p&gt;Now that we know the history of Vim, its time to install Vim on your Computers. If you are rocking a Linux Operating system, chances are you already have a version of Vim pre-installed. So, check if it exists by typing &lt;code&gt;vi&lt;/code&gt; or &lt;code&gt;vim&lt;/code&gt; in the command line. If it is available, you should see a screen that looks something like this.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;aligncenter&quot; alt=&quot;Vim start screen image here&quot; src=&quot;https://raw.githubusercontent.com/durgaswaroop/Your_First_Lesson_In_Vim/master/pictures/vim_start_screen.png&quot; width=&quot;450&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you see this then Vim is already installed.&lt;/p&gt;
&lt;p&gt;If you don&#39;t have it installed, don&#39;t worry. Vim is a freeware (correction: Charity ware) and so you can download it for free from Vim&#39;s official site &lt;a class=&quot;bodyclass&quot; href=&quot;http://www.vim.org/&quot;&gt;Vim.org&lt;/a&gt;. Vim is available for pretty much every major Operating system out there. I heard that there is a version of Vim available even for Toasters. I have no idea who might use that, but its there if you need it. And this is another reason why people like vim so much.No matter the OS, they can be sure that their favorite editor is available. So, Just download vim for your operating system and install it.&lt;/p&gt;
&lt;p&gt;And by the way, did I mention that Vim is primarily a terminal based program? It was initially designed to be run in terminals to access files on remote systems. A lot of people to this day, prefer the terminal version of Vim. But to those of you who like to have a Graphical User Interface (GUI) you&#39;ve that available as well.&lt;/p&gt;
&lt;p&gt;For windows users, it can be downloaded from the vim.org site. Look for Gvim (stands for Graphical Vim) For mac users, you can download Mac Vim which provides a good GUI experience. For Linux users, there are Gvim versions available for most of the distros. So, download the one suitable for your distribution.&lt;/p&gt;
&lt;p&gt;If you have successfully installed Vim on your systems open Vim either in Terminal or the GUI and you should see a welcome screen similar to the picture above. If you got that, then Congratulations, you have the power of Vim with you now.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Don&#39;t forget what Uncle Ben said, &amp;quot;With great power comes, great responsibility&amp;quot;. So, your responsibility as a Vim user is to spread the vim awesomeness with your co-workers and friends. It would be even better if you can share this article with them but that is entirely up to you. (Jedi mind tricks working implicitly)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And before we finish this article I will give you a sneak peak at the power of Vim and what you can do with it. Watch Damian Conway&#39;s Video on Vim : &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.youtube.com/watch?v=aHm36-na4-4&quot;&gt;More Instantly better Vim&lt;/a&gt;. Conway is one of the Vim geniuses whom I admire a lot. This video gives you a small window in to the world of Vim and what Vim can do in the hands of a seasoned user. You might not be able to understand understand how Conway is doing his magic but that is entirely fine. You obviously won&#39;t be able to understand Linux Kernel module code right when you&#39;re starting to write &lt;em&gt;Hello World&lt;/em&gt; programs. This video is just to show you how the masters use Vim and you will be able to do that too once you&#39;ve mastered it.&lt;/p&gt;
&lt;p&gt;Well, That is all for this article folks. Will see you again in the next one. Until then, Keep practicing and Happy Vimming!&lt;/p&gt;
&lt;a class=&quot;navlinkright&quot; href=&quot;http://www.freblogg.com/2016/10/your-first-lesson-in-vim-2.html&quot;&gt;Next → &lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;For more Vim stuff : &lt;a class=&quot;bodyclass&quot; href=&quot;http://vimtutorials.org/&quot;&gt;vimtutorials.org&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Follow &lt;a class=&quot;bodyclass&quot; href=&quot;https://www.facebook.com/FreBlogg/&quot;&gt;FreBlogg on Facebook&lt;/a&gt; for more interesting articles.&lt;/p&gt;
&lt;h4 id=&quot;attributions&quot;&gt;Attributions:&lt;/h4&gt;
&lt;p&gt;Vim Logo - Vim Replacement Icon http://wolfrosch.com/works/goodies/vim (CC BY-NC-ND 3.0)&lt;/p&gt;
&lt;p&gt;Floppy Disks - https://goo.gl/0Ns2Dj&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/8582332682163926968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2016/09/your-first-lesson-in-vim-introduction.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/8582332682163926968'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/8582332682163926968'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2016/09/your-first-lesson-in-vim-introduction.html' title='Introduction &amp; Installation | Your First Lesson In Vim'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-397283489392452163</id><published>2016-07-18T02:00:00.000+02:00</published><updated>2017-08-11T21:41:19.310+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gvim"/><category scheme="http://www.blogger.com/atom/ns#" term="tab pages"/><category scheme="http://www.blogger.com/atom/ns#" term="Vim"/><category scheme="http://www.blogger.com/atom/ns#" term="vim tabs"/><title type='text'>Using Tab Pages in Vim | Vim</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;https://pbs.twimg.com/profile_images/64545277/vim_logo_400x400.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img alt=&quot;vim-logo-freblogg-tabs&quot; border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://pbs.twimg.com/profile_images/64545277/vim_logo_400x400.png&quot; title=&quot;vim-logo-freblogg&quot; width=&quot;200&quot;&gt;&lt;/a&gt;Using Tabs (vim calls them tab pages) is one of the sure ways to increase your productivity. Vim Tabs are just like the tabs in your browsers. Each tab can have multiple splits (referred as windows in Vim&amp;#39;s documentation). So, you can have multiple splits open in one tab and then you can have multiple tabs.&lt;br&gt;
&lt;br&gt;
Tabs are a really handy way of grouping things together. So, I usually have multiple tabs open in any session. I have a main editor tab where i will have multiple splits open for the code I am looking at and since I work with a lot of data files, I will have one tab dedicated for the data-sets that I will be using for my program. And, then if required, I will have another tab open for any notes, info that I have previously noted down.&lt;br&gt;
&lt;/div&gt;&lt;a href=&quot;https://durgaswaroop.blogspot.com/2016/07/tab-pages-in-vim.html#more&quot;&gt;[..Read More..]&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/397283489392452163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2016/07/tab-pages-in-vim.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/397283489392452163'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/397283489392452163'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2016/07/tab-pages-in-vim.html' title='Using Tab Pages in Vim | Vim'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-5709000960189674837</id><published>2016-06-23T02:00:00.000+02:00</published><updated>2017-08-11T21:41:19.353+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Apache Spark"/><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Maven"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Wordcount"/><title type='text'>Word Count application with Apache Spark and Java</title><content type='html'>
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Apache Spark is becoming ubiquitous by day and has been dubbed the next big thing in the Big Data world. Spark has been replacing MapReduce with its speed and scalability. In this &lt;a href=&quot;http://www.freblogg.com/search/label/Apache%20Spark&quot; target=&quot;_blank&quot;&gt;Spark series&lt;/a&gt; we will try to solve various problems using Spark and &lt;a href=&quot;http://www.freblogg.com/search/label/Java&quot; target=&quot;_blank&quot;&gt;Java&lt;/a&gt;.&lt;br&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.freblogg.com/2016/06/spark-word-count-with-java.html&quot;&gt;&lt;img alt=&quot;spark-java-freblogg&quot; border=&quot;0&quot; src=&quot;http://www.datanami.com/wp-content/uploads/2014/12/spark-and-java-8.png&quot; title=&quot;&quot;&gt;&lt;/a&gt;&lt;/div&gt;
Word count program is the big data equivalent of the classic &lt;i&gt;Hello world&lt;/i&gt; program. The aim of this program is to scan a text file and display the number of times a word has occurred in that particular file. And for this word count application we will be using Apache spark 1.6 with Java 8.&lt;br&gt;
&lt;br&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href=&quot;https://durgaswaroop.blogspot.com/2016/06/spark-word-count-with-java.html#more&quot;&gt;[..Read More..]&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/5709000960189674837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2016/06/spark-word-count-with-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/5709000960189674837'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/5709000960189674837'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2016/06/spark-word-count-with-java.html' title='Word Count application with Apache Spark and Java'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6103469486614880434.post-2965375969751207078</id><published>2016-06-19T00:06:00.000+02:00</published><updated>2017-08-11T21:41:19.250+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bernie Sanders"/><category scheme="http://www.blogger.com/atom/ns#" term="Hillary Clinton"/><category scheme="http://www.blogger.com/atom/ns#" term="Politics"/><category scheme="http://www.blogger.com/atom/ns#" term="Presidential Elections"/><category scheme="http://www.blogger.com/atom/ns#" term="Trump"/><category scheme="http://www.blogger.com/atom/ns#" term="US Elections"/><title type='text'>Should a Sanders supporter vote for Hillary if she wins the nomination ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
If you are Bernie supporter  and you are unable to decide whether to vote for Hillary or not in the final elections (when Hillary gets the nomination), then this post will provide you some direction.&lt;br&gt;
&lt;br&gt;
If someone is supporting Bernie Sanders it could be because of any of these two reasons :&lt;br&gt;
&lt;br&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;He wants to vote for someone outside the establishment&lt;/li&gt;
&lt;li&gt;He believes Bernie’s vision and ideals&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.freblogg.com/2016/06/should-a-sanders-supporter-vote-for-hillary.html&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://media.jrn.com/images/b99660308z.1_20160129113530_000_gite9m9v.1-0.jpg&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;&lt;a href=&quot;https://durgaswaroop.blogspot.com/2016/06/should-a-sanders-supporter-vote-for-hillary.html#more&quot;&gt;[..Read More..]&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://durgaswaroop.blogspot.com/feeds/2965375969751207078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://durgaswaroop.blogspot.com/2016/06/should-a-sanders-supporter-vote-for-hillary.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/2965375969751207078'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6103469486614880434/posts/default/2965375969751207078'/><link rel='alternate' type='text/html' href='https://durgaswaroop.blogspot.com/2016/06/should-a-sanders-supporter-vote-for-hillary.html' title='Should a Sanders supporter vote for Hillary if she wins the nomination ?'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>