Skip to content

Instantly share code, notes, and snippets.

View johnloy's full-sized avatar

John Loy johnloy

View GitHub Profile
@johnloy
johnloy / index.html
Last active July 30, 2019 13:38
State management with custom DOM events
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="module">
const createAction = (el, initialState, name, action) => {
let currentState = initialState;
document.body.addEventListener(name, (e) => {
el.render(e.detail.state);
});
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 -'