foo
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Finds unused routes (routes with no corresponding controller action)' | |
task find_unused_routes: :environment do | |
checked_actions = %i[create destroy edit index new show update] | |
Rails.application.eager_load! | |
endpoints = Rails.application.routes.routes.map do |route| | |
ActionDispatch::Routing::RouteWrapper.new(route).endpoint | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Finds unused partials (i.e. view files starting with "_"). '\ | |
'May find false positives (programmatically chosen partials).' | |
task :find_unused_partials do | |
UnusedPartialFinder.run | |
end | |
module UnusedPartialFinder | |
module_function | |
RENDER_CALL_REGEX = %r{\Wrender[^'"]*(['"])/?((?:(?!\1).)+)\1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Finds unused views (i.e. view files not starting with "_"). '\ | |
'May find false positives (programmatically chosen views).' | |
task find_unused_views: :environment do | |
UnusedViewFinder.run | |
end | |
module UnusedViewFinder | |
module_function | |
ALLOWLISTED_PATHS_REGEX = %r{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryBot.factories.each do |factory| | |
name = factory.names.count == 1 ? factory.names.first : fail | |
klass = factory.build_class | |
next unless ActiveRecord::Base.in?(klass.ancestors) | |
RSpec.describe "factory :#{name}" do | |
it "creates a single #{klass} and no insane number of other records" do | |
record_counts = -> do | |
ActiveRecord::Base.descendants.to_h { |c| [c.name.to_sym, (c.count rescue 0)] } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'excon' | |
gem 'fortschritt' | |
end | |
# get list of gems from bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# put in credentials dir, e.g. ~/.local/share/gem/swap_credentials | |
require 'fileutils' | |
active_path = "#{__dir__}/credentials" | |
memo_path = "#{__dir__}/memo" | |
current = File.exist?(memo_path) && File.read(memo_path) | |
Dir["#{__dir__}/credentials_*"].each do |cred_path| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- warn-indent:false; -*- | |
# line 1 "~/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl" | |
# line 700 "~/code/regexp_parser/lib/regexp_parser/scanner/scanner.rl" | |
# THIS IS A GENERATED FILE, DO NOT EDIT DIRECTLY | |
# This file was generated from lib/regexp_parser/scanner/scanner.rl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# subarray_combinations([['a', 'b'], [1, 2]]) | |
# # => [['a', 1], ['a', 2], ['b', 1], ['b', 2]] | |
def subarray_combinations(array_of_arrays, index = 0) | |
return [] if index == array_of_arrays.size | |
subarray = array_of_arrays[index] | |
tails = subarray_combinations(array_of_arrays, index + 1) | |
if tails.empty? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'stringex' | |
require 'sexy_slug' | |
require 'benchmark' | |
string = (0..0xD799).map { |cp| cp.chr('utf-8') }.join | |
Benchmark.bmbm do |x| | |
x.report { string.to_url } | |
x.report { SexySlug.from(string) } | |
end |