Skip to content

Instantly share code, notes, and snippets.

View callmesangio's full-sized avatar
🏠
Working from home

Fabio Sangiovanni callmesangio

🏠
Working from home
  • independent software consultant
  • 06:25 (UTC +02:00)
  • Bluesky @sang.io
View GitHub Profile
@callmesangio
callmesangio / rate_limitable.rb
Created December 9, 2025 10:17
RateLimitable
# frozen_string_literal: true
# E.g.:
# limit :create, to: 10, within: 3.minutes, go: -> { new_session_url }
module RateLimitable
extend ActiveSupport::Concern
included do
add_flash_types :rate_limited
@callmesangio
callmesangio / email.rb
Last active August 27, 2025 09:57
Phlex/ActionMailer integration
module Views::Mailers::Users::Welcome
include Mailable
def initialize(user:)
@user = user
end
class Html < Phlex::HTML
def view_template
p { "Welcome, #{@user.name}!" }
@callmesangio
callmesangio / bootstraprails.sh
Created June 24, 2025 10:27
Helper script to bootstrap a new Rails project with `default_install_uses_path` Bundler option turned on.
#!/bin/bash
set -e
bundle init
bundle add rails --quiet
echo 'Done.'
railsnew='bundle exec rails new . --database=postgresql -f'
gum confirm "Proceed with \`$railsnew\`?" \
--default=false \
--show-output \
Sure, here are some ideas that will hopefully expand on my post:
1. validation: in Django, the responsibility of validating model data
is shared between forms and models. Plus, validation logic is not
triggered by default on `Model.save()`, you need to explicitly invoke
`Model.full_clean()` before saving, otherwise you may incur in errors
from the database itself. I think this is not a good pattern to go with.
This works great as long as the only source of incoming data is forms,
but in modern web apps data can come in from a very broad variety of
sources, which makes this approach unpractical.