<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://abhinavpy.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://abhinavpy.github.io/" rel="alternate" type="text/html" /><updated>2024-02-09T01:32:00-08:00</updated><id>https://abhinavpy.github.io/feed.xml</id><title type="html">Abhinav P Y / Personal Website</title><subtitle>personal description</subtitle><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><entry><title type="html">Future Blog Post</title><link href="https://abhinavpy.github.io/posts/2012/08/blog-post-4/" rel="alternate" type="text/html" title="Future Blog Post" /><published>2199-01-01T00:00:00-08:00</published><updated>2199-01-01T00:00:00-08:00</updated><id>https://abhinavpy.github.io/posts/2012/08/future-post</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2012/08/blog-post-4/">&lt;p&gt;This post will show up by default. To disable scheduling of future posts, edit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.yml&lt;/code&gt; and set &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;future: false&lt;/code&gt;.&lt;/p&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="cool posts" /><category term="category1" /><category term="category2" /><summary type="html">This post will show up by default. To disable scheduling of future posts, edit config.yml and set future: false.</summary></entry><entry><title type="html">Daily Blog Post 29th June 2022</title><link href="https://abhinavpy.github.io/posts/2022/06/daily-post/" rel="alternate" type="text/html" title="Daily Blog Post 29th June 2022" /><published>2022-06-29T00:00:00-07:00</published><updated>2022-06-29T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/06/Daily-Post</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/06/daily-post/">&lt;h2 id=&quot;knowledge-transfer-of-digital-ai-product-highest-priority-4-hours&quot;&gt;Knowledge Transfer of Digital AI product (Highest Priority) (4 hours)&lt;/h2&gt;
&lt;p&gt;Finish at least 4 videos from the KT Sessoins take by Vinay (Suggested by Yashas Manjunath).&lt;/p&gt;

&lt;h2 id=&quot;finish-the-introductory-numerify-pdf-1-hour&quot;&gt;Finish the Introductory Numerify PDF (1 Hour)&lt;/h2&gt;
&lt;p&gt;Finish as many topics as possible on the Numerify PDF.&lt;/p&gt;

&lt;h2 id=&quot;spring-mvc-finish-a-project-from-the-udemy-course-2-hours&quot;&gt;Spring MVC (Finish a project from the Udemy Course) (2 hours)&lt;/h2&gt;
&lt;p&gt;Java Spring course - Finish one full course with project&lt;/p&gt;

&lt;h2 id=&quot;leetcode---solve-10-problems-2-hours&quot;&gt;LeetCode - Solve 10 Problems (2 hours)&lt;/h2&gt;
&lt;p&gt;Finish problems and write solutions here on Github.&lt;/p&gt;

&lt;h2 id=&quot;finish-one-sheet-of-vocab-for-gre-high-priority-1-hour&quot;&gt;Finish one sheet of vocab for GRE (High Priority) (1 hour)&lt;/h2&gt;
&lt;p&gt;Finish a sheet and write down the meanings of all words learnt.&lt;/p&gt;

&lt;h2 id=&quot;learn-web-design-finish-html-andor-css-section-1&quot;&gt;Learn Web Design (Finish HTML and/or CSS Section 1)&lt;/h2&gt;
&lt;p&gt;Finish a module of FreeCodeCamp HTML or CSS. Or maybe even React.js.&lt;/p&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="50 Words Vocabulary Day 2" /><category term="LeetCode - 10 Problems" /><category term="Spring MVC - Notes and Learning" /><category term="Numerify PDF Concepts Book" /><category term="KT - Vinay 4 Videos" /><summary type="html">Knowledge Transfer of Digital AI product (Highest Priority) (4 hours) Finish at least 4 videos from the KT Sessoins take by Vinay (Suggested by Yashas Manjunath).</summary></entry><entry><title type="html">Daily Blog Post 2 May 2022</title><link href="https://abhinavpy.github.io/posts/2022/05/daily-post/" rel="alternate" type="text/html" title="Daily Blog Post 2 May 2022" /><published>2022-05-02T00:00:00-07:00</published><updated>2022-05-02T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/05/Daily-Post</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/05/daily-post/">&lt;h2 id=&quot;chapter-2---william-stallings-coa&quot;&gt;Chapter 2 - William Stallings COA&lt;/h2&gt;
&lt;p&gt;Finished Reading the chapter - spent 1.5 hours.&lt;/p&gt;

&lt;h2 id=&quot;chapter-2---ddia&quot;&gt;Chapter 2 - DDIA&lt;/h2&gt;
&lt;p&gt;Finished reading the first section of the chapter - spent 1 hour.&lt;/p&gt;

&lt;h2 id=&quot;day-2-of-100daysofcode-for-javascript-and-nodejs---jwt-implementation-in-javascript&quot;&gt;Day 2 of 100DaysOfCode for JavaScript and NodeJS - JWT Implementation in JavaScript&lt;/h2&gt;
&lt;p&gt;Spent about 2.5 hours trying to implement JWT in JavaScript.&lt;/p&gt;

&lt;h2 id=&quot;reactjs---day-2-of-100daysofcode&quot;&gt;ReactJS - Day 2 of 100DaysOfCode&lt;/h2&gt;
&lt;p&gt;Went through the first component. Spent about 0.5 hours on this.&lt;/p&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="Chapter 2 - William Stallings COA" /><category term="Chapter 2 - Design of Data Intensive Applications" /><category term="JWT implementation in JavaScript" /><category term="Google OpenID, OAuth2.0" /><category term="ReactJS" /><summary type="html">Chapter 2 - William Stallings COA Finished Reading the chapter - spent 1.5 hours.</summary></entry><entry><title type="html">Daily Blog Post 1 May 2022</title><link href="https://abhinavpy.github.io/posts/2022/05/daily-post/" rel="alternate" type="text/html" title="Daily Blog Post 1 May 2022" /><published>2022-05-01T00:00:00-07:00</published><updated>2022-05-01T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/05/Daily-Post</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/05/daily-post/">&lt;h2 id=&quot;reactjs---started-day-1-of-100daysofcode-of-reactjs&quot;&gt;ReactJS - Started Day 1 of 100DaysOfCode of ReactJS&lt;/h2&gt;
&lt;p&gt;Studied about react components.
hen it comes to React it is all about components. 
You can think of components as independent chunks of user interfaces.
Components can be as small as one HTML element or you can be a rebel, and jam your entire facebook clone in one component. 
At the end of the day, a lot of it depends on your needs and wants. In reality though you will probably
avoid the one component route because it defeats the purpose of using React.&lt;/p&gt;

&lt;p&gt;You see the benefit of component is you can build a bunch of independent isolated, and most importantly reusable user interfaces that you can run and piece together just like lego blocks.&lt;/p&gt;

&lt;p&gt;And as a result, build even super complex apps without going insane.&lt;/p&gt;

&lt;p&gt;While your app can have as many components as you’d like, it will always have atleast one called 
root component.&lt;/p&gt;

&lt;p&gt;We already glossed over it a bit, but just to reiterate the major benefits of using components and essentially, react, develop your next app or phone, you can build independent pieces of user interfaces, meaning 
changing logic, or layout in one component will not break your OLAP once component is ready to go, you can reuse it all
throughout your app.&lt;/p&gt;

&lt;p&gt;But component code is still stored in one place.&lt;/p&gt;

&lt;p&gt;So if you ever need to make some changes, you don’t have to run around like a headless chicken, simply locate the component, apply the changes, and all the instances will be automatically updated.&lt;/p&gt;

&lt;p&gt;And of course, let’s also not forget about speed.&lt;/p&gt;

&lt;p&gt;You see behind the scenes, React is using something called virtual DOM, where only the component that needs to be updated, is affected.&lt;/p&gt;

&lt;p&gt;And what’s really cool, it’s done without rerendering the whole app, which in turn, of course, increases the speed of your final product.&lt;/p&gt;

&lt;p&gt;And as a result the user experience as well.&lt;/p&gt;

&lt;p&gt;Before we go, let’s look at a typical example of React that everyone uses to show React Components in Action. 
And that is no other than our beloved Twitter.&lt;/p&gt;

&lt;p&gt;So as we are looking at the screen, on the left hand side of the homescreen we see various React Components. 
So you will see a bunch of words, however you probably notice that each link has pretty much the same structure, where there is some kind of icon and associated text.&lt;/p&gt;

&lt;p&gt;So essentially what we could do is set this up as one component. And what that means is we will just set up a structure,
and everywhere where we would want to use it, we will just need to pass in the data.&lt;/p&gt;

&lt;p&gt;And by data of course I mean, the specific icon that is going to be rendered. And then of course the text.&lt;/p&gt;

&lt;p&gt;And as a result, what that also means that I can reuse that component, all throughout my application, however I would like.&lt;/p&gt;

&lt;p&gt;But if I would want to make some changes, for example if I would want to add something here, I can change it in one place, and then all the instances will be automatically updated. so that would be a links example.&lt;/p&gt;

&lt;p&gt;And you can probably already guess, the same, for example, would work with a post. Because when we are
looking at the post, what do we have, we have some kind of picture, we have the name, of course, we have 
the text, we have all the retweet options, as well as likes and comments, but the only thing that is 
changing is the data. So the person who is posting and how many likes, and that sort of thing. The point that 
I am trying to make is that as you are looking at the application, you can see a bunch of places where we can 
set up a react component, and then use all the awesome benefits the components provide.&lt;/p&gt;

&lt;p&gt;Before we go futher, let’s cover the main goals of this course, and honestly there is only one:
By the end of the course I should be comfortable with React. 
Now what that means is you can do two things. First, you are aware of external resources. And more 
importantly, you’re comfortable with using them. When you’d want to learn something new. Essentially
you know where to find useful info. And second, you are comfortable applying theory to practice by 
building your own project using React.&lt;/p&gt;

&lt;p&gt;While the Core API of react is essentially quite small, since it is by far the most popular framework out there,
the ecosystem surrounding react is as vast as you can imagine. What that means is that essentially, there 
will always be something new to learn about React.&lt;/p&gt;

&lt;p&gt;That’s why I would suggest adopting a student mindset instead, where you are always open to expanding your
React knowledge. In my experience, the best way to learn and get comfortable with language and framework is 
by building a bunch of projects. So that is exactly what we will do during this course, we’ll start small, 
our first project will be somewhat silly, but slowly and surely, we will expand on our knowledge. And by the end
of the course, you will be comfortable building your own complex React apps.&lt;/p&gt;

&lt;p&gt;Structure&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Dev Environment&lt;/li&gt;
  &lt;li&gt;Tutorial&lt;/li&gt;
  &lt;li&gt;Projects&lt;/li&gt;
  &lt;li&gt;Redux&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Course Requirements&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;HTML&lt;/li&gt;
  &lt;li&gt;CSS&lt;/li&gt;
  &lt;li&gt;JavaScript (ES6)&lt;/li&gt;
  &lt;li&gt;Coding Addict - JavaScript Nuggets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The more javascript you know the easier it is going to become. Because at the end of the day 
React is just javascript. 
So if you are familiar with things like spread operator, ro functions, destructuring etc. 
you will be in good shape.&lt;/p&gt;

&lt;p&gt;Dev Environment&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Node&lt;/li&gt;
  &lt;li&gt;Browser = Chrome&lt;/li&gt;
  &lt;li&gt;VSCode&lt;/li&gt;
  &lt;li&gt;React Developer Tools&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;css---100daysofcode-day---1&quot;&gt;CSS - 100DaysOfCode Day - 1&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Box Model - Extrinsic and Intrinsic Sizing.&lt;/li&gt;
  &lt;li&gt;Content Sizing&lt;/li&gt;
  &lt;li&gt;The area of the box model&lt;/li&gt;
  &lt;li&gt;A useful analogy&lt;/li&gt;
  &lt;li&gt;Debugging the box model&lt;/li&gt;
  &lt;li&gt;Controlling the box model&lt;/li&gt;
  &lt;li&gt;Resources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Content Sizing - Extrinsic sizing, Intrinsic sizing.&lt;/p&gt;

&lt;p&gt;The areas of the box model - margin box, border box, padding box, content box.&lt;/p&gt;

&lt;p&gt;The border box surrounds the padding box and its space is occupied by the border value. The border box is the bounds of your box and the border edge is the limit of what you can visually see. The border property is used to visually frame an element.&lt;/p&gt;

&lt;p&gt;The final area, the margin box, is the space around your box, defined by the margin rule on your box. Properties such as outline and box-shadow occupy this space too because they are painted on top, so they don’t affect the size of our box. You could have an outline-width of 200px on our box and everything inside and including the border box would be exactly the same size.&lt;/p&gt;

&lt;p&gt;Every browser applies a user agent stylesheet to HTML documents. The CSS used varies between each browser, but they provide sensible defaults to make content easier to read. They define how elements should look and behave if there’s no CSS defined. It is in the user agent styles where a box’s default display is set, too. For example, if we are in a normal flow, a &amp;lt;div&amp;gt; element’s default display value is block, a &amp;lt;li&amp;gt; has a default display value of list-item, and a &lt;span&gt; has a default display value of inline.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;An inline element has block margin, but other elements won’t respect it. Use inline-block, and those elements will respect the block margin, while the element maintains most of the same behaviors it had as an inline element. A block item will, by default, fill the available inline space, whereas a inline and inline-block elements will only be as large as their content.&lt;/p&gt;

&lt;p&gt;Alongside an understanding of how user agent styles affect each box, you also need to understand box-sizing, which tells our box how to calculate its box size. By default, all elements have the following user agent style: box-sizing: content-box;.&lt;/p&gt;

&lt;p&gt;Having content-box as the value of box-sizing means that when you set dimensions, such as a width and height, they will be applied to the content box. If you then set padding and border, these values will be added to the content box’s size.&lt;/p&gt;

&lt;h2 id=&quot;oauth-20&quot;&gt;OAuth 2.0&lt;/h2&gt;
&lt;p&gt;YouTube Link: https://youtu.be/Aj143QiiQPY&lt;/p&gt;

&lt;h2 id=&quot;api-kong&quot;&gt;API Kong&lt;/h2&gt;
&lt;p&gt;Wrote slides : https://docs.google.com/presentation/d/1WVtuhszW1a7pJk109EFxMZWOGhMQyUvIsMSl0yP9vUU/edit?usp=sharing&lt;/p&gt;

&lt;h2 id=&quot;computer-organization-and-architecture&quot;&gt;Computer Organization and Architecture&lt;/h2&gt;
&lt;p&gt;Read Chapter - 1 of William Stallings COA Book.&lt;/p&gt;

&lt;h2 id=&quot;dynamic-programming---100daysofcode---day-1&quot;&gt;Dynamic Programming - 100DaysOfCode - Day 1&lt;/h2&gt;
&lt;p&gt;https://leetcode.com/tag/dynamic-programming/discuss/662866/DP-for-Beginners-Problems-or-Patterns-or-Sample-Solutions&lt;/p&gt;

&lt;p&gt;The above problem list will be followed:&lt;/p&gt;

&lt;p&gt;Problem for Day - 1 : Longest Increasing Subsequence Variant : 
  Longest Increasing Subsequence: https://leetcode.com/problems/longest-increasing-subsequence/&lt;/p&gt;

&lt;p&gt;Sample Solution for LIS:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  int lengthOfLIS(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
    int n = nums.size();
  
    vector&amp;lt;int&amp;gt;LIS(n+1, 1);
    for(int i = 0; i &amp;lt; n; i++) {
      for(int j = 0; j &amp;lt; i; j++) {
        if(nums[i] &amp;gt; nums[j]) {
          LIS[i] = max(LIS[i], 1 + LIS[j]);
        }
      }
    }
  
    int ans = 0;
    for(i = 0; i &amp;lt; n; i++) {
      ans = max(ans, LIS[i]);
    }
    return ans;
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="CSS" /><category term="ReactJS" /><category term="API Kong Gateways" /><category term="OAuth2.0" /><category term="COA" /><summary type="html">ReactJS - Started Day 1 of 100DaysOfCode of ReactJS Studied about react components. hen it comes to React it is all about components. You can think of components as independent chunks of user interfaces. Components can be as small as one HTML element or you can be a rebel, and jam your entire facebook clone in one component. At the end of the day, a lot of it depends on your needs and wants. In reality though you will probably avoid the one component route because it defeats the purpose of using React.</summary></entry><entry><title type="html">RESTful API Golang 18 April 2022</title><link href="https://abhinavpy.github.io/posts/2022/04/resp-api-golang/" rel="alternate" type="text/html" title="RESTful API Golang 18 April 2022" /><published>2022-04-18T00:00:00-07:00</published><updated>2022-04-18T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/04/RESTAPIgolang</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/04/resp-api-golang/">&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package main

import(
	&quot;encoding/json&quot;
	&quot;fmt&quot;
	&quot;io/ioutil&quot;
	&quot;log&quot;
	&quot;net/http&quot;
	&quot;github.com/gorilla/mux&quot;
)

type event struct {
	ID string `json: &quot;ID&quot;`
	Title string `json: &quot;Title&quot;`
	Description string `json: &quot;Description&quot;`
}

type allEvents []event

var events = allEvents{
	event{ID : &quot;1&quot;, Title: &quot;Title1&quot;, Description: &quot;Desc1&quot;},
	event{ID : &quot;2&quot;, Title: &quot;Title2&quot;, Description: &quot;Desc2&quot;},
}

func homePage(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, &quot;Welcome to the homepage!!!&quot;)
	fmt.Println(&quot;Endpoint Hit: homePage&quot;)
}

func returnAllEvents(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, &quot;The events are as follows: &quot;)
	json.NewEncoder(w).Encode(events)
	fmt.Println(&quot;Endpoint Hit: returnAllEvents&quot;)
}

func getSingleEvent(w http.ResponseWriter, r *http.Request) {
	eventID := mux.Vars(r)[&quot;id&quot;]

	for _, singleEvent := range events {
		if singleEvent.ID == eventID {
			fmt.Fprintf(w, &quot;Successfully found required event: &quot;)
			json.NewEncoder(w).Encode(singleEvent)
		}
	}
	fmt.Println(&quot;Endpoint Hit: getSingleEvent&quot;)
}

func createSingleEvent(w http.ResponseWriter, r *http.Request) {
	var newEvent event
	reqBody, _ := ioutil.ReadAll(r.Body)

	json.Unmarshal(reqBody, &amp;amp;newEvent)
	events = append(events, newEvent)
	
	fmt.Fprintf(w, &quot;The newly entered data is as follows: &quot;)
	json.NewEncoder(w).Encode(newEvent)
}

func deleteSingleEvent(w http.ResponseWriter, r *http.Request) {
	eventID := mux.Vars(r)[&quot;id&quot;]
	for i, singleEvent := range events {
		if singleEvent.ID == eventID {
			events = append(events[:i], events[i+1:]...)
			fmt.Fprintf(w, &quot;The event with ID %v has been deleted successfully&quot;, eventID)
		}
	}
}

func updateSingleEvent(w http.ResponseWriter, r *http.Request) {
	eventID := mux.Vars(r)[&quot;id&quot;]
	var updatedEvent event

	reqBody, _ := ioutil.ReadAll(r.Body)
	
	json.Unmarshal(reqBody, &amp;amp;updatedEvent)

	for i, singleEvent := range events {
		if singleEvent.ID == eventID {
			singleEvent.Title = updatedEvent.Title
			singleEvent.Description = updatedEvent.Description
			events = append(events[:i], singleEvent)
			fmt.Fprintf(w, &quot;Successfully updated event %v&quot;, eventID)
		}
	}
	fmt.Println(&quot;Endpoint Hit: updateSingleEvent&quot;)
}

func main() {
	router := mux.NewRouter().StrictSlash(true)
	router.HandleFunc(&quot;/&quot;, homePage).Methods(&quot;GET&quot;)
	router.HandleFunc(&quot;/events&quot;, returnAllEvents).Methods(&quot;GET&quot;)
	router.HandleFunc(&quot;/event/{id}&quot;, getSingleEvent).Methods(&quot;GET&quot;)
	router.HandleFunc(&quot;/event&quot;, createSingleEvent).Methods(&quot;POST&quot;)
	router.HandleFunc(&quot;/event/{id}&quot;, deleteSingleEvent).Methods(&quot;DELETE&quot;)
	router.HandleFunc(&quot;/event/{id}&quot;, updateSingleEvent).Methods(&quot;PATCH&quot;)
	log.Fatal(http.ListenAndServe(&quot;:8080&quot;, router))
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="RESTful API" /><category term="Golang" /><summary type="html">``` package main</summary></entry><entry><title type="html">Twitter API Golang.</title><link href="https://abhinavpy.github.io/posts/2022/03/twitter-api-go/" rel="alternate" type="text/html" title="Twitter API Golang." /><published>2022-04-12T00:00:00-07:00</published><updated>2022-04-12T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/03/TwitterAPIGolang</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/03/twitter-api-go/">&lt;h1 id=&quot;using-the-twitter-api-to-get-tweets&quot;&gt;Using the Twitter API to get tweets&lt;/h1&gt;

&lt;p&gt;This post will talk through the steps on how to create your own Twitter bot in Go! We will be making use of go-twitter which is a Go client library for the Twitter API. Big thanks to the developers over there for making an easy to use library.&lt;/p&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Twitter developer account&lt;/li&gt;
  &lt;li&gt;Valid Golang installation&lt;/li&gt;
  &lt;li&gt;Basic programming knowledge&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;creating-a-twitter-api-key&quot;&gt;Creating a Twitter API key&lt;/h2&gt;

&lt;p&gt;If you haven’t already got a developer account on Twitter you will need to sign up. The steps to do this are documented here.&lt;/p&gt;

&lt;p&gt;Once you have an approved developer account head over to the dashboard and create a new Project.&lt;/p&gt;

&lt;p&gt;Take note of your API key, API key secret, access token, access token secret as we will need these in a few moments time.&lt;/p&gt;

&lt;h2 id=&quot;gocode&quot;&gt;Go….code!&lt;/h2&gt;
&lt;p&gt;Open the twitter-bot directory in your favourite editor and create a file named main.go.&lt;/p&gt;

&lt;p&gt;Firstly we will focus on authenticating with twitter. We are going to store the keys in environment variables. It’s not a good idea to have sensitive information stored in our code as when it reaches our source control (Github, Gitlab, etc) it may be visible to others.&lt;/p&gt;

&lt;p&gt;Head over to the developer dashboard page where you should see the project you just created. On the left hand side click the name of your project under Projects &amp;amp; Apps. Navigate to the Keys and tokens page which is where we grab the API keys from.&lt;/p&gt;

&lt;p&gt;We need four values CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN and ACCESS_TOKEN_SECRET. These can all be found on the Keys and tokens page. Once you have the values populate the export commands with the right values.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;export CONSUMER_KEY=&amp;lt;API_KEY_VALUE&amp;gt;
export CONSUMER_SECRET=&amp;lt;API_KEY_SECRET_VALUE&amp;gt;
export ACCESS_TOKEN=&amp;lt;ACCESS_TOKEN_VALUE&amp;gt;
export ACCESS_TOKEN_SECRET=&amp;lt;ACCESS_TOKEN_SECRET_VALUE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once we have exported the environment variables we need to read them in via our Go code. The following code will do that and it will be the method we use when the code is complete&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package main
import (
	&quot;fmt&quot;
	&quot;os&quot;
)

type Credentials struct {
	ConsumerKey       string
	ConsumerSecret    string
	AccessToken       string
	AccessTokenSecret string
}

func main() {
	creds := Credentials{
		ConsumerKey:       os.Getenv(&quot;CONSUMER_KEY&quot;),
		ConsumerSecret:    os.Getenv(&quot;CONSUMER_SECRET&quot;),
		AccessToken:       os.Getenv(&quot;ACCESS_TOKEN&quot;),
		AccessTokenSecret: os.Getenv(&quot;ACCESS_TOKEN_SECRET&quot;),
	}

	 fmt.Printf(&quot;%+v\n&quot;,creds)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This bit of the code can be divided into three sections&lt;/p&gt;

&lt;p&gt;Imports This is where we import other packages that we make use of in our code. It’s only a short list at the moment but we will be adding a few by the time we have completed the Twitter bot!
Struct We define a struct to store the keys that we need to use for authenticating with Twitter.
main function This function is slightly special in that it is the entrypoint and will be called automatically when we run our program. For now we are just going to prove that we can read in our environment variables.&lt;/p&gt;

&lt;p&gt;Copy the code snippet into main.go and run it using the following command&lt;/p&gt;

&lt;p&gt;go run main.go&lt;/p&gt;

&lt;p&gt;This should output something similar to this&lt;/p&gt;

&lt;p&gt;{randomvalue1 randomvalue2 randomvalue3 randomvalue4}&lt;/p&gt;

&lt;p&gt;In your case each of the values should be referring to the keys from twitter.&lt;/p&gt;

&lt;h2 id=&quot;authenticating-with-twitter&quot;&gt;Authenticating with Twitter&lt;/h2&gt;
&lt;p&gt;Now that we have exported our environment variables and are able to read them in we are ready to authenticate with Twitter.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;func getClient(creds *Credentials) (*twitter.Client, error) {

	// These values are the API key and API key secret
	config := oauth1.NewConfig(creds.ConsumerKey, creds.ConsumerSecret)
	// These values are the consumer access token and consumer access token secret
	token := oauth1.NewToken(creds.AccessToken, creds.AccessTokenSecret)
	httpClient := config.Client(oauth1.NoContext, token)
	client := twitter.NewClient(httpClient)

	verify := &amp;amp;twitter.AccountVerifyParams{
		SkipStatus:   twitter.Bool(true),
		IncludeEmail: twitter.Bool(true),
	}
	user, _, err := client.Accounts.VerifyCredentials(verify)
	if err != nil {
		fmt.Println(err)
		return nil, err
	}
	// print out the Twitter handle of the account we have used to authenticate with 
	fmt.Println(&quot;Successfully authenticated using the following account : &quot;, user.ScreenName)
	return client, nil
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can now call this function from within our main function. Replace this line(we don’t need to log the credentials out anymore)&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;fmt.Printf(&quot;%+v\n&quot;,creds)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;with&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;client, err := getClient(&amp;amp;creds)
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;search-tweets&quot;&gt;Search tweets&lt;/h2&gt;
&lt;p&gt;As I have mentioned previously the go-twitter client library makes it nice and easy to talk to the Twitter API in Go! Let’s create our next function where we make use of the search functionality&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;func searchTweets(client *twitter.Client) error {

	search, _, err := client.Search.Tweets(&amp;amp;twitter.SearchTweetParams{
		Query: &quot;bonjour&quot;,
	})

	if err != nil {
		fmt.Println(err)
		return err
	}
	fmt.Println(&quot;search : &quot;, search)
	return nil
}

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

&lt;p&gt;Add the following line to our main() function (at the bottom)&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;searchTweets(client)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and then run the code with go run main.go&lt;/p&gt;

&lt;p&gt;Your terminal window will turn into what looks like a wall of text that doesn’t make a lot of sense. This code works but there’s definitely room for improvement! All of the tweets that were returned were in French (Not surprising given the search parameter) and the big wall of text is not very readable. Let’s make some improvements to the searchTweets() function.&lt;/p&gt;

&lt;h2 id=&quot;improving-our-search-function&quot;&gt;Improving our search function&lt;/h2&gt;
&lt;p&gt;I’m not sure about you but unfortunately I’m unable to speak French so the first change we’ll make is to add a language to the search parameters. We do this by adding the following parameter for English Lang: “en”,. This will bring back tweets where Twitter has detected the language to be English. Let’s change our search parameter to become the following&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;search, _, err := client.Search.Tweets(&amp;amp;twitter.SearchTweetParams{
    Query: &quot;bonjour&quot;,
    Lang:  &quot;en&quot;,
})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The second change is to parse the interesting bits of each tweet into a struct so we can ignore the bits we don’t care about and more clearly see the bits we do care about! Let’s try and keep things anonymous by only grabbing the tweet likes, retweets and the tweet itself. To do this let’s create another struct but this time it will hold tweet data instead of credentials&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;type TweetData struct {
	Tweet         string
	LikeCount    int
	RetweetCount int
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When we use the client to search tweets we get a twitter.Search object back which has an array of tweets and metadata. To grab out the values we want to keep we will loop over the array of tweets creating a struct to hold the data. We will print each struct so it makes it more readable than the previous wall of text!&lt;/p&gt;

&lt;p&gt;New and improved…&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;func searchTweets(client *twitter.Client) error {
	search, _, err := client.Search.Tweets(&amp;amp;twitter.SearchTweetParams{
		Query: &quot;bonjour&quot;,
		Lang:  &quot;en&quot;,
	})

	if err != nil {
		fmt.Println(err)
		return err
	}

	for _, v := range search.Statuses {
		tweet := TweetData{
			Tweet:        v.Text,
			LikeCount:    v.FavoriteCount,
			RetweetCount: v.RetweetCount,
		}
		fmt.Printf(&quot;%+v\n&quot;, tweet)
	}
	return nil
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Replace the existing searchTweets() with the above snippet of code. Feel free to add/remove/change the SearchTweetParams to something you find more interesting. You could change the query parameter to something else (maybe “Formula 1”). You could also add on some additional parameters to the query.&lt;/p&gt;

&lt;p&gt;At the moment this is a pretty simple use case but hopefully it gives you a foundation to build on. We could go on and build up an array of tweets and do some kind of processing on them. We could send tweets via the client when a certain condition is true.&lt;/p&gt;

&lt;h2 id=&quot;tldr&quot;&gt;TLDR&lt;/h2&gt;
&lt;p&gt;If you just want to skip ahead to the completed code snippet or want to use the completed snippet for reference, here it is. If you come straight here don’t forget to make sure you have your API keys setup.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package main

import (
	&quot;fmt&quot;
	&quot;os&quot;

	&quot;github.com/dghubble/go-twitter/twitter&quot;
	&quot;github.com/dghubble/oauth1&quot;
)

type Credentials struct {
	ConsumerKey       string
	ConsumerSecret    string
	AccessToken       string
	AccessTokenSecret string
}

type TweetData struct {
	Tweet        string
	LikeCount    int
	RetweetCount int
}

func main() {
	creds := Credentials{
		ConsumerKey:       os.Getenv(&quot;CONSUMER_KEY&quot;),
		ConsumerSecret:    os.Getenv(&quot;CONSUMER_SECRET&quot;),
		AccessToken:       os.Getenv(&quot;ACCESS_TOKEN&quot;),
		AccessTokenSecret: os.Getenv(&quot;ACCESS_TOKEN_SECRET&quot;),
	}

	client, err := getClient(&amp;amp;creds)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	searchTweets(client)
}

func getClient(creds *Credentials) (*twitter.Client, error) {

	// These values are the API key and API key secret
	config := oauth1.NewConfig(creds.ConsumerKey, creds.ConsumerSecret)
	// These values are the consumer access token and consumer access token secret
	token := oauth1.NewToken(creds.AccessToken, creds.AccessTokenSecret)
	httpClient := config.Client(oauth1.NoContext, token)
	client := twitter.NewClient(httpClient)

	verify := &amp;amp;twitter.AccountVerifyParams{
		SkipStatus:   twitter.Bool(true),
		IncludeEmail: twitter.Bool(true),
	}
	user, _, err := client.Accounts.VerifyCredentials(verify)
	if err != nil {
		fmt.Println(err)
		return nil, err
	}
	// print out the Twitter handle of the account we have used to authenticate with
	fmt.Println(&quot;Successfully authenticated using the following account : &quot;, user.ScreenName)
	return client, nil
}

func searchTweets(client *twitter.Client) error {
	search, _, err := client.Search.Tweets(&amp;amp;twitter.SearchTweetParams{
		Query: &quot;Formula 1&quot;,
		Lang:  &quot;en&quot;,
	})

	if err != nil {
		fmt.Println(err)
		return err
	}

	for _, v := range search.Statuses {
		tweet := TweetData{
			Tweet:        v.Text,
			LikeCount:    v.FavoriteCount,
			RetweetCount: v.RetweetCount,
		}
		fmt.Printf(&quot;%+v\n&quot;, tweet)
	}
	return nil
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="Twitter API" /><category term="Golang" /><summary type="html">Using the Twitter API to get tweets</summary></entry><entry><title type="html">Golang Prep April 8th 2022</title><link href="https://abhinavpy.github.io/posts/2022/04/daily-post/" rel="alternate" type="text/html" title="Golang Prep April 8th 2022" /><published>2022-04-08T00:00:00-07:00</published><updated>2022-04-08T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/04/Golang-Prep</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/04/daily-post/">&lt;h1 id=&quot;golang-interview-questions&quot;&gt;Golang Interview Questions&lt;/h1&gt;
&lt;p&gt;All these questions and content were sourced from InterviewBit.com&lt;/p&gt;

&lt;p&gt;Golang or most popularly known as Go is one of the youngest programming languages that was released in the year 2012 at Google by developers Robert Griesemer, Rob Pike and Ken Thompson. It is said that Golang was born out of frustration with the demerits of the existing programming languages.&lt;/p&gt;

&lt;p&gt;Go is a high level, open-source programming language that was mainly developed keeping in mind the efficiency of code without compromising on the simplicity and faster compilation time to help develop software applications at a faster pace. Companies like Google, Apple, Uber are using Golang due to its proven ability of less learning time, faster code development, improved runtime efficiency, reduced bugs, concurrency, garbage collection strategies and so on.&lt;/p&gt;

&lt;h2 id=&quot;1-what-is-golang&quot;&gt;1. What is Golang?&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Go is a high level, general-purpose programming language that is very strongly and statically typed by providing support for garbage collection and concurrent programming.&lt;/li&gt;
  &lt;li&gt;In Go, the programs are built by using packages that help in managing the dependencies efficiently. It also uses a compile-link model for generating executable binaries from the source code. Go is a simple language with elegant and easy to understand syntax structures. It has a built-in collection of powerful standard libraries that helps developers in solving problems without the need for third party packages. Go has first-class support for Concurrency having the ability to use multi-core processor architectures to the advantage of the developer and utilize memory efficiently. This helps the applications scale in a simpler way.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-why-should-one-learn-golang-what-are-the-advantages-of-golang-over-other-languages&quot;&gt;2. Why should one learn Golang? What are the advantages of Golang over other languages?&lt;/h2&gt;
&lt;p&gt;Go language follows the principle of maximum effect with minimum efforts. Every feature and syntax of Go was developed to ease the life of programmers. Following are the advantages of Go Language:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Simple and Understandable&lt;/strong&gt;: Go is very simple to learn and understand. There are no unnecessary features included. Every single line of the Go code is very easily readable and thereby easily understandable irrespective of the size of the codebase. Go was developed by keeping simplicity, maintainability and readability in mind.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Standard Powerful Library&lt;/strong&gt;: Go supports all standard libraries and packages that help in writing code easily and efficiently.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Support for concurrency&lt;/strong&gt;: Go provides very good support for concurrency using Go Routines or channels. They take advantage of efficient memory management strategies and multi-core processor architecture for implementing concurrency.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Static Type Checking&lt;/strong&gt;: Go is a very strong and statically typed programming language. Statically typed means every variable has types assigned to it. The data type cannot be changed once created and strongly typed means that there are rules and restrictions while performing type conversion. This ensures that the code is type-safe and all type conversions are handled efficiently. This is done for reducing the chances of errors at runtime.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Easy to install Binaries&lt;/strong&gt;: Go provides support for generating binaries for the applications with all required dependencies. These binaries help to install tools or applications written in Go very easily without the need for a Go compiler or package managers or runtimes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Good Testing Support&lt;/strong&gt;: Go has good support for writing unit test cases along with our code. There are libraries that support checking code coverage and generating code documentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;3-what-are-golang-packages&quot;&gt;3. What are Golang Packages?&lt;/h2&gt;
&lt;p&gt;Go Packages (in short pkg) are nothing but directories in the Go workspace that contains Go source files or other Go packages themselves. Every single piece of code starting from variables to functions are written in the source files are in turn stored in a linked package. Every source file should belong to a package.&lt;/p&gt;

&lt;p&gt;The package is declared at the top of the Go source file as package &lt;package_name&gt;&lt;/package_name&gt;&lt;/p&gt;

&lt;p&gt;The packages can be imported to our source file by writing: import &lt;package_name&gt;&lt;/package_name&gt;&lt;/p&gt;

&lt;p&gt;An example of the Go package is fmt. This is a standard Go Package that has formatting and printing functionalities such as Println().&lt;/p&gt;

&lt;h2 id=&quot;4-is-golang-case-sensitive-or-insensitive&quot;&gt;4. Is Golang case sensitive or insensitive?&lt;/h2&gt;
&lt;p&gt;Go is a case-sensitive language.&lt;/p&gt;

&lt;h2 id=&quot;5-what-are-golang-pointers&quot;&gt;5. What are Golang pointers?&lt;/h2&gt;
&lt;p&gt;Go Pointers are those variables that hold the address of any variables. Due to this, they are called special variables. Pointers support two operators:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*&lt;/code&gt; operator: This operator is called a dereferencing operator and is used for accessing the value in the address stored by the pointer.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&lt;/code&gt; operator: This operator is called the address operator and is used for returning the address of the variable stored in the pointer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pointers are used for the following purposes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Allowing function to directly mutate value passed to it. That is achieving pass by reference functionality.&lt;/li&gt;
  &lt;li&gt;For increasing the performance in the edge cases in the presence of a large data structure. Using pointers help to copy large data efficiently.&lt;/li&gt;
  &lt;li&gt;Helps in signifying the lack of values. For instance, while unmarshalling JSON data into a struct, it is useful to know if the key is present or absent then the key is present with 0 value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;6-what-do-you-understand-by-golang-string-literals&quot;&gt;6. What do you understand by Golang string literals?&lt;/h2&gt;
&lt;p&gt;String literals are those variables storing string constants that can be a single character or that can be obtained as a result of the concatenation of a sequence of characters. Go provides two types of string literals. They are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Raw string literals: Here, the values are uninterrupted character sequences between backquotes. For example: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interviewbit&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Interpreted string literals: Here, the character sequences are enclosed in double quotes. The value may or may not have new lines. For example: “Interviewbit Website”&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;7-what-is-the-syntax-used-for-the-loop-in-golang-explain&quot;&gt;7. What is the syntax used for the loop in Golang? Explain.&lt;/h2&gt;
&lt;p&gt;Go language follows the below syntax for implementing for loop.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;for [condition |  ( init; condition; increment ) | Range]  
{  
   statement(s);  
   //more statements
}  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The for loop works as follows:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The init steps gets executed first. This is executed only once at the beginning of the loop. This is done for declaring and initializing the loop control variables. This field is optional as long as we have initialized the loop control variables before. If we are not doing anything here, the semicolon needs to be present.&lt;/li&gt;
  &lt;li&gt;The condition is then evaluated. If the condition is satisfied, the loop body is executed.
    &lt;ul&gt;
      &lt;li&gt;If the condition is not satisfied, the control flow goes to the next statement after the for loop.&lt;/li&gt;
      &lt;li&gt;If the condition is satisfied and the loop body is executed, then the control goes back to the increment statement which updated the loop control variables. The condition is evaluated again and the process repeats until the condition becomes false.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;If the Range is mentioned, then the loop is executed for each item in that Range.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package main

import &quot;fmt&quot;

func main() {
    // For loop to print numbers from 1 to 5
    for j := 1; j &amp;lt;= 5; j++ {
        fmt.Println(j)
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;8-what-do-you-understand-by-the-scope-of-the-variables-in-go&quot;&gt;8. What do you understand by the scope of the variables in Go?&lt;/h2&gt;
&lt;p&gt;The variable scope is defined as the part of the program where the variable can be accessed. Every variable is statically scoped (meaning a variable scope can be identified at compile time) in Go which means that the scope is declared at the time of compilation itself. There are two scopes in Go, they are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Local Variables: These are declared inside a function or a block and is accessible only within these entities.&lt;/li&gt;
  &lt;li&gt;Global Variables: These are declared outside function or block and is accessible by the whole source file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;9-what-do-you-understand-by-go-routines-in-golang&quot;&gt;9. What do you understand by Go routines in Golang?&lt;/h2&gt;
&lt;p&gt;A goroutine is nothing but a function in Golang that usually runs concurrently or parallelly with other functions. They can be imagined as a lightweight thread that has independent execution and can run concurrently with other routines. Goroutines are entirely managed by Go Runtime. Goroutines help Golang achieve concurrency.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In Golang, the main function of the main package is considered the main goroutine. It is the starting point of all other goroutines. These goroutines have the power to start their goroutines. Once the execution of the main goroutine is complete, it means that the program has been completed.&lt;/li&gt;
  &lt;li&gt;We can start a goroutine by just specifying the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go&lt;/code&gt; keyword before the method call. The method will now be called and run as a goroutine. Consider an example below:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package main
import (
    &quot;fmt&quot;
    &quot;time&quot;
)
func main() {
    go sampleRoutine()
    fmt.Println(&quot;Started Main&quot;)
    time.Sleep(1 * time.Second)
    fmt.Println(&quot;Finished Main&quot;)
}

func sampleRoutine() {
    fmt.Println(&quot;Inside Sample Goroutine&quot;)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this code, we see that the sampleRoutine() function is called by specifying the keyword go before it. When a function is called a goroutine, the call will be returned immediately to the next line of the program statement which is why “Started Main” would be printed first and the goroutine will be scheduled and run concurrently in the background. The sleep statement ensures that the goroutine is scheduled before the completion of the main goroutine. The output of this code would be:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Started Main
Inside Sample Goroutine
Finished Main
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;10-is-it-possible-to-return-multiple-values-from-a-function-in-go&quot;&gt;10. Is it possible to return multiple values from a function in Go?&lt;/h2&gt;
&lt;p&gt;Yes. Multiple values can be returned in Golang by sending comma-separated values with the return statement and by assigning it to multiple variables in a single statement as shown in the example below:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package main
import (
	&quot;fmt&quot;
)

func reverseValues(a,b string)(string, string){
    return b,a    //notice how multiple values are returned
}

func main(){
    val1,val2:= reverseValues(&quot;interview&quot;,&quot;bit&quot;)    // notice how multiple values are assigned
    fmt.Println(val1, val2)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the above example, we have a function reverseValues which simply returns the inputs in reverse order. In the main goroutine, we call the reverseValues function and the values are assigned to values val1 and val2 in one statement. The output of the code would be:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bit interview
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;11-is-it-possible-to-declare-variables-of-different-types-in-a-single-line-of-code-in-golang&quot;&gt;11. Is it possible to declare variables of different types in a single line of code in Golang?&lt;/h2&gt;
&lt;p&gt;Yes, this can be achieved by writing as shown below:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var a,b,c= 9, 7.1, &quot;interviewbit&quot;

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

&lt;p&gt;Here, we are assigning values of a type Integer number, Floating-Point number and string to the three variables in a single line of code.&lt;/p&gt;

&lt;h2 id=&quot;12-what-is-slice-in-go&quot;&gt;12. What is “slice” in Go?&lt;/h2&gt;
&lt;p&gt;Slice in Go is a lightweight data structure of variable length sequence for storing homogeneous data. It is more convenient, powerful and flexible than an array in Go. Slice has 3 components:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Pointer: This is used for pointing to the first element of the array accessible via slice. The element doesn’t need to be the first element of the array.&lt;/li&gt;
  &lt;li&gt;Length: This is used for representing the total elements count present in the slice.&lt;/li&gt;
  &lt;li&gt;Capacity: This represents the capacity up to which the slice can expand.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example: Consider an array of name arr having the values “This”,“is”, “a”,“Go”,“interview”,“question”.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package main
 
import &quot;fmt&quot;
 
func main() {
 
    // Creating an array
    arr := [6]string{&quot;This&quot;,&quot;is&quot;, &quot;a&quot;,&quot;Go&quot;,&quot;interview&quot;,&quot;question&quot;}
 
    // Print array
    fmt.Println(&quot;Original Array:&quot;, arr)
 
    // Create a slice
    slicedArr := arr[1:4]
 
    // Display slice
    fmt.Println(&quot;Sliced Array:&quot;, slicedArr)
 
    // Length of slice calculated using len()
    fmt.Println(&quot;Length of the slice: %d&quot;, len(slicedArr))
 
    // Capacity of slice calculated using cap()
    fmt.Println(&quot;Capacity of the slice: %d&quot;, cap(slicedArr))
}
Here, we are trying to slice the array to get only the first 3 words starting from the word at the first index from the original array. Then we are finding the length of the slice and the capacity of the slice. The output of the above code would be:

Original Array: [This is a Go interview question ]
Sliced Array: [is a Go]
Length of the slice: 3
The capacity of the slice: 5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here, we are trying to slice the array to get only the first 3 words starting from the word at the first index from the original array. Then we are finding the length of the slice and the capacity of the slice. The output of the above code would be:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Original Array: [This is a Go interview question ]
Sliced Array: [is a Go]
Length of the slice: 3
The capacity of the slice: 5

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

&lt;h2 id=&quot;13-what-are-go-interfaces&quot;&gt;13. What are Go Interfaces?&lt;/h2&gt;
&lt;p&gt;Go interfaces are those that have a defined set of method signatures. It is a custom type who can take values that has these methods implementation. The interfaces
are abstract which is why we cannot create its instance. But we can create a variable of type interface and that variable can then be assigned to a concrete value that has methods required by the interface. Due to these reasons, an interface can act as two things:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Collection of method signatures.&lt;/li&gt;
  &lt;li&gt;Custom types
They are created using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;type&lt;/code&gt; keyword followed by the name needed for the interface and finally followed by the keyword interface. The syntax goes as follows:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;type name_of_interface interface {
	// Method Signatures
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Consider an example of creating an interface of the name “golangInterfaceDemo” having two methods demo_func1() and demo_func2(). The interface will be defined as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// Create an interface
type golangInterfaceDemo interface{
    // Methods
    demo_func1() int
    demo_func2() float64
}

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

&lt;p&gt;Interface also promotes abstraction. In Golang, we can use interfaces for creating common abstractions which can be used by multiple types by defining method declarations that are compatible with the interface. Conside the following example:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package main
 
import &quot;fmt&quot;
 
// &quot;Triangle&quot; data type
type Triangle struct {
	base, height float32
}
 
// &quot;Square&quot; data type
type Square struct {
	length float32
}
 
// &quot;Rectangle&quot; data type
type Rectangle struct {
	length, breadth float32
}
 
// To calculate area of triangle
func (triangle Triangle) Area() float32 {
	return 0.5 * triangle.base * triangle.height
}
 
// To calculate area of square
func (square Square) Area() float32 {
	return square.length * square.length
}
 
// To calculate area of rectangle
func (rect Rectangle) Area() float32 {
	return rect.length * rect.breadth
}
 
// Area interface for achieving abstraction
type Area interface {
	Area() float32
}
 
func main() {
	// Declare and assign values to varaibles
	triangleObject := Triangle{base: 20, height: 10}
	squareobject := Square{length: 25}
	rectObject := Rectangle{length: 15, breadth: 20}
 
	// Define a variable of type interface
	var shapeObject Area
 
	// Assign to &quot;Triangle&quot; type variable to the Area interface
	shapeObject = triangleObject
	fmt.Println(&quot;Triangle Area = &quot;, shapeObject.Area())
 
	// Assign to &quot;Square&quot; type variable to the Area interface
	shapeObject = squareobject
	fmt.Println(&quot;Square Area = &quot;, shapeObject.Area())
 
	// Assign to &quot;Rectangle&quot; type variable to the Area interface
	shapeObject = rectObject
	fmt.Println(&quot;Rectangle Area = &quot;, shapeObject.Area())
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the above example, we have created 3 types for the shapes triangle, square and rectangle. We have also defined 3 Area() functions that calculate the area of the shapes based on the input object type passed. We have also defined an interface named Area and we have defined the method signature Area() within it. In the main function, we are creating the objects, assigning each object to the interface and calculating the area by calling the method declared in the interface. Here, we need not know specifically about the function that needs to be called. The interface method will take care of this considering the object type. This is called abstraction. The output of the above code will be:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Triangle Area =  100
Square Area =  625
Rectangle Area =  300
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;14-why-is-golang-fast-compared-to-other-languages&quot;&gt;14. Why is Golang fast compared to other languages?&lt;/h2&gt;
&lt;p&gt;Golang is faster than other programming languages because of its simple and efficient memory management and concurrency model. The compilation process to machine code is very fast and efficient. Additionally, the dependencies are linked to a single binary file thereby putting off dependencies on servers.&lt;/p&gt;

&lt;h2 id=&quot;15-how-can-we-check-if-the-go-map-contains-a-key&quot;&gt;15. How can we check if the Go map contains a key?&lt;/h2&gt;
&lt;p&gt;A map, in general, is a collection of elements grouped in key-value pairs. One key refers to one value. Maps provide faster access in terms of O(1) complexity to the values if the key is known.&lt;/p&gt;

&lt;p&gt;![Key to Value Mapping] (https://d3n0h9tb65y8q.cloudfront.net/public_assets/assets/000/001/748/original/How_can_we_check_if_the_Go_map_contains_a_key.png?1637335439)&lt;/p&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="Golang Basics" /><summary type="html">Golang Interview Questions All these questions and content were sourced from InterviewBit.com</summary></entry><entry><title type="html">Daily Blog Post 6 April 2022</title><link href="https://abhinavpy.github.io/posts/2022/04/daily-post/" rel="alternate" type="text/html" title="Daily Blog Post 6 April 2022" /><published>2022-04-06T00:00:00-07:00</published><updated>2022-04-06T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/04/Daily-Post</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/04/daily-post/">&lt;h3 id=&quot;gre-verbal&quot;&gt;GRE Verbal:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Completed Advanced Reading Comprehension 4. Scored 14/20. Could have scored slightly better. Took a lot of time - 1hr19min which has to be reduced.&lt;/li&gt;
  &lt;li&gt;Completed Advanced Sentence Equivalence 5. Hence finishing the section of Advanced Sentence Equivalence. Scored 12/20. Not a very good score. Will have to start revising all SE Questions to revise word meanings.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;gre-quant&quot;&gt;GRE Quant:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Completed Advanced Sequences Practice.&lt;/li&gt;
  &lt;li&gt;Completed Basic Geometry and Triangles Advanced Practice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;golang-practice-from-exercismorg&quot;&gt;Golang Practice from exercism.org&lt;/h2&gt;
&lt;p&gt;Url link: https://exercism.org/tracks/go/exercises/lasagna&lt;/p&gt;
&lt;h3 id=&quot;about-comments&quot;&gt;About Comments&lt;/h3&gt;
&lt;p&gt;In go, comments play an important role in documenting code. They are used by the godoc command, which extracts these comments to create documentation about Go packages.
A documentation comment should be a complete sentence that starts with the name of the thing being described and ends with a period.&lt;/p&gt;

&lt;p&gt;Comments should precede packages as well as export identifiers, for example exported functions, methods, package variables, constants and structs, which you will learn more about in the next exercises.
A package level variable can look like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var TemperatureCelsius float64
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;package-comments&quot;&gt;Package Comments&lt;/h3&gt;
&lt;p&gt;Package comments should be written directly before a package clause (&lt;strong&gt;package x&lt;/strong&gt;) and begin with &lt;strong&gt;Package x …&lt;/strong&gt; like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;//Package Kelvin provides tools to convert
// temperatures to and from kelvin
package kelvin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;function-comments&quot;&gt;Function Comments&lt;/h3&gt;
&lt;p&gt;A function comment should be written directly before the function declaration. It should be a full sentence that starts with a function name. For example, an exported comment for the function 
&lt;strong&gt;Calculate&lt;/strong&gt; should take the form &lt;strong&gt;Calculate …&lt;/strong&gt; It should also explain what arguments the function takes, what it does with them, and what its return values mean, ending in a period.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// CelsiusFreezingTemp returns an integer value equal to the temperature at which water freezes in degree celsius
func CelsiusFreezingTemp() int {
  return 0
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;go-comments-exercise---weather-forecast&quot;&gt;Go comments exercise - Weather Forecast&lt;/h3&gt;

&lt;p&gt;Instructions:&lt;/p&gt;

&lt;p&gt;Being hired by a big weather forecast company, your job is to maintain their codebase. Scrolling through their code, you find it hard to follow what the code is actually doing.
Good thing you know just the right thing to do.&lt;/p&gt;

&lt;p&gt;Step 1: Document Package Weather&lt;/p&gt;

&lt;p&gt;Write a package comment for &lt;strong&gt;package weather&lt;/strong&gt; that describes its contents. The package comment should introduce the package and provide information relevant to the package as a whole.&lt;/p&gt;

&lt;p&gt;Step 2: Document the Current Condition Variable&lt;/p&gt;

&lt;p&gt;Write a comment for the package variable &lt;strong&gt;CurrentCondition&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This should tell any user of the package what information the variable stores, and what they can do with it.&lt;/p&gt;

&lt;p&gt;Step 3: Document the currentLocation variable&lt;/p&gt;

&lt;p&gt;Just like the previous step, write a comment for currentLocation.&lt;/p&gt;

&lt;p&gt;Step 4: Document the Forecast() function&lt;/p&gt;

&lt;p&gt;Write a function comment for Forecast(). Your comments must describe what the function does, but not how it does it.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;func TestComments(t *testing.T) {
	filename := &quot;weather_forecast.go&quot;

	fs := token.NewFileSet()
	f, err := parser.ParseFile(fs, filename, nil, parser.ParseComments)
	if err != nil {
		t.Fatal(err)
	}

	wantedComments := 4
	got := len(f.Comments)
	if got != wantedComments {
		t.Errorf(&quot;Incorrect number of comments: got %d, want %d&quot;, got, wantedComments)
	}

	testPackageComment(t, f)

	ast.Inspect(f, func(node ast.Node) bool {
		switch n := node.(type) {
		case *ast.GenDecl:
			if n.Lparen.IsValid() {
				for _, v := range n.Specs {
					testBlockIdentifierComment(t, v.(*ast.ValueSpec))
				}
			} else {
				testIdentifierComment(t, n)
			}
		case *ast.FuncDecl:
			testFunctionComment(t, n)
		}
		return true
	})
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;numbers-in-go&quot;&gt;Numbers in Go&lt;/h3&gt;
&lt;p&gt;About Numbers&lt;/p&gt;

&lt;p&gt;Go contains basic numeric types that can represent sets of either integer or floating point values.&lt;/p&gt;

&lt;p&gt;This concept will concentrate on two number types:&lt;/p&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="GRE Reading Comprehension" /><category term="interview problems" /><category term="algorithms" /><category term="data structures" /><category term="Golang Basics" /><summary type="html">GRE Verbal: Completed Advanced Reading Comprehension 4. Scored 14/20. Could have scored slightly better. Took a lot of time - 1hr19min which has to be reduced. Completed Advanced Sentence Equivalence 5. Hence finishing the section of Advanced Sentence Equivalence. Scored 12/20. Not a very good score. Will have to start revising all SE Questions to revise word meanings.</summary></entry><entry><title type="html">Daily Blog Post 5 April 2022</title><link href="https://abhinavpy.github.io/posts/2022/04/daily-post/" rel="alternate" type="text/html" title="Daily Blog Post 5 April 2022" /><published>2022-04-05T00:00:00-07:00</published><updated>2022-04-05T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/04/Daily-Post</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/04/daily-post/">&lt;h3 id=&quot;reading-comprehension---greedge&quot;&gt;Reading Comprehension - GREEdge&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Finished Advanced Reading Comprehension Exercise 3. Scored 12/20. Need to perform better. Again, questions were confusing. Made one or two errors that could have been avoidable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;gre-quant&quot;&gt;GRE Quant&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Watch https://www.youtube.com/watch?v=K7B0ckmrviM&amp;amp;ab_channel=Crackverbal to gain confidence to solve Venn Diagram questions in GRE Quant.&lt;/li&gt;
  &lt;li&gt;Rule of thumb to differentiate when to use Venn Diagrams and Tables.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;golang-tutorials&quot;&gt;Golang Tutorials&lt;/h3&gt;
&lt;p&gt;About Basics
Go is a statically typed, compiled programming language. Go is syntactically similar to C. The language is often referred to as Golang because of its previous domain name
golang.org, but the proper name is Go.
The Basics concept will introduce three major language features: packages, functions and variables.
Packages: Go applications are organized in packages. A package is a collection of source files located in the same directory. All source files in a directory must share the same package name.
It is conventional for the package name to be the last directory in the import path. For example the files in the “math/rand” package begin with the statement package rand.
When a package is imported, only entities (functions, types, variables, and constants) whose names start with a capital letter can be used/accessed. The recommended style of naming in 
Go is that identifiers will be named using camelCase, except for those meant to be accessible across packages which should be PascalCase.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package lasagna
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Variables:
Go is statically types, which means all variables must have a defined type at compile time. 
Variables can be defined by explicitly specifying a type:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var explicit int
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You can also use an initializer, and the compiler will assign the variable type to match the type of the initializer:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;implicit := 10
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once declared variables can be assigned value using the = operator. 
Once declared a variable’s type can never be changed.
count := 1 //Initial value
count = 2 //update new value
count = false //This throws a compiler error due to assigning a ‘non’ int-type&lt;/p&gt;

&lt;p&gt;Constants:
Constants hold a piece of data just like variables, but their value cannot change during the execution of the program.
Constants are defined using the const keyboard and can be numbers, characters, strings or booleans:
const Age = 12&lt;/p&gt;

&lt;p&gt;Functions:
Go functions accept zero or more parameters. Parameters must be explicitly typed, there is no type inference.
Values are returned from the function using the return keyword.
A function is invoked by specifying the function name and passing arguments for each of the function’s parameters.
Note that Go supports two types of comments. Single line comments are preceded by // and multiple line comments are inserted between /* and */&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;package greeting
// Hello is a public function
func hello(name string) string {
  return hi(name)
}

// hi is a private function
func hi(name string) string {
  return &quot;hi&quot; + name;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Gopher’s Gorgeous Lasagna
Instructions:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Define the expected oven time in minutes: Define OvenTime constant with how many minutes the Lasagna should be in the oven. According to the cooking book, the expected oven time in minutes is 40.
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;OvenTime
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Calculate the remaining oven time in minutes: Define the RemainingOvenTime() function that takes the actual minutes the Lasagna has been in the oven as a parameter and returns how many minutes the lasagna still has to remain in the oven, based on the expected oven time in minutes from the previous task.
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;func RemainingOvenTime(actual int) int {
  //TODO
}
RemainingOvenTime(30)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Calculate the preparation time in minutes: Define the PreparationTime function that takes the number of layers you added to the lasagna as a parameter and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare.
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;func PreparationTime(numberOfLayers int) int {
  // TODO
}
PreparationTime(2)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Calculate the elapsed working time in minutes: Define the ElapsedTime function that takes two parameters: the first parameter is the number of layers you added to the Lasagna, the second parameter is the number of minutes the lasagna has been in the oven. The function should return how many minutes in total you have worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment.
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;func ElapsedTime(numberOfLayers, actualMinutesInOven int) int {
  // TODO
}
ElapsedTime(3, 20)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="GRE Reading Comprehension" /><category term="interview problems" /><category term="algorithms" /><category term="data structures" /><category term="Golang Basics" /><summary type="html">Reading Comprehension - GREEdge Finished Advanced Reading Comprehension Exercise 3. Scored 12/20. Need to perform better. Again, questions were confusing. Made one or two errors that could have been avoidable.</summary></entry><entry><title type="html">Daily Blog Post 4 April 2022</title><link href="https://abhinavpy.github.io/posts/2022/04/daily-post/" rel="alternate" type="text/html" title="Daily Blog Post 4 April 2022" /><published>2022-04-04T00:00:00-07:00</published><updated>2022-04-04T00:00:00-07:00</updated><id>https://abhinavpy.github.io/posts/2022/04/Daily-Post</id><content type="html" xml:base="https://abhinavpy.github.io/posts/2022/04/daily-post/">&lt;h2 id=&quot;reading-comprehension---greedge&quot;&gt;Reading Comprehension - GREEdge&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Finished Advanced Reading Comprehension Exercise 2. Scored 11/20. Need to do better. Questions were ambigious and confusing with similiar meaning options.&lt;/li&gt;
  &lt;li&gt;Revised Essential RC Practice 1.&lt;/li&gt;
  &lt;li&gt;Revised Essential RC Practice 2.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;clrs---dynamic-programming&quot;&gt;CLRS - Dynamic Programming&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;DP, Like Divide and Conquer solves problems by combining solutions to subproblems.&lt;/li&gt;
  &lt;li&gt;Divide and Conquer Algorithms partition the problem into disjoint subproblems, solve the subproblems recursively, and then combine their solutions to solve the original problem.&lt;/li&gt;
  &lt;li&gt;In contrast, DP applies when subproblems overlap-that is, when subproblems share subsubproblems. In this context a divide and conquer algorithm does more work than necessary, repeatedly solving the common subsubproblems.&lt;/li&gt;
  &lt;li&gt;A dynamic programming algorithm solves each subsubproblem just once and then saves its answer in a table, thereby avoiding the work of recomputing the answer each time it solves each subsubproblem.&lt;/li&gt;
  &lt;li&gt;We typically apply DP to optimization problems. Such problems can have many solutions. Each solution has a value, and we wish to find a solution with the optimal (minimum or maximum) value.&lt;/li&gt;
  &lt;li&gt;We call such a solution an optimal solution to the problem as opposed to the optimal solution to the problem.&lt;/li&gt;
  &lt;li&gt;When developing a dynamic-programming algorithm, we follow a sequence of four steps:
    &lt;ol&gt;
      &lt;li&gt;Characterize the structure of an optimal solution.&lt;/li&gt;
      &lt;li&gt;Recursively define the value of an optimal solution.&lt;/li&gt;
      &lt;li&gt;Compute the value of an optimal solution, typically in a bottom-up fashion.&lt;/li&gt;
      &lt;li&gt;Construct an optimal solution from computed information.
        &lt;h3 id=&quot;rod-cutting&quot;&gt;Rod Cutting&lt;/h3&gt;
        &lt;p&gt;The rod cutting problem is as follows given a rod of length n and a table of prices for lengths of rods. 
Determine the maximum revenue obtainable by cutting up the rod and selling the pieces.&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can cut a rod of length n in 2^(n-1) ways, since we have an independent option of cutting or not cutting, at distance i inches from the left end.
If an optimal solution cuts a rod into k pieces, for some 1&amp;lt;=k&amp;lt;=n, then an optimal decomposition n = i1 + i2 + i3 + i4 + … + ik of the rod into pieces of lengths
i1, i2, i3, i4, i5, …, ik provides maximum corresponding revenue rn = pi1 + pi2 + pi3 + … + pik.&lt;/p&gt;

&lt;p&gt;More generally, we can frame the values of rn from n &amp;gt;= 1 in terms of optimal revenues from shorter rods:
rn = max(pn, r1 + rn-1, r2 + rn-2, …. , rn-1 + r1).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The first argument, pn, corresponds to making no cuts at all and selling the rod of length n as it is.&lt;/li&gt;
  &lt;li&gt;The other n-1 arguments to max correspond to the maximum revenue obtained by making an initial cut of the rod into two pieces of size i and n - i, for each i.&lt;/li&gt;
  &lt;li&gt;Since we don’t know ahead of time which value of i optimizes revenue, we have to consider all possible values of i and pick the one that maximizes revenue.&lt;/li&gt;
  &lt;li&gt;We also have the option of picking no i at all if we can obtain more revenue by selling the rod uncut.&lt;/li&gt;
  &lt;li&gt;Note that to solve the original problem of size n, we solve smaller problems of the same type, but of smaller sizes. Once we make the first cut, we may consider the two pieces as independent instances of the rod-cutting problem. The overall optimal solution incorporates optimal solutions to the two related subproblems, maximizing revenue from each of those two pieces.&lt;/li&gt;
  &lt;li&gt;We say that the rod cutting problem exhibits optimal substructure: optimal solutions to a problem incorporate optimal solutions to related subproblems, which we may solve independently.&lt;/li&gt;
  &lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;geeksforgeeks-practice---arrays-and-dynamic-programming&quot;&gt;GeeksForGeeks Practice - Arrays and Dynamic Programming&lt;/h2&gt;
&lt;p&gt;Solved about 8-10 problems.&lt;/p&gt;

&lt;h2 id=&quot;quant---greedge&quot;&gt;Quant - GREedge&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Abhinav Prasad Yasaswi</name><email>abhinavp@asu.edu</email></author><category term="dynamic programming" /><category term="interview problems" /><category term="algorithms" /><category term="data structures" /><summary type="html">Reading Comprehension - GREEdge Finished Advanced Reading Comprehension Exercise 2. Scored 11/20. Need to do better. Questions were ambigious and confusing with similiar meaning options. Revised Essential RC Practice 1. Revised Essential RC Practice 2.</summary></entry></feed>