Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / backup.sh
Last active September 5, 2016 17:03
A work in progress, incremental backup script in Node.js
'use strict';
const fs = require('fs');
const crypto = require('crypto');
const currentDirectory = `${__dirname}/backup-tests/current`;
const backupDirectory = `${__dirname}/backup-tests/backup`;
const getFileHash = (filePath) => {
const contents = fs.readFileSync(filePath);
@enijar
enijar / colours.sh
Created September 5, 2016 11:29
Print Colours in Terminal
#!/usr/bin/env bash
for i in {0..255} ; do
printf "\x1b[38;5;${i}m%3d " "${i}"
if (( $i == 15 )) || (( $i > 15 )) && (( ($i-15) % 12 == 0 )); then
echo;
fi
done
@enijar
enijar / ssh_tasks.sh
Created August 24, 2016 08:38
Execute Set of Tasks via SSH
#!/usr/bin/env bash
ssh -i ~/path/to/ssh_key [email protected] -T <<EOF
echo "Execute some set of tasks"
cd /path/to/some/dir
echo "Pulling from master branch..."
git pull
echo -e ""
exit
EOF
@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);
},