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 / array.wat
Last active February 7, 2022 20:15
WASM array fill performance
;; test passing array to and back
(module
(import "js" "mem" (memory 1))
(import "console" "log" (func $log (param i32 f32)))
(global $blockSize (import "js" "blockSize") (mut i32))
(global $len (mut i32) (i32.const 0))
;; len = blockSize * 4
(func (global.set $len (i32.mul (global.get $blockSize) (i32.const 4))))
(start 1)
@dy
dy / stacker.html
Created January 14, 2022 21:27
Stacker debug
<!DOCTYPE html>
<a href="https://twitter.com/jviide/status/1257755526722662405">ref</a>
<script type="module">
import t from './libs/tst.js'
// function μ(h,...d){for(var a=[],g=0,f=0,b=-1,c;c=h[g++];)c--?c--?c--?c--?c--?a[++b]=c--?c--?[d[f++],c?{}:null]:1<g||[]:d[f++]:a[b]=this(...a[b]):Object.assign(a[b][1],d[f++]):a[b-1].push(a[b--]):a[b-2][1][a[b--]]=a[b--]:a[b-1]+=""+a[b--];return a[0]}
function μ(hash, ...fields){
// [root, tag, props, ...children]
var stack=[], i=0, f=0, d=-1, c
@dy
dy / git-issues.md
Created September 24, 2021 17:01
Git issues
  1. Adding/removing indentation of large blocks creates huge diff-log, although that's simply spaces.
  2. Renaming a file doesn't come along with diff-log, it must be a separate commit, otherwise log is huge.
@dy
dy / known-coefs.js
Created September 3, 2021 14:22
Simple rational scalars
[
// 0,
1/2,
1/3,2/3, .33,.333,.3333,.66,.666,.6666,
1/4,3/4,
1/5,2/5,3/5,4/5,
1/6,5/6,
1/7,
1/8,3/8,5/8,7/8,
1/9,
@dy
dy / find-ops-combinations.js
Last active September 5, 2021 00:26
Do prime sums and products ever intersect?
(() => {
// play around with initial sequences / operator combinations
let seqs = {}, ops = {'+':(a,b)=>a+b,'-':(a,b)=>a-b}//'/':(a,b)=>a/b,'*':(a,b)=>a*b}
const results = new Proxy({}, {
set(results, prop, value){
if (results[prop]) {
if (!results[prop].includes(value)) console.error('set', prop, ':', value, 'exists as', results[prop])
@dy
dy / record-audio.js
Last active January 14, 2023 13:25
Record youtube / any <video>/<audio> clip
// paste the code below into browser console in any youtube page and call `record(from, to)`
// from and to are in seconds
async function record(from, to) {
var mediaElement=document.querySelector('video')
var recordedChunks = [];
var mimeType = 'audio/webm;codecs="opus"'
var ac = new AudioContext();
var mediaSource = new MediaElementAudioSourceNode(ac, {mediaElement});
@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)
}