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 / 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 Feb 4, 2019
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
@kylefox
kylefox / snippet.js
Created Dec 22, 2017
Google Analytics Ecommerce Tracking for Podia
View snippet.js
// https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce
ga('tutorTracker.require', 'ecommerce');
var price = (Coach.Conversion.revenue_cents/100).toFixed(2);
var txID = Coach.Conversion.object.order_id.toString();
ga('tutorTracker.ecommerce:addTransaction', {
'id': txID,
'affiliation':
'Podia Storefront',
@kylefox
kylefox / .profile.sh
Last active Oct 17, 2017
Dracula terminal prompt. Screenshot: http://drops.kylefox.ca/F18fuY
View .profile.sh
####################################################################################
# Dracula themed prompt
# https://github.com/dracula/terminal.app/issues/2#issuecomment-254878940
# Colors
black="\[$(tput setaf 0)\]"
red="\[$(tput setaf 1)\]"
green="\[$(tput setaf 2)\]"
yellow="\[$(tput setaf 3)\]"
blue="\[$(tput setaf 4)\]"
You can’t perform that action at this time.