Skip to content

Instantly share code, notes, and snippets.

View leastbad's full-sized avatar
🤠
Keeping it real for the rest of us.

leastbad leastbad

🤠
Keeping it real for the rest of us.
View GitHub Profile
@leastbad
leastbad / gist:4545ac76957437d9b6b0e420b70410ee
Created August 7, 2018 00:16
Drop-in client dist version of fscreen
// https://github.com/rafrex/fscreen
'use strict';
var key = {
fullscreenEnabled: 0,
fullscreenElement: 1,
requestFullscreen: 2,
exitFullscreen: 3,
fullscreenchange: 4,
const isSelectorValid = (qs => (
selector => {
try { qs(selector) } catch (e) { return false }
return true
}
))(s => document.createDocumentFragment().querySelector(s))
@leastbad
leastbad / layers.css
Created September 20, 2019 07:49
Don't fall out of the nest
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
* * * * * * * { background-color: rgba(255,0,0,.2); }
* * * * * * * * { background-color: rgba(0,255,0,.2); }
* * * * * * * * * { background-color: rgba(0,0,255,.2); }
@leastbad
leastbad / action_mailbox.md
Last active April 26, 2023 04:30
Action Mailbox: The Missing Manual

This is all you really need to know in order to make Action Mailbox work in development.

  1. Fire up ngrok http 3000 and make note of your subdomain for steps 3 and 8.
  2. Create a Mailgun account because they offer sandbox addresses; grab your domain from the Dashboard.
  3. Go into Receiving and create a catch-all route pointing to: https://XXX.ngrok.io/rails/action_mailbox/mailgun/inbound_emails/mime
  4. Add your Mailgun API key to your credentials:
action_mailbox:
 mailgun_api_key: API KEY HERE
@leastbad
leastbad / autosize_controller.js
Created February 6, 2020 02:09
My autosize implementation
import { Controller } from 'stimulus'
export default class extends Controller {
initialize () {
this.setInputAttributes()
this.update()
}
update () {
this.element.style.height = 'auto'
@leastbad
leastbad / plink-plonk.js
Created February 15, 2020 18:35 — forked from tomhicks/plink-plonk.js
Listen to your web pages
@leastbad
leastbad / server.rb
Created March 8, 2020 07:57
It's a webserver
require 'socket'
server = TCPServer.new 5678
while session = server.accept
request = session.gets
puts request
unless request.nil?
filename = request.split(" ")[1]
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "input" ]
connect() {
this.minHeight = this.inputTarget.dataset.minHeight
if (this.minHeight == undefined) this.findLineHeight()
this.update()
}
@leastbad
leastbad / README.md
Created April 16, 2020 08:08
Choices.js Stimulus wrapper preview

Choices.js Stimulus wrapper

https://joshuajohnson.co.uk/Choices/

Soon, this will be published as an NPM package, but there's an absence of documentation right now. It supports almost all functions from the original library; soon it will support 100% of them.

This wrapper adds Ajax pre-fetch search. Happens if controller has a data-search-path attribute.

Stimulus controller targets use new v2 syntax. Controller attaches a reference to itself on the element so that you can access the internal state from external scripts.

@leastbad
leastbad / README.md
Last active February 25, 2021 04:52
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.