From 2f78d46b9751864a9a6cdadc30ad0fde706e846a Mon Sep 17 00:00:00 2001 From: abregman Date: Sun, 26 Jan 2020 13:46:43 +0200 Subject: [PATCH 1/8] Add Ansible and Regex questions --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 30dd8ba..8197a6b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ :information_source:  This repo contains questions and exercises on various technical topics, sometimes related to DevOps and SRE :) -:bar_chart:  There are currently **834** questions +:bar_chart:  There are currently **854** questions :warning:  You can use these for preparing for an interview but most of the questions and exercises don't represent an actual interview. Please read [Q&A](common-qa.md) for more details @@ -60,6 +60,7 @@ Testing
Testing
Databases
Databases
+ Regex
Beginner :baby:
Design
Design
you
Questions you ask
Exercises
Exercises
@@ -2166,6 +2167,14 @@ spun up and shut down, without you tracking every change in these sources. You want to run Ansible playbook only on specific minor version of your OS, how would you achieve that?
+
+What the "become" directive used for in Ansible?
+
+ +
+What are facts? How to see all the facts of a certain host?
+
+
What would be the result of the following play?
@@ -2184,7 +2193,7 @@ When given a written code, always inspect it thoroughly. If your answer is “th
-What would be the result of running the following task? +What would be the result of running the following task? How to fix it? ``` - hosts: localhost @@ -2205,6 +2214,18 @@ When given a written code, always inspect it thoroughly. If your answer is “th Explain the directory layout of an Ansible role
+
+What 'blocks' are used for in Ansible?
+
+ +
+How do you handle errors in Ansible?
+
+ +
+You would like to run a certain command if a task fails. How would you achieve that?
+
+
Write a playbook to install ‘zlib’ and ‘vim’ on all hosts if the file ‘/tmp/mario’ exists on the system.
@@ -2320,10 +2341,10 @@ A full list can be found at the link above. Also, note there is a significant di
Write a filter to capitalize a string
- +``` def cap(self, string): return string.capitalize() - +```
@@ -3616,7 +3637,7 @@ with open('file.txt', 'w') as file: Can you write a function which will print all the file in a given directory? including sub-directories
-#### Regex +#### Python Regex
How do you perform regular expressions related operations in Python? (match patterns, substitute strings, etc.)
@@ -6280,6 +6301,44 @@ A single data source (at least usually) which is stored in a raw format. What is OLAP (Online Analytical Processing)?
+## Regex + +Given a text file, perform the following exercises + +#### Extract + +
+Extract all the numbers
+
+ +
+Extract the first word of each line
+ +Bonus: extract the last word of each line +
+ +
+Extract all the IP addresses
+
+ +
+Extract dates in the format of yyyy-mm-dd or yyyy-dd-mm
+
+ +
+Extract email addresses
+
+ +#### Replace + +
+Replace tabs with four spaces
+
+ +
+Replace 'red' with 'green'
+
+ ## Design #### Architecture From ea8cee3eb33d4098484bc5b46c79a0fa6c3712a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Pl=C3=A9e?= Date: Sun, 26 Jan 2020 18:24:26 +0100 Subject: [PATCH 2/8] Small fix of typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8197a6b..c34bae6 100644 --- a/README.md +++ b/README.md @@ -170,10 +170,10 @@ In your answer you can mention one or more of the following: Explain mutable vs. immutable infrastructure
In mutable infrastructure paradigm, changes are applied on top of the existing infrastructure and over time -the infrastructure builds up a history of changes. Ansible, Puppet and Chef are examples to tools which +the infrastructure builds up a history of changes. Ansible, Puppet and Chef are examples of tools which follow mutable infrastructure paradigm. -In immutable infrastructure paradigm, every change is actually new infrastructure. So a change +In immutable infrastructure paradigm, every change is actually a new infrastructure. So a change to a server will result in a new server instead of updating it. Terraform is an example of technology which follows the immutable infrastructure paradigm.
From ae99012d61993771dd1ae772e125bccc40da57e3 Mon Sep 17 00:00:00 2001 From: abregman Date: Fri, 31 Jan 2020 23:37:43 +0200 Subject: [PATCH 3/8] Add a couple of Python questions --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c1a6961..e9a31c3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ :information_source:  This repo contains questions and exercises on various technical topics, sometimes related to DevOps and SRE :) -:bar_chart:  There are currently **854** questions +:bar_chart:  There are currently **864** questions :warning:  You can use these for preparing for an interview but most of the questions and exercises don't represent an actual interview. Please read [Q&A](common-qa.md) for more details @@ -993,14 +993,6 @@ A three-way handshake is primarily used to create a TCP socket connection. It wo TCP establishes a connection between the client and the server to guarantee the order of the packages, on the other hand, UDP does not establish a connection between client and server and doesn't handle package order. This makes UDP more lightweight than TCP and a perfect candidate for streaming services. -
-True or False? TCP is better than UDP
- -False. -UDP is faster, simpler and more efficient than TCP - -
-
What TCP/IP protocols are you familiar with?
@@ -2432,10 +2424,6 @@ def cap(self, string): You would like to run a task only if previous task changed anything. How would you achieve that?
-
-How do you test your Ansible based projects?
-
-
What are callback plugins? What can you achieve by using callback plugins?
@@ -2473,6 +2461,16 @@ Gotenks = 32 ```
+#### Ansible Testing + +
+How do you test your Ansible based projects?
+
+ +
+What is Molecule? How it works?
+
+ ## Terraform @@ -3691,7 +3689,7 @@ some_dict1.update(some_dict2) [Solution](coding/python/binary_search.py) -#### Files +#### Python Files
How to write to a file?
@@ -3714,10 +3712,48 @@ with open('file.txt', 'w') as file: Sum all the integers in a given file
+
+Print a random line of a given file
+
+ +
+Print every 3rd line of a given file
+
+ +
+Print the number of lines in a given file
+
+ +
+Print the number of of words in a given file
+
+
Can you write a function which will print all the file in a given directory? including sub-directories
+#### Python OS + +
+How to print current working directory?
+
+ +
+Given the path /dir1/dir2/file1 print the file name (file1)
+
+ +
+Given the path /dir1/dir2/file1 print the name of the directory where the file resides (dir2)
+
+ +
+Given the path /dir1/dir2/file1 print the path without the file name (/dir1/dir2)
+
+ +
+How do you execute shell commands using Python?
+
+ #### Python Regex
@@ -5730,6 +5766,10 @@ The most used projects are the Elasticserach, Logstash and Kibana. Also known as 5. The user creates a dashboard which composed out of the visualization created earlier
+
+You are running an app which outputs several log files (without timestamps). What do you do in order to process the information they include and display it in Kibana? you can ask for additional information if required for answering this question
+
+ ##### Elasticsearch
From 0f8bc36475a0a2c10aea566438a918f7fd0ef962 Mon Sep 17 00:00:00 2001 From: Aditya Prakash Date: Sun, 2 Feb 2020 02:14:11 +0530 Subject: [PATCH 4/8] answer to terraform taint --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c34bae6..e4a0ee0 100644 --- a/README.md +++ b/README.md @@ -2495,6 +2495,7 @@ It's a resource which was successfully created but failed during provisioning. T
What terraform taint does?
+terraform taint resource.id manually marks the resource as tainted in the state file. So when you terraform apply the next time, the resource will be destroyed and recreated.
From 31dbfbbc9d2d9c4f31ab014ddb40a61119e66ab3 Mon Sep 17 00:00:00 2001 From: abregman Date: Mon, 3 Feb 2020 23:25:45 +0200 Subject: [PATCH 5/8] Add a couple of questions --- README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9f3421b..9e88028 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ :information_source:  This repo contains questions and exercises on various technical topics, sometimes related to DevOps and SRE :) -:bar_chart:  There are currently **864** questions +:bar_chart:  There are currently **871** questions :warning:  You can use these for preparing for an interview but most of the questions and exercises don't represent an actual interview. Please read [Q&A](common-qa.md) for more details @@ -2180,7 +2180,7 @@ Role – Ansible roles allows you to group resources based on certain functional Ansible is: -* Agent-less +* Agentless * Minimal run requirements (Python & SSH) and simple to use * Default mode is "push" (it supports also pull) * Focus on simpleness and ease-of-use @@ -2188,6 +2188,10 @@ Ansible is:
What kind of automation you wouldn't do with Ansible and why?
+ +While it's possible to provision resources with Ansible it might not be the best choice for doing so as Ansible doesn't +save state by default and a task that creates 5 instances, when executed again will create additional 5 instances (unless +additional check is implemented).
@@ -2326,6 +2330,18 @@ When given a written code, always inspect it thoroughly. If your answer is “th ```
+
+Write a single task that verifies all the files in files_list variable exist on the host
+ +``` +- name: Ensure all files exist + assert: + that: + - item.stat.exists + loop: "{{ files_list }}" +``` +
+
Write a playbook to deploy the file ‘/tmp/system_info’ on all hosts except for controllers group, with the following content
@@ -2471,6 +2487,10 @@ Gotenks = 32 What is Molecule? How it works?
+
+You run Ansibe tests and you get "idempotence test failed". What does it mean? Why idempotence is important?
+
+ ## Terraform @@ -2574,7 +2594,7 @@ It's a resource which was successfully created but failed during provisioning. T
What terraform taint does?
-terraform taint resource.id manually marks the resource as tainted in the state file. So when you terraform apply the next time, the resource will be destroyed and recreated. +terraform taint resource.id manually marks the resource as tainted in the state file. So when you run terraform apply the next time, the resource will be destroyed and recreated.
@@ -2771,10 +2791,15 @@ A common answer to this is to use [hadolint](https://github.com/hadolint/hadolin Explain what is Docker compose and what is it used for
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. + +For example, you can use it to set up ELK stack where the services are: elasticsearch, logstash and kibana. Each running in its own container.
-What are the differences between Docker compose, Docker swarm and Kubernetes?
+Describe the process of using Docker Compose

+ +* Define the services you would like to run together in a docker-compose.yml file +* Run `docker-compose up` to run the services
@@ -3070,7 +3095,7 @@ The average performance of the above algorithm is O(log n). Best performance can * Radix Sort
-##### Data Structures & Types +#### Data Structures & Types
Implement Stack in any language you would like
@@ -3080,6 +3105,10 @@ The average performance of the above algorithm is O(log n). Best performance can Implement Hash table in any language you would like
+
+What is Integer Overflow? How is it handled?
+
+ #### :star: Advanced @@ -5903,6 +5932,12 @@ From the official docs: "Kibana is an open source analytics and visualization platform designed to work with Elasticsearch. You use Kibana to search, view, and interact with data stored in Elasticsearch indices. You can easily perform advanced data analysis and visualize your data in a variety of charts, tables, and maps."
+
+You see in Kibana, after clicking on Discover, "561 hits". What does it mean?
+ +Total number of documents matching the search results. If not query used then simply the total number of documents. +
+
What visualization types are supported/included in Kibana?
@@ -6038,7 +6073,29 @@ It's an architecture in which data is and retrieved from a single, non-shared, s ## General -##### HTTP +
+Define or Explain what is an API
+ +I like this definition from [here](https://blog.christianposta.com/microservices/api-gateways-are-going-through-an-identity-crisis): + +"An explicitly and purposefully defined interface designed to be invoked over a network that enables software developers to get programmatic access to data and functionality within an organization in a controlled and comfortable way." +
+ +#### Jira + +
+Explain/Demonstrate the following types in Jira: + + * Epic + * Story + * Task
+
+ +
+What is a project in Jira?
+
+ +#### HTTP
What is HTTP?
From e9425b948eb0807d9a8cb82d249e77fcfac71a93 Mon Sep 17 00:00:00 2001 From: Aaron Lake Date: Mon, 10 Feb 2020 16:18:36 -0500 Subject: [PATCH 6/8] Fix spelling mistake in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e88028..fe64fde 100644 --- a/README.md +++ b/README.md @@ -2532,7 +2532,7 @@ A configuration is a root module along with a tree of child modules that are cal
What is HCL?
-HCL stands for Hashicorp Conviguration Language. It is the language Hashicorp made to use as the configuration language for a number of its tools, including terraform. +HCL stands for Hashicorp Configuration Language. It is the language Hashicorp made to use as the configuration language for a number of its tools, including terraform.
From 510d0bf470681de77e46bbfb48c8b12814a7c4c8 Mon Sep 17 00:00:00 2001 From: Noskov Artem Date: Wed, 12 Feb 2020 10:20:30 +0500 Subject: [PATCH 7/8] Fixed Go questions Added answers for go questions --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index fe64fde..a68bc8b 100644 --- a/README.md +++ b/README.md @@ -4765,6 +4765,11 @@ func main() { } ```
+ +Constants in Go can only be declared using constant expressions. +But `x`, `y` and their sum is variable. +
+const initializer x + y is not a constant
@@ -4788,10 +4793,21 @@ func main() { } ```
+ +Go's iota identifier is used in const declarations to simplify definitions of incrementing numbers. Because it can be used in expressions, it provides a generality beyond that of simple enumerations. +
+`x` and `y` in the first iota group, `z` in the second. +
+[Iota page in Go Wiki](https://github.com/golang/go/wiki/Iota)
What _ is used for in Go?
+ +It avoids having to declare all the variables for the returns values. +It is called the [blank identifier](https://golang.org/doc/effective_go.html#blank). +
+[answer in SO](https://stackoverflow.com/questions/27764421/what-is-underscore-comma-in-a-go-declaration#answer-27764432)
@@ -4812,6 +4828,8 @@ func main() { } ```
+ +Since the first iota is declared with the value `3` (` + 3`), the next one has the value `4`
## Mongo From a136ed09c37f117ddce5e2b89f8725e42033eeab Mon Sep 17 00:00:00 2001 From: Noskov Artem Date: Fri, 14 Feb 2020 20:08:23 +0500 Subject: [PATCH 8/8] Add golang questions about arrays, heap, sync Questions source: github.com/proghub-official/golang-interview --- README.md | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/README.md b/README.md index a68bc8b..8c42312 100644 --- a/README.md +++ b/README.md @@ -4832,6 +4832,145 @@ func main() { Since the first iota is declared with the value `3` (` + 3`), the next one has the value `4`
+
+What will be the output of the following block of code?: + +``` +package main + +import ( + "fmt" + "sync" + "time" +) + +func main() { + var wg sync.WaitGroup + + wg.Add(1) + go func() { + time.Sleep(time.Second * 2) + fmt.Println("1") + wg.Done() + }() + + go func() { + fmt.Println("2") + }() + + wg.Wait() + fmt.Println("3") +} +``` +
+ +Output: 2 1 3 + +[Aritcle about sync/waitgroup](https://tutorialedge.net/golang/go-waitgroup-tutorial/) + +[Golang package sync](https://golang.org/pkg/sync/) +
+ +
+What will be the output of the following block of code?: + +``` +package main + +import ( + "fmt" +) + +func mod1(a []int) { + for i := range a { + a[i] = 5 + } + + fmt.Println("1:", a) +} + +func mod2(a []int) { + a = append(a, 125) // ! + + for i := range a { + a[i] = 5 + } + + fmt.Println("2:", a) +} + +func main() { + sl := []int{1, 2, 3, 4} + mod1(s1) + fmt.Println("1:", s1) + + s2 := []int{1, 2, 3, 4} + mod2(s2) + fmt.Println("2:", s2) +} +``` +
+ +Output:
+1 [5 5 5 5]
+1 [5 5 5 5]
+2 [5 5 5 5 5]
+2 [1 2 3 4]
+
+ +In `mod1` a is link, and when we're using `a[i]`, we're changing `s1` value to. +But in `mod2`, `append` creats new slice, and we're changing only `a` value, not `s2`. + +[Aritcle about arrays](https://golangbot.com/arrays-and-slices/), +[Blog post about `append`](https://blog.golang.org/slices) +
+ +
+What will be the output of the following block of code?: + +``` +package main + +import ( + "container/heap" + "fmt" +) + +// An IntHeap is a min-heap of ints. +type IntHeap []int + +func (h IntHeap) Len() int { return len(h) } +func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] } +func (h IntHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } + +func (h *IntHeap) Push(x interface{}) { + // Push and Pop use pointer receivers because they modify the slice's length, + // not just its contents. + *h = append(*h, x.(int)) +} + +func (h *IntHeap) Pop() interface{} { + old := *h + n := len(old) + x := old[n-1] + *h = old[0 : n-1] + return x +} + +func main() { + h := &IntHeap{4, 8, 3, 6} + heap.Init(h) + heap.Push(h, 7) + + fmt.Println((*h)[0]) +} +``` +
+ +Output: 3 + +[Golang container/heap package](https://golang.org/pkg/container/heap/) +
## Mongo