Skip to content

Instantly share code, notes, and snippets.

View ritec's full-sized avatar

Ri Caragol ritec

View GitHub Profile
attachments: parent_id, asset_id
domain_names: organisation_id
event_memberships: user_id, event_id
events: editor_id
group_actions: user_id, group_id
groups: user_id
icons: parent_id
invitations: sender_id
legacy_actions: item_upon_id
news_items: author_id
require 'fileutils'
namespace :spec do
def progress name, x, y
print "\r #{name}: #{x}/#{y} %6.2f%%" % [x.to_f/y * 100]
end
def generate_files name
kind = name.to_s.singularize
collection = Dir.glob Rails.root.join('app',name.to_s,'**','*').to_s
@ritec
ritec / bench_rails_memory_usage.rb
Created December 10, 2017 21:24 — forked from brianhempel/bench_rails_memory_usage.rb
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@ritec
ritec / sidekiq_monitoring
Created February 28, 2018 16:45 — forked from ngsmrk/sidekiq_monitoring
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@ritec
ritec / 01_thread.rb
Created March 8, 2018 01:58 — forked from rsim/01_thread.rb
Code examples from my "Using threads in Ruby applications" presentation in our local Ruby meetup http://www.meetup.com/ruby-on-rails-latvia/events/105142132/
Thread.new do
sleep 5
puts "finished"
end
thread = Thread.new do
sleep 5
puts "finished"
end
thread.join
@ritec
ritec / libreadline_6_not_found.sh
Last active March 25, 2019 20:58 — forked from wbotelhos/libreadline_6_not_found.sh
Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
# or if the error is with dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
ln -s /usr/local/opt/readline/lib/libreadline.8.0.dylib /usr/local/opt/readline/lib/libreadline.7.dylib
@ritec
ritec / import_job.rb
Created June 4, 2019 18:07 — forked from madebydna/import_job.rb
Nested Batch workflow with Sidekiq Pro
class ImportJob
include Sidekiq::Worker
sidekiq_options :queue => :import, :retry => false, :backtrace => true
def perform(project_id)
# create master batch
a = Sidekiq::Batch.new
a.description = "Master Batch A"
a.on(:success, "ImportJob#on_success", {"step" => "a"})
logger.info "Master Batch A starting #{a.bid}"
@ritec
ritec / blank.html
Created September 30, 2019 19:51 — forked from geetarista/blank.html
Blank favicon
<link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
@ritec
ritec / model.rb
Created July 30, 2021 20:24 — forked from aaronsakowski/model.rb
Searchkick autocomplete by token
searchkick autocomplete: ["name"],
settings: {
analysis: {
analyzer: {
searchkick_keyword: {
type: "custom",
tokenizer: "keyword",
filter: ["lowercase", "snowball"]
},
default_index: {
@ritec
ritec / webpacker_rails.md
Created April 13, 2023 18:45 — forked from maxivak/webpacker_rails.md
Webpack, Yarn, Npm in Rails