Skip to content

Instantly share code, notes, and snippets.

View LeFnord's full-sized avatar
🚀

peter scholz LeFnord

🚀
  • Leipzig/Lausitz, Saxony
View GitHub Profile
@tomhicks
tomhicks / plink-plonk.js
Last active March 18, 2024 02:23
Listen to your web pages
@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active May 15, 2024 20:55
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@qrush
qrush / application_job.rb
Last active March 31, 2020 01:38
Use Honeycomb to trace ActiveRecord calls inside of ActiveJob
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
@fernandoaleman
fernandoaleman / mysql2-mojave.md
Last active February 7, 2024 19:19
Install mysql2 on MacOS Mojave

For MacOS Catalina, visit Install mysql2 on MacOS Catalina

Problem

Installing mysql2 gem errors on MacOS Mojave.

Solution

Make sure openssl is installed on Mac via Homebrew.

@JasonTrue
JasonTrue / searchkick_and_elasticsearch_guidance.md
Last active March 7, 2024 14:42
Searchkick and Elastic Search guidance

Resources:

https://github.com/ankane/searchkick

Indexing

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'
@Chocksy
Chocksy / kill_sidekiq_job.rb
Last active April 25, 2024 14:07
Kill sidekiq jobs by process id for busy jobs and by jid for other sets.
# 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
@VvanGemert
VvanGemert / bulk_reindexer.rb
Created July 2, 2017 12:23
Asynchronous bulk reindexing module for Searchkick with Sidekiq
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
@gwilczynski
gwilczynski / benchmark.rb
Created March 2, 2017 23:23
Please don’t hate OpenStruct
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
@dux
dux / decorator_clone.rb
Last active October 20, 2023 13:51
Simple ruby decorators with example
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