Skip to content

Instantly share code, notes, and snippets.

View dy's full-sized avatar
🙌
you're doing good

Dmitry Iv. dy

🙌
you're doing good
View GitHub Profile
@dy
dy / signal-polyfill-preact.js
Created April 13, 2024 13:36
signal polyfill preact
// @preact/signals compatible wrapper for signal proposal
import { Signal } from 'signal-polyfill'
const { untrack, Watcher } = Signal.subtle
export const signal = v => wrap(new Signal.State(v))
export const computed = fn => wrap(new Signal.Computed(fn))
export { untrack as untracked }
@dy
dy / signals.md
Created February 22, 2024 20:19
Signals gotchas
@dy
dy / WeakishMap.js
Created November 18, 2023 19:53
WeakishMap
// based on https://github.com/WebReflection/not-so-weak/
const refs = new WeakMap;
const set = value => {
const ref = new WeakRef(value);
refs.set(value, ref);
return ref;
};
@dy
dy / hyper-fragment.js
Last active September 17, 2023 20:42
Hyper/persistent document fragments
// extension of document fragment, keeps references to children
// based on https://github.com/WebReflection/document-persistent-fragment/blob/master/esm/document-persistent-fragment.js
class Bug extends DocumentFragment {}
const shenanigans = !(new Bug instanceof Bug);
export default class HyperFragment extends DocumentFragment {
#nodes = []
// DocumentFragment overrides
@dy
dy / c-to-wasm.md
Last active August 18, 2023 03:05
C to WASM
@dy
dy / no-typescript.md
Last active August 16, 2023 14:58
Why not typescript
  1. () => {} is not the same as () => void.
  2. {a?: string | undefined} is tautology.
  3. void | undefined | {} | never | null is tautology.
  4. Native types Record, Partial etc are a bunch of internal jargon, meaningless from JS view.
  5. Interfaces and types are same thing differently named, only creates confusion.
  6. unknown vs any: little who cares about the difference.
  7. JSX.Element, React.ReactNode, React.ReactFragment is tautology
  8. const X = {abc:123} as const
@dy
dy / wasm-gotchas.md
Last active June 22, 2023 17:57
WASM gotchas

Params order

First taken from stack as block, then augmented with inline param.

(func $x (param i32 i32 i32))
...
(i32.const 0)(i32.const 1) (call $x (i32.const 3))

;; converts to
@dy
dy / resume.json
Last active February 28, 2023 17:21
Resume
{
"basics": {
"name": "Dmitry Ivanov",
"label": "Software Engineer",
"image": "https://raw.githubusercontent.com/dy/resume/master/index.png",
"email": "df.creative@gmail.com",
"phone": "+1 514 7755-376",
"url": "",
"summary": "Originally from Saint-Petersburg, earned Master's degree in Computer Graphics (CS) at Baltic State Technical University. Started his career as UI / Web designer collaborating at local startups, prominently kudago.com, with hobby passion for open-source. Afterwards moved to Montreal, Canada, where first collaborated with local businesses (TTBA, Amaze) as frontend / web engineer, then found an opportunity at Plotly Inc as WebGL specialist. Later switched to fintech at Mobeewave, that merged into Apple Wallet and Payments teams. Currently focused at audio / vis tech at elevenlabs.io and open-source projects.",
"location": {
@dy
dy / import-maps-polyfill.html
Last active February 19, 2023 14:56
Import maps core polyfill
<script id='import-maps-polyfill'>
const imports = {}
// intercept all subsequent scripts before init
;(new MutationObserver(rx=>rx.forEach(({target:s}) => {
if (s.tagName !== 'SCRIPT' || s.im) return
if (s.getAttribute('type') === 'importmap') {
Object.assign(imports, JSON.parse(s.textContent).imports)
}
@dy
dy / web-codec-decode.js
Created January 26, 2023 14:33
Web Codec API
// web codec API (one day, hopefully)
const codecConfig = {
codec: 'mp3',
sampleRate: 48000,
numberOfChannels: 2,
description: new ArrayBuffer
}
let chunk = new EncodedAudioChunk({
type: 'key',