Skip to content

Instantly share code, notes, and snippets.

Evan Prothro eprothro

Block or report user

Report or block eprothro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cassandra reconnection and retries.md
rails c
while true do
  r = nil
  duration = Benchmark.ms do
    r = Cassie.session.execute("select count(*) from system.hints")
  end
@eprothro
eprothro / sidekiq_local_processes_stats.rb
Created Nov 6, 2017
Prints stats about any locally running sidekiq workers
View sidekiq_local_processes_stats.rb
# Emit key statistics about locally running Sidekiq processes to a stream.
#
require 'sidekiq/api'
class SidekiqProcessesPrinter
attr_reader :format
def initialize(opts={})
@format = opts.fetch(:format){:plain}
end
@eprothro
eprothro / sidekiq_shared_queues_info.rb
Created Nov 6, 2017
Prints stats about all queues being processed by Sidekiq
View sidekiq_shared_queues_info.rb
# Emit key statistics about Sidekiq queues to a stream.
#
require 'sidekiq/api'
class SidekiqQueuesPrinter
attr_reader :format
def initialize(opts={})
@format = opts.fetch(:format){:plain}
end
@eprothro
eprothro / puma_workers_printer.rb
Created Nov 6, 2017
ruby script to print puma worker/fork thread utilization info
View puma_workers_printer.rb
require 'puma'
require 'puma/control_cli'
require 'json'
class PumaWorkersPrinter
attr_reader :format
def initialize(opts={})
@format = opts.fetch(:format){ :plain }
@password = opts.fetch(:password){ '' }
View kibana_json_input.json
{
"script": {
"inline": "doc['system.memory.used.bytes'].value / 1024 / 1024",
"lang": "painless"
}
}
@eprothro
eprothro / temporary_method_override.rb
Last active Oct 25, 2017
You can temporarily override (not overwrite) a ruby method for an object by defining a method on the object metaclass.
View temporary_method_override.rb
class Foo
def bar
:object_method
end
end
f = Foo.new
f.bar
# => :object_method
View Model Data Loading Patterns.md

Builder Pattern

Pros

  • Familar
  • Clean abstraction from model
  • No model changes required

Cons

  • Slow, 2N loading with cassandra-driver
View ruby temporary overrirde.md
class Foo
  
  def bar
    :object_method
  end
end

f = Foo.new
f.bar
View steel deflection.md
View s3_direct_uploading.rb
module S3DirectUploading
extend ActiveSupport::Concern
included do
S3_UPLOAD_BUCKET = Aws::S3::Resource.new.bucket(ENV['S3_UPLOAD_BUCKET'])
helper_method :build_s3_direct_post
end
protected
You can’t perform that action at this time.