Skip to content

Instantly share code, notes, and snippets.

Hopsoft hopsoft

Block or report user

Report or block hopsoft

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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
hopsoft /
Last active Apr 19, 2019
Query the recommended column order for PostgreSQL tables
View gist:4944d9c9ef85c5adfa29034b90a86222
brew link libffi --force
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
gem install ffi
hopsoft /
Last active Apr 19, 2019
Eliminate unauthorized ActionCable connection attempts


Unauthorized ActionCable connection attempts that produce the following

Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for at 2018-11-16 08:32:24 -0700
An unauthorized connection attempt was rejected
hopsoft / prefetch.js
Last active Mar 27, 2020
Turbolinks Prefetching
View prefetch.js
const hoverTime = 400
const fetchers = {}
const doc = document.implementation.createHTMLDocument('prefetch')
function fetchPage (url, success) {
const xhr = new XMLHttpRequest()'GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.setRequestHeader('Accept', 'text/html')
xhr.onreadystatechange = () => {
hopsoft / assignable_job.rb
Last active May 15, 2018
Arel subquery condition
View assignable_job.rb
class AssignableJob < ApplicationRecord
has_many :assignments, as: :record, dependent: :destroy
scope :assigned, -> do
subquery = Assignment.where(record_type: name).where(Assignment.arel_table[:record_id].eq(arel_table[:id])).select(Assignment.arel_table[].count)
where "(#{subquery.to_sql}) > 0" # TODO: move to Arel & remove string interpolation
hopsoft / users.yml
Last active Feb 9, 2018
User Fixture
View users.yml
<% 100.times do |i| %>
user_<%= i %>:
id: <%= SecureRandom.uuid %>
first_name: <%= Faker::Name.first_name %>
last_name: <%= Faker::Name.last_name %>
email: <%= %>
phone: <%= Faker::PhoneNumber.cell_phone %>
<% end %>
hopsoft / action_controller_parameters.rb
Created Jan 19, 2018
Manually & Recursively Filter Rails Params
View action_controller_parameters.rb
module ActionControllerParameters
def filtered
filter_hash self.to_unsafe_hash
def filterer
@filterer ||=
hopsoft / model_supports_bulk_updates.rb
Last active Apr 19, 2019
ActiveRecord Bulk / Batch Update
View model_supports_bulk_updates.rb
# frozen_string_literal: true
module ModelSupportsBulkUpdates
extend ActiveSupport::Concern
module ClassMethods
# Performs a bulk update with an efficient single query for all the records in the list.
# Note that the records are not reloaded form the database.
# This means that ActiveRecord will still see these records as dirty after the bulk_update.
def bulk_update(records)
You can’t perform that action at this time.