Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Strickland adamstrickland

  • Bonobos
  • New York, NY
View GitHub Profile
View event_publisher.rb
# 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
View user_search_service.rb
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
View laptop.local
#!/bin/sh
brew bundle --file=- <<EOF
tap "homebrew/cask"
brew "mas"
mas "Xcode", id: 497799835
brew "ruby-install"
View sample-docker-compose.yml
version: "3.7"
networks:
default:
driver: bridge
x-base: &base
networks:
- default
View database_cleaner_config.rb
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
View iter_test.rb
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 Mar 7, 2019
benchmarking some hash transformation techniques
View hash_transform.out
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 Jun 1, 2018
Benchmark for various ways of doing `if condition1 || condition2` (needs `benchmark-ips` installed)
View condbm.rb
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
View festivity.txt
_________________________________________
/ 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 |
View money.rb
module Mongoid
class << self
def Money(value)
Money.create_from_value(value)
end
end
class Money
class << self
def create_from_value(value)