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
| $ irb | |
| # Into the console! | |
| > require 'open-uri'; require 'nokogiri' # requiring the libraries you need. you might need to 'gem install nokogiri' for this to work | |
| => true # it's been required! | |
| > doc = Nokogiri::HTML(open('https://bluebottlecoffee.com/store/bella-donovan')) # opening the Blue Bottle website in nokogiri, turning it into Ruby | |
| => #<Nokogiri::HTML::Document:0x3fc5d1cd4bd8 name="document" ... etc. | |
| > doc.css('.mb30').children.text # let's find the CSS for coffee notes, and find the text | |
| => "Heavy, comforting, deeply-fruited " # here it is! |
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
| Hum. I don't think I know of a good way to do that that isn't a bit meta-y. I assume you're saying, for this group of policy methods, return false if ```assigned_to_company?``` is false. | |
| Here's a fun thing I found with help from the interwebs. Whether it's a good solution or not is up for debate. | |
| ```ruby | |
| module CompanyPolicyHelper | |
| def check_company_affiliation_for(*methods) | |
| methods.each do |method_name| | |
| method = instance_method(method_name) | |
| define_method(method_name) do |*args, &block| |
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
| %w(Willie Brian Kush Jenna Alex Angela Logesh Abby Geoff Izaak Sarah Kyle).shuffle.each_with_index do |player, i| | |
| puts "#{i + 1}. #{player.split('_').join(' ')}" | |
| 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
| Honorable Mentions: | |
| Sky Ferreira - Night Time, My Time | |
| Lorde - Pure Heroine | |
| Burial - Truant / Rough Sleeper | |
| Youth Lagoon - Wondrous Bughouse | |
| Jim James - Regions of Light and Space | |
| James Blake - Overgrown | |
| 25. Earl Sweatshirt - Doris | |
| 24. Young Galaxy - Ultramarine |
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
| require_relative './file_parser' | |
| require_relative './file_reader' | |
| require_relative './receipt' | |
| class ReceiptPrinter | |
| attr_reader :output | |
| def initialize | |
| remove_existing_output | |
| @output = create_receipts |
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
| # app/models/user.rb | |
| class User < ActiveRecord::Base | |
| validates :password, complexity: true # You may also pass this a method that returns true/false | |
| # ... | |
| end | |
| # app/validators/complexity_validator.rb | |
| class ComplexityValidator < ActiveModel::EachValidator | |
| def validate_each(record, attribute, value) | |
| record.errors.add(attribute, "must have a number") if value !~ /(?=.*\d)/ |
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
| http://open.spotify.com/user/gschorkopf/playlist/1uN5MMGqmKSpf0FVNEZl8A | |
| 100. Ducktails – Under Cover | |
| 99. Danny Brown - Kush Coma | |
| 98. DJ Rashad – Let It Go | |
| 97. Run The Jewels – Banana Clipper | |
| 96. Mutual Benefit – Strong Swimmer | |
| 95. Mount Kimbie – Made To Stray | |
| 94. AlunaGeorge – Attracting Flies | |
| 93. Washed Out – All I Know |
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
| # Goal: To clean up surrounding whitespace from a user's first_name field: | |
| # rspec test: | |
| describe User do | |
| describe "first_name" do | |
| it "sanitizes surrounding whitespace from column" do | |
| user = User.new(first_name: " Stafford ") | |
| expect(user.first_name).to eq "Stafford" | |
| 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
| # Version 1: | |
| def perform(order_attributes, user_attributes, order_total) | |
| UserMailer.order_confirmation(order_attributes, user_attributes, order_total).deliver | |
| end | |
| def order_confirmation(user_attributes, order_attributes, order_total) | |
| @user = user_attributes | |
| @order = order_attributes | |
| @total = order_total |
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
| FactoryGirl.define do | |
| factory :user do | |
| first_name "Geoff" | |
| last_name "S" | |
| role 'standard' | |
| factory :admin do | |
| role 'admin' | |
| end | |
| end |