Skip to content

Instantly share code, notes, and snippets.

@timdiggins
timdiggins / delayedjob-bugsnag.rb
Last active August 29, 2015 14:11 — forked from loopj/delayedjob-bugsnag.rb
notify bugsnag when delayed job errors occur
# some references which helped
# http://blog.salsify.com/engineering/delayed-jobs-callbacks-and-hooks-in-rails
# http://stackoverflow.com/a/16639849/109175
# example plugin: https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/plugins/clear_locks.rb
module Delayed
module Plugins
class Bugsnag < Plugin
callbacks do |lifecycle|
lifecycle.around(:invoke_job) do |job, &block|
begin
@timdiggins
timdiggins / gist:294f0a37312fcbeaac70
Created December 18, 2014 10:44
delayedjob plugin to log backtraces
module Delayed
module Plugins
class LogErrors < Plugin
callbacks do |lifecycle|
lifecycle.around(:invoke_job) do |job, &block|
begin
block.call(job)
rescue Exception => error
Delayed::Worker.logger.error(error.message)
Delayed::Worker.logger.error(error.backtrace.join("\n"))
@timdiggins
timdiggins / rake_testing_support.rb
Created March 20, 2015 13:11
testing rake in rspec (etc)
# ./spec/support/rake_testing_support.rb
def invoke_rake_task_in_test(task_name)
require 'rake'
Rails.application.load_tasks if Rake.application.tasks.count < 10
Rake::Task[task_name].reenable
Rake::Task[task_name].invoke
end
@timdiggins
timdiggins / test.rb
Created May 12, 2016 06:02
Simple script to test rspec_junit_formatter against all the rspec versions
#!/usr/bin/env ruby
def header(version)
puts
puts "-" * 80
puts " rspec #{version}"
end
def run(version, command)
system <<-SCRIPT
@timdiggins
timdiggins / thredded.rb
Last active January 10, 2017 18:45
MainAppDelegator
# config/intitializers/thredded.rb
# to allow you to not to have to add `main_app` before every path helper
# when embedding Thredded within a main-app supplied layout (with navbar and links to the main_app)
# ... Add this to the bottom of the initializer
Rails.application.config.to_prepare do
Rails.application.reload_routes!
thredded_methods = (Thredded::Engine.routes.url_helpers.methods + Thredded::UrlsHelper.instance_methods)
@timdiggins
timdiggins / 01_readme.md
Last active October 7, 2017 14:19
breaking rails conventions workshop
@timdiggins
timdiggins / disable_template_cache_clearing.rb
Last active January 29, 2018 21:59
speed up rails 5.0 feature specs by caching templates during suite
# spec/support/disable_template_cache_clearing
# may also need to configure, either here
Rails.application.config.action_view.cache_template_loading = true
# or in config/environments/test.rb:
# config.action_view.cache_template_loading = true
# ensure ActionView::Digestor is already autoloaded before patching it
ActionView::Digestor
@timdiggins
timdiggins / gist:3eba95ba752092e3648b9a3a932df41b
Last active February 20, 2018 18:21
traceback for thredded demo (v0.14.2) with onebox (1.8.39) Using content with http
RuntimeError in Thredded::Topics#show
Showing /Users/tim/workspaces/bws/thredded/app/views/thredded/posts_common/_content.html.erb where line #2 raised:
Unable to read pdf file: https://www.poettker.com/files/pdf/Produktkatalog_170912.pdf
Extracted source (around line #14):
def data
pdf_info = get_pdf_info
raise "Unable to read pdf file: #{@url}" if pdf_info.nil?
result = { link: link,
@timdiggins
timdiggins / traceback
Created February 20, 2018 18:44
traceback for oneboxing failure of https error
2018-02-20 18:41:58 - RuntimeError - Unable to read pdf file: https://www.poettker.com/files/pdf/Produktkatalog_170912.pdf:
/Users/tim/workspaces/bws/onebox/lib/onebox/engine/pdf_onebox.rb:14:in `data'
/Users/tim/workspaces/bws/onebox/lib/onebox/engine.rb:66:in `block in record'
/Users/tim/.rvm/gems/ruby-2.3.1@rails/gems/moneta-1.0.0/lib/moneta/mixins.rb:165:in `fetch'
/Users/tim/workspaces/bws/onebox/lib/onebox/engine.rb:66:in `record'
/Users/tim/workspaces/bws/onebox/lib/onebox/layout_support.rb:9:in `layout'
/Users/tim/workspaces/bws/onebox/lib/onebox/layout_support.rb:13:in `to_html'
/Users/tim/workspaces/bws/onebox/lib/onebox/preview.rb:35:in `engine_html'
/Users/tim/workspaces/bws/onebox/lib/onebox/preview.rb:16:in `to_s'
/Users/tim/workspaces/bws/onebox/lib/onebox/web.rb:33:in `block in <class:Web>'
@timdiggins
timdiggins / request_support.rb
Created February 23, 2019 10:19
An equivalent to capybara save_and_open_page for request specs
# frozen_string_literal: true
RSpec.shared_context "save_and_open_page for request" do
def asset_host
"http://localhost:3000"
end
def save_and_open_page
Dir.mkdir(Rails.root.join("tmp/requests")) unless Dir.exist?(Rails.root.join("tmp/requests"))
file = Rails.root.join("tmp/requests/screenshot-#{Time.now.to_s(:number)}.html")