This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rss" | |
require "ostruct" | |
RSS_FEED_URL = "https://world.hey.com/jorge/feed.atom" | |
def sync_posts | |
feed = RSS::Parser.parse(RSS_FEED_URL, false) | |
feed.items.each do |item| | |
post = OpenStruct.new title: item.title.content, date: item.published.content.strftime("%Y-%m-%d"), link: item.link.href |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
# https://github.com/rails/rails/pull/42761 | |
class Execution | |
TEST_FILE_PATH = "test/threshold_test.rb" | |
SINGLE_TEST_DURATION = 0.1 | |
attr_reader :threshold, :parallel | |
def initialize(threshold, parallel: false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_from_table_stats(klass) | |
result = klass.connection.execute("show table status like '#{klass.table_name}'") | |
result.first[result.fields.index("Rows")] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DisableReloaderWhileRunningTests | |
extend ActiveSupport::Concern | |
included do | |
setup do | |
@reloader_check = Rails.application.reloader.check | |
Rails.application.reloader.check = -> { false} | |
end | |
teardown do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
module PerformanceHelpers | |
BENCHMARK_DURATION = 1 | |
BENCHMARK_WARMUP = 1 | |
BASELINE_LABEL = "Baseline" | |
CODE_TO_TEST_LABEL = "Code" | |
# Usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
COUNT = 500000 | |
Benchmark.ips do |x| | |
x.report('Enumerable') do | |
total = 0 | |
COUNT.times do |i| | |
total += i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
require 'date' | |
require 'ostruct' | |
require 'open-uri' | |
require 'fileutils' | |
class BooksConverter | |
OUTPUT_FOLDER = "output" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} (#{source_user.email}) into #{target_username} (#{target_user.email})" | |
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: http://soupmatt.com/fixing-bundlewithout-on-heroku-cedar, | |
# which is based in an idea by @grosser. All the credits to them. | |
module Bundler | |
class Dsl | |
old_group = instance_method(:group) |
NewerOlder