Skip to content

Instantly share code, notes, and snippets.

View hayesr's full-sized avatar

Eric Hayes hayesr

View GitHub Profile
@hayesr
hayesr / audit-your-codebase.md
Created August 24, 2026 18:16 — forked from aarondfrancis/audit-your-codebase.md
A read-only, agent-orchestrated codebase audit prompt for data structures, state modeling, algorithms, and ownership.

Audit this entire codebase for materially useful simplifications in its data structures, state representation, control flow, algorithms, and ownership.

This is an audit-only exercise. Do not edit files, run tests, implement recommendations, commit, or push. Read-only inspection commands are allowed.

You are the coordinator. Continue until the complete codebase has been reviewed and the final audit is validated.

1. Establish the coverage contract

Inspect the repository and inventory every identifiable subsystem.

@hayesr
hayesr / component_presenter.rb
Created May 9, 2025 17:45
A simple component class for Rails
# Your component classes can inherit from this
class ComponentPresenter
# A 'macro' to define the partial path at the top of the class like:
# partial_path: 'components/popover'
# Or just define your own partial_path method
#
def self.partial_path(path)
define_method(:partial_path) do
path
end
tracks_with_date = [
["6GZeeRql1kto2a7koIve9i", "2018-11-13 05:02:50 UTC"],
["6pXJV9kSdjyAcDsM32ftLK", "2018-11-13 05:02:50 UTC"],
["5x9jMerOQr7oTF1GO4STRY", "2018-11-13 05:02:50 UTC"],
["2hLTFcVb0k2xpHXZblhu7Y", "2018-11-13 05:02:50 UTC"],
["77L5jfCpmpkDma5lXjG6oX", "2018-11-13 05:02:50 UTC"],
["6rux2bYOCSr2woxnQsoUE3", "2018-11-13 05:02:50 UTC"],
["0gjknY5vRTKbzMos2hhfN7", "2018-11-13 05:02:50 UTC"],
["0ZHn1GiKfyLgpvEks2wBcn", "2018-11-13 05:02:50 UTC"],
["25EmPX0QaVUOzi2sG3fZEp", "2018-11-13 05:02:50 UTC"],
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@hayesr
hayesr / finding-indexes.md
Created January 23, 2019 03:06
A tip for finding tables that need indexes

Finding which tables need extra indexes

pg_stat_user_tables is a fantastic system view that can show us invaluable information about the tables in our databases and can be used in diagnosing performance issues. Vacuum statistics like last_autovacuum and n_dead_tup will show if there are tables that aren’t being vacuumed efficiently and n_tup_hot_upd if you aren't performing HOT updates.

One of the things to look for first, though, is if there are tables that need new indexes as this can have a significant impact

@hayesr
hayesr / rails-jsonb-queries.rb
Last active December 13, 2018 15:12 — forked from mankind/rails-jsonb-queries
Rails-5 Postgres 9.6+ JSONB queries
# http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
# http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
# payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
# data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@hayesr
hayesr / image-to-color.md
Last active November 12, 2025 16:38
Extract colors from an image using ImageMagick
@hayesr
hayesr / find_actions_without_params.rb
Last active March 22, 2017 04:54
Find action lines in controller tests without params keyword (for Rails 5)
/(?:get|put|post|patch)\s+:\w+,\s+(?!params).+/
@hayesr
hayesr / application_helper.rb
Last active July 8, 2016 14:56
Simple Presenter System
module ApplicationHelper
def present(object, klass = nil)
klass ||= "#{object.class}Presenter".constantize
presenter = klass.new(object, self)
yield presenter if block_given?
presenter
end
end
function preresolve(dq)
if dq.qname:equal("www.google.com") then
dq:addAnswer(pdns.CNAME, "forcesafesearch.google.com.")
dq.rcode = 0
dq.followupFunction="followCNAMERecords" -- this makes PowerDNS lookup your CNAME
return true;
end
return false;
end