This file contains hidden or 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
| # CAVEAT: I have not run this code | |
| require 'rails/generators/erb/scaffold/scaffold_generator' | |
| module Erb | |
| module Generators | |
| class ScaffoldGenerator < Base | |
| protected |
This file contains hidden or 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
| TEXT = <<EOF | |
| See, the interesting thing about this text | |
| is that while it seems like the first line defines an indent | |
| it's actually the last line which has the smallest indent | |
| there are also some blank lines | |
| both with and without extra spaces in them | |
| and it just goes on and on |
This file contains hidden or 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
| TEXT = <<EOF | |
| See, the interesting thing about this text | |
| is that while it seems like the first line defines an indent | |
| it's actually the last line which has the smallest indent | |
| there are also some blank lines | |
| both with and without extra spaces in them | |
| and it just goes on and on |
This file contains hidden or 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
| TEXT = <<EOF | |
| See, the interesting thing about this text | |
| is that while it seems like the first line defines an indent | |
| it's actually the last line which has the smallest indent | |
| there are also some blank lines | |
| both with and without extra spaces in them | |
| and it just goes on and on |
This file contains hidden or 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
| TEXT = <<EOF | |
| See, the interesting thing about this text | |
| is that while it seems like the first line defines an indent | |
| it's actually the last line which has the smallest indent | |
| there are also some blank lines | |
| both with and without extra spaces in them | |
| and it just goes on and on |
This file contains hidden or 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
| TEXT = <<EOF | |
| See, the interesting thing about this text | |
| is that while it seems like the first line defines an indent | |
| it's actually the last line which has the smallest indent | |
| there are also some blank lines | |
| both with and without extra spaces in them | |
| and it just goes on and on |
This file contains hidden or 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 temporary_assign(object, attribute, new_value) | |
| previous_value = object.public_send attribute | |
| object.public_send "#{attribute}=", new_value | |
| yield | |
| ensure | |
| object.public_send "#{attribute}=", previous_value | |
| end | |
| # Example usage: | |
| # Want to debug SQL queries in tests? Log to STDOUT just for the |
This file contains hidden or 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
| require_relative 'micro_bench' | |
| # Various methods to update every value in a hash in place | |
| module HashUpdate | |
| module_function | |
| # also Hash#update | |
| def merge!(hash) | |
| hash.merge!(hash) do |key, value| | |
| value + 1 |
This file contains hidden or 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
| $ uname -a | |
| Darwin MacBook-Pro.fritz.box 14.0.0 Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64 | |
| $ ruby -v | |
| ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-darwin14.0] | |
| $ gem --version | |
| 2.4.4 |
This file contains hidden or 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
| # config/initializers/devise_safe_store_location.rb | |
| module SafeStoreLocation | |
| MAX_LOCATION_SIZE = ActionDispatch::Cookies::MAX_COOKIE_SIZE / 2 | |
| def store_location_for(resource_or_scope, location) | |
| super unless location && location.size > MAX_LOCATION_SIZE | |
| end | |
| end |