Skip to content

Instantly share code, notes, and snippets.

View mreinsch's full-sized avatar

Michael Reinsch mreinsch

View GitHub Profile
@mreinsch
mreinsch / rescue_from_defaults.rb
Last active June 3, 2023 00:05
the way we are catching errors and rendering custom error pages for http://www.doorkeeperhq.com/
# encoding: UTF-8
#
# This file is in: lib/rescue_from_defaults.rb
#
# To use it, include the RescueFromDefaults in the ApplicationController (see below for example)
#
# To test it we are using rspec and steak. See below for examples.
#
class AccessDenied < RuntimeError
end

Keybase proof

I hereby claim:

  • I am mreinsch on github.
  • I am mreinsch (https://keybase.io/mreinsch) on keybase.
  • I have a public key ASBVOsqAmcvVZvk1rJpx4KPv4M0AwbFBKtG-3t1zSkNRrgo

To claim this, I am signing this object:

@mreinsch
mreinsch / aliases
Last active December 6, 2016 03:57
relaying email from Postfix to a Rails application, using normal HTTP API endpoints
doorkeeper_contact: |"/srv/doorkeeper/current/script/email_handler contact_emails production"
doorkeeper_event_signup: |"/srv/doorkeeper/current/script/email_handler signup_emails production"
doorkeeper_bounce: |"/srv/doorkeeper/current/script/email_handler bounced_emails production"
@mreinsch
mreinsch / capyabara_helper_methods.rb
Created March 3, 2016 18:51
wait_for_ajax helper for capyabara
module CapybaraHelperMethods
def wait_for_ajax
counter = 0
while !finished_all_ajax_requests?
counter += 1
sleep 0.2
raise "AJAX request took too long." if counter >= (Capybara.default_wait_time * 5)
end
end
@mreinsch
mreinsch / rspec_logger_listener.rb
Created March 3, 2016 18:50
log details on test runs to log to make it easier to understand what is going on
module RSpecLoggerListener
extend self
def start(notification)
Rails.logger.info("\n\n====== Starting new test run")
end
def stop(notification)
Rails.logger.info("\n\n====== Test run finished")
end
def example_started(notification)
@mreinsch
mreinsch / simple_assets.rb
Last active December 10, 2015 00:28
Speed up asset compilation by simply coping assets if nothing changed (based on git). Also works fine with turbo_sprockets. Load this with: load 'simple_assets' in your deploy.rb
load 'deploy' unless defined?(_cset)
_cset :asset_env, "RAILS_GROUPS=assets"
_cset :assets_prefix, "assets"
_cset :assets_role, [:web]
_cset :normalize_asset_timestamps, false
after 'deploy:update_code', 'deploy:assets:precompile'
@mreinsch
mreinsch / gist:0143cf9c9a91ebfacfeb
Last active October 23, 2015 14:18 — forked from malclocke/gist:943565
delete all remote branches that have already been merged into master
$ git branch -r --merged master |
awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' |
xargs git push origin --delete
@mreinsch
mreinsch / event.rb
Last active October 8, 2015 06:41
example on how we're handling object dependencies when objects in elasticsearch need update. In our case, the JSON for an event includes data from the group, so whenever the group changes, the event needs to be updated as well. Also, if a group is closed, we want to remove it and all events from the index.
class Event < ActiveRecord::Base
include Elasticsearch::Model
belongs_to :group
after_save { IndexerJob.perform_later('update', self.class.name, self.id) }
after_destroy { IndexerJob.perform_later('delete', self.class.name, self.id) }
def in_search_index?
published? && group.in_search_index?
@mreinsch
mreinsch / elasticsearch.rb
Last active October 8, 2015 04:32
elasticsearch rspec helpers, add to spec/support
# some helpers to make integration testing with elasticsearch easier
# expects Capybara
# modify this!
MODELS_WITH_ELASICSEARCH_MODEL = [Group, Event]
begin
MODELS_WITH_ELASICSEARCH_MODEL.each do |c|
c.__elasticsearch__.create_index! force: true
c.__elasticsearch__.refresh_index!
@mreinsch
mreinsch / brew doctor
Created July 27, 2012 03:41
homebrew postgresql compile log
Your system is raring to brew.