Skip to content

Instantly share code, notes, and snippets.

View zben's full-sized avatar

Ben zben

View GitHub Profile
describe ExampleController, type: :controller do
describe '#show' do
context 'third party API returns 404' do
before do
stub_request(:get, "www.example.com").
to_return(body: {error: "record not found"}.to_json, status: 404)
get :show
end
#optimal is the actual count we want to maximize. {optimal: 4}
#means we want to find as many sets of 4s as possible.
#without optimal set, we will optimize for the biggest values possible.
def groups(books, optimal: nil)
#convert list of books to list of counts of each book type
#sort by descending order for optimal grouping
#eg: [1,1,2,2,3,3,4,5] => [2,2,2,1,1]
counts = books.inject({}) do |res, item|
res[item] ||= 0
require 'test/unit'
extend Test::Unit::Assertions
class FibonacciAggregator
def self.sum_of_even_numbers(limit: 4_000_000)
sum, lower, higher = 0, 1, 2
while lower <= limit
sum += lower if lower % 2 == 0
lower, higher = higher, lower + higher
require 'test/unit'
extend Test::Unit::Assertions
class FibonacciAggregator
class << self
def sum_of_even_numbers(limit: 4_000_000, debug_mode: false)
sum_of_numbers(limit: limit, debug_mode: debug_mode) do |number|
number % 2 == 0
end
end
  • ActiveRecordError
  • AdapterNotFound
  • AdapterNotSpecified
  • AssociationNotFoundError
  • AssociationRelation
  • AssociationTypeMismatch
  • Associations::Builder::Association
  • Associations::Builder::BelongsTo
  • Associations::Builder::CollectionAssociation
  • Associations::Builder::HasMany
require 'rubygems'
require 'ruby-dictionary'
class BoggleGame
attr_accessor :tiles, :words, :dictionary, :input
def initialize(array_of_array)
@tiles = []
@words = []
@input = array_of_array
class Task
attr_accessor :name, :parent
def initialize(name)
@name = name
@parent = nil
end
def get_time_required
0.0
class CompositeTask < Task
def initialize(name)
super(name)
@sub_tasks = []
end
def add_sub_task(task) @sub_tasks << task task.parent = self
end
def remove_sub_task(task) @sub_tasks.delete(task) task.parent = nil
end
def get_time_required
@zben
zben / output
Created March 21, 2012 15:45
magento error
"ident_custom1": {
"email": "{{ssmtp_root}}"
},
"ident_custom2": {
"email": "{{ssmtp_root}}"
},
"ident_sales": {
"email": "{{ssmtp_root}}"
},
"ident_support": {
@zben
zben / run_sample.rb
Created March 15, 2012 21:43
needs critique.
people = People.new.add_dir('./data')
puts 'Output 1:'
people.sort(gender: :asc, last_name: :asc).print
puts
puts 'Output 2:'
people.sort(birthday: :asc).print
puts
puts 'Output 3:'
people.sort(last_name: :desc).print