This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [0, 1, 2, 3, 5, 6] | |
puts Array(0..arr.size) - arr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [0, 1, 2, 3, 5, 6] | |
n = 0 | |
n += 1 until arr[n] != n | |
puts n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
url = URI.parse('http://localhost:4567/pizza') | |
req = Net::HTTP::Get.new(url.to_s) | |
res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) } | |
body = res.body | |
abort body if body != 'OK' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
get '/pizza' do | |
if rand(0..1).zero? | |
'OK' | |
else | |
'Something is wrong' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grep -Eo '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' access.log | uniq -c | sort --reverse | head -n10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<root> | |
<authorities> | |
<authority> | |
<originID>100</originID> | |
<timestamp>2016-06-08T15:56:32</timestamp> | |
<authorityName>authorityNameNew</authorityName> | |
<INN>1234567890</INN> | |
</authority> | |
</authorities> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'nokogiri' | |
describe 'Nokogiri' do | |
let(:xml) do | |
%( | |
<root> | |
<schools> | |
<school> | |
<id>1</id> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student | |
include HappyMapper | |
tag 'student' | |
has_one :name, String | |
has_one :school_id, String, tag: 'schoolId' | |
end | |
class School | |
include HappyMapper | |
tag 'school' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class School | |
include HappyMapper | |
tag 'school' | |
has_one :id, String | |
has_one :name, String | |
end | |
let(:schools) { School.parse(xml) } | |
it do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let(:doc) { Nokogiri::XML(xml) } | |
it do | |
school_id = doc.xpath('//school[name/text()="Second school"]/id').text | |
student_names = doc.xpath("//student[schoolId/text()=#{school_id}]/name").map(&:text) | |
expect(student_names).to match(%w(Alex Olivia)) | |
end |