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 / user.rb
Created August 27, 2014 20:57
whoa
class User < ActiveRecord::Base
# Owned events
has_many :events, dependent: :nullify
has_many :event_memberships, dependent: :nullify
has_many :member_events, through: :event_memberships, source: :user
end
@rsl
rsl / user.rb
Created August 27, 2014 20:57
whoa
class User < ActiveRecord::Base
class ApplicationController < ActionController::Base
whitelist_params user: [:name, :email], comment: [:body, :email] #...
# Creates user_params, comment_params with expected whitelisting
end
class PostsController < ApplicationController
# Automatically create the strong parameters required method
def PostsController.filter_parameters(options = {})
options[:for] = [options[:for]] if options[:for].is_a?(Symbol)
options[:for].each do |action_name|
define_method("#{action_name.to_s}_params") do
base = options[:require].keys.first
params.require(base).permit(*options[:require][base])
end
@rsl
rsl / valid.rb
Last active August 29, 2015 14:05
def foo
return unless
puts 'oh yeah'
end
def bar
return if
puts 'oh no'
end
@rsl
rsl / scrollfix.js
Last active August 29, 2015 14:04
Page scroll fix for jQuery Sortable [http://johnny.github.io/jquery-sortable/ not jQuery UI version]
$('#foo').xsortable({
onDrag: function ($item, position, _super, event) {
var $window = $(window);
var itemTop = $item.offset().top;
if (itemTop > ($window.scrollTop() + $window.height())) {
if (!window.lastItemTop || (itemTop > window.lastItemTop)) {
window.scrollBy(0, 10);
}
} else if (itemTop < $window.scrollTop()) {
if (!window.lastItemTop || (itemTop < window.lastItemTop)) {
@rsl
rsl / some.css.scss
Created July 17, 2014 18:31
don't conditionally set "display: none" as style. set a conditional class and leverage nested SCSS rules.
#survey_search {
&.hide {
display: none;
}
// Other rules
}