Skip to content

Instantly share code, notes, and snippets.

View brenogazzola's full-sized avatar

Breno Gazzola brenogazzola

View GitHub Profile
@brenogazzola
brenogazzola / types.db
Created January 12, 2021 18:12
File created by cloudwatch agent when running the wizard with collectd
absolute value:ABSOLUTE:0:U
apache_bytes value:DERIVE:0:U
apache_connections value:GAUGE:0:65535
apache_idle_workers value:GAUGE:0:65535
apache_requests value:DERIVE:0:U
apache_scoreboard value:GAUGE:0:65535
ath_nodes value:GAUGE:0:65535
ath_stat value:DERIVE:0:U
backends value:GAUGE:0:65535
bitrate value:GAUGE:0:4294967295
@brenogazzola
brenogazzola / fast_image.rb
Created February 12, 2021 00:25
Vips based image analyzer for Active Storage
# frozen_string_literal: true
module ActiveStorage
class Analyzer::FastImage < ActiveStorage::Analyzer
def self.accept?(blob)
blob.image?
end
def metadata
read_image do |image|
Sentry.init({
dsn: 'https://0d6cae56e34547f8b1dfc6cd534bca88@o313030.ingest.sentry.io/5692474',
whitelistUrls: [
/festalab\.com\.br\/packs\/js\/public.*js/,
/festalab\.com\.br\/packs\/js\/internal.*js/,
/festalab\.com\.br\/packs\/js\/legacy.*js/,
/festalab\.com\.br\/packs\/js\/fudgeballs.*js/
],
@brenogazzola
brenogazzola / rack-mini-profiler-trace-exceptions-dev
Created June 10, 2021 15:32
Track Exceptions of Rack Mini Profiler in DEV
Exceptions raised during request
Exceptions: (15 total)
IPAddr::InvalidAddressError (4)
Errno::ENOENT (9)
Errno::ECONNREFUSED (2)
Backtraces
#1: IPAddr::InvalidAddressError - "invalid address"
/Users/brenogazzola/.rbenv/versions/3.0.1/lib/ruby/3.0.0/ipaddr.rb:651:in `in6_addr'
@brenogazzola
brenogazzola / rack-mini-profiler-trace-exceptions-prod
Created June 10, 2021 15:34
Track Exceptions of Rack Mini Profiler in PROD
Exceptions raised during request
Exceptions: (9 total)
Errno::ENOENT (9)
Backtraces
#1: Errno::ENOENT - "No such file or directory @ rb_file_s_stat - /home/app/production/public/eventos.br"
/home/app/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/rails-ed3612e6d4f1/actionpack/lib/action_dispatch/middleware/static.rb:140:in `stat'
/home/app/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/rails-ed3612e6d4f1/actionpack/lib/action_dispatch/middleware/static.rb:140:in `file_readable?'
/home/app/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/rails-ed3612e6d4f1/actionpack/lib/action_dispatch/middleware/static.rb:119:in `block in try_precompressed_files'
@brenogazzola
brenogazzola / custom_active_storage_urls.rb
Last active October 17, 2022 15:34
Creating a custom ActiveStorage controller to generate "pretty urls" or help migration from another lib
# This demonstrates how we create a SEO friendly url for the previews of the artworks we sell.
#
# This is the URL we want:
# https://festalab.com.br/image/invitation/birthday/carnival.jpg
#
# First, the route.
#
# "model" is the name of the active storage model that has the preview.
# "classification" and "identifier" are together a unique key for the records.
@brenogazzola
brenogazzola / migrate_im_to_vips.md
Last active March 17, 2024 21:56
Steps to migrate ImageMagick to Libvips

For apps built before the image_processing gem became the default, the migration will involve two steps:

  1. Migrating to the image processing syntax while still using ImageMagick;
  2. Switching to Vips and updating the compression options;

Migrate to the image processing syntax

Before changing from ImageMagick to Vips, it's better to first test the new syntax and ensure everything is still working.

1. Move everything that has to do with compression to a saver hash:

variant(format: :jpg, strip: true, quality: 80)
@brenogazzola
brenogazzola / propshaft-bench-normalize.rb
Last active October 2, 2021 14:57
Benching fastest way to grab only the important part of the urls
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'); }
@brenogazzola
brenogazzola / util_controller.js
Created October 5, 2021 15:45
Stimulus Controller
import { Controller } from 'stimulus'
export default class extends Controller {
// ============================================================================
// Public
// ============================================================================
/*
* Removes an element from the DOM
*/
@brenogazzola
brenogazzola / middleware.rb
Last active November 11, 2021 03:51
Datadog
# frozen_string_literal: true
require "datadog/statsd"
class QueueTime
def initialize(app)
@app = app
end
def call(env)