Skip to content

Instantly share code, notes, and snippets.

Avatar

Nate Hopkins hopsoft

View GitHub Profile
@hopsoft
hopsoft / README.md
Last active Jul 11, 2022
Smart Heroku Review Apps managed by GitHub Actions
View README.md

Smart Heroku Review Apps managed by GitHub Actions

This gist aims to provide a simple solution for managing Heroku Review Apps with GitHub Actions due to the security incident that continues to disrupt Heroku's GitHub integration. Watch the demo to learn more.

Demo Video

.github
├── workflows
│   ├── heroku_review_app_create.yml
@hopsoft
hopsoft / README.md
Last active Aug 8, 2022
Heroku Review Apps managed by GitHub Actions
View README.md

Heroku Review Apps managed by GitHub Actions

This gist aims to provide a simple solution for managing Heroku Review Apps with GitHub Actions due to the security incident that continues to disrupt Heroku's GitHub integration.

.github
├── workflows
│   ├── heroku_review_app_create.yml
│   └── heroku_review_app_destroy.yml
@hopsoft
hopsoft / application_reflex.rb
Created Dec 1, 2021
ApplicationReflex setting ActiveSupport::CurrentAttributes via lifecycle callbacks
View application_reflex.rb
# frozen_string_literal: true
class ApplicationReflex < StimulusReflex::Reflex
# Put application-wide Reflex behavior and callbacks in this file.
#
# Example:
#
# # If your ActionCable connection is: `identified_by :current_user`
# delegate :current_user, to: :connection
#
@hopsoft
hopsoft / broadcastable.rb
Created Nov 22, 2021
Broadcastable model concern/mixin
View broadcastable.rb
# frozen_string_literal: true
module Broadcastable
extend ActiveSupport::Concern
def prepend_operation(options = {})
operation = {html: ApplicationController.render(partial: to_partial_path, locals: locals)}
operation.merge options
end
@hopsoft
hopsoft / README.md
Last active Nov 3, 2021
Descriptive messages with basic asserts
View README.md

Descriptive messages with basic asserts

What if I told you that it's possible to get helpful failure messages from basic asserts using idiomatic equality == checks? No DSLs in sight.

This is a proof of concept to demonstrate that it's possible... mostly to satisfy my own curiosity. The concepts here could theoretically be expanded to provide a useful extension to existing testing frameworks or perhaps lay a foundation for an entirely new one.

This experiment created with Ruby 3.0.1. Note to self: There's probably a way to do this with TracePoint instead of monkey patching but I couldn't figure out how to get a reference to the passed variable being compared.

Examples:

@hopsoft
hopsoft / broadcastable.rb
Created Aug 27, 2021
Broadcastable model concern for CableReady/CableCar
View broadcastable.rb
# frozen_string_literal: true
module Broadcastable
extend ActiveSupport::Concern
def prepend_operation(options = {})
operation = {html: ApplicationController.render(partial: to_partial_path, locals: locals)}
operation.merge options
end
@hopsoft
hopsoft / example_spec.rb
Created Jun 30, 2021
Asserts with equality check and detailed expected/got failure messages
View example_spec.rb
module ThreadAwareEquality
refine BasicObject do
alias_method :original_equals, :==
def ==(other)
Thread.current[:actual] = self
Thread.current[:expected] = other
original_equals other
end
end
View keybase.md

Keybase proof

I hereby claim:

  • I am hopsoft on github.
  • I am hopsoft (https://keybase.io/hopsoft) on keybase.
  • I have a public key ASCUrC24sEgI229zKeQ2yFjvNYN6NEHRunnG0LMQD050Iwo

To claim this, I am signing this object:

@hopsoft
hopsoft / README.md
Last active May 27, 2021
Docker proxyconnect connection refused error
View README.md

How to "fix" Docker's proxyconnect connection refused error

This worked for me on an Apple M1.

Problem

docker pull docker/getting-started
Error response from daemon: Get https://registry-1.docker.io/v2/: proxyconnect tcp: dial tcp 192.168.64.1:3128: connect: connection refused
@hopsoft
hopsoft / Dockerfile
Last active May 22, 2022
Dockerize your Rails app
View Dockerfile
FROM ruby:3.0-alpine
RUN apk add --no-cache --update \
ack \
bash \
build-base \
curl \
git \
htop \
less \