Skip to content

Instantly share code, notes, and snippets.

View zanetagebka's full-sized avatar

zaneta.gebka zanetagebka

View GitHub Profile
@zanetagebka
zanetagebka / example_activejob.rb
Created November 11, 2022 11:41 — forked from ChuckJHardy/example_activejob.rb
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@zanetagebka
zanetagebka / ransack-post-form-pagy-2.md
Created August 18, 2022 08:42 — forked from benkoshy/ransack-post-form-pagy-2.md
Pagy Documentation - Using Stimulus JS

Using Stimulus JS to POST

Whenever you use pagy links that require interception, you will need to reinitialise any javascript that you need to run. If you submit a form, and use a turbo frame to render those search results, and to also render the pagination links to those results, how are you going to reinitialize your javascript code to intercept those pagy page links?

Stimulus JS is very handy for reinitialising javascript code, and is useful if you are using a library like hotwire (by Basecamp) where changes are made to the DOM.

// pagy_controller.js - a stimulus JS controller
import { Controller } from "@hotwired/stimulus"
@zanetagebka
zanetagebka / fix_NSCFConstantString_initialize.txt
Last active May 17, 2023 15:16
Solve issue with objc[18501]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
# If you have issue with
# objc[18501]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
# objc[18501]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
# I had this problem when running `bin/rails c` on Mac M1 Pro. The solution for this is below
$ export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
$ export DISABLE_SPRING=true
This should help.
@zanetagebka
zanetagebka / fix-libv8-mac.txt
Created June 5, 2020 07:41 — forked from fernandoaleman/fix-libv8-mac.txt
Fixing libv8 and therubyracer on Mac
brew tap homebrew/versions
brew install v8-315
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
bundle install
@zanetagebka
zanetagebka / find_dups.rb
Created April 17, 2020 11:04 — forked from rob-murray/find_dups.rb
Rails find duplicate records
columns_that_make_record_distinct = [:some_id, :another_name]
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)
duplicate_records = Model.where.not(id: distinct_ids)