Skip to content

Instantly share code, notes, and snippets.

View crosebrugh's full-sized avatar

Chris Rosebrugh crosebrugh

View GitHub Profile
@crosebrugh
crosebrugh / simple_form-error-notification-to-flash.rb
Last active August 29, 2015 14:05
Vector simple_form error notification to flash
# A https://github.com/plataformatec/simple_form puts it's alert box inside of the form instead
# of using the flash object. This may look clunky depending on how the various backgrounds are set up on the page.
# E.g. in a view, f.error_notification puts the alert within the form instead of above
# it where flash info goes as per the layout
<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>
<%= f.full_error :confirmation_token %>
<div class="form-inputs">
@crosebrugh
crosebrugh / mapfile_analyze.rb
Created May 1, 2014 01:33
Analyze a .map file and output sizes of each pod, gem, the app itself, RubyMotion, iOS, as well the specific symbol sizes largest to smallest
#!/usr/bin/env ruby
# analyze a .map file and output sizes of each pod, gem, the app itself, RubyMotion, iOS
# also output functions (as per the -n option) sorted by size (high to low)
#
# change *_PREFIX constants and/or path_regexes to fit your specifics
#
# requires that RubyMotion is patched in order to generate the mapfile:
# /Library/RubyMotion2.26/lib/motion/project/builder.rb
#
@crosebrugh
crosebrugh / description...
Created August 7, 2011 17:44
rails admin performance in development with vs. without using model configs/included_models
app has 68 models of which 34 are included in rails_admin and are configured via a rails_admin block in their respective model.rb files.
the two logs attached show a 4x difference in request processing time with and without using the config/included_models functionality.
the first log traces the calls made to rails_admin config as models are loaded (look for ra_config). looks like death by a thousand cuts.
@crosebrugh
crosebrugh / gist:1128448
Created August 5, 2011 20:34
Using nested_form_for with rails_admin
class Product < ActiveRecord::Base
has_many :material_product_mappings, :dependent => :destroy, :inverse_of => :product
has_many :materials, :through => :material_product_mappings, :autosave => true
#...
rails_admin do
list do
field :material_product_mappings do
@crosebrugh
crosebrugh / application_controller.rb
Created August 4, 2011 19:36
Rails Admin config and runtime management
# add this to your ../app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_filter { |c| _admin_prolog(c) } # should be the first one!
after_filter { |c| _admin_epilog(c) } # should be the last one!
@crosebrugh
crosebrugh / runner_prof
Created January 2, 2011 19:50
Profile rails code with/without rails load time and support valgrind output
#!/usr/bin/env ruby
# code from ~/.rvm/gems/ree-1.8.7-2010.02@bench/gems/railties-3.0.3/lib/rails/commands/runner.rb
# added profiling: http://ruby-prof.rubyforge.org/
require 'optparse'
require 'rbconfig'
require 'rubygems'
require 'ruby-prof'