Skip to content

Instantly share code, notes, and snippets.

View iseitz's full-sized avatar
💭
www.linkedin.com/in/irina-karchebnaya-seitz

iseitz iseitz

💭
www.linkedin.com/in/irina-karchebnaya-seitz
View GitHub Profile
@iseitz
iseitz / the maximum value in the hash - Ruby
Last active September 29, 2017 20:43
Find the maximum value in the hash - Ruby (vowels, words count, temperature etc)
max = -1
vowels_hash.each do |vowel, frequency|
if frequency > max
max = frequency
end
end
@iseitz
iseitz / Ruby_trick
Created October 27, 2017 17:28
Ruby triks
animal = "cat"
class << animal
def speak
puts "miow"
end
end
animal.speak
#self is assigned to the object and then the method is found for this class of the object via Singleton (unique methods table). One to the right, one up
@iseitz
iseitz / card.rb
Created November 6, 2017 18:33
Creating a card class with specific rank and suit, then create a hand of several cards and checking if it has any face cards
class PlayingCard
attr_accessor :rank, :suite
def initialize (rank, suite)
@rank = rank
@suite = suite
end
def face_card?
['K', 'Q', 'J'].include?(@rank)
end

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

# On MAC OS High Sierra 10.13.6
# You must recompile Ruby with OpenSSL error:
$ rvm get head
$ rvm pkg remove
$ rvm requirements run
# (I just ran the `rvm requirements` and it installed the missing parts.
# I then reinstalled the newest version of Ruby and Rails, this worked for me.)
$ rvm reinstall 2.6.0
$ rvm get stable
# if there is a problem with getting the latest version run:
$ rvm get head
$ rvm reload
$ rvm get stable
# if that does not work try:
$ \curl -sSL https://get.rvm.io | bash -s stable
@iseitz
iseitz / nokogiri_libxml_homebrew_lion_installation.sh
Created February 21, 2019 06:49 — forked from vparihar01/nokogiri_libxml_homebrew_lion_installation.sh
How to fix: Nokogiri Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0. dlopen bundle.open. Using homebrew on lion to install nokogiri and lixml
FIXME:
WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
or
ERROR -: Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
@iseitz
iseitz / gist:afb5497b609def91cd1c1793ac4636d8
Created February 21, 2019 06:52
Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib
#uninstall nokogiri:
$ gem uninstall nokogiri
#install nokogiri
$ gem install nokogiri
#restart terminal\if needed run gem pristine byebug --version 11.0.0
#solved!
@iseitz
iseitz / rspec_rails_cheetsheet.rb
Created February 22, 2019 09:28 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@iseitz
iseitz / Capybara.md
Created February 22, 2019 10:36 — forked from tomas-stefano/Capybara.md
Capybara cheatsheet

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above