Skip to content

Instantly share code, notes, and snippets.

Avatar

Eliot Sykes eliotsykes

View GitHub Profile
@eliotsykes
eliotsykes / erb_parser.rb
Last active Dec 12, 2019
Parse ERB template ruby output expressions (using the temple gem)
View erb_parser.rb
# An example to extract the ruby output expressions from an ERB template using the temple gem:
#
# 1. Install 'temple' gem https://github.com/judofyr/temple
# 2. Require this erb_parser.rb file and run:
#
# ErbParser.call
#
# Dynamics will be:
# [[[:dynamic, " @page.title "],
# [:dynamic, " an_image "],
@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
Last active Oct 21, 2019
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?
ActiveSupport::Deprecation.warn(
"Versioned migrations are supported in your Rails version, you can delete file: #{__FILE__}"
)
return
@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 8, 2020
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"
)
You can’t perform that action at this time.