Skip to content

Instantly share code, notes, and snippets.

Arthur Nogueira Neves arthurnn

View GitHub Profile
@arthurnn
arthurnn / active_job_instrumentation.rb
Created Feb 12, 2019
Base instrumentation for ActiveJob + Sidekiq
View active_job_instrumentation.rb
def stats
# TODO
end
def dogtags
# TODO
end
ActiveSupport::Notifications.subscribe("enqueue.active_job") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
View sendgrid_delivery.rb
# frozen_string_literal: true
require 'sendgrid-ruby'
require 'sendgrid_mailer/mailer'
class SendgridDelivery
class InvalidEmail < StandardError; end
def initialize(*)
end
@arthurnn
arthurnn / example_test.rb
Last active Oct 29, 2018
Load ActiveRecord fixtures from a block instead of a yml file
View example_test.rb
require 'minitest/autorun'
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDOUT)
conn = { adapter: 'sqlite3', database: ':memory:' }
ActiveRecord::Base.establish_connection(conn)
class User < ActiveRecord::Base
connection.create_table :users, force: true do |t|
t.string :username
@arthurnn
arthurnn / multi_shard_test.rb
Created Feb 27, 2018
Rails 5 connection swapping for sharding env
View multi_shard_test.rb
require "active_record"
require "minitest/autorun"
ENV["RAILS_ENV"] = "development"
ActiveRecord::Base.configurations = {
"development" => { "adapter" => "sqlite3", "database" => "fake.db" },
"shard1" => { "adapter" => "sqlite3", "database" => "shard1.db" },
"shard2" => { "adapter" => "sqlite3", "database" => "shard2.db" }
}
View vitess.rb
class Vitess < Formula
desc "Vitess is a database clustering system for horizontal scaling of MySQL."
homepage "http://vitess.io"
url "https://github.com/arthurnn/vitess.git",
:branch => "arthurnn/easier_build",
:revision => "f73a77ebe144e022db27c6eb9df92dc6b60a52ae"
head "https://github.com/arthurnn/vitess.git",
:shallow => false
version "2.1.1.f73a77"
View assets.rake
require 'non_digest_assets'
namespace :assets do
task :non_digested do
NonDigestAssets.new.generate
end
end
View conn_handler_swap_test.rb
require "active_record"
require "minitest/autorun"
class Person < ActiveRecord::Base
establish_connection adapter: "sqlite3", database: "foobar.db"
end
class ConnHandlerSwapTest < Minitest::Test
def setup
@readonly = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
View test_encrypted_gem.rb
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem 'bcrypt'
gem "activerecord", "~> 5.0.0"
gem 'sqlite3'
gem 'attr_encrypted', github: 'attr-encrypted/attr_encrypted', require: false
end
View encrypt_test.rb
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "activerecord", "~> 5.0.0"
gem 'sqlite3'
gem 'attr_encrypted', '~> 3.0', require: false
end
require 'active_record'
View test.rb
require 'active_support/all'
module SetupAndTeardown
extend ActiveSupport::Concern
included do
class_attribute :callbacks
self.callbacks = []
end
You can’t perform that action at this time.