Skip to content

Instantly share code, notes, and snippets.

Avatar

Kelly Sutton kellysutton

View GitHub Profile
View file.rb
<<~MSG
Squiggle
MSG
<<-MSG
No-squigs
MSG
CHONSTANT = 'CONSTANT'
@kellysutton
kellysutton / payroll_calculator_step_0.rb
Created Dec 7, 2017
Refactoring: Removing Tangled Control Coupling
View payroll_calculator_step_0.rb
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 Sep 11, 2017
Embracing Functional Programming in Ruby
View extracted_slim_taxes.rb
def taxes
PayrollCalculator::Taxes.calculate(
@payroll.only_pay_and_location_data
)
end
View bad_comment.rb
# 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
View deploy-football.js
'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
View bigger_frequent_flier_creator_spec.rb
require 'rails_helper'
RSpec.describe FrequentFlierCreator do
describe '.create' do
subject do
described_class.create(
customer,
starting_balance,
status_level
)
View bigger_user_spec.rb
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' }
@kellysutton
kellysutton / best_payroll_runner.rb
Last active Jun 12, 2017
Replace Side Effects with Return Values
View best_payroll_runner.rb
class PayrollRunner
def run!
TaxEngineWrapper.new(tax_engine).apply(commands)
computed_taxes = tax_engine.calculate_taxes
payroll.assign_taxes(computed_taxes)
end
# This is now a pure function from the view of its callers.
# Sweet!
def commands
View tax_calculation_saver.rb
class TaxCalculationSaver
def self.save_taxes!(payroll)
total_tax_amount = payroll.employees.map do |employee|
TaxCalculator.calculate(payroll, employee)
end.sum
PayrollSaver.save!(payroll, total_tax_amount: total_tax_amount)
end
end
View graphql-example.txt
POST /graphql
Content-Type: application/graphql
{
post(id: 1) {
id
title
comments {
id
body
}
You can’t perform that action at this time.