Skip to content

Instantly share code, notes, and snippets.

@itacirgabral
itacirgabral / asyncAnimationFrame.js
Last active December 22, 2022 20:39
async await generator loop for requestAnimationFrame
async function* asyncAnimationFrame () {
const h = {}
h.promise = new Promise(r => h.resolve = r)
h.flipFrame = () => {
h.resolve()
h.promise = new Promise(r => h.resolve = r)
}
try {
while (true) {
h.idAF = requestAnimationFrame(h.flipFrame)
@ogun
ogun / outliersFilter.js
Created September 3, 2017 15:08 — forked from rmeissn/outliersFilter.js
A Javascript function to filter an array of values for outliers by using an interquartile filter
function filterOutliers(someArray) {
if(someArray.length < 4)
return someArray;
let values, q1, q3, iqr, maxValue, minValue;
values = someArray.slice().sort( (a, b) => a - b);//copy array fast and sort
if((values.length / 4) % 1 === 0){//find quartiles
@leodutra
leodutra / bitwise-hacks.js
Last active October 30, 2023 02:37
Fast Int Math + Bitwise Hacks For JavaScript
// http://michalbe.blogspot.com.br/2013/03/javascript-less-known-parts-bitwise.html
// http://jsperf.com/bitwise-vs-math-object
// http://united-coders.com/christian-harms/results-for-game-for-forfeits-and-the-winner-is/
// https://mudcu.be/journal/2011/11/bitwise-gems-and-other-optimizations/
// https://dreaminginjavascript.wordpress.com/2009/02/09/bitwise-byte-foolish/
// http://jsperf.com/math-min-max-vs-ternary-vs-if/24
"use strict";
var PI = Math.PI;