Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖
HTTP 203

James Enijar

🤖
HTTP 203
View GitHub Profile
@Enijar
Enijar / in-bounds.glsl
Created Jan 20, 2022
GLSL function to check if a point/mouse is inside a box
View in-bounds.glsl
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 Nov 10, 2021
Cross browser device orientation React hook.
View README.md

Device Orientation Hook

Cross browser device orientation React hook.

Usage

function App() {
  const orientation = useDeviceOrientation();
 return {orientation};
View README.md

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 Feb 5, 2020
Linear mapping function
View README.md

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 Nov 22, 2018
Node server queue idea.
View queue.js
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 Oct 31, 2018
IndexedDB Cache Images
View image-cache.js
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 Sep 5, 2016
A work in progress, incremental backup script in Node.js
View backup.sh
'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 Sep 5, 2016
Print Colours in Terminal
View colours.sh
#!/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 Aug 24, 2016
Execute Set of Tasks via SSH
View ssh_tasks.sh
#!/usr/bin/env bash
ssh -i ~/path/to/ssh_key username@255.255.255.255 -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 Nov 1, 2016
JavaScript Event System
View Event.js
const Event = {
events: {},
on(event, func) {
if (!this.events.hasOwnProperty(event)) {
this.events[event] = [];
}
this.events[event].push(func);
},