Skip to content

Instantly share code, notes, and snippets.

Ben Foxall benfoxall

Block or report user

Report or block benfoxall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View vis.js
class AudioVis {
constructor() {
this.analyser =
this.data = new Uint8Array()
this.frequencies = new Uint8Array()
}
populateArrays() {
@benfoxall
benfoxall / script.js
Last active Feb 13, 2018
A script that runs in 5 places
View script.js
if(typeof document !== 'undefined') {
// normal script tag
console.log("Hello #1")
navigator.serviceWorker.register(
document.currentScript.src
)
} else {
// running as a service worker
@benfoxall
benfoxall / font-sw.js
Last active Sep 22, 2017
Other Service Workers
View font-sw.js
importScripts('https://unpkg.com/sw-toolbox@3.6.0/sw-toolbox.js')
toolbox.router.get('/:path*', toolbox.cacheFirst, {
origin: /fonts\.(gstatic|googleapis)\.com/,
cache: {
name: 'fonts-v1',
maxEntries: 10
}
}
)
View one-liners.js
let delayed = new Promise(r => setTimeout(r, 500, 'hello'))
let element = Object.assign(
document.createElement('div'),
{textContent: 'hello'}
)
Object.assign(element.style, {
background: 'red'
})
View depth.js
(function(root) {
Object.assign(document.body.style, {
'transform': 'perspective(500px) rotateY(12deg) rotateX(9deg) rotateZ(-4deg) translate3d(56%, 26%, -516px)',
'transform-origin': '0 0',
'transform-style': 'preserve-3d'
})
const node_style = {
'outline': '3px solid rgba(255,0,150,0.5)',
'transform-style': 'preserve-3d',
View regression.js
// includes regression
// https://unpkg.com/regression@1.4.0/build/regression.min.js
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d')
document.body.appendChild(canvas)
Object.assign(canvas.style, {border:'1px solid #ccc', margin:0})
var m = 1
View basic-flooding.js
var rgb = new Uint8ClampedArray(50 * 3);
// Set the colours of a particular light (i) at a given intensity (s)
function set(r, g, b, i, s){
i *= 3;
if(i > 0) {
rgb[i] = rgb[i] + ((r - rgb[i]) * s); i++;
rgb[i] = rgb[i] + ((g - rgb[i]) * s); i++;
rgb[i] = rgb[i] + ((b - rgb[i]) * s); i++;
View chunktowav.js
var chunkToWAV = (function(chunkSize){
var head = atob(
'UklGRiQAAABXQVZFZm10IBAAAAABAAEAgD4AAAB9AAACABAAZGF0YQAAAAA='
)
var buffer = new ArrayBuffer(head.length + chunkSize)
var view = new DataView(buffer)
for (var i = 0; i < head.length; i++) {
@benfoxall
benfoxall / mathematical.js
Created Oct 14, 2016
Paste this into cojs.co
View mathematical.js
import {ctx, w, h} from 'canvas'
import {loop, drawEdge, scale, rotateX, rotateY, rotateZ} from 'helpers'
const pM = $M([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0.005,0.995]
])
@benfoxall
benfoxall / cluster.js
Created Oct 12, 2016
Cluster wrapper thing
View cluster.js
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
You can’t perform that action at this time.