This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios, { get, CancelToken } from 'axios' | |
import faker from 'faker' | |
// | |
// Only data property will be returned from the reuquest. This will simplify | |
// data processing, as it won't be neccesary to call .then() each time | |
// to return the request.data. | |
// See: https://github.com/axios/axios#response-schema | |
// | |
// The status codes validation, if needed, should be done in 'validateStatus' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const COLORS = { | |
info: ['#1E88E5', '#90CAF9'], | |
success: ['#388E3C', '#A5D6A7'], | |
error: ['#E53935', '#EF9A9A'], | |
warning: ['#F4511E', '#FFAB91'], | |
} | |
const print = Object.entries(COLORS).reduce( | |
(api, [name, colors]) => ({ | |
[name]: (shortLabel, longerMessage, optionalSuffix = '') => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instructions: | |
// npm install --save d3 jsdom | |
const fs = require('fs'); | |
const d3 = require('d3'); | |
const jsdom = require('jsdom'); | |
const { JSDOM } = jsdom; | |
const fakeDom = new JSDOM('<!DOCTYPE html><html><body></body></html>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function DraftEditor({ metaData, readOnly = false, decorators = [] }: IDraftEditor) { | |
const editorRef = useRef<HTMLDivElement>(null) | |
const handleFocusClick = () => { | |
const { current: editor } = editorRef | |
if (editor) { editor.focus() } | |
} | |
return ( | |
<div ref={editorRef} onClick={handleFocusClick} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const f = (a, b) => [].concat(...a.map(d => b.map(e => [].concat(d, e)))) | |
const cartesian = (a, b, ...c) => (b ? cartesian(f(a, b), ...c) : a) | |
const letters = Array.from({ length: 26 }, (k, v) => String.fromCharCode(v + 65)) | |
const numbers = Array.from({ length: 9 }, (k, v) => v) | |
console.log(cartesian(letters, numbers)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { types } from 'mobx-state-tree' | |
import bytes from 'bytes' | |
/* | |
* See: https://developers.google.com/web/updates/2016/06/persistent-storage | |
* See: https://developers.google.com/web/updates/2017/08/estimating-available-storage-space | |
*/ | |
const StorageEstimate = types | |
.model('StorageEstimate', { | |
usage: types.maybe(types.number), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useLocalStorage = (key, initial) => { | |
let local; | |
try { | |
local = JSON.parse(localStorage.getItem(key)); | |
} catch (err) { | |
// | |
} | |
if (!local) { | |
localStorage.setItem(key, JSON.stringify(initial)); | |
local = initial; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const GridSpace = styled.section` | |
height: 100%; | |
display: grid; | |
grid-template-columns: repeat(4, 1fr); | |
grid-template-rows: auto fit-content(100%); | |
grid-template-areas: | |
'c c c c' | |
't t t t'; | |
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DataModel = types | |
.model('DataModel', { | |
columns: types.optional(types.array(types.string), ['columnA', 'columnB']), | |
data: types.optional(types.array(types.array(types.string)), []), | |
}) | |
.views(self => ({ | |
get mergedData() { | |
const [keyA, keyB] = self.columns | |
return self.data.map(([valA, valB]) => ({ [keyA]: valA, [keyB]: valB })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Delaying response | |
let delay = time => result => new Promise(resolve => setTimeout(() => resolve(result), time)) | |
const result = await fetch(endpoint).then(delay(1000)).then(data => data.json()) | |
// Mocking Fetch | |
window.fetch = function () { | |
const body = { hello: "world" } | |
const blob = new Blob([JSON.stringify(body, null, 2)], { type : 'application/json' }) |