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
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 / liquid-mode.js
Created Nov 11, 2011
Liquid syntax highlighting for CodeMirror.
View liquid-mode.js
/*
This overlay provides a 'liquid' mode to the excellent CodeMirror editor (http://codemirror.net/).
Add something like this to your CSS:
.cm-liquid-tag {
color: #32273f;
background: #ead9ff;
}
.cm-liquid-variable {
@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)\]"
@kylefox
kylefox / stripe_subscription_coupons.rb
Created Jun 8, 2017
Inconsistent behavior between previewing subscription changes and saving subscription changes when removing subscription coupons.
View stripe_subscription_coupons.rb
# == Let's work with a subscription that has an existing coupon ==
subscription = Stripe::Subscription.retrieve('sub_ABC123')
subscription.discount.coupon.id # => "early-upgrade"
# Preview invoice keeps the coupon, as expected.
Stripe::Invoice.upcoming(
customer: subscription.customer,
subscription: subscription.id
).discount.coupon.id # => "early-upgrade"
View jquery.shake.js
jQuery.fn.shake = function(intShakes, intDistance, intDuration) {
this.each(function() {
$(this).css({position:"relative"});
for (var x=1; x<=intShakes; x++) {
$(this).animate({left:(intDistance*-1)}, (((intDuration/intShakes)/4)), "swing")
.animate({left:intDistance}, ((intDuration/intShakes)/2), "swing")
.animate({left:0}, (((intDuration/intShakes)/4)), "swing");
}
});
return this;
View spacing-scale.scss
$spacing-scale: (
0,
0.3125rem,
0.625rem,
0.9375rem,
1.25rem,
1.5625rem,
3.125rem,
4.688rem,
6.25rem,
View confirm.js
$(document).on('click', '.modal button.yes', function() {
console.log('You clicked yes!');
$.modal.close();
});
$(document).on('click', '.modal button.no', function() {
console.log('You clicked no!');
$.modal.close();
});
You can’t perform that action at this time.