Skip to content

Instantly share code, notes, and snippets.

@data-doge
data-doge / eugene.rb
Last active August 29, 2015 14:10
post '/accounts/orders/bids/create' --- controller + testing
###RSPEC TEST###
describe "POST /account/orders/bids/create" do
let(:account) { Account.create(dollars: 100, josh_coins: 100, user_id: "1234", email: "bob@bob.bob") }
describe "returns correct bid information" do
before do
@account = account
@data-doge
data-doge / wsup.rb
Created December 5, 2014 03:20
week7-shi
###CART_CONTROLLER_SPEC
describe "method calls" do
before { @product = create(:product) }
it "new cart is passed current_user" do
expect(Cart).to receive(:new).with(@current_user).and_call_original
patch :remove_product, {id: @product.id}
end
{
[
{
"user_id" : 2,
"tweets" : [
{
"content" : "blah blah blah blah",
"hashtags" : ["this", "that"]
},
{
@data-doge
data-doge / bad_ass_roman_numeral_soln
Created February 9, 2015 05:11
bad ass roman numeral soln
$cipher = {
"C" => 100,
"XC" => 90,
"L" => 50,
"XL" => 40,
"X" => 10,
"IX" => 9,
"V" => 5,
"IV" => 4,
"I" => 1
@data-doge
data-doge / gist:3b0f59e0f8f3f4d42385
Last active August 29, 2015 14:15
little crud hax
<!-- sinatra only support HTTP verbs GET and POST, so to implement PUT + DELETE HTTP verbs we need to hack a little bit-->
<form action='/tweets/<%=tweet.id%>' method='post'>
<input type='hidden' name='_method' value='delete' />
<!-- here, we have a hidden input which magically turns this post request into a delete request. how nice. -->
<input type='submit' value='X' />
</form>
@data-doge
data-doge / gist:2714ed9f2ccbb9544143
Created February 16, 2015 06:57
drill-the-self-keyword-challenge
## CLASS CONTEXT
class Person
def self.example_class_method
puts "We're calling an example class method"
puts "'self' is always defined. What is 'self' here? Let's see."
p self
puts "That was self!"
end
@data-doge
data-doge / gist:abe218707af0202256c0
Created February 16, 2015 07:02
intro-to-test-driven-development
# here's a simple example of driving your design using tests.
# by running this code and solving the failing tests one by one
# you should be able to finish this challenge easily.
# ask for help if you get stuck.
# consider all the questions (Q:) as you encounter them
# in this universe ...
# - people own pets
# - pets eat and walk
@data-doge
data-doge / gist:af42df0b06274ae0d4ab
Created February 16, 2015 07:09
design-drill-classical-inheritance-challenge
module SuperPowers
attr_accessor :magic_points
def initialize
super
@magic_points = 0
end
def use_laser_vision
@magic_points += 1
@data-doge
data-doge / gist:3e56e1414c40f8b2ef1f
Created February 26, 2015 03:22
controller_test_ex
require 'spec_helper'
describe "account_controller" do
describe "GET /accounts" do
let(:first_account) { Account.create(dollars: 100, josh_coins: 100, user_id: "1234", email: "bob@bob.bo1b") }
let(:second_account) { Account.create(dollars: 200, josh_coins: 200, user_id: "3456", email: "bob@bob.b1ob") }
let(:third_account) { Account.create(dollars: 300, josh_coins: 300, user_id: "3156", email: "bob@bob1.bob") }
@data-doge
data-doge / gist:242086a39aab490c99ef
Created March 25, 2015 02:53
orange trees 1 ruby
# This is how you define your own custom exception classes
class NoOrangesError < StandardError
end
class OrangeTree
attr_reader :height, :age
MAX_AGE = 13
FRUIT_BEARING_AGE = 4
# Ages the tree one year