Skip to content

Instantly share code, notes, and snippets.

View johnloy's full-sized avatar

John Loy johnloy

View GitHub Profile
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) {
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
//https://developer.mozilla.org/en-US/docs/Web/Events/resize
;
(function() {
var throttle = function(type, name, obj_) {
var obj = obj_ || window;
var running = false;
var func = function() {
if (running) {
return;
}
/* tslint:disable-next-line */
let stringifyObj = function (obj: object): any {};
if (!DEBUG) {
stringifyObj = (obj: object): string => {
const placeholder = "____PLACEHOLDER____";
const fns: Function[] = [];
let json = JSON.stringify(
obj,
function (_, value: any): any {
@johnloy
johnloy / timeoutify-a-callback.js
Last active August 27, 2021 18:54
Timeoutify a callback. From "You Don't Know JS: Async and Performance"
function timeoutify(fn,delay) {
var intv = setTimeout( function(){
intv = null;
fn( new Error( "Timeout!" ) );
}, delay )
;
return function() {
// timeout hasn't happened yet?
if (intv) {
@johnloy
johnloy / jump-to-section-of-man-page.sh
Last active August 27, 2021 19:46
jump to a section of a man page
man -P 'less -p ^READLINE' bash
@johnloy
johnloy / open-man-page-in-browser.sh
Last active August 27, 2021 19:46
Open a man page as html in default browser
groff -man -T html $(man -w man) > $TMPDIR/man.html | open -f -a 'Google Chrome' $TMPDIR/man.html
@johnloy
johnloy / set-vim-manpager.sh
Last active August 27, 2021 19:46
set vim as MANPAGER
# From http://vim.wikia.com/wiki/Using_vim_as_a_man-page_viewer_under_Unix
export MANPAGER='col -bx | vim -c ":set ft=man nonu nolist" -R -'
@johnloy
johnloy / README.md
Created August 23, 2016 12:59
Reusable parsing algorithm using pure functions

There's no need to fully parse the xml of entire clearleap api responses to JSON. And there doesn't seem to be a compelling reason to use xml2json, unless api responses need to be rendered on the back end in an isomorphic app. Usually, we just want to pluck certain values out, massage them a bit, and add them as properties of an object/structure better suited to presentation.

At its simplest, this can be done with a function that takes an instance of Node, performs DOM querying logic to retrieve and aggregate values from elements and attributes, and then returns a single value.

This gist shows a way to reuse and compose pure functions of this variety to converge parsing operations for invidual values into a final object. Because only pure functions are involved, presumably parsing could be parallelized with web workers (https://adambom.github.io/parallel.js/). Each pure function involved is also automatically memoized and passed wi