Skip to content

Instantly share code, notes, and snippets.

View ogirginc's full-sized avatar

Oğulcan Girginç ogirginc

View GitHub Profile
@kaspth
kaspth / routes.rb
Last active April 6, 2023 16:57
`draw` method to explore routes in the console
# 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.
@mateuszbialowas
mateuszbialowas / scratch.rb
Created May 25, 2022 17:36
ar-mapping-custom-pk-fk
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pry'
gem "sqlite3"
gem 'activerecord'
end
#!/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
@adrienpoly
adrienpoly / upgrade.md
Created September 24, 2021 09:32
Upgrade to Stimulus 3 recommandations

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
@searls
searls / whereable.rb
Created September 4, 2021 16:06
The initial implementation of a Whereable query filter for KameSame.
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?
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
@choncou
choncou / rails_optimistic_locking_example.rb
Last active June 15, 2021 12:10
Optimistic Locking in Rails: Preventing outdated updates
# 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" }
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
@soffes
soffes / test_case.rb
Created March 11, 2021 15:01
Simple ActiveRecord query counter
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