Skip to content

Instantly share code, notes, and snippets.

@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) {
@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 / 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 / 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 / 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 / .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 / 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 = [];
class Optimized extends React.PureComponent {
render() {
return this.props.children
}
}
const SomeConsumer = ({ slice, children } => (
<ActualConsumer>
{(state) => (
<Optimized slice={state[slice]}>
@bultas
bultas / fixNPM.sh
Last active February 6, 2018 11:06
If `NPM install` has spicy problems
rm -rf ./node_modules
npm cache clear --force
npm install
# If the problem persists
rm ./package-lock.json
rm -rf ./node_modules
npm cache clear --force
npm install
@bultas
bultas / dynamic-react-redux.js
Last active December 2, 2017 14:57
Dynamic Redux Connectors in React App
import React, { createElement } from 'react';
import { createStore } from 'redux';
import { render } from 'react-dom';
import { Provider, connect } from 'react-redux';
const ADD = 'ADD';
const store = createStore((state = 0, action) => {
if (action.type === ADD) {
return ++state;