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
// Round up to nearest base, in base 10. Works for both negative/positive numbers and numbers -1 < n < 1. | |
// Useful for calculating a sensible/readible graph domain max if you input the max value of your data. | |
export const roundUpBaseInRange = (n, bases = [1, 2, 4, 5, 6, 8, 10]) => { | |
// Store the sign, so we can restore it for the result lateron | |
const sign = Math.sign(n) | |
// Get modulus (remove sign) for next steps in calculation | |
const modulus = Math.abs(n) | |
// Calculate base10 exponent (i.e. amount of digits as float instead of integer) |
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 { configureCacheGroups } = require('./webpack.utils') | |
const cacheGroups = configureCacheGroups({ | |
'react': ['react', 'react-dom'], | |
'lodash': ['lodash'], | |
'redux': ['redux', 'react-redux'], | |
'semantic-ui': ['semantic-ui-react'], | |
'core-js': ['core-js'], | |
}) |
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
// quick idea to reduce an array by automatically merging result of iteratee(current, i, src) onto acc | |
const reduceMerge = (arr, iteratee) => | |
arr.reduce((acc, cur, i, src) => { | |
const val = iteratee(cur, i, src) | |
// allow falsy returns to result in noop for this iteration | |
if (!val) { | |
return acc | |
} else if (val.constructor === Object) { | |
return Object.assign(acc, val) | |
} |
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
@mixin with-speech-arrow ( | |
$align: left, | |
$size: 20px, | |
$border-color: #eee | |
) { | |
&:before, | |
&:after { | |
content: ''; | |
position: absolute; | |
border-color: transparent; |
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
/** | |
* Add an inset border (in a single direction) to an element | |
* Examples: | |
* @include inset-border(bottom) | |
* @include inset-border(right, 3px, red) | |
*/ | |
@mixin inset-border ($direction, $width: 1px, $color: black, $opacity: 0.05) { | |
$y: if($direction == bottom, -$width, if($direction == top, $width, 0)); | |
$x: if($direction == right, -$width, if($direction == left, $width, 0)); | |
box-shadow: inset #{$x} #{$y} 0 0 rgba($color, $opacity); |
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
class WeightedQuickUnionFind { | |
constructor (ids) { | |
this._map = new Map() // id-to-component map | |
this._sizes = new Map() // subtree size map | |
this.length = ids.length // component count | |
ids.forEach((id) => { | |
this._map.set(id, id) | |
this._sizes.set(id, 1) | |
}) |
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 React from 'react' | |
import { connect } from 'react-redux' | |
/** | |
* Item Component | |
*/ | |
const Item = ({ item }) => ( | |
<li className="item"> | |
<div> |
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
// Adapted from “Algorithms, Part I” course by “Princeton University” on coursera.org | |
const defaultCompare = (a, b) => | |
a < b ? -1 : 1 | |
const merge = (arr, aux, compare, low, mid, high) => { | |
// left and right half scan indices | |
let l = low, r = mid + 1 | |
// copy into auxillary array |
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
/** | |
* convert a string to css hex values suitable for use in css “content” prop | |
* @example | |
* hexify('foo@bar') // '\0066\006f\006f\0040\0062\0061\0072' | |
*/ | |
const hexify = (string) => | |
[...string] | |
.map((c) => `\\${Number(c.charCodeAt()).toString(16).padStart(4, '0')}`) | |
.join('') |
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
/** | |
* Types & Interfaces | |
*/ | |
type State = { [key: string]: any } | |
type Reducer = (currentState: State, action: Action) => State; | |
type Listener = (currentState?: State) => void; |
OlderNewer