Skip to content

Instantly share code, notes, and snippets.

View virolea's full-sized avatar

Vincent Rolea virolea

View GitHub Profile
@virolea
virolea / url_validator.rb
Last active February 16, 2023 17:01
Rails Custom URL validator
# Use this validator like this
#
# class User < ApplicationRecord
# validates :profile_link, url: true
# end
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless valid_url?(value)
record.errors.add(attribute, :invalid_url)
@virolea
virolea / client_middleware.rb
Created April 25, 2023 19:29
Code for the "A simple and pragmatic approach to fixing a memory leak" talk at RailsConf 2023
# This middleware dynamically switch a job queue based on its class name.
module TroubleshootMemoryMiddleware
module Client
class CustomQueueName
QUARANTINE_QUEUE = "quarantine"
def call(worker_class, job, queue, redis_pool)
# Jobs enqueued without ActiveJob are not wrapped.
job_class_name = if job["wrapped"].present?
@virolea
virolea / deploy.yml
Created December 27, 2023 17:43
Example kamal deploy.yml file for a standard Rails setup on Digital Ocean
# Name of your application. Used to uniquely configure containers.
service: your-app-name
# Name of the container image.
image: your-org/your-app-name
# Deploy to these servers.
servers:
web:
- REPLACE_WITH_YOUR_WEB_DROPLET_IP