Skip to content

Instantly share code, notes, and snippets.

View thimo's full-sized avatar
❤️
🏎💨

Thimo Jansen thimo

❤️
🏎💨
View GitHub Profile
@thimo
thimo / gist:e96a6d2d70163563bace87a45291b157
Created March 31, 2025 11:37
cart_calculator_spec.rb
require_relative "cart_calculator"
RSpec.describe CartCalculator do
let(:products) do
[
{ name: "Book", price: 20 },
{ name: "Pen", price: 5 },
{ name: "Notebook", price: 15 }
]
end
class CartCalculator
def initialize(products)
@products = products
end
# Calculate the total price including:
# - Sum of all product prices
# - Apply bulk discount: 10% off when total exceeds $100
# - Apply free shipping when total exceeds $50 (shipping cost is $10)
# Return a hash containing subtotal, discount, shipping, and final total
date = Time.zone.parse("2023-11-23")
MemberSignup.completed
.where(created_at: date.beginning_of_day..date.end_of_day)
.where("pg_data ->> 'funnel' = ?", "default")
.order(created_at: :asc)
.map { |ms| [ms.created_at.to_s, ms.id, ms.pg_data["funnel"], ms.pg_data["signupConfirmationJson"]["client_id"]] }
.each { |ms| puts ms.to_s } && nil
class TennisGame1
POINTS_NAMES = {
0 => 'Love',
1 => 'Fifteen',
2 => 'Thirty',
3 => 'Forty'
}.freeze
DEUCE = 'Deuce'.freeze
ADVANTAGE = 'Advantage'.freeze
WIN_FOR = 'Win for'.freeze
def ask_question question
print "#{question} "
return gets.chomp
end
def ask_exercise_level
puts "What's your exercise level (1-5)? "
puts ' 1. little or no exercise'
puts ' 2. exercise/sports 1 - 3 times per week'
puts ' 3. exercise/sports 4 - 5 times per week'
# Initialize the pizzas into variables that can be read from anywhere
def initialize_pizzas
@pizza_salami = 4.0
@pizza_quattro_stagioni = 8.5
@pizza_ham_cheese = 6.25
@pizza_shoarma = 7.3
end
# Ask the customer's name and return it
def customer_name