A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.
posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord
/* | |
Copy this into the console of any web page that is interactive and doesn't | |
do hard reloads. You will hear your DOM changes as different pitches of | |
audio. | |
I have found this interesting for debugging, but also fun to hear web pages | |
render like UIs do in movies. | |
*/ | |
const audioCtx = new (window.AudioContext || window.webkitAudioContext)() |
class ApplicationJob < ActiveJob::Base | |
around_perform do |job, block| | |
Honeycomb.start_span(name: job.class.name) do |span| | |
span.add_field 'type', 'worker' | |
span.add_field 'queue.name', job.queue_name | |
block.call | |
end | |
end | |
end |
For MacOS Catalina, visit Install mysql2 on MacOS Catalina
Installing mysql2
gem errors on MacOS Mojave.
Make sure openssl
is installed on Mac via Homebrew.
https://github.com/ankane/searchkick
By default, simply adding the call 'searchkick' to a model will do an unclever indexing of all fields (but not has_many or belongs_to attributes).
In practice, you'll need to customize what gets indexed. This is done by defining a method on your model called search_data
def search_data
Change a devise app from scratch | |
video link here: https://drive.google.com/file/d/1S59pmFe-Cp_s8aJLMax296x4AN0x0naK/view?usp=sharing | |
Add these Gems to your Gemfile | |
gem 'omniauth-oktaoauth' | |
gem 'activerecord-session_store' |
# FOR BUSY JOBS | |
# take the process_id from the /busy page in sidekiq and kill the longest running one. | |
workers = Sidekiq::Workers.new | |
long_process_id = 'integration.3:4:71111aaa111' # Eg: 'integration.3:4:71d1d7f4ef5a' | |
workers.each do |process_id, thread_id, work| | |
process = Sidekiq::Process.new('identity' => process_id) | |
process.stop! if process_id == long_process_id | |
end | |
# FOR SCHEDULED JOBS |
require 'sidekiq/api' | |
# BulkReindexer | |
module BulkReindexer | |
def self.reindex_model(model, promote_and_clean = true) | |
puts "Reindexing #{model.name}..." | |
index = model.reindex(async: true, refresh_interval: '30s') | |
puts "All jobs are in queue. Index name: #{index[:index_name]}" | |
loop do | |
# Check the size of queue |
require 'benchmark' | |
require 'benchmark/ips' | |
require 'ostruct' | |
require 'active_model' | |
BillingAddressStruct = Struct.new(:street, :city, :zipcode, :country, :state) | |
BillingAddressOpenStruct = OpenStruct | |
BillingAddressStructFromHash = Struct.new(:street, :city, :zipcode, :country, :state) do |
class DecoratorClone | |
def initialize(model) | |
@model = model | |
end | |
def method_missing(m, *args) | |
raise NameError, "Decorator method '#{m}' not found" unless @model.respond_to?(m) | |
@model.send(m, *args) | |
end | |
end |