Skip to content

Instantly share code, notes, and snippets.

View adamstrickland's full-sized avatar

Adam Strickland adamstrickland

  • New York, NY
View GitHub Profile
require_relative "./interactor"
ctx = SomeInteractor::Context.new(var_a: true)
res = SomeInteractor.new(ctx).call
assert res.success?
res = SomeInteractor.new(var_a: false).call
assert res.failure?
# frozen_string_literal: true
require "delivery_boy"
class EventPublisher
KAFKA_TOPIC_PREFIX = ENV.fetch("KAFKA_TOPIC_PREFIX")
THREAD_LOCAL_KEY = :event_publisher_transaction_queue
DEFAULT_EVENT_DELIVERER = "ThreadLocalBackedDeliverer".freeze
delegate :add_event, :transaction_opened!, :transaction_committed!, :transaction_rolled_back!, to: :deliverer
class UserSearchService
def initialize(search_term, limit = nil, offset = nil)
@search_term = if search_term.is_a?(String)
search_term.split(" ")
else
search_term.values.reject(&:blank?)
end
@limit = limit
@offset = offset
end
#!/bin/sh
brew bundle --file=- <<EOF
tap "homebrew/cask"
brew "mas"
mas "Xcode", id: 497799835
brew "ruby-install"
version: "3.7"
networks:
default:
driver: bridge
x-base: &base
networks:
- default
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
require "securerandom"
require "benchmark"
require "google_hash"
require "memory_profiler"
require "pry"
class Item
def initialize
@keep = ([0, 1].sample == 1)
@key = SecureRandom.uuid
@adamstrickland
adamstrickland / hash_transform.out
Last active March 7, 2019 20:09
benchmarking some hash transformation techniques
Rehearsal -------------------------------------------------------
{}.tap 0.000382 0.000257 0.000639 ( 0.000871)
[[]].to_h 0.000031 0.000001 0.000032 ( 0.000032)
{}.each_with_object 0.000027 0.000001 0.000028 ( 0.000028)
---------------------------------------------- total: 0.000699sec
user system total real
{}.tap 0.000030 0.000001 0.000031 ( 0.000029)
[[]].to_h 0.000033 0.000011 0.000044 ( 0.000033)
{}.each_with_object 0.000023 0.000012 0.000035 ( 0.000032)
@adamstrickland
adamstrickland / condbm.rb
Last active June 1, 2018 16:09
Benchmark for various ways of doing `if condition1 || condition2` (needs `benchmark-ips` installed)
require "benchmark"
require "benchmark/ips"
thing = :baz
puts "2 conditions, neither is true"
Benchmark.ips do |x|
x.report("conditional") do
if thing == :foo || thing == :bar
true
@adamstrickland
adamstrickland / festivity.txt
Created September 29, 2016 15:12
Festivity
_________________________________________
/ Festivity Level 1: Your guests are \
| chatting amiably with each other, |
| admiring your Christmas-tree ornaments, |
| singing carols around the upright |
| piano, sipping at their drinks and |
| nibbling hors d'oeuvres. |
| |
| Festivity Level 2: Your guests are |
| talking loudly -- sometimes to each |