start new:
tmux
start new with session name:
tmux new -s myname
// navigate to https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Intersection_observer_concepts_and_usage | |
// open console and run the code below | |
const target = document.getElementById('How_intersection_is_calculated') | |
const observer = new IntersectionObserver(entries => console.log(entries[0], entries[0].isIntersecting), {root: null, threshold: 0.9}) | |
observer.observe(target) |
let socket = new WebSocket('wss://echo.websocket.org') | |
async function main(socket) { | |
for await (let {value, done} of getDataFromWebSocket(socket)) { | |
if (!done) console.log('Data:', value) | |
else console.log('WebSocket is closed.') | |
} | |
return 'Done running the main fn!' | |
} // hit return/enter |
function makeArrayNegativeIndexable(arr) { | |
if (!Array.isArray(arr)) return arr | |
return new Proxy(arr, { | |
get(target, prop) { | |
return target[getIndex(target.length, prop)] | |
}, | |
set(target, prop, val) { | |
let index = getIndex(target.length, prop) |
// basic destructuring | |
const { key1 } = { key1: 10 } // key1 = 10 | |
const [x, y, z] = [1, 2, 3] // x = 1, y = 2, z = 3 | |
const [head, ...tail] = [1, 2, 3] // head = 1, tail = [2, 3] | |
const { a: { b } } = { a: { b: 20 } } // b = 20 | |
// storing value in a variable with a different name | |
const { key1: varForKey1 } = { key1: 20 } // varForKey1 = 20 | |
const { 'quoted-key': x } = { 'quoted-key': 10 } // x = 10 |
function co(genInstance) { | |
const success = v => step(genInstance, {value: v, failed: false}) | |
const failure = err => step(genInstance, {error: err, failed: true}) | |
if ('function' === typeof genInstance) genInstance = genInstance() | |
// kick start generator | |
const retVal = genInstance.next() | |
if (retVal.done) return retVal.value | |
else return retVal.value.then(success, failure) |
-- Our goal is to create a type describing a list of events. This is our | |
-- type-level DSL. | |
-- We will then use typeclass resolution to "interpret" this type-level DSL | |
-- into two things: | |
-- 1. A comma-separated list of events | |
-- 2. A method that, when given an event name and a payload, will try to parse | |
-- that event type with the payload. A form of dynamic dispatching | |
-- | |
-- To model a list of types we will use tuples. You can imagine the list of | |
-- types "Int, String, Char" to look like: |
// If multiple calls to fn are made within time t | |
// this will call fn only once after a delay of | |
// t milliseconds after the most recent call | |
function debounce1(fn, t) { | |
let timeout | |
return function (...args) { | |
let self = this | |
clearTimeout(timeout) |
package main | |
import ( | |
"fmt" | |
"log" | |
"strings" | |
) | |
// Ops | |
const ( |