Skip to content

Instantly share code, notes, and snippets.

View TrumpClone's full-sized avatar

Optimus Advocate TrumpClone

View GitHub Profile
module Synchronizable
DEFAULT_WAIT_TIME = 10.seconds
extend self
def synchronize(*args, &block)
Transaction.run { with_advisory_lock(*args, &block) }
end
private
module Events::EventDomain
class NewRegisteredUser < Base
end
end
def run_non_critical(fallback: nil, controller: nil, only_production: true)
if only_production && Rails.application.config.consider_all_requests_local
return yield
end
begin
if defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.transaction_open?
Transaction.run(requires_new: true) { yield }
else
yield
@TrumpClone
TrumpClone / asd
Created March 25, 2017 15:11
asd
[1] pry(main)> Distribution::Deliveries::Base.last
=> #<Distribution::Deliveries::Sendgrid @values={:id=>3, :template_id=>1, :title=>"pizda", :from=>"hyi@hui.hyi", :subject=>"poshko", :events=>["user_answered_ticket"], :method_name=>"sendgrid", :segment_type=>"eventless", :segment_name=>"allowed_for_payment_notification", :segment_params=>{}, :created_at=>2017-03-22 16:03:05 +0000, :updated_at=>nil}>
[2] pry(main)> Distribution::Deliveries::Base.last.json
NoMethodError: undefined method `json' for #<Distribution::Deliveries::Sendgrid:0x007fbdd7aec0a8>
from (pry):2:in `__pry__'
[3] pry(main)> Distribution::Deliveries::Base.last.as_json
=> {"id"=>3,
"template_id"=>1,
"title"=>"pizda",
"from"=>"hyi@hui.hyi",
@TrumpClone
TrumpClone / test.rb
Created April 20, 2017 14:00
amon master
shared_context 'stub jobs', :stub_jobs do
around do |spec|
original_method = ActiveJob::Base.method(:perform_later)
begin
ActiveJob::Base.send(:define_singleton_method, :perform_later) do |*args|
RSpec::Matchers::StubJobs.state.push(class: self, args: args)
end
RSpec::Matchers::StubJobs.collect(&spec)
ensure
@TrumpClone
TrumpClone / alias_matchers.md
Created May 2, 2017 08:21 — forked from JunichiIto/alias_matchers.md
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
@TrumpClone
TrumpClone / README.md
Created July 13, 2017 14:11 — forked from chrisroos/README.md
Example of using bundler/inline

I came across 'bundler/inline' in Bundler pull request 3440, which I'd found from Rails pull request 20429. This now has a little snippet on the What's new page of the Bundler site.

This little example demonstrates how I might use it to create a single file using minitest.

I've just noticed that this script was working for me because I already had minitest installed as a system gem. If I uninstall the gem then the script fails because it can't find minitest. The source code documents an option to install gems if they don't exist (gemfile(true) do) but that doesn't seem to work for me. I see the following error:

Fetching gem metadata from https://rubygems.org/...
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...

Using metaclass 0.0.4

@TrumpClone
TrumpClone / Gemfile
Created November 17, 2017 10:31 — forked from pboling/Gemfile
My latest project's Gemfile, implements bundle group pattern
source 'https://rubygems.org'
# Follows the bundler group pattern described here:
# http://iain.nl/getting-the-most-out-of-bundler-groups
# Gemfile.mine in root dir allows locally custom gems.
# NOTE: Doing this will change the Gemfile.lock - commit with care.
eval File.read(File.join(File.dirname(__FILE__), 'Gemfile.mine')) if File.exists? File.join(File.dirname(__FILE__), 'Gemfile.mine')
ruby '1.9.3'
# frozen_string_literal: true
module Distribution::Transmission::Hooks::Hookable
HookError = Class.new(StandardError)
UnexistentHookError = Class.new(HookError)
class << self
def included(base_class)
base_class.extend ClassMethods
end
# frozen_string_literal: true
module Distribution::Transmission::Hooks::Hookable
HookError = Class.new(StandardError)
UnexistentHookError = Class.new(HookError)
class << self
def included(base_class)
base_class.extend ClassMethods
end