Skip to content

Instantly share code, notes, and snippets.

source 'https://rubygems.org'
gem 'rails', '3.2.0'
gem 'mysql2'
# Using this branch of ActiveAdmin to allow batch editing of records.
#gem 'activeadmin', :git => 'https://github.com/mattvague/active_admin.git', :branch => '270_batch_edit_api'
gem 'activeadmin', '0.4.0'
gem 'sass-rails', '3.2.4'
@seanlinsley
seanlinsley / gist:2038003
Last active June 7, 2019 08:00
A better form to edit multiple child records. Created for https://github.com/gregbell/active_admin/issues/1097
<%= semantic_form_for @parent do |a| %>
<%= a.inputs "Family Details" do %>
<%= a.input :name %>
<%= a.input :user %>
<%= a.input :region %>
<% end %>
<%= a.inputs "Children" do %>
<table>
@seanlinsley
seanlinsley / hack.sh
Created June 2, 2012 22:29 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@seanlinsley
seanlinsley / Rakefile
Created November 30, 2012 10:48
Faster rake is better rake
# Rakefile inspired by http://rhnh.net/2010/09/07/speeding-up-rails-rake
def load_rails_environment
require File.expand_path('../config/application', __FILE__)
require 'rake'
TimeAudit::Application.load_tasks
end
# By default, do not load the Rails environment. This allows for faster
# loading of all the rake files, so that getting the task list, or kicking
# off a spec run (which loads the environment by itself anyways) is much quicker.
@seanlinsley
seanlinsley / gist:4184258
Created December 1, 2012 19:17
Clone a remote git repo, with all branches included
git clone --mirror https://github.com/Daxter/active_admin.git acitve_admin/.git
cd active_admin
git config --bool core.bare false # it's initially a bare repo, so we've got to fix that
git checkout
@seanlinsley
seanlinsley / application.rb
Last active December 10, 2015 10:38
Why can't nested /lib loading be easy?
module YourApplication
class Application < Rails::Application
# Loads ruby files in a given directory.
# NOTE: `require_dependency` auto-reloads on file change when in development.
# POSTERITY: this was needed to prevent auto-namespacing of lib/a/b.rb files.
def loader(*dirs)
dirs.each do |dir|
Dir["#{Rails.root}/#{dir}/*.rb"].each do |path|
d = dir.gsub /lib\/?/, '' # removes lib and lib/
require_dependency (d.blank? ? '' : d + '/') + File.basename(path, '.rb')
@seanlinsley
seanlinsley / batch_actions.js.coffee
Last active December 10, 2015 20:08
WIP for github.com/gregbell/active_admin/issues/1815
$ ->
confirmBox = (message, inputs, callback) ->
html = """<div id="dialog_confirm" title="Confirmation"><p>#{message}</p>""" +
inputs.map((a)-> """<label>#{a}</label><input name="#{a}"></input>""").join("\n") +
"</div>"
$(html).appendTo('body').dialog
modal: true
buttons:
OK: ->
callback $(@).find('input').serializeArray()
@seanlinsley
seanlinsley / log_formatting.rb
Last active April 14, 2017 16:07
proper logging -- with color :)
# Define a setter to pass in a custom log formatter
class ActiveSupport::BufferedLogger
def formatter=(formatter)
@log.formatter = formatter
end
end
# Defines a custom log format (time, severity, message, PID, backtrace)... all with color!
class Formatter
SEVERITY_TO_TAG = {'DEBUG'=>'meh', 'INFO'=>'fyi', 'WARN'=>'hmm', 'ERROR'=>'wtf', 'FATAL'=>'omg', 'UNKNOWN'=>'???'}
@seanlinsley
seanlinsley / attack_of_the_symbols.rb
Last active December 14, 2015 12:29
While trying better understand where all those darn symbols are coming from, I discovered that Active Admin is very leaky: https://github.com/gregbell/active_admin/pull/1926 These are the hacks I developed in that journey. Hopefully this helps someone else!
# At the beginning of each web request, log the current number of symbols in memory.
class ApplicationController < ActionController::Base
protect_from_forgery
@@sym_count_logger = Logger.new('log/sym_count.log')
before_filter do
@@sym_count_logger.info Symbol.all_symbols.count
end
end
@seanlinsley
seanlinsley / gist:5288401
Created April 1, 2013 22:43
Ruby 1.8, Rails 3.0 test failures on Active Admin as of 3371999c47c9
Failures:
1) ActiveAdmin::Namespace registering a page adding to the menu disabling the menu should not create a menu item
Failure/Error: expect {
expected KeyError, got #<IndexError: key not found>
# /home/sean/.rvm/gems/ruby-1.8.7-p371@active_admin/gems/rspec-expectations-2.9.1/lib/rspec/expectations/fail_with.rb:33:in `fail_with'
# /home/sean/.rvm/gems/ruby-1.8.7-p371@active_admin/gems/rspec-expectations-2.9.1/lib/rspec/expectations/handler.rb:19:in `handle_matcher'
# /home/sean/.rvm/gems/ruby-1.8.7-p371@active_admin/gems/rspec-expectations-2.9.1/lib/rspec/expectations/extensions/kernel.rb:12:in `to'
# /home/sean/code/gems/active_admin/spec/unit/namespace/register_page_spec.rb:70
# /home/sean/.rvm/gems/ruby-1.8.7-p371@active_admin/gems/rspec-core-2.9.0/lib/rspec/core/example.rb:80:in `instance_eval'