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
# Sprockets no longer creates undigested assets, so we have to emulate the old behavior to keep vendored JS libraries happy. | |
# This automatically uses the newest asset in cases where the same file exists multiple times (like with Capistrano). | |
# | |
# https://github.com/rails/sprockets-rails/issues/49 | |
# | |
# digested: 4-star-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.jpg | |
# undigested: 4-star.jpg | |
assets_without_digest = -> do | |
digest = /(-{1}[a-z0-9]{64}*\.{1}){1}/ | |
assets = Dir.glob File.join Rails.root, 'public/assets/**/*' |
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
# written for https://github.com/rails/rails/pull/30919 | |
# 1. find all gems that depend on a particular gem | |
# 2. download them all | |
# 3. search through their source! | |
auth = 'Authorization:YOUR_API_KEY' | |
gems = JSON.parse(`curl -H '#{auth}' https://rubygems.org/api/v1/gems/activerecord/reverse_dependencies.json`); nil | |
gems.size |
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
# 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'=>'???'} |
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 asks the user if they want a read-only or read-write PSQL session. PSQL | |
# provides `\prompt`, but that doesn't provide a way to conditionally prompt | |
# based on whether it was being run interactively, or from bash-completion. | |
# | |
# Save this file to ~/.psqlprompt and add the below to ~/.psqlrc: | |
# | |
# \set read_only `bash ~/.psqlprompt` | |
# set default_transaction_read_only = :read_only; | |
# | |
function psql_prompt() { |
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
,.---._ | |
,,,, / `, | |
\\\\ / '\_ ; | |
|||| /\/``-.__\;' | |
::::/\/_ | |
{{`-.__.-'(`(^^(^^^(^ 9 `.=========' | |
{{{{{{ { ( ( ( ( (-----:= | |
{{.-'~~'-.(,(,,(,,,(__6_.'=========. | |
::::\/\ | |
|||| \/\ ,-'/, |
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 |
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
begin | |
# your code | |
rescue | |
tries ||= 0 | |
(tries += 1) < 3 ? retry : raise | |
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
# 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
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| |