Skip to content

Instantly share code, notes, and snippets.

View barneycarroll's full-sized avatar
🛠️
Working on Mithril type stuff

Barney Carroll barneycarroll

🛠️
Working on Mithril type stuff
View GitHub Profile
@barneycarroll
barneycarroll / perception-color.js
Created July 11, 2022 07:30
The iterative colour picker script from the Perception Census 2022 'Fundamentals of Perception' at https://perceptioncensus.dreamachine.world/
function addClick(){
colorPickerStatus.nClicks = colorPickerStatus.nClicks + 1;
}
function restartClicks() {
colorPickerStatus.nClicks = 0;
}
function restartPicker() {
colorPickerStatus.nClicks = 0;
@barneycarroll
barneycarroll / AutoGrid.js
Last active July 7, 2022 14:59
A component that consumes a populated CSS grid container and applies column styles according to bin packing optimisation
import m from 'mithril'
import O from 'mergerino'
import {viewOf} from 'mithril-machine-tools'
export default Simple
export function Simple(){
let size = 0
let column = 0
let slot
@barneycarroll
barneycarroll / bootstrap.forms.extra.css
Created July 4, 2022 06:15
Bootstrap form extensions 🫠
/* Default style extends .5em of empty space */
.form-switch {
padding-left: 2em;
}
.form-switch .form-check-input {
margin-left: -2em;
}
/* Bootstrap default switch input assumes extra valence in on state */
.form-switch .form-check-input:checked {
export default generator =>
new Proxy(generator, {apply(){
return recorder(
generator, this, arguments
)
}})
function recorder([generator, context, args], ...records){
const iterator = generator.apply(context, args)
// Serialise command-line parameters of form:
// `--boolean`, `--key=value`, `--multiple:value1 --multiple:value2`
export default args => args.reduce((input, arg) => {
const [param, key, verb, value] = (/--(\w+)(=|:)?(.+)?/).exec(arg) || []
if (param)
input[key] = (
// No verb means boolean; '=' means direct assignment; ':' means accumulate array
!verb ? true : verb == "=" ? value : !input[key] ? [value] : [...input[key], value]
)
@barneycarroll
barneycarroll / cor.js
Created October 26, 2021 08:14
Generators as generic sub-routines
‎‎​
@barneycarroll
barneycarroll / changeTag.js
Created August 3, 2021 12:12
Replace an element with a new one that has a different tagName
export default function changeTag(original, tagName){
// Create a replacement tag of the desired type
const replacement = document.createElement(tagName)
// Grab all of the original's attributes, and pass them to the replacement
Array.prototype.forEach.call(original.attributes, ({name, value}) => {
replacement.setAttribute(name, value)
})
// Persist contents
@barneycarroll
barneycarroll / ui_io.js
Created May 23, 2021 20:57
User Interface Input / Output is a tool for observing all event triggers (UI input) & DOM mutations (UI output). Initialised with an optional callback function which receives all such entries in format {type: 'mutation' || 'event', time: performance.now(), data: originalEventOrMutationRecords}, the returned instance exposes {logs, next, disconne…
import muty from 'muty'
export default function ui_io(callback = Function.prototype){
const {addEventListener} = EventTarget.prototype
const promises = []
const listeners = []
const logs = []
function register(entry){
@barneycarroll
barneycarroll / eventListenerListener.js
Created May 12, 2021 11:39
Intercept & release / remove all event listeners. Partially as an easy way to make Mithril router single-SPA compliant.
const {addEventListener} = EventTarget.prototype
export default function EventListenerListener({
blocking = false,
removing = true,
visitor = Function.prototype,
} = {}){
if(this instanceof EventListenerListener){}
else return new EventListenerListener(...arguments)