Skip to content

Instantly share code, notes, and snippets.

View brenogazzola's full-sized avatar

Breno Gazzola brenogazzola

View GitHub Profile
@brenogazzola
brenogazzola / direct_upload.js
Created January 20, 2022 23:41
Active Storage Direct Upload Progress
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)
},
@brenogazzola
brenogazzola / fix_action_text.rb
Last active February 14, 2022 20:29
Fix ActionText Images
# 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?
@brenogazzola
brenogazzola / rbenv_uninstall_gems.sh
Created October 17, 2022 17:44 — forked from fijimunkii/rbenv_uninstall_gems.sh
rbenv: uninstall all gems
#!/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
}
// 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))
@brenogazzola
brenogazzola / direct_upload.js
Created February 6, 2023 20:30
Manual Multiple File Direct Upload
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
@brenogazzola
brenogazzola / propshaft.rb
Created October 30, 2023 21:00
Enhance Propshaft to compress files during precompilation
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")