Skip to content

Instantly share code, notes, and snippets.

Avatar

Nate Hopkins hopsoft

View GitHub Profile
@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 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
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
hopsoft / example.html.erb
Created Aug 13, 2020
StimulusReflex + SlimSelect that supports DOM mutations and reentrancy triggered by reflexes
View example.html.erb
<%= f.select :country_codes, country_select_data, {}, {multiple: true, data: {
controller: "select", action: "stimulus-reflex:after@document->select#delayedSetup", reflex: "change->Adapter#assign_attributes"}} %>
@hopsoft
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
cable_ready["example"].inner_html(
selector: "#example-container",
html: ExampleController.render(
@hopsoft
hopsoft / README.md
Last active Aug 8, 2019
Create and publish an NPM package cheat sheet
View README.md
  1. Create an account on NPM https://www.npmjs.com

  2. Init your project

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

@hopsoft
hopsoft / install-ruby.sh
Created May 21, 2019
Install ruby with rbenv and jemalloc on ubuntu
View install-ruby.sh
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