Skip to content

Instantly share code, notes, and snippets.

View epreston's full-sized avatar

Ed Preston epreston

View GitHub Profile
@epreston
epreston / isTranferable.js
Created April 30, 2023 05:18
javascript - compatibility - determine if an object is transferable to worker thread
function isTranferable(obj) {
try {
return (
obj instanceof ArrayBuffer ||
obj instanceof MessagePort ||
obj instanceof ImageBitmap || // safari 15+ ios 15+
obj instanceof OffscreenCanvas // safari 16.4+ ios 16.4+
);
} catch {
return false;
@epreston
epreston / WebGL-WebGPU-frameworks-libraries.md
Created August 6, 2024 16:10 — forked from dmnsgn/WebGL-WebGPU-frameworks-libraries.md
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
@epreston
epreston / http-rollup-server.cjs
Created November 26, 2023 03:32
tool: http server and rollup watcher dev env
#!/usr/bin/env node
var fs = require('fs');
var http = require('http');
var path = require('path');
var rollup = require('rollup');
var rollupConfig = require('../rollup.config');
var CONTENT_TYPES = {
'.html': 'text/html',
@epreston
epreston / mini-reset.css
Created August 8, 2023 08:34
css - minimal and opinionated css reset from kevin powell
/* makes sizing simpler */
*,
*::before,
*::after {
box-sizing: border-box;
}
/* remove default spacing */
/* force styling of type through styling, rather than elements */
@epreston
epreston / imgCompress.js
Created August 8, 2023 07:05
javascript - node tool - deeply compress images in a folder
import imagemin from 'imagemin';
import imageminWebp from 'imagemin-webp';
import imageminPngquant from 'imagemin-pngquant';
const produceWebP = async () => {
const outputFolder = './images/webp';
await imagemin(['images/*.png'], {
destination: outputFolder,
plugins: [
@epreston
epreston / basic.eslintrc.json
Last active August 6, 2023 18:16
eslintrc.json - root template, config and rules for prettier, helpful extras
{
"root": true,
"env": {
"es2022": true,
"browser": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
@epreston
epreston / FastSimplexNoise.js
Created April 28, 2023 21:49
noise 2D - fast simplex noise utility function
/*
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
* Better rank ordering method by Stefan Gustavson in 2012.
*
* This code was placed in the public domain by its original author,
* Stefan Gustavson. You may use it as you see fit, but
* attribution is appreciated.
*/
@epreston
epreston / addObjectPool.js
Created April 29, 2023 09:22
add object pool support to a prototype - avoid small object allocation with reuse - alloc, get, release
const isFn = (a) => typeof a === 'function';
export function addObjectPool(objtype, resetFunction, maxSize = Number.MAX_SAFE_INTEGER) {
const pool = [];
function newObject() {
return new objtype();
}
if (isFn(resetFunction)) {
@epreston
epreston / runWhenBrowserEnvReady.js
Last active April 28, 2023 22:09
run callback when browser environment ready - run immediately outside of browser
const isRunningInBrowser = typeof window !== 'undefined';
function runWhenBrowserEnvReady(fn) {
if (isRunningInBrowser) {
const doc = document;
doc.readyState[0] === 'l' ? doc.addEventListener('DOMContentLoaded', fn) : fn();
} else {
fn();
}
}
@epreston
epreston / resolveWhenIdle.js
Last active April 28, 2023 22:01
wait for idle promise - runs async right before paint - safari fallback
const idleOptions = { timeout: 500 };
const request = window.requestIdleCallback || window.requestAnimationFrame;
const cancel = window.cancelIdleCallback || window.cancelAnimationFrame;
const resolveWhenIdle = {
request,
cancel,
promise: (num) => new Promise((resolve) => request(resolve, Object.assign({}, idleOptions, num))),
};