This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect, useCallback } from 'react' | |
export const IDLE = 'IDLE' | |
export const LOADING = 'LOADING' | |
export const SUCCESS = 'SUCCESS' | |
export const ERROR = 'ERROR' | |
export function useAsyncData(fetchFn, deps) { | |
const stableFetchFn = useCallback(fetchFn, deps) | |
const [{ state, data, error }, setState] = useState({ state: IDLE }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Used to extract a from a Swagger API spec */ | |
function generateTypeScriptInterface(targetDef, definitions) { | |
if (typeof targetDef === 'string') { | |
definitions = | |
definitions || | |
window.__defs__ || | |
(window.__defs__ = JSON.parse(document.querySelector('body pre').textContent).definitions); | |
targetDef = definitions[targetDef]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Loading "smoothscroll-polyfill" & "smoothscroll-anchor-polyfill" + setting scroll-behavior to smooth in 247 bytes: | |
((d,s,u)=>{d.documentElement.setAttribute('style','scroll-behavior:smooth');let i=s=>{let e=d.createElement('script');e.src=s;d.head.append(e)};i(u+s+`-polyfill/dist/${s}.min.js`);i(u+s+'-anchor-polyfill')})(document,'smoothscroll','//unpkg.com/') | |
// Readable version: | |
((doc, name, cdn) => { | |
// Set scroll-behavior, setAttribute so it works in browsers that don't recognize the property | |
doc.documentElement.setAttribute('style', 'scroll-behavior: smooth;'); | |
// Function to insert scripts... | |
const insertScript = url => { | |
const scriptElement = doc.createElement('script'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isPlainObject = object => Object.prototype.toString.call(object) === '[object Object]' | |
const recursiveAssign = (target, ...sources) => { | |
sources.forEach(source => { | |
Object.entries(source).forEach(([key, value]) => { | |
if (isPlainObject(target[key]) && isPlainObject(value)) recursiveAssign(target[key], value) | |
else target[key] = value | |
}) | |
}) | |
return target | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shortest (96 chars): | |
Number.prototype[Symbol.iterator]=function(){let i=0;return{next:()=>({done:i>this,value:i++})}} | |
// Only return value if not done yet (112 chars): | |
Number.prototype[Symbol.iterator]=function(){let i=0;return{next:()=>({done:i>this,...!(i>this)&&{value:i++}})}} | |
// Readable: | |
Number.prototype[Symbol.iterator] = function() { | |
let i = 0; |
I hereby claim:
- I am jonaskuske on github.
- I am jonaskuske (https://keybase.io/jonaskuske) on keybase.
- I have a public key ASDmu_cLaafasTpFdOxjEHDjScJaycNtp3EydJ3CtvvNBQo
To claim this, I am signing this object:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copy this into the browser console | |
let _=i=$D=1;Object.defineProperty(this,'mood',{set(){console.log(`Made ${i++} folks happy!`);Math.random()<.1&&(_=0)}}) | |
// Then you can do this and find out how many people you made happy :) | |
please: for (;_;) mood = $D |