Skip to content

Instantly share code, notes, and snippets.

View stackdumper's full-sized avatar

Elijah A. stackdumper

View GitHub Profile
@stackdumper
stackdumper / run.js
Created March 25, 2018 14:05
Run script in web worker
const run = (fn, ...args) => {
return new Worker(URL.createObjectURL(new Blob([`(${fn})(${args})`])));
}
@stackdumper
stackdumper / controls.js
Created March 22, 2018 18:20
FPS controls for THREE.js
import lock from 'pointer-lock';
const movement = {};
const USER_SPEED = 0.15;
const handleMove = (initial, camera, move) => {
initial.x += move.dx / 3;
if (initial.y + move.dy < 90 && initial.y + move.dy > -90) {
@stackdumper
stackdumper / index.js
Created March 22, 2018 15:34
Map object to array recursively
/**
* Convert map object to multidimensional array
* @param {Object} object map object
* @return {Array} map array
*/
const mapObjectToArray = object =>
Object.keys(object).map((key) => {
if (typeof object[key] === 'object') {
return mapObjectToArray(object[key]);
} else if (typeof object[key] === 'number') {
@stackdumper
stackdumper / index.js
Created March 18, 2018 20:08
2d object normalization
const normalizeMap = (map, min, max) => {
const keys = Object.keys(map);
const values = Object.values(map);
let normalizedValues;
if (typeof values[0] === "object") {
normalizedValues = values.map(v => normalizeMap(v, min, max));
} else {
normalizedValues = normalizeArray(values, min, max);
@stackdumper
stackdumper / index.js
Created March 5, 2018 08:46
Cloud Functions: Upload image from URL to Cloud Storage.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const request = require('request').defaults({ encoding: null });
const cors = require('cors')({ origin: true });
admin.initializeApp(functions.config().firebase);
const bucket = admin.storage().bucket();
exports.uploadImageByURL = functions.https.onRequest((req, res) => {
@stackdumper
stackdumper / webpack.config.js
Created March 4, 2018 09:13
Webpack config for React + Styled Components
const webpack = require('webpack');
const path = require('path');
const config = {
entry: [
'babel-polyfill', './src/index'
],
output: {
path: path.join(__dirname, 'bundle'),
filename: 'bundle.js'