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 / javascript_avoiding_mutations_the_easy_way.md
Last active February 2, 2019 12:51
Javascript: Avoiding Mutations the Easy Way

JavaScript: Avoiding Mutations the Easy Way

Removing an Element from an Array

// Bad:
list.pop()

// Good:
list.filter(element => element !== 'hi')
@lujanfernaud
lujanfernaud / ruby_graphql_custom_scalar_hash.md
Created January 29, 2019 17:47
Ruby GraphQL: Custom Scalar Hash

Ruby GraphQL: Custom Scalar Hash

module CustomScalars
  class Hash < GraphQL::Schema::Scalar
    description 'Represents a regular hash.'
  end
end
@lujanfernaud
lujanfernaud / rails_capybara_open_page_with_assets.md
Created October 31, 2018 07:25
Rails and Capybara: Open Page With Assets

Rails and Capybara: Open Page With Assets

To automatically open pages saved when using save_and_open_page we need to add the launchy gem to the test environment.

# Gemfile

group :test do
  gem 'launchy', '~> 2.4', '>= 2.4.3'
end
@lujanfernaud
lujanfernaud / rails_code_organization_in_models.md
Last active October 30, 2018 20:50
Rails: Code Organization in Models

Rails: Code Organization in Models

Organize code in models using the following convention:

  1. Constants
  2. Associations
  3. Validations
  4. Callbacks
  5. Other macros (Devise, FriendlyId, etc.)
  6. Scopes
@lujanfernaud
lujanfernaud / rails_status_with_enum.md
Last active October 30, 2018 20:21
Rails: Status Using ActiveRecord::Enum

Rails: Status Using ActiveRecord::Enum

In Rails we can easily assign and switch the status of an object using ActiveRecord::Enum.

class Post < ActiveRecord::Base
  enum status: { active: 0, archived: 1 }
end

post.active!
@lujanfernaud
lujanfernaud / rails_guard_rails_best_practices.md
Created October 29, 2018 07:02
Rails: Adding guard-rails_best_practices

Rails: Adding guard-rails_best_practices

Add gem using source from GitHub to :development environment.

group :development do
  # ...
  gem 'guard'
  gem 'guard-rails_best_practices',
 github: 'logankoester/guard-rails_best_practices', require: false
@lujanfernaud
lujanfernaud / rails_create_file_download.md
Last active October 20, 2018 06:51
Rails: Create File Download

Rails: Create File Download

Download Generated Data

send_data

# Inside controller action.

send_data data, filename
@lujanfernaud
lujanfernaud / css_intrinsic_ratio.md
Last active September 27, 2018 05:35
CSS: Intrinsic Ratio

CSS: Intrinsic Ratio

Make the container of an image keep the size and aspect ratio of the image.

.intrinsic-ratio-container {
  position: relative;
  padding-bottom: 56.285714%; /* This defines the aspect ratio. */
  height: 0;
 color: #ddd; /* Same color as background-color to hide the image description text. */
@lujanfernaud
lujanfernaud / git_un-add_file_from_last_commit.md
Created August 21, 2018 08:46
Git: Un-add File From Last Commit