Skip to content

Instantly share code, notes, and snippets.

@bultas
bultas / compareImages.js
Created May 30, 2018 23:40
Compare images - perceptual diffing
import R from 'ramda';
import fs from 'fs';
import { PNG } from 'pngjs';
import pixelmatch from 'pixelmatch';
export const getImages = imagesPaths => {
return new Promise(resolve => {
let filesRead = 0;
let images = [];
@bultas
bultas / .gvimrc
Created November 21, 2018 16:47 — forked from ryanflorence/.gvimrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Font
:set guifont=Source\ Code\ Pro:h14
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Hide pointless junk at the bottom, doesn't work in .vimrc for some reason?
:set laststatus=0
:set noshowmode "don't show --INSERT--
:set noruler "don't show line numbers/column/% junk
@bultas
bultas / findCustomElements.js
Created December 13, 2018 20:31
Find custom elements
const allCustomElements = [];
function isCustomElement(el) {
const isAttr = el.getAttribute('is');
// Check for <super-button> and <button is="super-button">.
return el.localName.includes('-') || isAttr && isAttr.includes('-');
}
function findAllCustomElements(nodes) {
for (let i = 0, el; el = nodes[i]; ++i) {
@bultas
bultas / listAllEventListeners.js
Created December 14, 2018 22:12 — forked from dmnsgn/listAllEventListeners.js
List all event listeners in a document
const listeners = (function listAllEventListeners() {
let elements = [];
const allElements = document.querySelectorAll('*');
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
}
for (let i = 0; i < allElements.length; i++) {
const currentElement = allElements[i];
@bultas
bultas / handlePOSTNode.js
Last active January 11, 2019 18:09
Node handle basic HTTP request - read POST and return JSON
const http = require("http");
const handle = (req, res) => {
let data = "";
req.on("data", chunk => {
data += chunk;
});
req.on("end", () => {
@bultas
bultas / headlines.css
Created January 24, 2019 11:05
CSS numbered Headlines
/* Fixed h3 numbering http://2ality.com/2012/01/numbering-headingshtml.html */
body {
counter-reset: h2counter;
}
h1 {
counter-reset: h2counter;
}
@bultas
bultas / store.js
Created February 7, 2019 11:09
Store - vanilla JS TEA/Redux module
export const dispatch = e => window.dispatchEvent(e);
const handler = subscribe => state => update => action => {
const [newState, cmds] = update(state)(action);
if (state != newState) {
subscribe(newState);
}
state = newState;
if (cmds && cmds.length > 0) {
--icon-search: url('data:image/svg+xml,\
<svg viewBox="-24 -24 48 48" xmlns="http://www.w3.org/2000/svg">\
<title>Search</title>\
<g transform="translate(-4 -8)">\
<g transform="rotate(45)" fill="none" stroke="black">\
<circle r="14" stroke-width="3"/>\
<line x1="17" x2="30" stroke-width="6" stroke-linecap="round"/>\
</g>\
</g>\
</svg>');
/**
* @param {HTMLFunction} html
* @returns {(instance: Instance) => (number) => string}
*/
const template = html => instance => multiplier => html`
<h1>Hello ${instance.data.name}</h1>
<h2>count: ${2 * multiplier}</h2>
`;
/**
@bultas
bultas / reducer.js
Last active June 26, 2019 19:04
Redux-Loop Reducer boilerplate
/// @ts-check
import { loop, Cmd } from 'redux-loop';
import { error } from 'lib/result';
import { fetchItem } from 'effects/itemEffects';
import { ITEM_LOCATION } from 'constants/routerConstants';
const initState = {
fetching: null,