This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Rails + PostgreSQL Performance Audit Playbook | |
| A field-tested method for finding what's actually burning your database CPU, built for a | |
| Rails monolith on managed PostgreSQL (Cloud SQL / RDS / etc.). It assumes no APM — just | |
| `pg_stat_statements`, `pg_stat_activity`, and discipline. It pairs well with an LLM: point | |
| one at this file plus your query results and let it do the attribution; the queries below | |
| are ordered so a human can run them and paste results back. | |
| ## The core idea |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "rake" | |
| Rake::Task["assets:precompile"].enhance do | |
| assembly = Rails.application.assets | |
| output_path = assembly.config.output_path | |
| assembly.load_path.assets.each do |asset| | |
| asset_path = output_path.join(asset.digested_path) | |
| compressed_path = output_path.join(asset.digested_path.to_s + ".br") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { DirectUpload } from '../rails/activestorage' | |
| export default class { | |
| constructor (input) { | |
| this.input = input | |
| this.submit = input.form.querySelector('.btn-submit') // The submit button. We show loading progress here | |
| this.progress = this.submit.querySelector('.btn-submit-progress') // The progress bar inside the submit | |
| this.loader = this.submit.querySelector('.btn-submit-loader') // The loader animation inside the submit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Remove all drafts from your drafts view | |
| // Navigate to drafts | |
| // F12 to raise dev console | |
| // Paste the below | |
| (async function(x) { | |
| for (const e of [...document.querySelectorAll('[type="trash"]')]) { | |
| e.click(); | |
| await new Promise(resolve => setTimeout(resolve, 500)) | |
| document.querySelector('[data-qa="drafts_page_draft_delete_confirm"]').click(); | |
| await new Promise(resolve => setTimeout(resolve, 1500)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| uninstall() { | |
| list=`gem list --no-versions` | |
| for gem in $list; do | |
| gem uninstall $gem -aIx | |
| done | |
| gem list | |
| gem install bundler | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # After active storage urls are changed, use this to recreate all trix attachments | |
| def self.refresh_trixes | |
| ActionText::RichText.where.not(body: nil).find_each do |trix| | |
| Trix::RefreshJob.perform_later(trix) | |
| end | |
| end | |
| # After active storage urls are changed, use this to recreate a specific strix attachments | |
| def self.refresh_trix(trix) | |
| return unless trix.embeds.size.positive? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Rails from '@rails/ujs' | |
| const DirectUpload = { | |
| start () { | |
| document.addEventListener('direct-upload:initialize', DirectUpload.initialize) | |
| document.addEventListener('direct-upload:start', DirectUpload.begin) | |
| document.addEventListener('direct-upload:progress', DirectUpload.progress) | |
| document.addEventListener('direct-upload-error', DirectUpload.error) | |
| document.addEventListener('direct-upload:end', DirectUpload.end) | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # frozen_string_literal: true | |
| require "datadog/statsd" | |
| class QueueTime | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Controller } from 'stimulus' | |
| export default class extends Controller { | |
| // ============================================================================ | |
| // Public | |
| // ============================================================================ | |
| /* | |
| * Removes an element from the DOM | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark/ips' | |
| content = %( | |
| .prop 1 { background: url(file.jpg); } | |
| .prop 2 { background: url( file.jpg ); } | |
| .prop 3 { background: url("file.jpg"); } | |
| .prop 4 { background: url('file.jpg'); } | |
| .prop 5 { background: url('/file.jpg'); } | |
| .prop 6 { background: url('./file.jpg'); } | |
| .prop 7 { background: url('./images/file.jpg'); } |
NewerOlder