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 / problem_solving_for_developers.md
Last active April 10, 2024 11:58
Problem Solving for Developers
@lujanfernaud
lujanfernaud / back_pain_stretches_with_stuart_mcgill.md
Last active March 23, 2024 19:50
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 / minitest_and_database_cleaner.md
Last active December 28, 2023 17:37
Minitest and Database Cleaner

Minitest and Database Cleaner

test_helper.rb

require 'database_cleaner'
require 'database_cleaner_support'

DatabaseCleaner.clean_with :truncation
DatabaseCleaner.strategy = :transaction
@lujanfernaud
lujanfernaud / removing_trailing_spaces.md
Last active December 13, 2022 09:34
Ruby and Nokogiri: Removing trailing spaces

Ruby and Nokogiri: Removing trailing spaces

sample_input = "<div>Hi&nbsp; &nbsp; &nbsp;</div>"
parsed_input = Nokogiri::HTML.parse(sample_input).text #=> "Hi   "

parsed_input.gsub(/\p{Space}*\z/, "") #=> "Hi"

\p{Space} catches any whitespace character.

@lujanfernaud
lujanfernaud / seeds-faker-carrierwave.rb
Created September 7, 2017 21:00
Rails: Seed database with remote Faker images and CarrierWave
# We need to use 'remote_<object>_url' as attribute instead of '<object>'.
# Having Image, we would use 'remote_image_url: <url>'.
titles = [Faker::RockBand.name, Faker::BossaNova.artist, Faker::Book.title]
54.times do |n|
start_date = Faker::Date.between(1.day.from_now, 6.months.from_now)
end_date = start_date + 1.day
Event.create!(title: titles.sample + " ##{n}",
@lujanfernaud
lujanfernaud / rails_dynamic_path_inside_partial.md
Last active April 5, 2022 11:54
Rails: Dynamic Path Inside Partial

Rails: Dynamic Path Inside Partial

We have a _user partial that we want to render from two different resources, passing a collection. The only thing that needs to change in the partial is the path inside the link_to helper.

We can use self.send("path", object) inside link_to to achieve this.

groups/_user.html.erb

@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