class MyModel < ActiveRecord::Base
has_many :things
end
model = MyModel.new
model.things.build do
#stuff...
end
class Cart < ActiveRecord::Base
has_many :line_items
def total
line_items.sum(&:price)
end
end
class LineItem < ActiveRecord::Base
This file contains 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
describe CommentsController do | |
describe '#create' do | |
context 'with valid form' do | |
let(:expect_commenting) { expect{ post :create, comment: { user_id: 1, body: "This is a comment" } } } | |
subject { | |
post :create, comment: { user_id: 1, body: "This is a comment" } | |
@controller | |
} |
This file contains 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
--format nested | |
--order rand | |
--colour | |
# If using spork: --drb |
This file contains 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 Test < SimpleDelegator | |
def initialize | |
end | |
end | |
#=> nil | |
t = Test.new | |
#=> nil | |
t[:thing] = 'help' |
This file contains 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 | |
#encoding: UTF-8 | |
################################################################################ | |
################################################################################ | |
################################################################################ | |
# Overly simplistic implementation of how a RSpec test works # | |
################################################################################ |
This file contains 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 | |
require 'benchmark' | |
require 'digest' | |
n = 5_000_000 | |
xruns = 10 | |
puts <<-EOS | |
Hash Benchmarks | |
=============== |
This file contains 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
#define MAX_STEPS 100000 | |
#define NO_SOLUTION -1 | |
int arrayJump(int *A, int size) { | |
int *p = A, steps = 0; | |
while (++steps < MAX_STEPS && A <= (p+=*p) && p < A+size); | |
return steps >= MAX_STEPS ? NO_SOLUTION : steps; | |
} |
This file contains 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
Compile with `gcc -Wall -lssl -lcrypto shait.c` |
This file contains 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
char *sha256_hexdigest(const void *buf_to_hash, size_t buf_len, char *hexdigest) | |
{ | |
uint8_t binary_hash[SHA256_DIGEST_LENGTH]; | |
uint8_t *digest; | |
SHA256_CTX context; | |
int i; | |
SHA256_Init(&context); | |
SHA256_Update(&context, buf_to_hash, buf_len); | |
SHA256_Final(binary_hash, &context); |