Skip to content

Instantly share code, notes, and snippets.


Nate Hopkins hopsoft

View GitHub Profile
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
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

Keybase proof

I hereby claim:

  • I am hopsoft on github.
  • I am hopsoft ( on keybase.
  • I have a public key ASCUrC24sEgI229zKeQ2yFjvNYN6NEHRunnG0LMQD050Iwo

To claim this, I am signing this object:

hopsoft /
Last active May 27, 2021
Docker proxyconnect connection refused error

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

This worked for me on an Apple M1.


docker pull docker/getting-started
Error response from daemon: Get proxyconnect tcp: dial tcp connect: connection refused
hopsoft / Dockerfile
Last active Sep 18, 2021
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 \
hopsoft / _example.html.erb
Created Feb 25, 2021
Stimulus Controller for slim-select that supports AJAX content
View _example.html.erb
<%= select_tag column_name,
options_for_select(...), {
multiple: true,
placeholder: "Select multiple...",
data: {
controller: "select",
action: "stimulus-reflex:after@document->select#delayedSetup",
options_url: typeahead_path(...)
}} %>
hopsoft / example.html.erb
Created Aug 13, 2020
StimulusReflex + SlimSelect that supports DOM mutations and reentrancy triggered by reflexes
View example.html.erb
<%= :country_codes, country_select_data, {}, {multiple: true, data: {
controller: "select", action: "stimulus-reflex:after@document->select#delayedSetup", reflex: "change->Adapter#assign_attributes"}} %>
hopsoft / examples_reflex.rb
Last active May 17, 2020
Surgical DOM Updates with StimulusReflex
View examples_reflex.rb
# app/reflexes/examples_reflex.rb
class ExamplesReflex < ApplicationReflex
include CableReady::Broadcaster
before_reflex :surgical_update, only: [:noop]
def surgical_update
selector: "#example-container",
html: ExampleController.render(
hopsoft /
Last active Aug 8, 2019
Create and publish an NPM package cheat sheet
  1. Create an account on NPM

  2. Init your project

    mkdir example
    cd example
    yarn init
  3. Create a JavaScript file

hopsoft /
Created May 21, 2019
Install ruby with rbenv and jemalloc on ubuntu
sudo apt-get update
sudo apt-get install libjemalloc-dev
RUBY_CONFIGURE_OPTS='--with-jemalloc' rbenv install 2.6.3
# test (look for jemalloc warnings)
MALLOC_CONF=invalid_flag:foo ruby -v