Skip to content

Instantly share code, notes, and snippets.

jorgemanrubia / measure.rb
Last active Jul 14, 2021
Script to measure and compare speed of running tests in parallel versus sequentially
View measure.rb
require "benchmark"
class Execution
TEST_FILE_PATH = "test/threshold_test.rb"
attr_reader :threshold, :parallel
def initialize(threshold, parallel: false)
jorgemanrubia / count_from_table_stats.rb
Created Apr 22, 2021
Estimated count from table stats (MySQL)
View count_from_table_stats.rb
def count_from_table_stats(klass)
result = klass.connection.execute("show table status like '#{klass.table_name}'")
View Disable reloading while tests are running.rb
module DisableReloaderWhileRunningTests
extend ActiveSupport::Concern
included do
setup do
@reloader_check = Rails.application.reloader.check
Rails.application.reloader.check = -> { false}
teardown do
jorgemanrubia / performance_helpers.rb
Last active May 1, 2020
Minitest helper to compare code with benchmark-ips
View performance_helpers.rb
require 'benchmark/ips'
module PerformanceHelpers
# Usage:
jorgemanrubia / enumerators_performance.rb
Last active May 4, 2017
Ruby enumerators performance
View enumerators_performance.rb
require 'benchmark/ips'
COUNT = 500000
Benchmark.ips do |x|'Enumerable') do
total = 0
COUNT.times do |i|
total += i
jorgemanrubia / converter.rb
Created Oct 4, 2015
Script to convert reading list in csv format
View converter.rb
require 'csv'
require 'date'
require 'ostruct'
require 'open-uri'
require 'fileutils'
class BooksConverter
OUTPUT_FOLDER = "output"
jorgemanrubia / discourse_users_merger.rb
Last active Apr 18, 2022
Script for merging existing discourse users
View discourse_users_merger.rb
module DiscourseUsersMerger
class Merger
def merge(target_username, source_username)
raise "User to merge and target user can't be the same" if target_username == source_username
target_user = User.find_by_username!(target_username)
source_user = User.find_by_username!(source_username)
puts "About to merge #{source_username} (#{}) into #{target_username} (#{})"
puts "#{source_user.topics.count} topics with #{source_user.posts.count} posts will be moved. Ok to continue? (y/n)"
continue = STDIN.gets.chomp.downcase == 'y'
jorgemanrubia / bundler.rb
Last active Dec 10, 2015
Exclude gems in heroku Cedar. Heroku will ignore :development and :test by default, but not other groups (such as :cucumber). Previous Bamboo stack let you define BUNDLE_WITHOUT, but it doesn't work anymore on Cedar.
View bundler.rb
# Put this code in some file and require it at the beginning of your Gemfile
# Then you can list the groups to exclude from heroku. E.g:
# exclude_in_heroku :cucumber, :development, :test
# Based on this post by Matt Campbell:,
# which is based in an idea by @grosser. All the credits to them.
module Bundler
class Dsl
old_group = instance_method(:group)
jorgemanrubia / gist:3012801
Created Jun 28, 2012
script for preparing the execution of the build pipeline of zendone
View gist:3012801
# Deletes trash files
rm -f tmp/*.oauth
rm -f log/*.log
rm -f db/schema.rb
rm -f tmp/evernote_session_data
rm -f rerun.txt