Skip to content

Instantly share code, notes, and snippets.

View kylefox's full-sized avatar

Kyle Fox kylefox

View GitHub Profile
kylefox / context_for_sign_in_after_confirmation.rb
Created March 24, 2020 18:08
Rails controller concern for automatically signing in Devise users after they confirm their email address.
shared_context 'sign in after confirmation' do |resource_name:|
before do
@request.env['devise.mapping'] = Devise.mappings[resource_name]
shared_examples 'failed confirmation' do |error:|
it { have_http_status :ok }
it { render_template 'devise/confirmations/new' }
it "has errors on @#{resource_name}" do
kylefox / heroku-16.txt
Created February 20, 2020 23:10
ImageMagick capabilities: iMac vs heroku-16 vs heroku18
Format Module Mode Description
3FR DNG r-- Hasselblad CFV/H3D39II
AAI* AAI rw+ AAI Dune image
AI PDF rw- Adobe Illustrator CS2
ART* ART rw- PFS: 1st Publisher Clip Art
ARW DNG r-- Sony Alpha Raw Image Format
AVI MPEG r-- Microsoft Audio/Visual Interleaved
AVS* AVS rw+ AVS X image
BGR* BGR rw+ Raw blue, green, and red samples
kylefox / find_unused_helpers.rb
Created March 28, 2019 21:49 — forked from kennethkalmer/find_unused_helpers.rb
Find unused helpers in a Rails app
#!/usr/bin/env ruby
# Shotgun approach (read: slow and dirty hack) to help find unused helpers in a Rails application
start =
# Build an array of filename globs to process.
# Only search file types that might use or define a helper.
extensions = %w[rb js haml erb jbuilder].map { |ext| "app/**/**/*.#{ext}" }
"object": {
"id": "sub_Ees5zGujQ85DxG",
"object": "subscription",
"application_fee_percent": null,
"billing": "charge_automatically",
"billing_cycle_anchor": 1554603702,
"billing_thresholds": null,
"cancel_at": null,
"cancel_at_period_end": false,
kylefox / 001_add_record_uuid_to_active_storage_attachments.rb
Last active January 12, 2022 21:52
Migrations that make ActiveStorage attachments work with UUID primary keys.
class AddRecordUuidToActiveStorageAttachments < ActiveRecord::Migration[5.2]
def change
# After applying this migration, you'll need to manually go through your
# attachments and populate the new `record_uuid` column.
# If you're unable to do this, you'll probably have to delete all your attachments.
# You've pretty much got useless garbage data if that's the case :(
add_column :active_storage_attachments, :record_uuid, :uuid
kylefox / .gitignore
Created December 9, 2018 02:33 — forked from jbergler/.gitignore
Acestream on Mac
kylefox / attachment-utils.js
Created October 17, 2018 15:58
Convert Base64 data URLs to File objects for Trix attachments
window.AttachmentUtils = (function() {
var BASE64_MARKER = ';base64,';
var Utils = {
// Takes a file size (in bytes) and returns a human-friendly string representation.
humanFileSize: function(size) {
if(size < 1) return "0 bytes";
import { Controller } from "stimulus"
class PageSectionFormController extends Controller {
initialize() {
this.sectionID = parseInt(this.element.getAttribute("data-page-section-id"))
this.preview = this.application.getControllerForElementAndIdentifier(
import Customer from 'Customer';
import API from 'API';
import Spies from 'Spies';
beforeEach(() => {
afterEach(() => {
kylefox / validate_join_model.rb
Last active February 7, 2018 21:53
When two models (Project, Employee) belong to a parent (Company) and are joined through a join model (ProjectEmployee), what's the best way to ensure that the two instances being joined belong to the same parent? Ex: how do you ensure the joined project and employee belong to the same company?
class Company < ApplicationRecord
has_many :employees
has_many :projects
class Project < ApplicationRecord
belongs_to :company
has_many :project_employees