Skip to content

Instantly share code, notes, and snippets.

View lazaronixon's full-sized avatar

Lázaro Nixon lazaronixon

View GitHub Profile
@lazaronixon
lazaronixon / translations_helper.rb
Created May 22, 2025 17:30
translations_helper
module TranslationsHelper
TRANSLATIONS = {
email_address: { "🇺🇸": "Enter your email address", "🇪🇸": "Introduce tu correo electrónico", "🇫🇷": "Entrez votre adresse courriel", "🇮🇳": "अपना ईमेल पता दर्ज करें", "🇩🇪": "Geben Sie Ihre E-Mail-Adresse ein" },
password: { "🇺🇸": "Enter your password", "🇪🇸": "Introduce tu contraseña", "🇫🇷": "Saisissez votre mot de passe", "🇮🇳": "अपना पासवर्ड दर्ज करें", "🇩🇪": "Geben Sie Ihr Passwort ein" },
update_password: { "🇺🇸": "Change password", "🇪🇸": "Cambiar contraseña", "🇫🇷": "Changer le mot de passe", "🇮🇳": "पासवर्ड बदलें", "🇩🇪": "Passwort ändern" },
user_name: { "🇺🇸": "Enter your name", "🇪🇸": "Introduce tu nombre", "🇫🇷": "Entrez votre nom", "🇮🇳": "अपना नाम दर्ज करें", "🇩🇪": "Geben Sie Ihren Namen ein" },
account_name: { "🇺🇸": "Name this account", "🇪🇸": "Nombre de esta cuenta", "🇫🇷": "Nommez ce compte", "🇮🇳": "इस खाते का नाम दें", "🇩🇪": "Benennen Sie dieses Konto" },
room_name: { "🇺🇸": "Name the room", "🇪🇸": "Nombrar la sala", "🇫🇷": "Nommez la salle",
@lazaronixon
lazaronixon / example.rb
Created May 3, 2025 00:53
Active job report
# Job
discard_on CustomAppException, report: true
# In config/initializers/error_reporting.rb
class ErrorSubscriber
def report(error, handled:, severity:, context:)
if context[:source] == "application.active_job"
Sentry.capture_exception(error, extra: context)
end
end
@lazaronixon
lazaronixon / latest_by.rb
Last active April 24, 2025 19:16
has_one_latest_by
class Member
has_one :latest_activity, -> { from(Activity.latest_by_member, :activities) }, class_name: "Activity"
end
class Activity
scope :latest_by_member, -> { select("DISTINCT ON (member_id) *").order(:member_id, created_at: :desc) }
end
@lazaronixon
lazaronixon / linux.json
Last active May 11, 2025 01:24
Zed Editor
{
"theme": "One Light",
"buffer_font_family": "DejaVu Sans Mono",
"buffer_font_size": 16,
"show_whitespaces": "none",
"gutter": { "code_actions": false, "runnables": false, "breakpoints": false },
"indent_guides": { "enabled": false },
"toolbar": { "breadcrumbs": false, "quick_actions": false },
"git_panel": { "dock": "right" },
"scroll_beyond_last_line": "off",
@lazaronixon
lazaronixon / positionable.rb
Created April 22, 2025 13:36
positionable.rb
module Element::Positionable
extend ActiveSupport::Concern
included do
before_create :set_position
before_update :reposition_before_update
validates_numericality_of :position, greater_than_or_equal_to: 1, on: :update
end
@lazaronixon
lazaronixon / _form.html.erb
Last active May 29, 2025 23:40
Hotwire Event-Driven Update Pattern
<%= form_with model: citizen, class: "card flex flex-col gap", data: { controller: "form" } do |form| %>
<div class="flex flex-col gap mb-2">
<div class="flex flex-col gap-half">
<% countries = Country.order(:name) %>
<%= label_tag :country_id, "Country", class: "text-sm font-medium leading-none" %>
<%= select_tag :country_id, options_from_collection_for_select(countries, :id, :name, citizen.country_id), include_blank: "Select one", class: "input", data: { action: "form#submit", form_submitter_param: "on_country_change" } %>
</div>
<div class="flex flex-col gap-half">
<% states = State.where(country_id: citizen.country_id).order(:name) %>
@lazaronixon
lazaronixon / tagbuilder.rb
Created September 9, 2024 08:09
TagBuilder
class TagBuilder
def initialize(context, tag_name, content = nil, klass: nil, default_attributes: {}, **attributes, &block)
@context = context
@tag_name = tag_name
@content = content
@klass = klass
@default_attributes = default_attributes
@attributes = attributes
@block = block
end
@lazaronixon
lazaronixon / tabs.css
Last active August 30, 2024 07:02
Tab bar rails
.tabs {
display: flex;
flex-direction: column;
gap: var(--size-2);
}
.tabs__list {
background-color: var(--color-border-light);
block-size: var(--size-10);
border-radius: var(--rounded-md);
@lazaronixon
lazaronixon / application_helper.rb
Last active August 14, 2024 11:33
Current page helpers
module ApplicationHelper
def current_page_with_controllers?(controllers)
controllers.any? { |controller| current_page? controller: controller }
end
def current_page_with_actions?(actions)
actions.any? { |action| current_page? action: action }
end
def current_page_with_controllers_and_actions?(controllers, actions)
<div data-controller="popover">
<button class="btn" popovertarget="popover" data-popover-target="button">
Open popover
</button>
<div popover id="popover" class="popover" data-popover-target="menu" data-action="beforetoggle->popover#update">
<%= render "dimensions_form" %>
</div>
</div>