Skip to content

Instantly share code, notes, and snippets.

@mattdesl
mattdesl / randao-roll.js
Created Sep 16, 2022
roll a 6-sided die with the blockchain using Ethereum Proof of Stake RANDAO.
View randao-roll.js
const Web3 = require("web3");
const BN = Web3.utils.BN;
(async () => {
const network = "mainnet";
const web3 = new Web3(
new Web3.providers.HttpProvider(
`https://${network}.infura.io/v3/${process.env.INFURA_API_KEY}`
)
);
View stylegan.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Python 3 PFM Reader-Writer
import numpy as np
import re
import sys
'''
Read a PFM file into a Numpy array. Note that it will have
a shape of H x W, not W x H. Returns a tuple containing the
loaded image and the scale factor from the file.
'''
def read_pfm(file):
@vlasky
vlasky / point_in_polygon_using_winding_number.js
Last active Nov 7, 2022
JavaScript implementation of winding number algorithm to determine whether a point is inside a polygon
View point_in_polygon_using_winding_number.js
//JavaScript implementation of winding number algorithm to determine whether a point is inside a polygon
//Based on C++ implementation of wn_PnPoly() published on http://geomalgorithms.com/a03-_inclusion.html
function pointInPolygon(point, vs) {
const x = point[0], y = point[1];
let wn = 0;
for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
let xi = vs[i][0], yi = vs[i][1];
let xj = vs[j][0], yj = vs[j][1];
View gist:96a1f554c3f88eef2f9d0024fc42940f
var cameraZ = camera.position.z;
var planeZ = 5;
var distance = cameraZ - planeZ;
var aspect = viewWidth / viewHeight;
var vFov = camera.fov * Math.PI / 180;
var planeHeightAtDistance = 2 * Math.tan(vFov / 2) * distance;
var planeWidthAtDistance = planeHeightAtDistance * aspect;
// or
@dmnsgn
dmnsgn / WebGL-WebGPU-frameworks-libraries.md
Last active Dec 8, 2022
A collection of WebGL and WebGPU frameworks and libraries
View WebGL-WebGPU-frameworks-libraries.md

A non-exhaustive list of WebGL and WebGPU frameworks and libraries. It is mostly for learning purposes as some of the libraries listed are wip/outdated/not maintained anymore.

Engines and libraries

Name Stars Last Commit Description
three.js ![GitHub Rep
@roboshoes
roboshoes / tween.js
Last active Jan 25, 2018
Small tweening function for the quick tween.
View tween.js
export function tween( time, update ) {
const start = Date.now();
var isCanceled = false;
var isComplete = false;
var chain = [];
function loop() {
if ( isCanceled ) return;
@ayamflow
ayamflow / gist:b602ab436ac9f05660d9c15190f4fd7b
Created May 9, 2016
Safari border-radius + overflow: hidden + CSS transform fix
View gist:b602ab436ac9f05660d9c15190f4fd7b
// Add on element with overflow
-webkit-mask-image: -webkit-radial-gradient(white, black);
@gordonbrander
gordonbrander / boing.js
Last active Nov 6, 2022
boing.js - minimal 2D spring physics
View boing.js
export const Spring = (x, y, mass, stiffness, viscosity) => ({
prevX: x,
prevY: y,
currX: x,
currY: y,
mass, stiffness, viscosity
});
Spring.copy = (spring) => ({
prevX: spring.prevX,
View ffmpeg.md

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

You can get the list of installed codecs with: