Skip to content

Instantly share code, notes, and snippets.

@fabriciofreitag
fabriciofreitag / detailed_hash_diff.rb
Last active December 21, 2021 03:13
Custom RSPec matcher for detailed hash compasion and diff
RSpec::Matchers.define :be_a_hash_like do |expected_hash|
match do |actual_hash|
matching_results = actual_hash == expected_hash
unless matching_results
system(
"git --no-pager diff $(echo '#{JSON.pretty_generate(expected_hash)}' | git hash-object -w --stdin) " +
"$(echo '#{JSON.pretty_generate(actual_hash)}' | git hash-object -w --stdin) --word-diff",
out: $stdout,
err: :out
)
@sj26
sj26 / apple_record.rb
Created June 23, 2013 04:58
How I do STI: Utilize descendent tracking and override model_name so they use the same URL helpers and parameters as their base class. Makes things like responders and form_for work as expected, while preserving things like to_partial_path.
class AppleRecord < Record
end
@goodviber
goodviber / gist:54898bc705a928a3e18c9b725d52e5ca
Created July 12, 2018 11:45
can't find executable webpack-dev-server for gem webpacker (Gem::Exception)
bundle exec rails webpacker:binstubs
@stackng
stackng / rails content_for caching
Created March 29, 2011 06:30
make action and fragment caching of rails3 compatible with content_for
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
@michaelglass
michaelglass / alerts_and_confirms.rb
Last active September 24, 2019 10:15
test alerts & confirms in poltergeist & capybara webkit
module AlertConfirmer
class << self
def reject_confirm_from &block
handle_js_modal 'confirm', false, &block
end
def accept_confirm_from &block
handle_js_modal 'confirm', true, &block
end
@pseudomuto
pseudomuto / Gemfile
Last active March 29, 2019 18:52
Blog Code: Monitoring Rails Requests
source "https://rubygems.org/"
...
...
gem "statsd-instrument"
@glebm
glebm / form_helper.js.coffee
Last active December 17, 2015 19:09
AngularJS Form Helper
angular.module('myApp').factory 'FormHelper', [->
class FormHelper
constructor: (scope, object, formName) ->
@scope = scope
@formName = formName
@object = -> @scope[object]
scope.$watch "#{formName}.$pristine", (pristine) =>
@unsaved = !pristine
@saved = false unless pristine
scope.$watch "#{formName}.$valid", (valid) =>
@gogogarrett
gogogarrett / artist_controller.rb
Last active December 17, 2015 03:38
Using Reform with a Workflow object to allow the controller to be simpler.
class ArtistsController < ApplicationController
def create
@form = create_new_form
workflow = Workflows::ArtistWorkflow.new(@form, params[:artist])
workflow.process do |obj|
return respond_with obj
end
render :new