Skip to content

Instantly share code, notes, and snippets.

@kellysutton
kellysutton / 01-react-inline.html.erb
Created December 23, 2020 14:38
Sketch of React rendering Rails ERB
<main>
<% @posts.each do |post| %>
<!-- Under the hood, we find the right file in webpack and attach the expected object to window.Post -->
<Post
title={post.title}
description={post.description}
/>
<% end %>
</main>
@kellysutton
kellysutton / Gemfile
Last active December 16, 2020 13:13
Web Push Package in Rails.
# The rubygems.org grocer-pushpackager needs a bump. Ride that <del>dragon</del> master.
gem 'grocer-pushpackager', git: 'git@github.com:layervault/grocer-pushpackager.git'
# Houston will help us send the notifications themselves.
gem 'houston'
<<~MSG
Squiggle
MSG
<<-MSG
No-squigs
MSG
CHONSTANT = 'CONSTANT'
@kellysutton
kellysutton / payroll_calculator_step_0.rb
Created December 7, 2017 16:51
Refactoring: Removing Tangled Control Coupling
class PayrollCalculator
def initialize(payroll, options = {})
@payroll = payroll
@skip_benefits = options[:skip_benefits]
@skip_taxes = options[:skip_taxes]
@skip_donations = options[:skip_donations]
end
def calculate
if !@skip_benefits
@kellysutton
kellysutton / extracted_slim_taxes.rb
Created September 11, 2017 22:58
Embracing Functional Programming in Ruby
def taxes
PayrollCalculator::Taxes.calculate(
@payroll.only_pay_and_location_data
)
end
@kellysutton
kellysutton / bad_comment.rb
Last active August 31, 2017 03:42
Comment Drift
# This methods adds 2 numbers together
# @param x [Number] The first number that you would
# like to add
# @param y [Number] The number you would
# like to add to the first number
# @return [Number] The result of adding `x` and `y` together
def add(x, y)
x + y
end
@kellysutton
kellysutton / gist:2050328
Created March 16, 2012 14:35
ActionMailer assets with hash-based asset hosting

In config/production.rb

  config.action_mailer.asset_host = "https://123123.cloudfront.net"

In config/initializers/mail_image_tag.rb

module ActionView
'use strict';
const http = require('https');
// Forward the button press onto our Heroku app
// as a POST request with a JSON body.
exports.handler = (event, context, callback) => {
const params = {
serialNumber: event.serialNumber,
event: event
require 'rails_helper'
RSpec.describe FrequentFlierCreator do
describe '.create' do
subject do
described_class.create(
customer,
starting_balance,
status_level
)
@kellysutton
kellysutton / bigger_user_spec.rb
Last active June 16, 2017 15:24
Count the Contexts
RSpec.describe User do
describe '#full_name' do
subject do
described_class.new(first_name, middle_name, last_name)
end
let(:first_name) { 'Roy' }
let(:last_name) { 'Biv' }
context 'middle name is given' do
let(:middle_name) { 'Gee' }