This file contains hidden or 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
| function isString(sample) { | |
| return typeof(sample) === 'string' || sample instanceof String; | |
| } | |
| function isString(sample) { | |
| return sample.constructor == String; | |
| } |
This file contains hidden or 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
| var literalString = 'wazzup'; | |
| console.log(typeof literalString); // string | |
| console.log(literalString instanceof String); // false | |
| console.log(literalString.constructor === String); // true | |
| var constructedString = new String('wazzup'); | |
| console.log(typeof constructedString); // Object | |
| console.log(constructedString instanceof String); // true | |
| console.log(constructedString.constructor === String); // true |
This file contains hidden or 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
| vasia.with_lock do | |
| petya.withdrawal(100) | |
| vasya.deposit(100) | |
| end |
This file contains hidden or 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
| # две транзакции ниже выполняются через разные подключени к базе | |
| ActiveRecord::Base.transaction do | |
| petya.withdrawal(100) | |
| vasya.deposit(100) | |
| end | |
| ActiveRecord::Base.transaction do | |
| vasya.withdrawal(50) | |
| petya.deposit(50) |
This file contains hidden or 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
| # Если в кошельке Пети нет денег, то Вася все равно полчит свои 100р | |
| class Account < ApplicationRecord | |
| validates :balance, numericality: { greater_than_or_equal_to: 0 } | |
| end | |
| petya.withdrawal(100) | |
| vasya.deposit(100) | |
| # Если в кошельке Пети нет денег, то Вася уже ничего не получит |
This file contains hidden or 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
| def hash_to_form(hash) | |
| form = '' | |
| form << "<form method='#{hash[:method]}' action='#{hash[:url]}'>\n" | |
| hash[:inputs].each do |key, value| | |
| form << " <input type='hidden' name='#{key}' value='#{value}' />\n" | |
| end | |
| form << " <input type='submit' value='Submit' />\n" | |
| form << "</form>" | |
| puts form | |
| end |
This file contains hidden or 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
| signature = (/digest=(.+)/).match(headers['Content-Signature'])[1] | |
| decoded_signature = Base64.urlsafe_decode64(signature) | |
| content = request.body.string | |
| pubilc_key = OpenSSL::PKey::RSA.new(YOUR_PUBLIC_KEY) | |
| digest = OpenSSL::Digest::SHA256.new | |
| pubilc_key.verify(digest, decoded_signature, content) |
This file contains hidden or 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
| describe SomeAPI, type: :request do | |
| describe 'GET /api/some' do | |
| context "user is signed in" do | |
| before do | |
| Grape::Endpoint.before_each do |endpoint| | |
| endpoint.stub(:current_user).and_return(user) | |
| end | |
| end | |
| after { Grape::Endpoint.before_each nil } |
This file contains hidden or 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
| RSpec::Matchers.define :have_index_page_content do |expected| | |
| match do |actual| | |
| have_content('Welcome to Website') | |
| end | |
| end |
This file contains hidden or 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
| openssl pkcs7 -print_certs -in old.p7b -out new.crt | |
| # openssl pkcs7 -print_certs -in old.p7b -out new.cer |