Skip to content

Instantly share code, notes, and snippets.

View ryenski's full-sized avatar
🎯
Focusing

Ryan Heneise ryenski

🎯
Focusing
View GitHub Profile
@ryenski
ryenski / activity.rb
Last active December 5, 2018 12:36
Audit trail activity tracker, similar to PaperTrail, but without undo.
# == Schema Information
#
# Table name: activities
#
# id :uuid not null, primary key
# user_id :uuid
# tenant_id :uuid
# trackable_type :string
# trackable_id :uuid
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :authenticate_user!
include CurrentTenant
end
@ryenski
ryenski / _row.html.erb
Created January 26, 2018 21:55
Clickable table rows with Stimulus.js
<tr data-action="click->table#click" data-controller="table">
<td> 2018-01-11 </td>
<td>
<a data-target="table.url" href="/invoices/1">$7,000.00</a>
</td>
</tr>
@lawso017
lawso017 / mentionable_trix.js.coffee
Last active July 6, 2022 10:13
@mentions with trix-editor and selectize.js
window.addEventListener "trix-initialize", (e) =>
Utility.TrixMentions.prepare($(e.target))
@niksumeiko
niksumeiko / disable-html-form-input-autocomplete-autofill.md
Last active July 10, 2024 12:10
Disable HTML form input autocomplete and autofill

Disable HTML Form Input Autocomplete and Autofill

  1. Add autocomplete="off" onto <form> element;
  2. Add hidden <input> with autocomplete="false" as a first children element of the form.
<form autocomplete="off" method="post" action="">
    <input autocomplete="false" name="hidden" type="text" style="display:none;">
    ...
@benschwarz
benschwarz / README.md
Created October 14, 2015 14:56
Intercom CSP (Content security policy)

You'll need to add a whole slew of hosts for intercom if you've got CSP in place (which you should).

Heres what you'll need to add:

connect-src: https://api-ping.intercom.io https://nexus-websocket-a.intercom.io https://nexus-websocket-b.intercom.io wss://nexus-websocket-a.intercom.io wss://nexus-websocket-b.intercom.io https://api-iam.intercom.io 
script-src: https://widget.intercom.io https://js.intercomcdn.com
image-src: https://js.intercomcdn.com
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active May 28, 2024 17:41
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@endymion
endymion / contact.rb
Last active February 18, 2024 22:49
Example of integrating a Ruby on Rails app with Zapier using the REST hooks pattern. With support for triggering the REST hooks from Resque background jobs.
class Contact < ActiveRecord::Base
...
def after_create
if Hook.hooks_exist?('new_contact', self)
Resque.enqueue(Hook, self.class.name, self.id)
# To trigger directly without Resque: Hook.trigger('new_contact', self)
end
end
@turadg
turadg / subdomains.rb
Last active January 21, 2024 19:45 — forked from rtekie/subdomains.rb
Drop-in utility to test your app subdomains with Capybara, Rspec, and a Javascript driver (Poltergeist, Webkit, or Selenium)
# Support for Rspec / Capybara subdomain integration testing
# Make sure this file is required by spec_helper.rb
# (e.g. save as spec/support/subdomains.rb)
def switch_to_subdomain(subdomain)
# lvh.me always resolves to 127.0.0.1
hostname = subdomain ? "#{subdomain}.lvh.me" : "lvh.me"
Capybara.app_host = "http://#{hostname}"
end
@cpuguy83
cpuguy83 / loading_spinner.coffee
Last active August 30, 2020 13:49
Simple loading spinner for long requests with turbolinks and bootstrap modal
@PageSpinner =
spin: (ms=500)->
@spinner = setTimeout( (=> @add_spinner()), ms)
$(document).on 'page:change', =>
@remove_spinner()
spinner_html: '
<div class="modal hide fade" id="page-spinner">
<div class="modal-head card-title">Please Wait...</div>
<div class="modal-body card-body">
<i class="icon-spinner icon-spin icon-2x"></i>