Skip to content

Instantly share code, notes, and snippets.

View kklimuk's full-sized avatar

Kirill Klimuk kklimuk

View GitHub Profile
def users_with_discounts
@users_with_discounts ||= {}
if @users_with_discounts.has_key?(:return_value)
@users_with_discounts[:return_value]
else
@users_with_discounts[:return_value] = computation_that_returns_nil
end
end
# a proc, which I will insist on calling a function
notifier = proc { |id, message| SlackClient.new.notify(id, message.strip) }
notifier.call('@kirill', 'hello, world ')
module Notifier
 def self.notify(id, message)
  SlackClient.new.notify(id, prettify(message))
 end
def self.prettify(message)
 HTMLCleaner.clean(message.strip)
 end
end
class Notifier
attr_reader :notifier
def initialize(notifier)
raise ArgumentError, 'Expected the notifier to respond to `notify`' unless notifier.respond_to?(:notify)
@notifier = notifier
end
def notify(id, message)
notifier.notify(id, prettify(message))
class Notifier
attr_reader :notifier
def initialize(notifier)
raise ArgumentError, 'Expected the notifier to respond to `notify`' unless notifier.respond_to?(:notify)
@notifier = notifier
end
def notify(id, message)
notifier.notify(id, prettify(message))
class Foo
def call
'hi'
end
end
foo = proc { 'hi' }
Foo.new.call # 'hi'
foo.call # 'hi'
@kklimuk
kklimuk / 2023.11.12-cassidoo.ts
Last active November 13, 2023 19:09
2023.11.12 - Cassidoo's Interview Question of the Week
// Given a list of tasks, where each task has a duration, and a limited amount of available time to work,
// write a function to return the tasks that can be completed within the given time, without re-ordering
// the original list of tasks.
type Task = { name: string; duration: number };
const tasks = [
{ name: "Task 1", duration: 4 },
{ name: "Task 2", duration: 2 },
{ name: "Task 3", duration: 7 },
{ name: "Task 4", duration: 5 },