Skip to content

Instantly share code, notes, and snippets.

@AlexRatmansky
Last active February 20, 2020 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexRatmansky/291c9525bcca8a116407596f2cf4a77c to your computer and use it in GitHub Desktop.
Save AlexRatmansky/291c9525bcca8a116407596f2cf4a77c to your computer and use it in GitHub Desktop.
Web Audio API
javascript:(function(){const%20audioCtx=new(window.AudioContext||window.webkitAudioContext);const%20oscillator=audioCtx.createOscillator();oscillator.connect(audioCtx.destination);oscillator.type="sine";let%20numItems=0;oscillator.frequency.setValueAtTime(1,audioCtx.currentTime);oscillator.start();const%20observer=new%20MutationObserver(function(mutationsList){numItems+=mutationsList.length;oscillator.frequency.setValueAtTime(Math.log(numItems+1)*440,audioCtx.currentTime);setTimeout(()=>{numItems-=mutationsList.length;if(numItems===0){oscillator.frequency.setValueAtTime(1,audioCtx.currentTime)}else{oscillator.frequency.setValueAtTime(Math.log(numItems+1)*440,audioCtx.currentTime)}},100)});observer.observe(document,{attributes:true,childList:true,subtree:true,characterData:true})})();
// function decorator
var withJson = f => async url => {
var result = await f(url)
.catch(error => {console.log('->', error)})
return result
}
// decorated function
var fetchJson = withJson(fetch)
console.time('fetch')
await fetchJson('http://localhost:3000/api/v1/dataset/list')
.then(response => response.json())
.then(data => {console.log(data)})
console.timeEnd('fetch')
/*
await fetch('http://localhost:3000/api/v1/dataset/list')
.then(response => response.json())
.then(data => {console.log(data)})
*/

sfsdf

asdasdd

plink-plonk

const audioCtx = new window.AudioContext();
const oscillator = audioCtx.createOscillator();
oscillator.connect(audioCtx.destination);
oscillator.type = "sine";
let numItems = 0
oscillator.frequency.setValueAtTime(
1,
audioCtx.currentTime
);
oscillator.start();
const observer = new MutationObserver(function (mutationsList) {
numItems += mutationsList.length
oscillator.frequency.setValueAtTime(
Math.log(numItems + 1) * 440,
audioCtx.currentTime
);
setTimeout(() => {
numItems -= mutationsList.length
if (numItems === 0) {
oscillator.frequency.setValueAtTime(
1,
audioCtx.currentTime
)
} else {
oscillator.frequency.setValueAtTime(
Math.log(numItems + 1) * 440,
audioCtx.currentTime
)
}
}, 100)
});
observer.observe(document, {
attributes: true,
childList: true,
subtree: true,
characterData: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment