Skip to content

Instantly share code, notes, and snippets.

View rsl's full-sized avatar
🏳️‍🌈
still a bad fish and free bird

Russell Norris rsl

🏳️‍🌈
still a bad fish and free bird
View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
@rsl
rsl / routes_snippet.rb
Created July 14, 2016 16:13
Routing fix for devise_saml_authenticatable
# Snip snip snip
devise_for :users, skip: [:registrations, :saml_authenticatable], controllers: {sessions: 'devise_sessions'}
# Manually add user editing but disallow registrations [above]
as :user do
get 'users/edit' => 'devise_registrations#edit', as: 'edit_registration'
patch 'users' => 'devise_registrations#update', as: 'registration'
# To avoid conflict saml_authenticatable routes are manually defined here.
# Also we override the controller.
resource :session, as: 'saml_session', only: [], controller: 'devise_saml_sessions', path: '/companies/:id/saml' do
@rsl
rsl / gist:6529686
Created September 11, 2013 20:58
this seems to do what i want
def self.find_by_ordered_ids(ids)
order_by = ['case']
ids.each_with_index do |id, index|
order_by << "WHEN id='#{id}' THEN #{index}"
end
order_by << 'end'
where(id: ids).order(order_by.join(' '))
end
@rsl
rsl / gist:6282912
Created August 20, 2013 15:23
conditional rescues. there has to be something better than this. this screams inefficient. but tbh it's not an issue that will really happen in production.
def create_database
Apartment::Database.create database_name
rescue Apartment::SchemaExists => err
raise err unless Rails.env.development?
end
class Test::Unit::TestCase # Or ActiveSupport::TestCase if you are using Rails
# This is a debugging utility to find slow tests.
# Usage: rake FIND_SLOW_TESTS=true test:units
unless ENV["FIND_SLOW_TESTS"].blank?
alias_method :old_run, :run
def run(*args, &block)
start_time = Time.now
old_run *args, &block
test_time = Time.now - start_time
puts "\nSLOW TEST: #{self.name}, #{test_time}s" if test_time > 0.5
Fetching: rails-4.0.0.rc1.gem (100%)
ERROR: Error installing rails:
rails requires SlimGems version >= 1.8.11. Try 'gem update --system' to update SlimGems itself.
rsl@swanstation:~/dev/foo master
$ gem update --system
SlimGems is already up-to-date (1.3.9.5)
@rsl
rsl / test.rb
Created January 25, 2013 18:06
require 'test_helper'
class SubscriptionNotifierTest < ActionMailer::TestCase
fixtures :companies
should_eventually "test other subscription mailer actions"
test 'should send cancellation email' do
company = companies(:no_categories)
email = SubscriptionNotifier.cancelled_subscription(company).deliver
@rsl
rsl / gist:2407469
Created April 17, 2012 16:55
Fubar
def fubar?(bar=(def fubar?; puts "nope"; end))
puts "fubar!"
end
fubar?
fubar?
@rsl
rsl / descriptive_sql_load_log.rb
Created July 19, 2011 20:39 — forked from JackDanger/descriptive_sql_load_log.rb
Let Rails display file names and line numbers for log activity.
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
protected
# Turn:
# User Load (6.3ms) SELECT * FROM "users"
# Into:
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users"