Skip to content

Instantly share code, notes, and snippets.

@enijar
enijar / image-cache.js
Created October 31, 2018 08:46
IndexedDB Cache Images
class Cache {
constructor(props = {}) {
this.version = props.version || 1;
this.assets = {};
this.db = null;
}
init() {
return new Promise(resolve => {
const request = indexedDB.open('tactics.cache', this.version);
@enijar
enijar / plugins.md
Last active August 25, 2022 02:24
Useful
@enijar
enijar / in-bounds.glsl
Created January 20, 2022 14:02
GLSL function to check if a point/mouse is inside a box
bool inBounds(vec2 mouse, vec2 uv, float width, float height) {
float mx = mouse.x;
float my = 1.0 - mouse.y;
bool inX = mx >= uv.x - width && mx <= uv.x + width;
bool inY = my >= uv.y - height && my <= uv.y + height;
return inX && inY;
}
@enijar
enijar / footer.php
Last active November 23, 2021 10:19
Minify JavaScript and CSS Files
@enijar
enijar / README.md
Last active November 10, 2021 17:04
Cross browser device orientation React hook.

Device Orientation Hook

Cross browser device orientation React hook.

Usage

function App() {
  const orientation = useDeviceOrientation();
 return {orientation};

Mac Mini Installation Instructions

Instructions for getting the Mac Mini provisioned for running event applications.

Login

The username should be set to finervision. The password will be a generic password, and will need to be added to the company's 1Password vault.

IMPORTANT

@enijar
enijar / README.md
Created February 5, 2020 22:43
Linear mapping function

Takes a value from range (x1, y1) and maps that value to a new range (x2, y2).

const map = (value, x1, y1, x2, y2) => (value - x1) * (y2 - x2) / (y1 - x1) + x2;

const value = 5; // range (1, 10)
console.log(map(value, 1, 10, 0, 1)); // 0.5
@enijar
enijar / queue.js
Last active November 22, 2018 12:43
Node server queue idea.
const TPS = 20;
const Queue = {
counter: 1,
items: {},
/**
* Add an item to the queue, with the given func to call
* @param {Function} func
* @param {Boolean} repeating
* @return {Number}
*/
@enijar
enijar / package.json
Last active December 28, 2017 13:57
React + Babelify + Watchify with Node Scripts
{
"private": true,
"name": "ReactValidation",
"version": "1.0.0",
"description": "Validates form elements.",
"repository": {
"type": "git",
"url": "git@bitbucket.org:Enijar/reactvalidation.git"
},
"dependencies": {
@enijar
enijar / Event.js
Last active November 1, 2016 03:30
JavaScript Event System
const Event = {
events: {},
on(event, func) {
if (!this.events.hasOwnProperty(event)) {
this.events[event] = [];
}
this.events[event].push(func);
},