Skip to content

Instantly share code, notes, and snippets.

Avatar

Tyler Rick TylerRick

  • USA
View GitHub Profile
@TylerRick
TylerRick / content_for_inside_cache.rb
Last active Jun 11, 2020 — forked from stackng/rails content_for caching
Add ability to use content_for within a fragment cache block (Rails 5.2)
View content_for_inside_cache.rb
# config/initializers/content_for_inside_cache.rb
module AbstractController
class Base
attr_internal :cached_content_for
end
module Caching
# actionpack/lib/action_controller/caching/fragments.rb
module Fragments
@TylerRick
TylerRick / detailed_hash_diff.rb
Last active May 26, 2020 — forked from fabriciofreitag/detailed_hash_diff.rb
Custom RSPec matcher for detailed hash compasion and diff
View detailed_hash_diff.rb
require 'facets/hash/recurse'
# Usage:
# expect(actual).to match_hash(expected)
#
RSpec::Matchers.define :match_hash do |expected|
match do |actual|
# Sort hashes before comparing so that the diff only shows actual changes between keys and
# values.
actual = actual.recurse {|h| h.sort_by {|k,v| k.to_s }.to_h }
@TylerRick
TylerRick / .gitignore
Created Jan 19, 2018 — forked from ZJONSSON/force_labels.js
Automatic floating labels using d3 force-layout
View .gitignore
d3-force-labels.js
@TylerRick
TylerRick / main.rb
Created Jan 16, 2018 — forked from coorasse/main.rb
CanCanCan Issue
View main.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.1.4'
View spree_export_import.rake
namespace :spree do
desc "Export Products to CSV File"
task :export_products => :environment do
require 'csv'
products = Product.where(:deleted_at => nil).all
puts "Exporting to #{RAILS_ROOT}/products.csv"
CSV.open("#{RAILS_ROOT}/products.csv", "w") do |csv|
csv << [