Skip to content

Instantly share code, notes, and snippets.

View JAMSUPREME's full-sized avatar

JUSTIN SPENCER JAMSUPREME

View GitHub Profile
@JAMSUPREME
JAMSUPREME / 1_big_controller.rb
Last active July 19, 2016 22:27
All the bad things
# This is an example of a controller that is doing too many things.
# It has a lot of code, and as new features get added this controller continues to bloat
class Admin::AdminController < ApplicationController
include ApprovalConcern
before_action :redirect_unless_admin
def index
render 'index'
end
@JAMSUPREME
JAMSUPREME / 1_light_controller.rb
Created July 22, 2016 15:30
Introducing improvements
# Introducing Commands
# The controller is still bloated, but we'll solve that problem later
# Here we pull all of the "business logic" into useful abstractions so the controller is easy to read and maintain
class Admin::AdminController < ApplicationController
before_action :redirect_unless_admin
def index
render 'index'
end
@JAMSUPREME
JAMSUPREME / 1_isolated_command.rb
Last active July 22, 2016 17:13
Command examples
# Common "result" returned by commands
class Result
attr_accessor :successful, :value, :msg
def successful?
@successful
end
def fail(msg)
@successful = false
@msg = msg
@JAMSUPREME
JAMSUPREME / README.md
Last active February 1, 2019 21:10
Gem and app version mgmt

Overview

The purpose of this gist is to explain some recommendations for managing versions for gems and applications. Specifically, the concepts will be the following:

  • How do we version? What are the conventions for branches and releases?
  • When do we tag? Can I tag if it is not a release?
  • When do we branch, and how long should that branch live?
  • What is upstream and what is downstream?

By the time we reach the conclusion hopefully you've discovered the answers to all of these questions!

@JAMSUPREME
JAMSUPREME / 1_hefty_model.rb
Last active September 9, 2016 13:43
Abstractions v2 stuff
# Example of a few bad things (not a comprehensive list of bad ideas)
class Event < ActiveRecord::Base
# Less OK - scopes and retrieval helpers
scope :expensive, -> { where('desired_fee > 1000') }
scope :more_expensive_than, ->(cost) { where('desired_fee > ?', cost) }
def jan_events
where("strftime('%m', tentative_date) = 01")
end
# Not OK - arcane code that probably isn't reusable
@JAMSUPREME
JAMSUPREME / hats.rb
Created September 8, 2017 18:31
Ruby private vs protected
class Hat
def explain
puts "You have a #{hat_type} hat!"
end
private
def hat_type
@JAMSUPREME
JAMSUPREME / _stable.rb
Last active October 27, 2017 22:00
pipey
module Pipey
def <<(next_pipey)
if self.result.is_a?(EmptyPipe)
next_pipey.call
else
next_pipey.call(self.result)
end
end
# For self.execute
@JAMSUPREME
JAMSUPREME / README.md
Last active March 24, 2020 16:22
CI/CD Primer

CI/CD Primer

This is designed to be a quick primer on Continuous Integration and Continuous Delivery. We will also use the term "Continuous Deployment" to mean a subset of Continuous Delivery in which you are delivering with every commit.

Acronyms and Terms

II/ID: Intermittent Integration & Delivery

For the sake of this discussion, we should have a term for "The opposite of CI/CD" and we'll call that "Intermittent Integration" and "Intermittent Delivery" so that we have a shared vocabulary.

@JAMSUPREME
JAMSUPREME / get-ec2.yaml
Last active February 11, 2024 02:14
SSM Automation
description: |-
### EC2 stopper by tag
Stop EC2 instances by tag
schemaVersion: '0.3'
mainSteps:
- name: getInstancesByTag
action: 'aws:executeAwsApi'
outputs:
- Name: InstanceIds
@JAMSUPREME
JAMSUPREME / README.md
Last active June 5, 2020 18:54
Feature toggle primer

Feature Toggle Primer

This is a quick primer on feature toggles. We'll go into:

  • What is a feature toggle?
  • Why use them?
  • How does it work?
  • How do I manage them?
  • What are the risks?