Skip to content

Instantly share code, notes, and snippets.

View stackdumper's full-sized avatar

Elijah A. stackdumper

View GitHub Profile
import React, { Component } from 'react';
import { NavigationActions } from 'react-navigation';
import { reaction } from 'mobx';
import { inject, observer } from 'mobx-react';
const navigateWithReset = (navigation, targetRoute) => {
const resetAction = NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: targetRoute })],
});
@stackdumper
stackdumper / index.js
Created April 29, 2018 17:31
react-coolkeys
import React, { Component } from 'react'
import Mousetrap from 'mousetrap'
const KeymapContext = React.createContext()
export const CoolKeysProvider = ({ keymap, children }) => (
<KeymapContext.Provider value={keymap}>{children}</KeymapContext.Provider>
)
@stackdumper
stackdumper / eslintrc.yaml
Created April 15, 2018 07:01
Eslint react sort comp
react/sort-comp:
- warn
-
order:
- static-methods
- constructor
- lifecycle
- /^on.+$/
- /^handle.+$/
- getters
/* 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')