Skip to content

Instantly share code, notes, and snippets.

View MatiasFernandez's full-sized avatar

Matias Fernandez MatiasFernandez

View GitHub Profile
@MatiasFernandez
MatiasFernandez / log_sql.rb
Last active May 28, 2019 15:45
Show SQL logging in rails console
ActiveRecord::Base.logger = Rails.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
@MatiasFernandez
MatiasFernandez / sidekiq_queue.rb
Last active September 21, 2016 20:02
Sidekiq API Extension. Some useful code to interact with Sidekiq API in a simple way
class SidekiqQueue < Sidekiq::Queue
def newer(limit = 1)
fetch_one_or_more_jobs(starting: :back, limit: limit)
end
def older(limit = 1)
fetch_one_or_more_jobs(starting: :front, limit: limit)
end
def all
@MatiasFernandez
MatiasFernandez / application.rb
Created May 3, 2016 17:25
Log Capybara Exceptions
# Note: Add the uncommented lines inside the Application class definition inside application.rb file
# [...]
# class XYZ < Rails::Application
if Rails.env == 'test'
require 'diagnostic'
config.middleware.use(::Diagnostic)
end
@MatiasFernandez
MatiasFernandez / gist:82da986c9ccfe8fe836e
Created December 16, 2014 20:51
Filter "Visual Event" events by DOM element using jQuery
$.grep(VisualEvent.instance.s.elements, function(e) { return e.node == $('JQUERY_SELECTOR')[0] })
@MatiasFernandez
MatiasFernandez / basic_auth.rb
Created December 16, 2014 15:16
Add HTTP Basic Auth to any environment except Development and Test to Rails App
unless Rails.env.development? || Rails.env.test?
YourApplication::Application.configure do |config|
config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Application Name") do |u, p|
[u, p] == [ENV['HTTP_USER'], ENV['HTTP_PASSWORD']]
end
end
end