Skip to content

Instantly share code, notes, and snippets.

View lazaronixon's full-sized avatar

Lázaro Nixon lazaronixon

View GitHub Profile
@lazaronixon
lazaronixon / medical_record.rb
Last active June 22, 2024 17:01
Api upload
class MedicalRecord < ApplicationRecord
enum kind: %i[ imaging results notes ]
belongs_to :patient, class_name: "User", inverse_of: :medical_records
has_one_attached :document, dependent: :detach
scope :with_kind, -> (kind) { where kind: kind }
after_create_commit :deliver_updation
<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>
@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)
@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 / 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 / _form.html.erb
Last active September 22, 2025 15:08
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 / 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 / linux.json
Last active December 11, 2025 04:58
Zed Editor
{
"ui_font_family": "JetBrainsMono Nerd Font",
"agent": { "always_allow_tool_actions": true, "default_view": "text_thread" },
"features": { "edit_prediction_provider": "none" },
"theme": "One Light",
"buffer_font_family": "JetBrainsMono Nerd Font",
"buffer_font_size": 14,
"ui_font_size": 14,
"agent_ui_font_size": 14,
"show_whitespaces": "none",
@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 / 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