Skip to content

Instantly share code, notes, and snippets.

View dy's full-sized avatar

Dmitry Iv. dy

View GitHub Profile
@dy
dy / parallel-record.js
Last active March 20, 2021 17:24
Parallel media recorders
// try splitting buffer to N parts, recording in parallel, generating blob
async function recordParallel() {
const audioContext = new AudioContext();
const mimeType = 'audio/webm;codecs=opus'
const bufs = [], all = []
for (let i = 0; i < 10; i++ ) {
// 2705 - min chunk length for opus encoder in Chrome, so we increase block size to 4096 plus silent header
@dy
dy / diacritics.fea
Created January 29, 2021 03:09
Fix google font diacritics
lookup diacritics {
markClass [gravecomb acutecomb] <anchor 160 512> @TOP_MARKS;
# ш м т
pos base [\uni0448 \uni043C \uni0442] <anchor 500 512> mark @TOP_MARKS;
} diacritics;
feature mark {
lookup diacritics;
} mark;
@dy
dy / css-calc.html
Last active December 4, 2020 13:50
CSS-calc based math expressions in JS
<script>
let hiddenNode = document.documentElement.appendChild(document.createElement('div'))
hiddenNode.style.visibility = 'hidden'
hiddenNode.style.height = 0
function calc(expression) {
let cssExpression = expression
// a + b → var(--a) + var(--b)
.replace(/([a-z]\w*)(\b[^(]|$)/ig, 'var(--$1)$2')
// -var(--a) → -1 * var(--a)
@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 / 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 / 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": "[email protected]",
"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 / foobarbaz.md
Created February 13, 2020 01:28
Metasyntactic dictionary
@dy
dy / readable-stream-async-iterator.js
Created December 4, 2019 16:49
Readable stream async iterator polyfill
// polyfill readable stream iterator
export const ReadableStream = window.ReadableStream && window.ReadableStream.prototype[Symbol.asyncIterator] ?
window.ReadableStream : (() => {
function ReadableStream (...args) {
let readers = []
let obj = args[0]
let stream = new window.ReadableStream(...args)
@dy
dy / 2-chars.txt
Created November 21, 2019 18:26
NPM package names
-
-
--
-.
-0
-1
-2
-3
-4
-5
@dy
dy / suspense.md
Last active November 5, 2019 17:54
React concurrent mode flaw

React concurrent mode is flawed design workaround. That issue cannot happen with web-components.

Component itself must be responsible for its rendering content and loading state - putting loading logic into Suspense wrapper creates redundant waterfall.

const initialResource = fetchProfileData(0);

function App() {
  const [resource, setResource] = useState(initialResource);
  return (