Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am the-undefined on github.
  • I am undef_find (https://keybase.io/undef_find) on keybase.
  • I have a public key whose fingerprint is EB04 6762 4B5F 420E CEDA 609D DB45 DF15 B731 7152

To claim this, I am signing this object:

@the-undefined
the-undefined / rails_bug_20738.rb
Created September 12, 2015 04:03
Bug templates for Rails Engine Issue #20738 - assertions last passed on Rails Version 4.1.9
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', '4.1.9'
@the-undefined
the-undefined / failing_template_for_rails_bug_20738.rb
Last active September 13, 2015 05:45
Failing bug template for rails issue #20738
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 do
source 'https://rubygems.org'
gem 'rails', path: '.'
@the-undefined
the-undefined / index.rb
Created January 15, 2016 06:57
command pattern to build queries based on conditions
module Index
module_function
def call(parent:, search_term:, sort:, direction:)
queries = [
parent_query(parent),
search_query(search_term),
sort_query(sort, direction)
]
@the-undefined
the-undefined / index.rb
Last active January 15, 2016 07:01
Sorting, filtering, and searching using the command pattern to apply a list queries to the collection when they meet criteria for usage.
module Index
module_function
def call(parent_filter:, search_term:, sort:, direction:)
queries = [
filter_query(parent_filter),
search_query(search_term),
sort_query(sort, direction)
]
@the-undefined
the-undefined / presenter.rb
Last active January 20, 2016 15:27
What to use for the `view_context` in a presenter spec
class Presenter
def user_select_options
view_context.options_from_collection_for_select(
User.all,
:id,
:full_name
)
end
private
@the-undefined
the-undefined / presenter.rb
Last active January 20, 2016 15:28
Presenter that yield to the view for route information
class Presenter
include SortableColumns
def sortable_column_heading(text:, attr:, &block)
label = sort_link_text(text, attr)
link_params = sort_link_params(attr)
block.call(label, link_params)
end
@the-undefined
the-undefined / irb.sh
Last active January 21, 2016 09:12
Initialize is a private method, so.... put it under private
$ irb
001:0> Class.new.initialize
NoMethodError: private method `initialize' called for #<Class:0x007fc9188e3f08>
@the-undefined
the-undefined / year_query.rb
Created January 26, 2016 09:20
Make a query on the year of a date column (rails / PostgreSQL)
TimeWindow.where(%{EXTRACT(YEAR FROM start_date) = ?}, 2020)
# Example of a guard clause performing a nil check
class BlahSpeaker
has_one :audience
def speak
return if audience.nil?
audience.address('blah ' * 100)
end
end