Skip to content

Instantly share code, notes, and snippets.

View andrevenancio's full-sized avatar

André Venâncio andrevenancio

View GitHub Profile
I am attesting that this GitHub handle andrevenancio is linked to the Tezos account tz1eht4WAjkqU7kaupJd8qCDmec9HuKfGf68 for tzprofiles
sig:edsigtcwSHrvNnWVxEM2TYPshEKgGetgix9JGYVeHkKsv39xwZtGRKtJvynRFkQbHaxCuSr15GiWkoBGWh6z4cPGVSx8ps7egiN
var Box2D={};
(function(F,G){function K(){}if(!(Object.prototype.defineProperty instanceof Function)&&Object.prototype.__defineGetter__ instanceof Function&&Object.prototype.__defineSetter__ instanceof Function)Object.defineProperty=function(y,w,A){A.get instanceof Function&&y.__defineGetter__(w,A.get);A.set instanceof Function&&y.__defineSetter__(w,A.set)};F.inherit=function(y,w){K.prototype=w.prototype;y.prototype=new K;y.prototype.constructor=y};F.generateCallback=function(y,w){return function(){w.apply(y,arguments)}};
F.NVector=function(y){if(y===G)y=0;for(var w=Array(y||0),A=0;A<y;++A)w[A]=0;return w};F.is=function(y,w){if(y===null)return false;if(w instanceof Function&&y instanceof w)return true;if(y.constructor.__implements!=G&&y.constructor.__implements[w])return true;return false};F.parseUInt=function(y){return Math.abs(parseInt(y))}})(Box2D);var Vector=Array,Vector_a2j_Number=Box2D.NVector;if(typeof Box2D==="undefined")Box2D={};if(typeof Box2D.Collision==="undefined")Box2D.Collision={};
if(typeof Bo
@andrevenancio
andrevenancio / index.html
Created May 17, 2018 17:13 — forked from stefnotch/index.html
gl-matrix Class and chaining (https://jsbench.github.io/#1aa0ac752bc15eca5b53ad313e1f610a) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>gl-matrix Class and chaining </title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
// list conflicted copies
find ~/Dropbox/ -path "*(*'s conflicted copy [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*" -print
// remove conflicted copies
find ~/Dropbox/ -path "*(*'s conflicted copy [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*" -exec rm -f {} \;
@andrevenancio
andrevenancio / gist:c46ace1311ccd86d7a7ed3d5c0f10369
Created August 23, 2016 05:23
Remove all node_modules from Dropbox
find ~/Dropbox/ -name "node_modules" -type d -exec rm -rf '{}' +
var pos = tracker.getCurrentPosition();
var angleRadians = Math.atan2(pos[25][1] - pos[23][1], pos[25][0] - pos[23][0]);
@andrevenancio
andrevenancio / update.js
Last active December 20, 2017 23:56
Simple example on how to drop some frame, optimising calculations, or renders every N frames on a RequestAnimationFrame update method. (ES6)
let lastTime = Date.now();
const N = 24;
update() {
requestAnimationFrame(update);
// refresh only N times per second
if (Date.now() - lastTime < 1000 / N) {
return;
}
@andrevenancio
andrevenancio / correlation.js
Last active July 5, 2016 02:36
Returns the correlation between two data sets with the same width and height. 0% completely different, 100% same image. (ES6)
correlation(curData, oldData, minCorrelation) {
const sampledDataWidth = 80;
const sampledDataHeight = 60;
let count = 0;
const total = curData.data.length;
for (let i = 0; i < total; i += 4) {
// sampling the R channel, since the images are grayscaled and threshold samplying any of the channels will give the same results.
if (curData.data[i] !== oldData.data[i]) {
count++;
}
@andrevenancio
andrevenancio / threshold.js
Created July 5, 2016 01:39
apply a threshold filter with a fixed constant. (ES6)
threshold(pixels, threshold) {
const d = pixels.data;
for (let i = 0; i < d.length; i += 4) {
const r = d[i + 0];
const g = d[i + 1];
const b = d[i + 2];
let v = 0;
if ((r + g + b) > threshold) {
v = 255;
}
@andrevenancio
andrevenancio / grayscale.js
Last active July 5, 2016 01:15
apply a grayscale filter with a pre-build contrast brightness option. (ES6)
grayscale(pixels, contrast, brightness) {
const d = pixels.data;
for (let i = 0; i < d.length; i += 4) {
const r = d[i + 0];
const g = d[i + 1];
const b = d[i + 2];
const a = d[i + 3];
let v = 0.2126 * r + 0.7152 * g + 0.0722 * b;
if (contrast && brightness) {