Skip to content

Instantly share code, notes, and snippets.

View raphaelameaume's full-sized avatar

Raphaël Améaume raphaelameaume

View GitHub Profile
@paulirish
paulirish / rAF.js
Last active July 2, 2024 11:59
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@edankwan
edankwan / snoise2d.js
Created April 6, 2014 06:42
2d snoise Javascript post
// port from GLSL code base on https://github.com/ashima/webgl-noise/blob/master/src/noise2D.glsl
//JS SNOISE PORT
function snoise2d(x, y) {
var C0 = 0.211324865405187;
var C1 = -0.577350269189626;
var C2 = 1.79284291400159;
var OVER_289 = 1 / 289;
@activetheory
activetheory / levels.glsl
Created January 5, 2016 00:06
A GLSL module for color levels manipulation
float levelChannel(float inPixel, float inBlack, float inGamma, float inWhite, float outBlack, float outWhite) {
return (pow(((inPixel * 255.0) - inBlack) / (inWhite - inBlack), inGamma) * (outWhite - outBlack) + outBlack) / 255.0;
}
vec3 levels(vec3 inPixel, float inBlack, float inGamma, float inWhite, float outBlack, float outWhite) {
vec3 o = vec3(1.0);
o.r = levelChannel(inPixel.r, inBlack, inGamma, inWhite, outBlack, outWhite);
o.g = levelChannel(inPixel.g, inBlack, inGamma, inWhite, outBlack, outWhite);
o.b = levelChannel(inPixel.b, inBlack, inGamma, inWhite, outBlack, outWhite);
return o;
@ilfroloff
ilfroloff / ClassA.js
Last active March 4, 2024 09:01
JavaScript Singleton using class
'use strict';
import Singleton from 'Singleton';
class ClassA extends Singleton {
constructor() {
super();
}
singletonMethod1() {
// ...
@mjackson
mjackson / .eslintrc
Last active January 12, 2018 22:28
My personal ESLint config
{
"extends": "airbnb",
"parser": "babel-eslint",
"rules": {
"array-bracket-spacing": [2, "always"],
"comma-dangle": 0,
"consistent-return": 1,
"curly": [1, "multi-or-nest", "consistent"],
"eqeqeq": [2, "smart"],
"max-len": 1,
@Rich-Harris
Rich-Harris / service-workers.md
Last active July 10, 2024 17:04
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@Samsy
Samsy / gist:f8c2a62e41519a404ee8617f88234a7b
Last active April 20, 2021 19:48
Orbit control with smoother
import {
EventDispatcher,
Vector2,
Vector3,
MOUSE,
Quaternion,
Spherical,
PerspectiveCamera,
OrthographicCamera,
} from 'three';
@ljharb
ljharb / array_iteration_thoughts.md
Last active May 22, 2024 09:22
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

@dmnsgn
dmnsgn / WebGL-WebGPU-frameworks-libraries.md
Last active July 18, 2024 00:25
A collection of WebGL and WebGPU frameworks and libraries

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
@ayamflow
ayamflow / gist:96a1f554c3f88eef2f9d0024fc42940f
Last active May 15, 2024 12:37
Threejs Fit plane to screen
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