Skip to content

Instantly share code, notes, and snippets.

View denisdefreyne's full-sized avatar

Denis Defreyne denisdefreyne

View GitHub Profile
"orange" == "red" # => false
1 + 3 == 4 # => true
12 - 1 != 10 # => true
17 == 17 # => true
false != 12 # => true
1.2 == 3.4 # => false
class Point
attr_reader :x
attr_reader :y
def initialize(x, y)
@x = x
@y = y
end
end
class Employee
attr_reader :id
attr_reader :name
def initialize(id, name)
@id = id
@name = name
end
end
# Find the book “Gödel, Escher, Bach”
repo = BookRepository.new
geb = repo.find(isbn: "978-0-14-028920-6")
geb_also = repo.find(isbn: "978-0-14-028920-6")
geb == geb_also # => false?!
AMOUNT = 100_000_000
num_tuesday_boy = 0
num_tuesday_boy_and_two_boys = 0
AMOUNT.times do
weekday1 = [:mon, :tue, :wed, :thu, :fri, :sat, :sun].sample
weekday2 = [:mon, :tue, :wed, :thu, :fri, :sat, :sun].sample
gender1 = [:boy, :girl].sample
gender2 = [:boy, :girl].sample
@denisdefreyne
denisdefreyne / Gemfile
Last active February 14, 2022 07:25
Ruby #hash implementation experiment
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'rubocop', '~> 1.25'
gem 'benchmark-ips', '~> 2.9'
gem 'descriptive_statistics', '~> 2.5'
Person = new Class {{
firstName: :attr,
lastName: :attr,
fullName: function {
`${this.firstName} ${this.lastName}`
},
const input1 = [[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]];
// This should totes be part of JavaScript by default.
const maxBy = (arr, fn) => {
if (arr.length === 0) {
throw new Error("no!! just no");
}
if (arr.length === 1) {
return arr[0];
################################################################################
# Helper functions and constants
YES = [[]]
NO = []
IF =
lambda do |val, if_yes, if_no|
val.each { return if_yes.call }
if_no.call