Cross browser device orientation React hook.
function App() {
const orientation = useDeviceOrientation();
return {orientation};
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; | |
} |
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
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} | |
*/ |
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); |
'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); |
#!/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 |
#!/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 |
const Event = { | |
events: {}, | |
on(event, func) { | |
if (!this.events.hasOwnProperty(event)) { | |
this.events[event] = []; | |
} | |
this.events[event].push(func); | |
}, |