This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def StandardError *names | |
names.each{ |n| const_set n, Class.new(StandardError) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'rails', '3.2.13' | |
gem 'ransack' | |
require 'rails/all' | |
require 'ransack' | |
ActiveRecord::Base.establish_connection adapter: 'sqlite3', | |
database: ':memory:' | |
ActiveRecord::Schema.define do | |
create_table :users, force: true do |t| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This class lets you evaluate any block | |
# and record any methods it calls. | |
# | |
# Wire.listen { foo + bar } | |
# # => [:foo, :bar, :+] | |
# | |
# You're also able to chain method calls! | |
# | |
# Wire.listen { foo + bar.baz } | |
# # => [:foo, :bar, :baz, :+] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def arbre(&block) | |
Arbre::Context.new(&block).to_s | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location ~* "-[a-z0-9]{32}\.(png|gif|jpg|jpeg|css|js)$" { | |
expires max; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The Active Admin equivalent of putting this in your application layout: | |
# <head> | |
# <%= cloudinary_js_config %> | |
# </head> | |
module ActiveAdmin | |
module Views | |
module Pages | |
class Base < Arbre::HTML::Document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SASS variable overrides must be declared before loading up Active Admin's styles. | |
// | |
// To view the variables that Active Admin provides, take a look at | |
// `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the | |
// Active Admin source. | |
// | |
// For example, to change the sidebar width: | |
// $sidebar-width: 242px; | |
$primary-color: dynamic_active_admin_color(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < ActiveRecord::Base | |
before_save :strip_empty_strings | |
def strip_empty_strings | |
self.class.columns.select{ |c| c.type == :string }.each do |c| | |
send "#{c.name}=", send(c.name).try(:strip).presence # sets to nil if completely empty | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Example | |
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# class SomethingYouDontControl | |
# def! :something_you_expect_not_to_exist do |arg| | |
# arg + 1 | |
# end | |
# end | |
# | |
# I wanted to provide built-in memoization, but it's not currenlty possible | |
# while preserving strict argument checking. https://bugs.ruby-lang.org/issues/9777 | |
# | |
module Kernel |