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 Guide < ActiveRecord::Base | |
belongs_to :user | |
acts_as_votable | |
def score | |
upvotes.count - downvotes.count | |
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
Started POST "/guides/2-sdkfjsk/comments" for 127.0.0.1 at 2014-01-08 09:14:59 -0500 | |
Processing by CommentsController#create as HTML | |
Parameters: {"utf8"=>"✓", "authenticity_token"=>"D2BvBIgU+tniZvr2NgQE/TpHY6J2xHOUm701jqTcJ9A=", "comment"=>{"body"=>"", "user_id"=>"some value"}, "{:id=>\"comments_guide_id\", :name=>\"comments"=>{"guide_id"=>{"\", :value=>2}"=>""}}, "commit"=>"Create Comment", "guide_id"=>"2-sdkfjsk"} | |
Completed 500 Internal Server Error in 1ms | |
NoMethodError (undefined method `[]=' for nil:NilClass): | |
app/controllers/comments_controller.rb:27:in `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
<p id="notice"><%= notice %></p> | |
<h1>Now Discussing: <%= @guide.title %></h1> | |
<p> | |
<strong>Link to Guide:</strong> | |
<%= link_to @guide.title, "http://#{@guide.link}" %> | |
</p> | |
<p> |
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 upvote | |
@guide = Guide.find(params[:id]) | |
@guide.liked_by current_user | |
redirect_to :back | |
end | |
def downvote | |
@guide = Guide.find(params[:id]) | |
@guide.downvote_from current_user | |
redirect_to :back |
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 north_korean_cipher(coded_message) | |
input = coded_message.split('') # splits the coded message into array of letters | |
letters = %w(a b c d e f g h i j k l m n o p q r s t u v w x y z) | |
code = letters.rotate(-4) | |
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
// This is a Solo Challenge. | |
// There is a section below where you will write your code. | |
// Do not alter this object here. | |
var terah = { | |
name: "Terah", | |
age: 32, | |
height: 66, |
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
☐ create variable containing options [1-9] | |
☐ look at first row and see what numbers from 1-9 are missing | |
☐ then look at column and see what else is missing | |
☐ finally, check the box | |
☐ (note that we're removing values from 'options' every time we check) | |
☐ compare what's missing to our options | |
☐ when options.size == 1, then we know that that's the answer | |
☐ if not, then move on to next empty cell | |
OPTIONS = [1,2,3,4,5,6,7,8,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
input1 = "100/2" | |
input2 = '100/90' | |
operator = '-' | |
def to_num(frac) | |
components = frac.split('/').map(&:to_i) | |
value = (components[0].to_f / components[1].to_f) | |
value | |
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
def pig_latin(word) | |
if %w(a e i o u).include? word[0] | |
word + "ay" | |
else | |
word[1..-1] + word[0] + "ay" | |
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 MidpointCalculator | |
def initialize(information) | |
@quantity1 = information[:quantity1].to_f | |
@quantity2 = information[:quantity2].to_f | |
@price1 = information[:price1].to_f | |
@price2 = information[:price2].to_f | |
end | |
def calculate | |
numerator = ((@quantity1 - @quantity2) / (@quantity1 + @quantity2 ) / 2) |