Skip to content

Instantly share code, notes, and snippets.

😊

Luján Fernaud lujanfernaud

😊
Block or report user

Report or block lujanfernaud

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View css_intrinsic_ratio.md

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 / rails_create_file_download.md
Last active Oct 20, 2018
Rails: Create File Download
View rails_create_file_download.md

Rails: Create File Download

Download Generated Data

send_data

# Inside controller action.

send_data data, filename
@lujanfernaud
lujanfernaud / rails_guard_rails_best_practices.md
Created Oct 29, 2018
Rails: Adding guard-rails_best_practices
View rails_guard_rails_best_practices.md

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_status_with_enum.md
Last active Oct 30, 2018
Rails: Status Using ActiveRecord::Enum
View rails_status_with_enum.md

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_code_organization_in_models.md
Last active Oct 30, 2018
Rails: Code Organization in Models
View rails_code_organization_in_models.md

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_capybara_open_page_with_assets.md
Created Oct 31, 2018
Rails and Capybara: Open Page With Assets
View rails_capybara_open_page_with_assets.md

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
View ruby_graphql_custom_scalar_hash.md

Ruby GraphQL: Custom Scalar Hash

module CustomScalars
  class Hash < GraphQL::Schema::Scalar
    description 'Represents a regular hash.'
  end
end
@lujanfernaud
lujanfernaud / javascript_avoiding_mutations_the_easy_way.md
Last active Feb 2, 2019
Javascript: Avoiding Mutations the Easy Way
View javascript_avoiding_mutations_the_easy_way.md

JavaScript: Avoiding Mutations the Easy Way

Removing an Element from an Array

// Bad:
list.pop()

// Good:
list.filter(element => element !== 'hi')
@lujanfernaud
lujanfernaud / problem_solving_for_developers.md
Last active Feb 22, 2019
Problem Solving for Developers
View problem_solving_for_developers.md
You can’t perform that action at this time.