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
| [{"user_id":200,"body":"hi","nickname":"ken","id":71,"avatar_url":"http://www.gravatar.com/avatar/2a9b8f5273d934fe57daa8cf54c3a017?d=http%3A%2F%2Fi.imgur.com%2FUPWvbDz.jpg","messages":["hi"],"time":"05:20 PM"},{"user_id":201,"body":"hi","nickname":"marco","id":72,"avatar_url":"http://www.gravatar.com/avatar/111488d071a62ac94887bf02e8dd0df9?d=http%3A%2F%2Fi.imgur.com%2FUPWvbDz.jpg","messages":["hi"],"time":"05:24 PM"},{"user_id":200,"body":"hi","nickname":"ken","id":73,"avatar_url":"http://www.gravatar.com/avatar/2a9b8f5273d934fe57daa8cf54c3a017?d=http%3A%2F%2Fi.imgur.com%2FUPWvbDz.jpg","messages":["hi","hi"],"time":"05:28 PM"},{"user_id":201,"body":"what's up ken?","nickname":"marco","id":75,"avatar_url":"http://www.gravatar.com/avatar/111488d071a62ac94887bf02e8dd0df9?d=http%3A%2F%2Fi.imgur.com%2FUPWvbDz.jpg","messages":["what's up ken?"],"time":"05:32 PM"},{"user_id":200,"body":"not much, how about you?","nickname":"ken","id":76,"avatar_url":"http://www.gravatar.com/avatar/2a9b8f5273d934fe57daa8cf54c3a017?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
| values = [1,1,2,4,2,1,9,99, 0] | |
| counts = values.inject({}) do |acc, value| | |
| acc[value] ||= 0 | |
| acc[value] += 1 | |
| acc | |
| end | |
| puts counts.inspect |
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 'benchmark' | |
| class Dog | |
| def say(*words) | |
| puts 'Doggie says: ' + words.slice(1, words.length - 1).join(' ') | |
| end | |
| def method_missing(method, *args, &block) | |
| if /^say_\B/ =~ method.to_s |
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 'benchmark' | |
| class Dog | |
| [:woof, :bark, :hello].each do |word| | |
| define_method("say_#{word}!") do | |
| puts "Doggy says #{word}!" | |
| end | |
| 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
| class Quote < ActiveRecord::Base | |
| validates :saying, presence: true, length: { maximum: 140, minimum: 3 } | |
| validates :author, presence: true, length: { maximum: 50, minimum: 3 } | |
| before_create :remove_leading_and_trailing_quotes | |
| def remove_leading_and_trailing_quotes | |
| self.saying = self.saying.gsub(/\A"/, '').gsub(/"\Z/, '') | |
| 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
| <h1>"<%= @quote.saying %>"</h1> |
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 Deck | |
| RANKS = [:spades, :hearts, :diamonds, :clubs] | |
| SUITS = [2,3,4,5,6,7,8,9,10,"J","Q","k","A"] | |
| def initialize | |
| @cards = Array.new | |
| SUITS.each do |y| | |
| RANKS.each do |x| | |
| @cards << Card.new(x, y) | |
| 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
| # Arguments: | |
| # n (an integer) containing 16 digits | |
| # Return value: | |
| # an array containing each of the 16 digits with even indexed items doubled (or if it's greater than 10, doubled and minus 9) | |
| # Example: | |
| # [0,0,0,0,1,1,0,1,9,8,7,6,5,4,3,2,1] # original revered for reference | |
| # double_3(00002101985614622) => [0,0,0,0,2,1,0,1,9,8,5,6,1,4,6,2,2] | |
| def double_3(digits) | |
| transformed_digits = [] | |
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
| 18:18:58 From Marco Morawec : Rails Motto: “Conventions over Configurations” | |
| 18:25:40 From senthium : Is there a way to show a diagram to show how the tables are actually linked? | |
| 18:26:53 From senthium : For example, if the user has many places? /uma | |
| 18:27:27 From Alex Bezobchuk : also, https://ryanboland.com/blog/creating-a-database-diagram-with-rails-erd/ looks promising | |
| 18:27:40 From senthium : User.find(1).places and place.find(!).user both works? | |
| 18:27:54 From senthium : Is it a two way street? | |
| 18:28:07 From senthium : Thank you | |
| 18:41:56 From amarkpark : I’m trying to add my questions by my computer is having memory issues | |
| 18:42:33 From Nicola : Add here, I’ll copy/paste for you | |
| 18:42:46 From yhu : testing in production in start-ups is very common. |
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 LinkedListNode | |
| attr_accessor :value, :next_node | |
| def initialize(value, next_node=nil) | |
| @value = value | |
| @next_node = next_node | |
| end | |
| end | |
| def print_values(list_node) |