Skip to content

Instantly share code, notes, and snippets.

Kyle Fox kylefox

Block or report user

Report or block kylefox

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
@kylefox
kylefox / context_for_sign_in_after_confirmation.rb
Created Mar 24, 2020
Rails controller concern for automatically signing in Devise users after they confirm their email address.
View context_for_sign_in_after_confirmation.rb
shared_context 'sign in after confirmation' do |resource_name:|
before do
@request.env['devise.mapping'] = Devise.mappings[resource_name]
end
shared_examples 'failed confirmation' do |error:|
it { is_expected.to have_http_status :ok }
it { is_expected.to render_template 'devise/confirmations/new' }
it "has errors on @#{resource_name}" do
@kylefox
kylefox / heroku-16.txt
Created Feb 20, 2020
ImageMagick capabilities: iMac vs heroku-16 vs heroku18
View heroku-16.txt
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
kylefox / find_unused_helpers.rb
Created Mar 28, 2019 — forked from kennethkalmer/find_unused_helpers.rb
Find unused helpers in a Rails app
View find_unused_helpers.rb
#!/usr/bin/env ruby
#
# Shotgun approach (read: slow and dirty hack) to help find unused helpers in a Rails application
#
start = Time.now
# 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}" }
View subscription.json
{
"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
kylefox / 001_add_record_uuid_to_active_storage_attachments.rb
Last active Jan 13, 2020
Migrations that make ActiveStorage attachments work with UUID primary keys. https://github.com/rails/rails/pull/32466
View 001_add_record_uuid_to_active_storage_attachments.rb
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
end
end
@kylefox
kylefox / .gitignore
Created Dec 9, 2018 — forked from jbergler/.gitignore
Acestream on Mac
@kylefox
kylefox / attachment-utils.js
Created Oct 17, 2018
Convert Base64 data URLs to File objects for Trix attachments
View attachment-utils.js
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";
// http://stackoverflow.com/a/20732091
View page_section_form_controller.js
import { Controller } from "stimulus"
class PageSectionFormController extends Controller {
initialize() {
this.sectionID = parseInt(this.element.getAttribute("data-page-section-id"))
this.preview = this.application.getControllerForElementAndIdentifier(
document.querySelector(`[data-controller="rich-text-preview"][data-page-section-id="${this.sectionID}"]`),
'rich-text-preview',
);
View customer_spec.js
import Customer from 'Customer';
import API from 'API';
import Spies from 'Spies';
beforeEach(() => {
Spies.start();
});
afterEach(() => {
Spies.stop();
@kylefox
kylefox / validate_join_model.rb
Last active Feb 7, 2018
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?
View validate_join_model.rb
class Company < ApplicationRecord
has_many :employees
has_many :projects
end
class Project < ApplicationRecord
belongs_to :company
has_many :project_employees
You can’t perform that action at this time.