Skip to content

Instantly share code, notes, and snippets.

Eliot Sykes eliotsykes

Block or report user

Report or block eliotsykes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@eliotsykes
eliotsykes / ar_base_configurations_usage.md
Last active Aug 15, 2018
ActiveRecord::Base.configurations usage
View ar_base_configurations_usage.md

Usage of ActiveRecord::Base.configurations with surrounding lines to help answer https://twitter.com/eileencodes/status/1028624971675979777

Source: ~200 open source Rails apps and engines https://github.com/eliotsykes/real-world-rails

~/dev/real-world-rails (master)
$ ag --ruby -C 15 'ActiveRecord::Base.config'
apps/alaveteli/config/initializers/alaveteli.rb:60-require 'user_spam_scorer'
apps/alaveteli/config/initializers/alaveteli.rb:61-require 'alaveteli_rate_limiter'
apps/alaveteli/config/initializers/alaveteli.rb:62-require 'alaveteli_spam_term_checker'
@eliotsykes
eliotsykes / versioned_migrations.rb
Created May 25, 2018
Versioned migrations support in Rails 4.2
View versioned_migrations.rb
# This file lives at config/initializers/versioned_migrations.rb
def supports_versioned_migrations?
Rails::VERSION::MAJOR >= 5
end
if supports_versioned_migrations?
puts "-"*80
puts "Versioned migrations are supported in your Rails version, you can safely delete file:"
puts __FILE__
puts "-"*80
@eliotsykes
eliotsykes / os_rails_apps_with_skylight_gem.md
Created Jan 22, 2018
Some open source Rails apps that use/used Skylight gem
View os_rails_apps_with_skylight_gem.md

Some open source Rails apps that use/used Skylight gem

Search done on collected Rails codebases at https://github.com/eliotsykes/real-world-rails/

$ ag -G Gemfile skylight
apps/adopt-a-hydrant/Gemfile.lock
181:    skylight (0.10.6)
233:  skylight
@eliotsykes
eliotsykes / check_rollbar.rake
Last active Jul 27, 2017
Check Rollbar is reporting errors raised in rake tasks
View check_rollbar.rake
# Create file at lib/tasks/check_rollbar.rake
require 'securerandom'
# Run this with `heroku run rake check_rollbar`
desc "Check Rollbar reports errors raised in Rake tasks"
task check_rollbar: :environment do
unique_msg = "Hello from rake check_rollbar (unique identifier: #{SecureRandom.hex})"
begin
raise ActiveRecord::RecordNotFound, unique_msg
View angularjs-rails-apps.md

Open Source AngularJS Rails Apps

Expect some false positives here, but hopefully most of these are open source Rails apps that use (or once used) AngularJS.

If you'd like to help update the list, please comment below with any of these apps you discover do not use AngularJS and include my username (@eliotsykes) in your message.

Confirmed using AngularJS

View original_bracket_validator.rb
require 'set'
def is_valid(code)
openers_to_closers = {
'(' => ')',
'{' => '}',
'[' => ']'
}
openers = Set.new(openers_to_closers.keys.to_set)
@eliotsykes
eliotsykes / sidekiq_rails_apps.md
Created Apr 28, 2017
Open Source Rails apps using Sidekiq
View sidekiq_rails_apps.md
@eliotsykes
eliotsykes / multiline_expressions_in_ruby.md
Last active Sep 1, 2018
Multiline expressions in Ruby
View multiline_expressions_in_ruby.md

How to break long lines up in Ruby

This page lists the options for breaking single-line expressions into multiple lines in Ruby.

Developers and teams need to come to their own decisions about which guideline(s) they prefer (preferences below are just my personal choices and I encourage you to disregard them).

# With trailing parens
x = [1, 2, 3].join(
  '-'
@eliotsykes
eliotsykes / extract_custom_matcher.md
Last active Mar 31, 2017
Extract Custom RSpec Matcher
View extract_custom_matcher.md

Original

expect(page).to have_css("h3", text: "Expected text here...")
click_button "Submit"
expect(page).to(
  have_css("h3", text: "Expected text here..."),
  "stay on page on invalid form submit"
)
@eliotsykes
eliotsykes / class_variables.rb
Last active Mar 16, 2017
Class Variables shared by all instances
View class_variables.rb
# 1. Create a file class_variables.rb with the contents below
# 2. Run the file with `ruby class_variables.rb` in Terminal
# 3. Review the output and the code below and explore why:
#
# - the class variable @@total_results_count correctly counts the number
# of all Result instances.
#
# - the class variable @@errors does not track the errors for
# a single instance, instead it wrongly tracks *all* errors
# for all Result instances.
You can’t perform that action at this time.