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 / seeds-faker-carrierwave.rb
Created Sep 7, 2017
Rails: Seed database with remote Faker images and CarrierWave
View seeds-faker-carrierwave.rb
# 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 / 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 / minitest_and_database_cleaner.md
Last active Dec 16, 2019
Minitest and Database Cleaner
View minitest_and_database_cleaner.md

Minitest and Database Cleaner

test_helper.rb

require 'database_cleaner'
require 'database_cleaner_support'

DatabaseCleaner.clean_with :truncation
DatabaseCleaner.strategy = :transaction
@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
You can’t perform that action at this time.