# General question
- [x] Tell us about your background, which projects you are working and worked. Specify interesting points of your work.
- [x] What was the biggest team you worked with?
- [ ] What was the biggest code base you worked with?
- [x] Which technologies you worked with?
- [x] Which languages you worked with?
- [x] Which databases you worked with?
- [x] Any NoSQL databases?
- [x] Any key value stores?
- [ ] Did you use any libraries except active_record to interact with db? (sequel, romrb)
- [x] How were you managing background jobs?
- [ ] Which frameworks have you used?
- [x] Have you ever managed a team?
- [x] Have you ever provided an architecture for a team?
- [x] What was the organization workflow in your previous jobs? Which tools/services were you using to organize your work?
- [x] Which services were you using?
- [x] How were you managing the interaction between frontend and backend?
- [x] Where were your views located? Within monolith or client server app?
- [ ] Was there any Serverside rendering involved?
- [ ] Two-factor authentication (2FA)
- [ ] SMS
- [ ] Google authentication
- [ ] Mobile App
- [x] Full-text search
- [x] Which technology were you using? (Elasticsearch, Sphinx, Lucene, Algolia)
- [ ] Which payment systems have you worked with?
- [ ] How were you deploying to production?
- [ ] How were you testing (QA) the written code?
- [ ] What was your coverage?
- [x] What was the workflow from product requirement to production?
- [x] What were you using for deployment? (docker, capistrano, manual, some orchestration framework)
- [x] What were you using for version control? (gitlab, github, bitbucket etc..?)
- [ ] Which flow were you using? (gitflow, gitlab flow)
- [ ] How were you reviewing the code? (any services)
- [ ] How were you managing the testing environment?
- [ ] Have you ever created a facebook newsfeed like functionality? Explain more, if yes
- [ ] What were you using for cache and how you were organizing them?
- [ ] Did you have any internal documentation system? How were you organizing API docs?
- [ ] Do you have any experience with high load? Roughly, how many requests per second had your biggest project have?
- [x] Did you have experience in creating a public API?
- [ ] If yes, which authentication methods were you using?
- [ ] Which framework were you using for HTTP requests
- [ ] How were you documenting it?
- [x] Have you used any microservice architecture in your previous work?
- [x] How did you organize the messaging between microservices?
- [x] How did you organize the authentication between services?
- [ ] How did you deploy them?
- [x] How were you using the database? (shared or isolated)
- [x] Any experience with RabbitMQ?
- [x] Any experience with DDD?
- [x] Explain what DDD is, how it works, and what your experience was with it
- [ ] Do you know about SOLID, how were you using it?
# Code Questions
## Logic and data structure skills
[ ] For logic skills https://coderbyte.com/dashboard/wetravelinc-3wozx:senior-ruby-developer-0jm8buew9k
- [ ] You have eight apples all of the same weight. 7 of them weigh the same, and one of them weighs slightly more.
- [ ] How can you find the apple that is heavier by using a balance and only two weighings?
- [ ] You have unlimited amount of water and two buckets - [ ] one for 5 liters second is 3 liters. How you can measure 4 liters?
- на 5 литров и 3 литра.Вопрос: Как вы отмерите 4 литра?Ответ: Наполните водой пятилитровое ведро и вылейте часть воды в трехлитровое. У вас сейчас 3 литра в маленьком ведре и 2 — в большом. Опустошите маленькое ведро и перелейте туда оставшиеся 2 литра из большого. Снова наполните большое ведро и перелейте из него воду в малое. Там уже есть 2 литра воды, так что долить придется литр, а в большом останется 4 литра.
## Ruby
- [ ] Everything in ruby is object, Explain it
- [ ] What is public, Private, Protected. What is the main difference ruby from another oop languages
```ruby
class Parent
def say
puts 'public word'
end
private
def private_say
puts "private word"
end
protected
def protected_say
puts "protected word"
end
end
class Child < Parent
def force_to_say
say rescue puts "say error"
protected_say rescue puts "protected_say error"
private_say rescue puts "private_say error"
self.say rescue puts "self.say error"
self.protected_say rescue puts "self.protected_say error"
self.private_say rescue puts "self.private_say error"
Parent.new.say rescue puts "Parent.new.say error"
Parent.new.protected_say rescue puts "Parent.new.protected_say error"
Parent.new.private_say rescue puts "Parent.new.private_say error"
end
end
Child.new.force_to_say
```
- [ ] What is the symbol, why it used in ruby, what is the difference between strings and symbols
- [ ] What is the operator overloading in ruby, and how I can overload + operator.
- [ ] What is the class variable, instance variable. what is the problem of using class variables. how can it be fixed with instance variables
- [ ] Blocks, procs, lambda. What are they, how can be used, what are differences
- [ ] What are modules, and what is their usage
- [ ] In Ruby code, you quite often see the trick of using an expression like array.map(&:method_name) as a shorthand form of array.map { |element| element.method_name }. How exactly does it work?
- [ ] There are three ways to invoke a method in ruby. Can you give me at least two?
- [ ] Did you ever created own gem?
- [ ] did you ever created SDK(api wrapper)?
- [ ] Variable types in Ruby: numbers (Fixnum, Bignum, Float), String, Array, Hash, Boolean, Range, nil Classes and objects
- [ ] Realize factorial and fibonachi functions
```ruby
puts fact 4
#=> 24
puts fib 6
#=> 21
# SOLUTION:
# factorial
def fact(n)
return 1 if n == 0
n * fact(n-1)
# OR
# (1..n).reduce(1, :*)
end
# OR we can extend Integer functionality
class Integer
def !
(1..self).inject(:*)
end
end
# fibonacci
def fib(n)
n > 0 ? n + fib(n-1) : 0
# OR
# (1..n).reduce(0, :+)
end
```
- [ ] What is the difference
```ruby
module ExampleModule
def method1
end
def method2
end
end
class ExampleClass
include ExampleModule
end
class ExampleClass2
extend ExampleModule
end
```
- [ ] Any experience with dsl?
- [ ] Meta programming task: need to implement such method:
```ruby
with_array([]) do
push 1
push 2
pop
push 3
end
# => [1,3]
# SOLUTION:
class Utils
def initialize(collection, &block)
@collection = collection
instance_eval(&block)
end
def push(arg)
@collection << arg
end
def pop
@collection.pop
end
def execute
p @collection
end
end
def with_array(collection, &block)
Utils.new(collection, &block).execute
end
```
- [ ] How to call same name function of parent class? What is the difference between `super` and `super()`
- [ ] What is the difference: and vs &&, or vs ||?
```ruby
var1 = true and false
var2 = true && false
# true
# false
```
- [ ] Caching of json views, What is russian doll caching which problems this caching method has? How you can fix it. What is memoizations? multi-string memoization? example:
```ruby
def posts_number
@posts_number ||= current_user.posts.count
end
def posts_number
@posts_number ||= begin
current_user.posts.count
end
end
```
- [ ] How to compare 2 ruby objects. What is difference between equal? eql? == and ===
- equal? returns true if both sides are same instances
- `==` default implementation returns equal? but different classes overloaded that operator to implement own object equality check
- `===` default implementation returns == operator, case statement uses `===` for coparison used by regexp class to check match also string and regex match equality
- `eql?` : if you give an object as hash key, Hash Class has to calculate hash value of an given key object. Hash Class uses key objects hash method to get hash, and eql? method to compare when you try to access hash with index. Default Object hash implementation is returning object id. Default eql? implementation is the same as equal? method.
- [ ] Realize fruit basket class
```ruby
# Question Realize FruitBasket class
def compare_baskets(basket1, basket2)
if basket1 == basket2
puts "basket and basket2 are similar"
else
puts "basket and basket2 are different"
end
end
basket = FruitBasket.new('banana')
basket << 'apple'
basket << 'orange'
basket += 'grape'
puts '== Looking inside basket'
basket.each_fruit do | fruit |
puts "There is #{fruit} in basket"
end
#> == Looking inside basket
#> There is banana in basket
#> There is apple in basket
#> There is orange in basket
#> There is grape in basket
basket2 = FruitBasket.new('banana')
basket2 << 'apple'
basket2 << 'orange'
basket2 << 'grape'
puts '== Comparing baskets' #> == Comparing baskets
compare_baskets(basket, basket2) #> basket and basket2 are similar
basket = basket - 'grape'
compare_baskets(basket, basket2) #> basket and basket2 are different
puts basket #> Fruits in basket are: banana, apple, orange
puts basket2 #> Fruits in basket are: banana, apple, orange, grape
puts -basket #> Fruits in basket are: orange, apple, banana
puts -basket2 #> Fruits in basket are: grape, banana, apple, orange
## Answer: Realization of FruitBasket class
class FruitBasket
attr_reader :list
def initialize(*args)
@list = args
end
def << (fruit)
@list << fruit
end
def >> (fruit)
@list >> fruit
end
def to_s
fruits = @list.join(', ')
"Fruits in basket are: #{fruits}"
end
def each_fruit(&block)
@list.each do |f|
yield f
end
end
def -(fruit)
l = @list - [fruit]
self.class.new *l
end
def +(fruit)
l = @list + [fruit]
self.class.new *l
end
def -@
self.class.new @list.reverse
end
def ==(other)
other.to_a == @list
end
def to_a
list
end
end
```
- Realize my_each method for a Array class which will behave similar to each method
```ruby
puts arr = [2,4,5]
l = -> e { puts e * 2}
arr.each(&l)
#=> 4 8 10
arr.my_each do |e|
l.call e
end
#=> 4 8 10
# SOLUTION:
Array.class_eval do
def my_each
for n in 0...self.size
yield self[n]
end
end
# OR
def my_each2
size.times do |i|
yield self[i]
end
end
# OR
def my_each3
i = 0
while i < self.length
yield self[i]
i += 1
end
end
end
```
- [ ] What is rack
- https://thoughtbot.com/upcase/videos/rack http://railscasts.com/episodes/151-rack-middleware https://habr.com/post/131429/
- [ ] What is Singleton pattern http://dalibornasevic.com/posts/9-ruby-singleton-pattern
## Rails
- [ ] Assosiations http://rusrails.ru/active-record-associations#svyaz-has_and_belongs_to_many
- [ ] What is N+1 problem? how to solve? (Preload, Eagerload, Includes and Joins):https://habrahabr.ru/post/191762/https://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html
- [ ] What is polymorphic associations :http://rusrails.ru/active-record-associations#polymorphic-associations
- [ ] What is STI (single table inheritance), please provide example :http://www.rusrails.ru/active-record-associations#nasledovanie-s-edinoy-tablitsey-sti
- [ ] routes http://rusrails.ru/rails-routing:
- [ ] Which methods of Application testin are you using? Which tools you using for testing TDD, BDD, rspec mock/stub/double, simplecov, ruby-prof, webmock,
## Sql
- [ ] What is normalization? Explain different levels of normalization?
- [ ] What is denormalization and when would you go for it?
- [ ] How do you implement one-to-one, one-to-many and many-to-many relationships while designing tables?
- [ ] What is a transaction and what are ACID properties?
- [ ] Describe what you know about PK, FK, and UK.
Primary keys – Unique clustered index by default, doesn’t accept null values, only one primary key per table.
Foreign Key – References a primary key column. Can have null values. Enforces referential integrity.
Unique key – Can have more than one per table. Can have null values. Cannot have repeating values. Maximum of 999 clustered indexes per table.
2. [ ] What is a Join and explain different types of Joins?
Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.
**Types of joins:** INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.
- [ ] What is the difference between a UNION and a JOIN?
A JOIN selects columns from 2 or more tables. A UNION selects rows.
- [ ] Design a db schema for product/category functionality for an internet shop
Requirements:
- Any Category can have multiple Products.
- Any Product can belong to several Categories.
- Any Category can have several Sub-Categories.
- [ ] Given following tables
table **wt_categories**
<table border=“1” style=“border-collapse:collapse”>
<tr><th>id</th><th>name</th><th>description</th><th>parent_id</th><th>created_at</th><th>updated_at</th></tr>
<tr><td>1</td><td>Computers</td><td>Computers</td><td>NULL</td><td>2019-05-23 15:45:46</td><td>2019-05-23 15:45:56</td></tr>
<tr><td>2</td><td>Tablets</td><td>Tablets</td><td>NULL</td><td>2019-05-23 15:45:39</td><td>2019-05-23 15:45:49</td></tr>
<tr><td>3</td><td>Smartphones</td><td>Smartphones<br/></td><td>NULL</td><td>2019-05-23 15:45:43</td><td>2019-05-23 15:45:51</td></tr>
<tr><td>4</td><td>Chromebooks</td><td>Chromebooks</td><td>1</td><td>2019-05-23 15:45:44</td><td>2019-05-23 15:45:53</td></tr>
<tr><td>5</td><td>Laptops</td><td>Laptops</td><td>1</td><td>2019-05-23 15:45:41</td><td>2019-05-23 15:45:48</td></tr></table>
table **wt_products**
<table border=“1” style=“border-collapse:collapse”>
<tr><th>id</th><th>name</th><th>description</th><th>price</th><th>created_at</th><th>updated_at</th></tr>
<tr><td>1</td><td>Samsung Galaxy S10</td><td>Samsung</td><td>950</td><td>2019-05-23 15:54:03</td><td>2019-05-23 15:53:58</td></tr>
<tr><td>2</td><td>Samsung Galaxy S9</td><td>Samsung</td><td>800</td><td>2019-05-23 15:54:03</td><td>2019-05-23 15:53:58</td></tr>
<tr><td>3</td><td>IPhone X</td><td>Apple</td><td>900</td><td>2019-05-23 15:54:35</td><td>2019-05-23 15:54:40</td></tr>
<tr><td>4</td><td>IPhone Xs</td><td>Apple</td><td>1000</td><td>2019-05-23 15:56:03</td><td>2019-05-23 15:55:59</td></tr>
<tr><td>5</td><td>Asus VivoBook</td><td>Asus VivoBook</td><td>500</td><td>2019-05-23 15:57:20</td><td>2019-05-23 15:57:23</td></tr>
<tr><td>6</td><td>Acer </td><td>Acer</td><td>300</td><td>2019-05-23 15:57:20</td><td>2019-05-23 15:57:23</td></tr>
<tr><td>7</td><td>MacBook Pro</td><td>Apple</td><td>2299</td><td>2019-05-23 15:58:07</td><td>2019-05-23 15:58:13</td></tr></table>
table **product_categories**
<table border=“1” style=“border-collapse:collapse”>
<tr><th>id</th><th>product_id</th><th>category_id</th></tr>
<tr><td>1</td><td>1</td><td>3</td></tr>
<tr><td>2</td><td>2</td><td>3</td></tr>
<tr><td>3</td><td>3</td><td>3</td></tr>
<tr><td>4</td><td>4</td><td>3</td></tr>
<tr><td>5</td><td>5</td><td>5</td></tr>
<tr><td>6</td><td>6</td><td>4</td></tr>
<tr><td>7</td><td>7</td><td>5</td></tr></table>
- [ ] Show all Categories.
- `select * from wt_categories;`
- [ ] Show all Products in the Category of Smartphones with sorting from higher price to lower price
- a. `select * from wt_products p left join wt_product_categories pc on p.id = pc.product_id where pc.category_id = 3 order by p.price desc;`
- b. `select * from wt_products p left join wt_product_categories pc on p.id = pc.product_id left join wt_categories c on c.id = pc.category_id where c.name = 'Smartphones' order by p.price desc;`
- [ ] Show all Category Names and sum of all Product prices where sum of these Product prices is more than 2000
- `select c.name, sum(p.price) from wt_categories c left join wt_product_categories pc on c.id = pc.category_id left join wt_products p on p.id = pc.product_id group by c.name, p.price having sum(p.price) > 2000`
- [ ] Select all suppliers where price is more than 20
```json
DROP TABLE IF EXISTS products;
CREATE TABLE products(item int,supplier int,price decimal(6,2));
INSERT INTO products VALUES(1,1,10),(1,4,21),(1,3, 25),(1,2,15),(2,2,20),(2,1,21),(2,3,18);
SELECT * FROM products;
```
**table Products**
| item | supplier | price |
| ---- | -------- | ----- |
| 1 | 1 | 10.0 |
| 1 | 4 | 21.00 |
| 1 | 3 | 25.0 |
| 1 | 2 | 15.00 |
| 2 | 2 | 20.00 |
| 2 | 1 | 21.00 |
| 2 | 3 | 18.00 |
solution
```sql
SELECT item, supplier, price FROM products GROUP BY item, supplier, price HAVING price > 20 ORDER BY price;
```
# Architecture design questions
## Create design for following requirements
### Questionaries for each booking
**Design software architecture and database structure for following feature:** In Wetravel we have trips. For each trip you can add questionaries. First 3 questions(Firstname, lastname, email) are default and required. You can't delete them. But you can add additional questions. We had 4 type of questions. Questions can be required or not

- Text: As answer you there is a textfield
- Checkboxes: There are multiple answer options where you can select multiple. It can have other option, when
user selects it he have to add own answer to checkbox
- Radio Box: Multiple choice question where you can select only one. It can have other option, when
user selects it he have to add own answer to checkbox
- File upload: Where you can upload multiple files as an answer
- Date Time: where you select date time from dropdown
Answers:
- [ ] Trip can be booked for multiple participants. In this case traveler has to enter answer for each participant

## Create application architecture based on microservices
See [Here](https://hackmd.io/@xbaLkoBkQYOJUoQ42YPvlg/HkMgczD7S)
# Homework
## URL Shortener(For middles)
Test application:
Build an api application that store an url in a database and provide the user a tiny url
to publish on the web, the application should have the following features:
- Implement Authentication for api calls
- only registered and authorized api clients can perform actions in the system and use the features
- Code should be test covered
- Client should see list all added links
- delete link
- update url
- can set custom url token
- Like http://localhost:3000/my-custom-url-token.
- if there no custom token system should generate one
- example of how it works:
your website = localhost:3000
put his destination for example www.apple.com
and get a tiny url using our domain http://localhost:3000/6hgdd.
when a user put in the browser http://localhost:3000/6hgdd he get redirected to www.apple.com
## Rack app(For middle and senior)
```
User description
email, first_name, last_name, password
passwords should not be stored as plaintext
Todo description
title, due_to, priority, status
User should be able to register with email and password
User should update her/his profile with first_name, last_name
User should be able to see all entries of her/his own after login
User should be able to create todos
User should be able to update a todo entry of her/his own
User should not be allowed to modify or to see other users' entries
User should be able to sort todos by all terms (title, priority etc.)
Todos marked as done should not be listed on main screen
Todos should be able to be reincarnated - thus they will be going to appear on active entries listing
Do not use ActiveRecord
Do not use ActionPack
Do not use Sinatra/Padrino, Hanami etc.
Use bcrypt
Implement your app as a pure rack application
https://isotope11.com/blog/build-your-own-web-framework-with-rack-and-ruby-part-2
https://www.slideshare.net/maraby/building-a-framework-on-rack
```