Skip to content

Instantly share code, notes, and snippets.

@dandrust
dandrust / gist.rb
Created January 29, 2024 01:14
Database server for pairing interview
require 'socket'
require 'singleton'
require 'stringio'
# A small persistence library that, at the moment, only
# implements an in-memory persistence strategy for getting
# and setting key-value pairs
module Persistence
module_function
@dandrust
dandrust / product_response.rb
Created December 13, 2023 20:42
product serialization
# Fit this into a translation layer...class?
# Should be able to return only a segment of the plan design
# If time and energy allows benchmark it, see if there are any obvious hotspots
module ProductResponse
module Serialized
Benefit = Struct.new(:plan_design_attribute_id, :tier_group_id, :vals, keyword_init: true) do
class << self
def build_from_plan_design_value(pdv)
new(vals: [], **pdv.attributes.symbolize_keys.slice(:plan_design_attribute_id, :tier_group_id))
require 'json'
staging_vars_hash = JSON.parse(`heroku config --app=feature-staging-app --json`)
vars_to_copy_hash = staging_vars_hash.reject { |k,_| k.match(/\AHEROKU/) }
vars_string = vars_to_copy_hash.to_a.map { |k_v_array| k, v = *k_v_array; "#{k}='#{v}'" }.join(" ")
`heroku config:set --app=feature-staging #{vars_string}`
desc "Resets feature-staging-app to mock production state"
task :reset do
system("heroku maintenance:on --app=feature-staging-app")
system("heroku run rails db:rollback STEP=2 --app=feature-staging-app")
system("git push feature-staging-app master")
system("heroku maintenance:off --app=feature-staging-app")
end
desc "Performs a dry run with elapsed time logging"
task :dry_run do
@time_summary = []
with_timestamps("capturing backup of database", @time_summary) do
system("heroku pg:backups:capture --app=feature-staging-app")
end
with_timestamps("entering maintenance mode", @time_summary) do
system("heroku maintenance:on --app=feature-staging-app")
heroku pg:backups:capture --app=production-app
heroku pg:backups --app=production-app
=== Backups
ID Created at Status Size Database
──── ───────────────────────── ─────────────────────────────────── ──────── ────────
b001 2018-08-01 14:21:51 +0000 Completed 2018-08-01 14:22:09 +0000 1.62GB BLUE
heroku pg:backups:restore production-app::b001 --app=feature-staging-app
require 'json'
staging_vars_hash = JSON.parse(`heroku config --app=feature-staging-app --json`)
vars_to_copy_hash = staging_vars_hash.reject { |k,_| k.match(/\AHEROKU/) }
vars_string = vars_to_copy_hash.to_a.map { |k_v_array| k, v = *k_v_array; "#{k}='#{v}'" }.join(" ")
`heroku config:set --app=feature-staging #{vars_string}`
@dandrust
dandrust / missing_routes.rb
Created April 25, 2018 03:13
identify routes defined by hashes that are not declared in routes.rb
desc 'identify routes defined by hashes that are not declared in routes.rb'
task :missing_routes => :environment do
file_paths = FileList[
"#{Rails.root}/app/helpers/**/*.rb",
"#{Rails.root}/app/views/**/*.html.erb"
]
file_paths.each do |file_path|