Skip to content

Instantly share code, notes, and snippets.

View stackdumper's full-sized avatar

Elijah A. stackdumper

View GitHub Profile
/* VT100 terminal reset (<ESC>c) */
console.log('\033c');
/* numbers comparations */
> '2' == 2
true
> '2' === 2
@stackdumper
stackdumper / script.js
Created April 13, 2018 06:51
interesting task solution
const genSolution = (number) => {
const string = number.toString();
let result = '';
for (let i = string.length; i > 0; i -= 3) {
result = ((i - 3 > 0) ? ',' : '') + string.slice(i - 3 >= 0 ? i - 3 : 0, i) + result;
}
return result;
}
module.exports = ({ map, position, chunkSize }) => {
const [x, y, z] = position.map((n) => Number(n))
let blockHidden = true
for (let k = -1; k <= 1; k++) {
const yPos = y + k
if (yPos > 0) {
if (!(map[x] && map[x][z] && map[x][z][yPos])) {
@stackdumper
stackdumper / noise.js
Created April 9, 2018 06:43
Noise.js for WebWorkers
/*
* A speed-improved perlin and simplex noise algorithms for 2D.
*
* Based on example code by Stefan Gustavson ([email protected]).
* Optimisations by Peter Eastman ([email protected]).
* Better rank ordering method by Stefan Gustavson in 2012.
* Converted to Javascript by Joseph Gentle.
*
* Version 2012-03-09
*
const getFreq = (pos, divider, offset) => pos > divider - offset
? pos < divider + offset ? divider - offset : divider + offset - (pos - (divider - offset))
: pos
@stackdumper
stackdumper / index.js
Created April 2, 2018 12:34
Export countries to firestore document
const fetch = require('node-fetch');
const fireAdmin = require('firebase-admin');
fireAdmin.initializeApp({
credential: fireAdmin.credential.applicationDefault()
});
const getCountries = () =>
new Promise((resolve, reject) => {
fetch('https://restcountries.eu/rest/v2/all')
@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') {