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 / patdj.js
Last active November 8, 2019 06:28
DOM patching without: provide two DOM elements, the second (and contents) will be modified such that it resembles the first
function patdj(target, update, preserve = true) {
if (update.nodeType != 1 && update.nodeType == target.nodeType)
target.nodeValue = update.nodeValue
else if (update.nodeType != target.nodeType || update.tagName !== target.tagName || update.type !== target.type){
const { nextSibling, parentNode } = target;
const replacement = preserve ? update.cloneNode(true) : update;
parentNode.removeChild(target);
export default () => {
const queue = []
let then
return {
onbeforeupdate : () => !blocker,
oncreate : resolve,
onupdate : resolve,
view : ({
instance,
@barneycarroll
barneycarroll / .js
Last active August 2, 2019 21:10
Functor Mithril!
import m from './functor-mithril'
function Async(){
let cache
return ({content, setup, teardown}, dom) => {
if(content && !cache && teardown)
dom(node => {
void node.clientHeight
/*! rasterizeHTML.js - v1.2.2 - 2016-09-06
* http://www.github.com/cburgmer/rasterizeHTML.js
* Copyright (c) 2016 Christoph Burgmer; Licensed MIT */
/* Integrated dependencies:
* url (MIT License),
* css-mediaquery (BSD License),
* CSSOM.js (MIT License),
* ayepromise (BSD License & WTFPL),
* xmlserializer (MIT License),
* sane-domparser-error (BSD License),
import {m} from './deps.js'
import viewOf from './viewOf.js'
// View component exposing a single function:
// Once invoked, the function causes the subtree to be reinitialised
export default () => {
let timestamp
const refresh = () => {
@barneycarroll
barneycarroll / jquery.lipo.js
Last active March 23, 2019 23:38
Get rid of redundant whitespace & empty structural elements, in that order
void function semanticContentScope(context, jQuery){
var $ = context.jQuery || jQuery || false;
if(!$){
return false;
}
// Strips elements of duplicate, leading and trailing whitespace and removes empty non-functional elements recursively
function semanticContent(markup){
// Conversion
@barneycarroll
barneycarroll / tern.es5.js
Last active February 14, 2019 06:15
A ternary function for convenient conditional expressions (especially in Mithril views, where ternary operators can look confusing).
// Verbose ternary function to add debugging points and make views more legible.
// If `defer` is true and the pass/fail outcome is a function, it will be invoked:
// This allows you to conditionally return expressions which would break execution depending on `condition`
function tern( condition, pass, fail, defer ){
if( !fail ) fail = ''
if( defer && condition instanceof Function ) condition = condition()
var outcome = condition ? pass : fail;
@barneycarroll
barneycarroll / dabblet.css
Created November 27, 2012 14:45
Fixing shitty WebKit text rendering for thin and quirky fonts
/**
* Fixing shitty WebKit text rendering for thin and quirky fonts
*/
html {
font-family: 'Quicksand';
font-size: 24px;
padding: 1em 5em;
-webkit-text-stroke-width: .25px;}
@barneycarroll
barneycarroll / Drizzle.md
Created September 6, 2018 18:21
Drizzle, a short story by Hjalmar Söderberg

Drizzle

Autumn is here again with its dismal days, and the sun is hiding himself in the darkest corner of the heavens so that no one shall see how pale and aged and worn he has grown in this latter time. But while the wind whistles in the window-chinks and the rain purls in the rainspouts and a wet dog howls in front of a closed gate down below on the street and before the fire has burned down in our tile stove, I will tell you a story about the drizzle. Listen now!

For some time back the good God had become so angered over the wickedness of men that he resolved to punish them by making them still wickeder. He should, in his great goodness, have liked above all things to have drowned them all together in a new Deluge: he had not forgotten how agreeable was the sight when all living creatures perished in the flood. But unfortunately in a sentimental moment he had promised Noah never to do so again.

"Harken, my friend I" he therefore said to the Devil one day. "You are assuredly no saint, but occasionall