Skip to content

Instantly share code, notes, and snippets.

View mayuresh-srivastava's full-sized avatar
🏠
Working from home

Mayuresh Srivastava mayuresh-srivastava

🏠
Working from home
View GitHub Profile
@natematykiewicz
natematykiewicz / unroutable_routes.rake
Last active June 9, 2022 19:47
Find routes that will raise a routing error when requested
desc 'Find routes that will raise a routing error when requested'
task unroutable_routes: :environment do
# A lot of this code was taken from how `rake routes` works
# https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/railties/lib/rails/commands/routes/routes_command.rb
require 'action_dispatch/routing/inspector'
unroutables = Rails.application.routes.routes.
map { |r| ActionDispatch::Routing::RouteWrapper.new(r) }.
reject { |r| r.internal? || r.engine? || r.path.starts_with?('/rails/') || !r.controller }.
@baweaver
baweaver / dio_quick_example.rb
Created January 17, 2021 05:53
Quick example of the new Dio gem, https://www.github.com/baweaver/dio
require 'dio'
# Dive into arbitrary objects using their methods
Dio[1] in { succ: { succ: { succ: 4 } } }
# => true
Node = Struct.new(:value, :children)
tree = Node[1,
Node[2, Node[3, Node[4]]],
@db0sch
db0sch / regenerate_credentials.md
Last active July 30, 2024 12:59
How to regenerate the master key for Rails 5.2 credentials

If your master.key has been compromised, you might want to regenerate it.

No key regeneration feature at the moment. We have to do it manually.

  1. Copy content of original credentials rails credentials:show somewhere temporarily.
  2. Remove config/master.key and config/credentials.yml.enc
  3. Run EDITOR=vim rails credentials:edit in the terminal: This command will create a new master.key and credentials.yml.enc if they do not exist.
  4. Paste the original credentials you copied (step 1) in the new credentials file (and save + quit vim)
  5. Add and Commit the file config/credentials.yml.enc
@simonw
simonw / how-to.md
Last active April 16, 2025 15:21
How to create a tarball of a git repository using "git archive"
@rvalenciano
rvalenciano / practic3.rb
Created September 11, 2015 20:22
Custom attr_accessor
class SuperFoo
attr_accessor :data
def initialize
@data = {}
end
def self.data_accessor(*args)
args.each do |arg|
@iangreenleaf
iangreenleaf / gist:b206d09c587e8fc6399e
Last active June 6, 2025 20:28
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.