Skip to content

Instantly share code, notes, and snippets.

@Fjan
Fjan / assert_valid_markup.rb
Created November 17, 2010 09:04
Add this to your test_helper.rb to detect HTML escaping issues
# add gem 'tidy' to your Gem file
# drop this snippet in class ActiveSupport::TestCase in test_helper.rb
# then just put "assert_valid_markup" in various places in your tests
# HTML tidy needs to be installed on your system (Snow Leopard has it installed by default)
def assert_valid_markup(markup=@response.body)
errors = []
Tidy.path='/usr/lib/libtidy.dylib' # This is were it lives by default on OS X
Tidy.open(:input_xml => true) do |tidy|
tidy.options.char_encoding = 'utf8'
@Fjan
Fjan / erubis_preprocessing.rb
Created November 20, 2010 00:19
Enable preprocessing in erubis with the <%=== %> directive
# Just drop this in the initializers directory of a rails 3 app and then use <%=== code %> in your templates
# and the code will be eval'ed at compile time, for example: <%=== link_to 'home', '/' %> actually puts
# <a href="/">home</a> in the compiled template avoiding the need to call link_to on every render
# This can provide a significant speedup of your rails views but beware that many rails helpers can produce
# different output depending on the context that is not available at compile time.
# For example, @form.text_field :name would produce different HTML if there was an error on the :name field.
# It doesn't work yet on asset tags like <%= javascript_include_tag :default %>
module ActionView
@Fjan
Fjan / gist:6642e259d5bc9e4afcb5b32eff4716cc
Created February 13, 2019 10:36
Crash starting nanoc 4.11.1 via Guard::Nanoc
11:30:40 - ERROR - Guard::Nanoc failed to achieve its <start>, exception was:
> [#b39debf6872d] NoMethodError: undefined method `<<' for nil:NilClass
> [#b39debf6872d] /Users/jmfaber/.rvm/gems/ruby-2.5.3/gems/nanoc-4.11.1/lib/nanoc/cli/commands/compile_listeners/abstract.rb:54:in `on'
> [#b39debf6872d] /Users/jmfaber/.rvm/gems/ruby-2.5.3/gems/nanoc-4.11.1/lib/nanoc/cli/commands/compile_listeners/file_action_printer.rb:13:in `start'
> [#b39debf6872d] /Users/jmfaber/.rvm/gems/ruby-2.5.3/gems/guard-nanoc-2.1.4/lib/guard/nanoc.rb:46:in `setup_listeners'
> [#b39debf6872d] /Users/jmfaber/.rvm/gems/ruby-2.5.3/gems/guard-nanoc-2.1.4/lib/guard/nanoc.rb:23:in `start'
> [#b39debf6872d] /Users/jmfaber/.rvm/gems/ruby-2.5.3/gems/guard-2.15.0/lib/guard/runner.rb:83:in `block (2 levels) in _supervise'
> [#b39debf6872d] /Users/jmfaber/.rvm/gems/ruby-2.5.3/gems/guard-2.15.0/lib/guard/ui/config.rb:62:in `block in with_progname'
> [#b39debf6872d] /Users/jmfaber/.rvm/gems/ruby-2.5.3/gems/lumberjack-1.0.13/lib/lumberjack/logger.rb
@Fjan
Fjan / gist:6cbbff28125adff6694f2df1484b776a
Created February 15, 2019 09:25
error when guard-nanoc compiles
10:09:48 - INFO - Guard is now watching at '/Users/…/Projects/blog'
/Users/…/.rvm/gems/ruby-2.5.3/gems/nanoc-4.11.1/lib/nanoc/base/services/compiler/phases/write.rb:30:in `join': No live threads left. Deadlock? (fatal)
2 threads, 2 sleeps current:0x00007ff38bc57a10 main thread:0x00007ff388c0ba10
* #<Thread:0x00007ff389085c30 sleep_forever>
rb_thread_t:0x00007ff388c0ba10 native:0x00000001141395c0 int:0
/Users/…/.rvm/gems/ruby-2.5.3/gems/nanoc-4.11.1/lib/nanoc/base/services/compiler/phases/write.rb:30:in `join'
/Users/…/.rvm/gems/ruby-2.5.3/gems/nanoc-4.11.1/lib/nanoc/base/services/compiler/phases/write.rb:30:in `join'
/Users/…/.rvm/gems/ruby-2.5.3/gems/nanoc-4.11.1/lib/nanoc/base/services/compiler/phases/write.rb:44:in `each'
/Users/…/.rvm/gems/ruby-2.5.3/gems/nanoc-4.11.1/lib/nanoc/base/services/compiler/phases/write.rb:44:in `join'
/Users/…/.rvm/gems/ruby-2.5.3/gems/nanoc-4.11.1/lib/nanoc/base/services/compiler/phases/write.rb:68:in `stop'
This file contains a UTF8 character a byte 4096 to display a problem with TTY::File.binary?
😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃