Skip to content

Instantly share code, notes, and snippets.

View lujanfernaud's full-sized avatar
🦪
Working from home

Luján Fernaud lujanfernaud

🦪
Working from home
View GitHub Profile
@lujanfernaud
lujanfernaud / html_spellcheck_feature.md
Last active October 12, 2021 08:03
HTML: Spellcheck Feature
@lujanfernaud
lujanfernaud / ruby_immutable_value_object_with_struct.md
Last active July 16, 2021 07:27
Ruby: Immutable Value Object with Struct

Ruby: Immutable Value Object with Struct

Freezing the initializer after passing the args to super makes the object immutable.

# frozen_string_literal: true

# Freezing the initializer after passing the args to `super` makes the object immutable.
#
# Example:
@lujanfernaud
lujanfernaud / heroku_reduce_slug_size_with_slugignore.md
Created May 12, 2021 12:21
Heroku: Reduce Slug Size With .slugignore

Heroku: Reduce Slug Size With .slugignore

Adding a .slugignore file to the root folder of the project will make Heroku to remove the files and folders referenced after we push code to Heroku and the buildpack runs.

What is the Slug?

A compressed copy of the application comprising all files in the git repo along with packages installed during deployment.

Sources

@lujanfernaud
lujanfernaud / rails_permitting_arrays_in_strong_parameters.md
Created May 5, 2021 07:01
Rails: Permitting Arrays in Strong Parameters

Rails: Permitting Arrays in Strong Parameters

We can do so by adding an array value to the param:

params.permit(:email, :name, sites: [])

We can even use nested arrays:

@lujanfernaud
lujanfernaud / ruby_require_all_files_within_a_directory.md
Created March 19, 2021 14:59
Ruby: Require All Files Within a Directory

Ruby: Require All Files Within a Directory

Dir[File.expand_path('../config/routes/*.rb', __dir__)].each do |file|
  require_relative file
end
@lujanfernaud
lujanfernaud / ruby_validate_email.md
Created February 23, 2021 17:44
Ruby: Validate Email

Ruby: Validate Email

We can match against URI::MailTo::EMAIL_REGEXP.

  def valid_email?(email)
    email && email.match?(URI::MailTo::EMAIL_REGEXP)
  end
@lujanfernaud
lujanfernaud / ruby_validate_url.md
Last active February 23, 2021 18:53
Ruby: Validate URL

Ruby: Validate URL

We can match against %r{^(http|https)://[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,6}(:[0-9]{1,5})?(/.*)?$}ix.

Non Rails version:

  VALID_URL_REGEXP = %r{^(http|https)://[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,6}(:[0-9]{1,5})?(/.*)?$}ix.freeze

 def valid_url?(url)
@lujanfernaud
lujanfernaud / back_pain_stretches_with_stuart_mcgill.md
Last active April 30, 2024 21:26
Back Pain: Stretches with Stuart McGill

Back Pain: Stretches with Stuart McGill

The Cat Camel

Get on all fours and slowly move back and forth from a downward spinal curve with the head looking up like a cat and then move into a rounded spine while the head looks down like a camel. Each cycle should take about three to four seconds. 7-8 cycles are all that is needed.

Gist: Only do 7-8 cycles. More than that could be bad.

Video: https://www.youtube.com/watch?t=96&v=bcbuhePZZj0

@lujanfernaud
lujanfernaud / log_interactor_execution.rb
Last active August 7, 2020 12:37
Debugging: LogInteractorExecution
# Usage:
#
# class SomeInteractor
# include Interactor
# include LogInteractorExecution
#
# # ...
#
# private
#