Skip to content

Instantly share code, notes, and snippets.

@spullen
spullen / app_builder.rb
Last active April 28, 2019 01:37
Custom AppBuilder for Ruby on Rails
class AppBuilder < Rails::AppBuilder
def initialize(generator)
super(generator)
at_exit do
postprocess
end
end
def readme
@spullen
spullen / protocols_collection.js
Created August 22, 2013 23:36
Send a JSON collection with custom headers to describe the entire paginated collection. This removes mixing meta data about the paginated collection with the actual data we want to work with.
// using Backbone.Pageable https://github.com/wyuenho/backbone-pageable
App.Collections.Protocols = Backbone.PageableCollection.extend({
model: App.Models.Protocol,
url: '/protocols',
state: {
firstPage: 1,
currentPage: 1,
pageSize: 100
class ProtocolsController < ApplicationController
respond_to :json
before_action :set_protocol, only: [:show, :update, :destroy]
def index
respond_with @protocols = Protocol.ordered
end
def show
<% @categories.each do |category, category_count| %>
<tr class="<%= category %> value" data-count="<%= category_count %>">
<td><%= category_count %></td><td><%= category_count * 100 / @violations_to_check %>%</td><td><%= category_count %></td><td><i class="icon-arrow-up"></i></td>
</tr>
<% end %>
@spullen
spullen / ldap_adapter.rb
Created August 20, 2013 13:44
Database and LDAP Authentication
require 'net/ldap'
module LdapAdapter
# Add valid users to database
mattr_accessor :ldap_create_user
@@ldap_create_user = false
mattr_accessor :ldap_config
# @@ldap_config = "#{Rails.root}/config/ldap.yml"
@spullen
spullen / devise.rb
Created November 15, 2012 15:28
Hybrid Authentication 3
# config/initializers/devise.rb
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# snip...
config.warden do |manager|
manager.default_strategies(:scope => :user).unshift :ldap_authenticatable
end
@spullen
spullen / devise_create_user.rb
Created November 8, 2012 20:43
HybridAuthenticatable 2
# db/migrate/<timestamp>_devise_create_user.rb
# This is pretty much stock rails g devise User
# with the only exception being t.boolean :override_ldap, :default => false
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :username, :null => false, :default => ""
t.string :email, :null => false, :default => ""
@spullen
spullen / <timestamp>_devise_create_user.rb
Created November 8, 2012 16:46
HybridAuthenticatable
# db/migrate/<timestamp>_devise_create_user.rb
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :username, :null => false, :default => ""
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""