Skip to content

Instantly share code, notes, and snippets.

View dy's full-sized avatar

Dmitry Iv. dy

View GitHub Profile
@dy
dy / xyz2rgb.js
Created February 3, 2025 03:58
WASM vs JS – rgb to xyz transform
// test some performance parts
// wasm is surprizingly not as fast, even in full version
import t from 'tst'
import watr from 'watr'
const f64pow = `(func $f64pow (param f64 f64)(result f64)(local f64 i64 i64 i64 f64 f64 f64 f64 f64 f64)(local.set 2(f64.const 0x1p+0))(block(br_if 0(f64.eq(local.get 1)(f64.const 0x0p+0)))(local.set 3(i64.const 0))(block(br_if 0(i64.gt_s(i64.reinterpret_f64(local.get 0))(i64.const -1)))(br_if 0(f64.ne(f64.nearest(local.get 1))(local.get 1)))(local.set 3(i64.shl(i64.extend_i32_u(f64.ne(f64.nearest(local.tee 2(f64.mul(local.get 1)(f64.const 0x1p-1))))(local.get 2)))(i64.const 63)))(local.set 0(f64.neg(local.get 0))))(local.set 2(f64.const 0x1p+0))(block(br_if 0(f64.eq(local.get 0)(f64.const 0x1p+0)))(block(br_if 0(f64.ne(local.get 0)(f64.const 0x0p+0)))(local.set 2(select(f64.const inf)(f64.const 0x0p+0)(i64.lt_s(i64.reinterpret_f64(local.get 1))(i64.const 0))))(br 1))(block(br_if 0(f64.ne(f64.abs(local.get 0))(f64.const inf)))(local.set 2(select(f64.const 0x0p+0)(f64.const inf)
@dy
dy / float64.js
Last active December 27, 2024 18:09
Construct float from sign, exponent, significand ints
function constructFloat64(sign, exp, sig) {
// Constants
const EXPONENT_BIAS = 1023n;
const EXPONENT_MASK = 0x7FFn;
const SIGNIFICAND_MASK = 0xFFFFFFFFFFFFFn;
console.log(sign, exp, sig, BigInt(sig) & SIGNIFICAND_MASK)
// Mask and adjust the components
sign = sign < 0 ? 1n : 0n;
@dy
dy / floathex.js
Last active December 27, 2024 18:08
Float hex - create 0x1.abcp123 form from float number
// based on https://observablehq.com/@jrus/hexfloat
const flt_arr = new Float64Array([1]);
const int_arr = new Int32Array(flt_arr.buffer);
const SIGN_MASK = 0x7fffffff; // 0111 1111 1111 1111 1111 1111 1111 1111
const EXP_MASK = 0x7ff00000; // 0111 1111 1111 0000 0000 0000 0000 0000
// HI = 1 on little endian platforms, 0 on big-endian platforms.
const HI = 1, LO = 0;
const floathex = (x) => {
@dy
dy / resume.json
Last active December 16, 2024 13:17
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 / name-transforms.md
Created October 3, 2024 03:44
Word/name transforms for npm

Here’s a minimal and organized markdown structure, focusing on word transformations with examples, excluding duplicates:

Word Transformations

1. Vowel Shifts and Substitutions

  • Changing vowels to create variation while keeping the basic consonant structure.
    • Examples:
      • Spray → Sprae, Sprea, Sprao, Sprai
      • Tone → Toon, Teun, Tyn, Tun
@dy
dy / scoped-script.html
Created September 15, 2020 13:36
Scoped script polyfill
<!DOCTYPE html>
<script id='scoped-script'>
let i = 0;
(new MutationObserver(rx=>rx.forEach(({target:s}) => {
if (s.tagName !== 'SCRIPT' || s.scoped || !s.hasAttribute('scoped')) return
s.scoped=true
if (!s.id) s.id='__s'+i++
s.innerHTML=`(function(){${s.innerHTML}}).call(document.getElementById('${s.id}').parentNode)`
}))).observe(document, {childList:true,subtree:true,attributes:true,attributeFilter:['scoped']})
@dy
dy / require.js
Last active April 26, 2024 23:19
require.js in browser
/**
* Require stub for browser.
* Prepend this script in head.
* Set `data-module="name"` attribute on script tag to define module name to register (or it will be parsed as src file name).
* Works only in browsers supporting Object.observe (Chrome with flags)
*/
//module/exports changing observer to expose global variables
var module = {};
var exports = {};
@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;
};