Skip to content

Instantly share code, notes, and snippets.

View scottbarrow's full-sized avatar

Scott Barrow scottbarrow

View GitHub Profile
@scottbarrow
scottbarrow / README.md
Created October 28, 2020 15:21 — forked from leastbad/README.md
stimulus-websocket preview

This controller can be put on body or any other element.

  1. Adds a websocket accessor to the element
  2. Controller exposes a connected boolean getter
  3. Controller bails with a warning if no shared consumer is available
  4. Element will have data-action-cable-connected or data-action-cable-disconnected attributes which can be used for CSS selectors
  5. Element will emit action-cable:connected or action-cable:disconnected events only when state is flipping
  6. Errors => Disconnected to keep things simple

I intend to document the navigator.onLine accessor and the window:online/offline events so devs can handle PWA modes.

@scottbarrow
scottbarrow / form.html.erb
Created October 3, 2020 20:06 — forked from julianrubisch/form.html.erb
StimulusReflex Form Reset Controller
<%= form_with(model: model, data: {controller: "reflex-form", reflex_form_reflex: "ExampleReflex#submit"}) do |form| %>
<%= form.button data: {action: "click->reflex-form#submit"} %>
<% end %>
@scottbarrow
scottbarrow / populate_stripe_input.js
Created October 17, 2019 03:13 — forked from mbrochh/some_test.js
Controlling a Stripe payent popup with Cypress.io
// for this to work you need to set `"chromeWebSecurity": false` in cypress.json
describe('Make Stripe Payment', function() {
before(function() {
cy.visit('http://localhost:3000/en/stripe/checkout/')
Cypress.Cookies.preserveOnce('sessionid')
})
it('should enter credit card details and finalise payment', function() {
cy.get('[data-test="button-FormStripeCart-PayWithCreditCard"]').click()
@scottbarrow
scottbarrow / rubocoper
Created October 3, 2019 01:28 — forked from deivid-rodriguez/rubocoper
Adds RuboCop to a project, one commit per cop
#!/usr/bin/env ruby
require 'open3'
#
# Adds RuboCop to a project, one cop per commit
#
class RuboCoper
def run
autocorrect_all
@scottbarrow
scottbarrow / brew_symlink_error_sierra.md
Created August 14, 2018 18:32 — forked from dalegaspi/brew_symlink_error_sierra.md
Homebrew Symlink errors in Mac OSX High Sierra
@scottbarrow
scottbarrow / array_iteration_thoughts.md
Created April 13, 2018 20:32 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style