🏳️⚧️
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
| #!/usr/bin/env ruby | |
| if ARGV.empty? | |
| warn "Need a list of URLs to benchmark" | |
| exit 1 | |
| end | |
| class Siege | |
| REQUESTS = 10 | |
| CONCURRENCY = 1 |
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
| ## Duplicated methods: | |
| def default_billing_address=(address) | |
| raise CustomerDoesNotOwnAddress if address.addressable != self | |
| self.default_billing_address_id = address.id | |
| end | |
| def default_billing_address | |
| billing_address = self.addresses.find(default_billing_address_id) if default_billing_address_id.present? | |
| billing_address ||= self.addresses.order(:created_at).first |
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
| Question: Convert following into the latter data structure in less than 30 lines: | |
| List: | |
| A, B, C | |
| A, C, E | |
| E, F, D | |
| D, A, J | |
| E, D, J | |
| List |
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
| a = [1,2,3] | |
| a.map { |n| [n, n * n] } | |
| # => [[1, 1], [2, 4], [3, 9]] | |
| a.flat_map { |n| [n, n * n] } | |
| # => [1, 1, 2, 4, 3, 9] |
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
| class Invoice < ActiveRecord::Base | |
| has_many :line_items | |
| # ... | |
| delegate :<<, :to => :line_items | |
| 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
| class User < ActiveRecord::Base | |
| has_many :posts | |
| end | |
| class Post < ActiveRecord::Base | |
| belongs_to :user | |
| end | |
| alice = User.create |
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
| module Reverb | |
| def self.included(base) | |
| @@verbs ||= [] | |
| @@verbs << base | |
| end | |
| def self.inject(base) | |
| base.class_exec do | |
| Array(@@verbs).each do |verb| | |
| verb_name = verb.name.to_sym |
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
| class ApplicationController | |
| # ... | |
| class BreakPoint < StandardError | |
| def initialize(messages) | |
| @messages = messages | |
| end | |
| def to_s | |
| @messages.join("\n") |
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
| # Emulate ActiveRecord's block <3 | |
| class Invoice | |
| def initialize | |
| yield self | |
| end | |
| end | |
| # Checkout delegate to the invoice | |
| class Checkout | |
| def initialize(invoice) |
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
| class CheckoutForm < ActiveRecord::Base | |
| attr_accessible :delivery_type # ... | |
| # ... | |
| module Defaults | |
| def delivery_type | |
| super || default_delivery_type | |
| end |