This file contains hidden or 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
# All these requires are just for running via `irb`, if using `bin/rails console` you probably just need the method. | |
require "active_support/all" # Got an inflector NoMethodError, so I'm just being lazy here. | |
require "action_dispatch" | |
require "action_dispatch/routing/route_set" | |
require "action_dispatch/routing/inspector" | |
require "action_controller" # For the ActionController::Parameters autoload, which any route helper uses. | |
# Console helper play around with the routing DSL and tweak an individual route you're building. |
This file contains hidden or 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
# frozen_string_literal: true | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'pry' | |
gem "sqlite3" | |
gem 'activerecord' | |
end |
This file contains hidden or 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 | |
if ARGV.size < 2 | |
puts "USAGE: ruby-replace FROM TO FILES..." | |
puts | |
puts "ALTERNATIVE:" | |
puts "ls | ruby-replace FROM TO" | |
exit | |
end |
To upgrade to Stimulus 3.0 and minimize the side effects of the npm package name change here is my suggestion
# add the proxy package
yarn add stimulus
# add the new @hotwired/stimulus package
yarn add @hotwired/stimulus
# add the dedicated package for the Webpack helpers
This file contains hidden or 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
class Whereable | |
def initialize(where:, model: Item, ranking_conditions: [], valid: true, data_source: nil) | |
@model = model | |
@where = where | |
@data_source = data_source | |
@ranking_conditions = ranking_conditions | |
@valid = valid | |
end | |
def valid? |
This file contains hidden or 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 "benchmark/ips" | |
require "active_support/all" | |
class Hash | |
def refined_symbolize_keys | |
transform_keys { |key| key.to_sym rescue key } | |
end | |
end | |
module HashRefinements |
This file contains hidden or 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
# Run with `ruby rails_optimistic_locking_example.rb` | |
# | |
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } |
This file contains hidden or 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 'benchmark/ips' | |
numbers = (1..10000).to_a | |
numbers_as_string = "," + (1..10000).to_a.join(",") + "," | |
Benchmark.ips do |x| | |
x.report("binary search numbers") do |i| | |
while i > 0 |
This file contains hidden or 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
class TestCase < ActiveSupport::TestCase | |
def setup | |
super | |
DatabaseCleaner.start | |
@queries = [] | |
ActiveSupport::Notifications.subscribe('sql.active_record') do |_, _, _, _, payload| | |
@queries << payload[:sql] unless payload[:name].in? %w[CACHE SCHEMA] | |
end | |
end |