Skip to content

Instantly share code, notes, and snippets.

View eliotsykes's full-sized avatar

Eliot Sykes eliotsykes

View GitHub Profile
@eliotsykes
eliotsykes / index.html.erb
Last active July 28, 2023 16:29
Testing Rails: defining temporary controller, view and route in feature spec
<% # This file lives at spec/features/views/index.html.erb %>
<h1>My Temporary Page</h1>
@eliotsykes
eliotsykes / active_job_deserializer_extension.rb
Created September 21, 2022 07:59
ActiveJob compatibility for Rails 5.2 -> 6.0 upgrade
# File: config/initializers/active_job_deserializer_extension.rb
return unless (VERSION::MAJOR == 5 && VERSION::MINOR == 2)
require "active_job/arguments"
module ActiveJobDeserializerExtension
# This copies the hash deserialization from activejob 6.0 so activejob 5.2 is forwards compatible, it can run jobs
# with hash args that were serialized by activejob 6.0. This allows Rails 5.2 and 6.0 to run within the same app
# during the upgrade period.
def deserialize_hash(serialized_hash)
@eliotsykes
eliotsykes / jobs.rb
Last active December 21, 2020 15:58 — forked from webmat/dashboards.rb
Active Admin for DelayedJob
# Place this file in app/admin/jobs.rb
ActiveAdmin.register Delayed::Job, as: 'DelayedJob' do
# menu parent: 'Some Existing Menu' # optional
permit_params :priority, :queue, :run_at
actions :index, :show, :edit, :update, :destroy
config.batch_actions = true
index do
@eliotsykes
eliotsykes / erb_parser.rb
Last active December 12, 2019 11:18
Parse ERB template ruby output expressions (using the temple gem)
# 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 August 15, 2018 05:56
ActiveRecord::Base.configurations usage

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 October 21, 2019 13:04
Versioned migrations support in Rails 4.2
# 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 January 22, 2018 19:55
Some open source Rails apps that use/used Skylight gem
@eliotsykes
eliotsykes / check_rollbar.rake
Last active July 27, 2017 16:09
Check Rollbar is reporting errors raised in rake tasks
# 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
@eliotsykes
eliotsykes / angularjs-rails-apps.md
Last active August 1, 2017 18:17
AngularJS Rails apps

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

@eliotsykes
eliotsykes / original_bracket_validator.rb
Last active July 12, 2017 08:59
Ruby Bracket Validator
require 'set'
def is_valid(code)
openers_to_closers = {
'(' => ')',
'{' => '}',
'[' => ']'
}
openers = Set.new(openers_to_closers.keys.to_set)