Skip to content

Instantly share code, notes, and snippets.

View nicolas-brousse's full-sized avatar
🚲

Nicolas Brousse nicolas-brousse

🚲
View GitHub Profile
@nicolas-brousse
nicolas-brousse / _alert.html.slim
Created March 29, 2018 12:42
Komponent gem usage example
= content_tag(:div, html_attributes) do
= yield_or_property(:message)

Usage

$ ruby fake_smtp_server
require "net/smtp"
class Mailcatcher < Formula
desc "Catches mail and serves it through a dream."
homepage "https://github.com/sj26/mailcatcher"
url "https://github.com/sj26/mailcatcher/archive/v0.6.5.zip"
sha256 "393303738ec6c7e0254b22b3f6b8f7988363791890516f820e90372afef4d65c"
version "0.6.5"
def install
ENV["GEM_HOME"] = libexec
system "gem", "build", "mailcatcher.gemspec"
@nicolas-brousse
nicolas-brousse / file_size_validator.rb
Created September 12, 2018 11:11
Rails ActiveStorage FileSizeValidator
# frozen_string_literal: true
module ActiveStorage
module Validations
class FileSizeValidator < ActiveModel::EachValidator
include ActiveSupport::NumberHelper
MESSAGES = { minimum: :file_size_too_short, maximum: :file_size_too_long }.freeze
CHECKS = { minimum: :>=, maximum: :<= }.freeze
@nicolas-brousse
nicolas-brousse / list_dependencies.rb
Last active October 25, 2018 18:38
Get dependencies list of a Ruby project by reading its Gemfile and Gemfile.lock
#!/usr/bin/env ruby
# frozen_string_literal: true
# USAGE:
# $ ./list_dependencies.rb
# $ ./list_dependencies.rb /path/to/project
#
# @see: https://stackoverflow.com/questions/44681231/how-to-list-ruby-production-only-dependencies-using-gemfile-lock-and-lockfilepar
@nicolas-brousse
nicolas-brousse / 01_README.md
Last active February 15, 2019 13:12
[WIP] A simple decorator for Rails

Usage

🚀 I create the dekorator gem if this interrest you.

Get started

Copy ApplicationDecorator inside app/decorators/application_decorator.rb and DecoratorsHelper inside decorators_helper.rb.

Then you could create and use your own decorators by create new class that extend from ApplicationDecorator.

@nicolas-brousse
nicolas-brousse / 01_README.md
Last active January 13, 2023 23:04
Rails health check

HealthCheck

Install

Add the following line to your Gemfile

gem "server_health_check-rails"

Description

My issue was about ordering and pagination. I was ordering a query on a column (of_the_moment_weight) that could have multi times the same value. Tehcnically, all entries could have the same value.

The result is that some entry appear on multiple page. But it shouldn't be the case.

Solution

Use two columns for ordering.

// Loads stimulus controllers from ../components/ folder
//
// Normal output:
// button/button_controller.js => data-controller="button--button"
// form/text_field/text_field_controller.js => data-controller="form--text-field--text-field"
//
// Expected output:
// button/button_controller.js => data-controller="button"
// form/text_field/text_field_controller.js => data-controller="form--text-field"
@nicolas-brousse
nicolas-brousse / form--base_component.rb
Created December 2, 2020 15:05
[WIP] Share of a ViewComponent::FormBuilder
# frozen_string_literal: true
module Form
class BaseComponent < ApplicationComponent
class << self
attr_accessor :default_options
end
include Components::Validations