Monday, February 27, 2017

Cool capybara sheet.

=Navigating=
    visit('/projects')
    visit(post_comments_path(post))

=Clicking links and buttons=
    click_link('id-of-link')
    click_link('Link Text')
    click_button('Save')
    click('Link Text') # Click either a link or a button
    click('Button Value')

=Interacting with forms=
    fill_in('First Name', :with => 'John')
    fill_in('Password', :with => 'Seekrit')
    fill_in('Description', :with => 'Really Long Text…')
    choose('A Radio Button')
    check('A Checkbox')
    uncheck('A Checkbox')
    attach_file('Image', '/path/to/image.jpg')
    select('Option', :from => 'Select Box')

=scoping=
    within("//li[@id='employee']") do
      fill_in 'Name', :with => 'Jimmy'
    end
    within(:css, "li#employee") do
      fill_in 'Name', :with => 'Jimmy'
    end
    within_fieldset('Employee') do
      fill_in 'Name', :with => 'Jimmy'
    end
    within_table('Employee') do
      fill_in 'Name', :with => 'Jimmy'
    end

=Querying=
    page.has_xpath?('//table/tr')
    page.has_css?('table tr.foo')
    page.has_content?('foo')
    page.should have_xpath('//table/tr')
    page.should have_css('table tr.foo')
    page.should have_content('foo')
    page.should have_no_content('foo')
    find_field('First Name').value
    find_link('Hello').visible?
    find_button('Send').click
    find('//table/tr').click
    locate("//*[@id='overlay'").find("//h1").click
    all('a').each { |a| a[:href] }

=Scripting=
    result = page.evaluate_script('4 + 4');

=Debugging=
    save_and_open_page

=Asynchronous JavaScript=
    click_link('foo')
    click_link('bar')
    page.should have_content('baz')
    page.should_not have_xpath('//a')
    page.should have_no_xpath('//a')

=XPath and CSS=
    within(:css, 'ul li') { ... }
    find(:css, 'ul li').text
    locate(:css, 'input#name').value
    Capybara.default_selector = :css
    within('ul li') { ... }
    find('ul li').text
    locate('input#name').value

Thursday, February 23, 2017

Reverse transparent image.

Let we have the png file:

And the task is use this as mask with white background to see other background bellow.
At first we need to revert transparency. I use imagemagick CLI for this:

> convert london-landmark.png -background white -alpha background -channel a -negate +channel london-landmark2.png

The result is:



Then it looks on the page:




Wednesday, February 22, 2017

Full decs task

In a casino, all the playing cards got mixed up, and some of them got lost.
You have to collect as many full decks as possible.

You get N mixed up French playing cards as your input.

The cards are of the following ranks:
2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A

The four suits are:
S (Spade), C (Club), H (Heart), D (Diamond)

The cards are given using their rank followed by their suit:

2 of Spades: 2S
Ace of Clubs: AC
10 of Hearts: TH

Write a function that will accept an array of cards and return the number of full decks contained in the array.

Examples:
a) ["9C", "KS", "AC", "AH", "8D", "4C", "KD", "JC", "7D", "9D", "2H", "7C", "3C", "7S", "5C", "6H", "TH"] -> 0

b) ["2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH", "AS", "AC", "AD", "AH", "2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH", "AS", "AC", "AD", "AH", "2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH", "AS", "AC", "AD"] -> 2



def full_decks_count input
  res = input.inject({}) do |h, el|
    h[el] ||= 0
    h[el] += 1
    h
  end

  return 0 if res.count < 52
  res.values.min
end

Monday, February 13, 2017

Questions to think

1. Let we have Post(title, body) -> Comments(body).
Write the active record query to get all posts, where "query" is into title or body or comment.

A: https://gist.github.com/Irostovsky/1a9401630d1d27bba69af136f115f2e2#file-tasks_1-rb

2. What is the difference of the procedure, functional and object oriented programming?

3. Array sorting methods?

4. Что такое медиана, персонтиль, квантиль?

5. CAP

6. ACID

7. Коллизия хешей

8. Фильтр Блума

9. ООП Паттерны

10. HTTP methods, OPTIONS, CORS

11. Алгоритм Дифи-Холмана

12. Маска подсети, сколько машин в сети?

13. GIL и потоки в языках. Многопоточность в руби.

14. Что такое oauth? Написать свой oath server.

15. What is systemd?

16. What is index into sql DB?

17. What is sharing?

18. Examples of rails injection?

19. Extend modules:
class A; end;
module M; end;
a = A.new
a.extend M
What does it mean?

20. What is ddos? How to prevent in rails?

21. Notification in Rails. Errbit, sentry gems

22. What is micro service? 

23. What is middleware, rack?

24. VCR gem to test external requests, like webmock.

25. Difference between proc and lambda? Return.

26. Deep linking.

27. Cloud front + s3. CDN.

28. Understanding object_id in ruby.

29. What is Hobo gem?


Friday, February 10, 2017

Some ruby online tools

https://codepad.remoteinterview.io/OMMOOQORTT

Allow to share screen in real time between 2 users at least.

http://rubyfiddle.com/
Just a simple console, even without p method and printing array element-by-element.


Thursday, February 9, 2017

Why Toptal

Well, somewhere, when you have stable long-term project, good customer and salary you found yourself stopped. I mean stopped into professional way. You do not interning in new technologies except used in your current projects and even not deep into fundamental understanding of things.

It was with me. After 4+ years of freelance with same project I found that I m out of the modern life. Generally I code on ruby/rails, using just jquery/less for the front-end. But found that Javascript went ahead and new interning things like Angular and React are extremely popular.  So I need changes, I need fresh breath of the new vision, I want to use latest tech news.
It is only way to live in our quick world. It is not bad. It is just a fact. Like 3-4 centuries ago man was needed to have knife to protect himself, now you need to learn new and do this quick, quicker then others.
After looking market I found that there are several sites proposed modern works and projects. Toptal is the leader for now. So I try to pass through it screens to learn something new! And I want to join the best Toptal community.