Skip to content

Instantly share code, notes, and snippets.

Avatar

James Browning Jamesernator

View GitHub Profile
View doAbortable.ts
export default async function doAbortable<R>(
signal: AbortSignal | undefined,
func: (abortSignal: AbortSignal) => R | Promise<R>,
): Promise<R> {
const controller = new AbortController();
const abortInner = () => controller.abort();
if (signal?.aborted) {
abortInner();
} else {
signal?.addEventListener("abort", abortInner, { once: true });
View README.md

Harden - Fixing the override mistake

The override mistake

The override mistake is a problem introduced with ES5's ability to mark properties as non-writable. When a property on the prototype of an object is marked non-writable, it makes the property unaddable on the object.

A notable example of this is if we freeze (which marks all properties as non-writable) on Object.prototype.

View api-cheatsheet-array.md

Array<T>

Array<T>.prototype.*

  • concat(: (T | Array<T>)[]): T[]
    concat(items) 🔒
    • Returns a new array that is the concatenation of this and all items. Non-array parameters are treated as if they were arrays with single elements.
    • ES3
    • ['a'].concat('b', ['c', 'd']) → [ 'a', 'b', 'c', 'd' ]
  • copyWithin(:number, :number, ?:number): this
View drawLine.js
async function drawCircles(mousedownEvent) {
const { top, left } = theCanvas.getBoundingClientRect()
for await (const clickEvent of clicks(theCanvas)) {
const radius = Math.random() * 19 + 1 // Circles between 1-20 inclusive
const color = randomColor()
drawCircle(
theCanvas,
clickEvent.clientX - left,
clickEvent.clientY - top,
radius,
View yieldfromasync.py
async def yieldfromexample():
RESULT = yield from EXPR
# Would become
async def yieldfromexample():
_i = aiter(EXPR)
try:
_y = await anext(_i)
except StopAsyncIteration as _e:
_r = _e.value
@Jamesernator
Jamesernator / steam_names
Last active Jul 27, 2018
This is All Names I've Gone By On Steam Since Choosing Music Names
View steam_names
Boris the Spider
Swamp
Dry County
White Lightning
Murder By Numbers
Dreadmonboogaloo
Expresso Love
Lizard Life
Fuzzbox Voodoo
Makin' Thunderbirds