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
@lujanfernaud
lujanfernaud / rake_tasks_helper.rb
Last active Mar 27, 2020
RSpec: Rake Tasks Helper
View rake_tasks_helper.rb
# Example usage =============
#
# describe :namespace do
# include RakeTasksHelper
#
# describe ':task' do
# it 'works' do
# invoke_task('namespace:task')
# end
# end
@lujanfernaud
lujanfernaud / rubocop_autocorrect_specific_cops.md
Last active Feb 27, 2020
RuboCop: Autocorrect Using Specific Cops
View rubocop_autocorrect_specific_cops.md

RuboCop: Autocorrect Using Specific Cops

We can autocorrect using only some cops by passing --only CopType/CopName.

rubocop --only Style/HashTransformKeys

First run with --safe-auto-correct to see the affected changes:

View rails_url_helpers.md

Rails: URL Helpers

Access path helpers from outside controllers.

Rails.application.routes.url_helpers
Rails.application.routes.url_helpers.dashboard_path
Rails.application.routes.url_helpers.users_path
Rails.application.routes.url_helpers.pages_path
@lujanfernaud
lujanfernaud / rspec_only_failures.md
Last active Jan 28, 2020
RSpec: Run Only Failures
View rspec_only_failures.md

RSpec: Run Only Failures

In spec/spec_helper.rb:

RSpec.configure do |config|
  # This setting allows us to only re-run examples that had failures.
  # https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
  #
  # Usage:
@lujanfernaud
lujanfernaud / rofi_alt_tab_window_switching.md
Last active Dec 27, 2019
Rofi: Alt+Tab Window Switching
View rofi_alt_tab_window_switching.md

Rofi: Alt+Tab (Super+Tab) Window Switching

This is using “Super” instead of “Alt”. If you want to use the latter you only need to replace all “Super” instances with “Tab”.

Bash Script

#!/bin/bash

# Related discussion:
@lujanfernaud
lujanfernaud / problem_solving_for_developers.md
Last active Feb 22, 2019
Problem Solving for Developers
View problem_solving_for_developers.md
@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')
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 / 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
@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
You can’t perform that action at this time.