Skip to content

Instantly share code, notes, and snippets.

Stephen John Sorensen spudly

Block or report user

Report or block spudly

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@spudly
spudly / Smiley.js
Created Oct 4, 2017
An experimental prototype showing how you can use a react-style reconciler to render web components
View Smiley.js
const reconcileProps = (vElement, element) => {
Object.keys(vElement.props).forEach(prop => {
const eventMatch = prop.match(/^on([A-Z]\w+)/);
if (eventMatch) {
// TODO: need a way to remove event listeners when they change or are removed
element.addEventListener(eventMatch[1].toLowerCase(), vElement.props[prop]);
} else if (element[prop] !== vElement.props[prop]) {
element[prop] = vElement.props[prop]; // eslint-disable-line no-param-reassign
}
});
@spudly
spudly / generateStream.js
Created Aug 29, 2017
Create a node readable stream from a generator function.
View generateStream.js
const {Readable} = require('stream');
const generateStream = (generator) => {
const stream = new Readable({objectMode: true});
stream._read = () => {
const next = generator.next();
if (next.done) {
stream.push(null);
} else {
stream.push(next.value);
@spudly
spudly / getRules.js
Last active Mar 23, 2017
Script to display merged eslint rules, including extended configs. Useful for when you want to drop a dependency on another eslint config.
View getRules.js
const getRuleFinder = require('eslint-find-rules');
const ruleFinder = getRuleFinder(__dirname + '/index.js');
console.log(JSON.stringify(ruleFinder.getCurrentRulesDetailed(), null, 2));
View getElementHeight.js
import makeVisible from './makeVisible';
const getElementHeight = el => {
const restore = makeVisible(el);
const height = el.scrollHeight;
restore();
return height;
}
export default getElementHeight;
@spudly
spudly / filter.regex
Created Sep 14, 2016
Filter out React Plain Object warnings & font warnings in the chrome dev tools
View filter.regex
^((?!(plain object|font)).)*$
// To use, enter in the console filter field and make sure "Regex" is checked
View .gitconfig
[alias]
feature = "!f() { git checkout -b feature/$1 --no-track origin/master; }; f"
release = "!f() { git checkout -b release/$1 --no-track origin/master; }; f"
hotfix = "!f() { git checkout -b hotfix/$1 --no-track origin/master; }; f"
bugfix = "!f() { git checkout -b bugfix/$1 --no-track origin/master; }; f"
View streamToString.js
const streamToString = async stream => new Promise((resolve, reject) => {
let string = '';
stream.on('data', chunk => { string += chunk; });
stream.on('error', reject);
stream.on('end', () => resolve(string));
});
@spudly
spudly / streamToArray.js
Created May 18, 2016
Returns a promise that pulls from a stream and resolves with an array of stream chunks.
View streamToArray.js
const streamToArray = async stream => new Promise((resolve, reject) => {
const array = [];
stream.on('data', chunk => array.push(chunk));
stream.on('error', reject);
stream.on('end', () => resolve(array));
});
View createRange.js
function* createRange(from, to, step = 1) {
let i = from;
while (from < to ? i <= to : i >= to) {
yield i;
i += Math.abs(step) * (from < to ? 1 : -1);
}
}
@spudly
spudly / stringToStream.js
Last active Jun 15, 2016
Converts a string to a stream
View stringToStream.js
import {Readable} from 'stream';
const stringToStream = string => {
const stream = new Readable();
stream.setEncoding('utf8');
stream.push(string);
stream.push(null);
return stream;
};
You can’t perform that action at this time.