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 / 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 / stimulate.rb
Created July 10, 2020 18:49
server-side stimulate
def stimulate(target, data)
dataset = {}
data.each do |k, v|
dataset["data-#{k}"] = v.to_s
end
channel.receive({
"target" => target,
"attrs" => element.attributes.to_h.symbolize_keys,
"dataset" => dataset
})
@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 / README.md
Last active September 21, 2020 21:56
Polymorphic comment controller preview

With apologies for the half-baked solution presented, this is the interesting parts of a polymorphic comment engine that makes use of Stimulus, StimulusReflex and CableReady.

Note that app/javascript/controllers/index.js has to set application.consumer = consumer

This was written in the pre-morphs era, so I've done my best to fill in the blanks on what I'd do today in the Reflex.

Not shown: any view templates. Basic idea:

<%= render partial: "comments/comment", collection: @comments %>