This file contains hidden or 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 seenKeys = new Set() | |
const MULTIPLIER = Math.pow(2, 24) | |
const generateRandomKey = () => { | |
const key = Math.floor(Math.random() * MULTIPLIER).toString(32) | |
if (seenKeys.has(key) || !isNaN(+key)) | |
return generateRandomKey() | |
seenKeys.add(key) | |
return key |
This file contains hidden or 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 gFoo = function* () { | |
const a = yield Promise.resolve(1) | |
const b = yield Promise.resolve(2) | |
const c = yield Promise.resolve(3) | |
const d = yield Promise.resolve(4) | |
return [a, b, c, d] | |
} | |
const co = genF => (...args) => { |
This file contains hidden or 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
export const eventName = 'in view' | |
export const tagName = 'inview-observer' | |
const io = new IntersectionObserver((entries, observer) => { | |
entries.forEach(entry => { | |
const target = entry.target | |
target.dispatchEvent(new Event('in view')) | |
}) | |
}, { threshold: 0.25 }) |
This file contains hidden or 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, { PureComponent } from 'react' | |
import PropTypes from 'prop-types' | |
import { autobind } from 'core-decorators' | |
import { path, omit, forEach, compose, curry } from 'ramda' | |
const themeManagers = new WeakMap() | |
@autobind | |
export class ThemeManager { |
This file contains hidden or 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
module ChurchNumberals where | |
type ChurchNumberals a = (a -> a) -> a -> a | |
one :: ChurchNumberals a | |
one f = f | |
two :: ChurchNumberals a | |
two f = f . f |
This file contains hidden or 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
module ValidateCCNumbers where | |
toDigits :: Integer -> [Int] | |
toDigits 0 = [0] | |
toDigits n | |
| n > 0 = | |
if a > 0 | |
then toDigits a ++ [fromInteger b :: Int] | |
else [fromInteger b :: Int] | |
where |
This file contains hidden or 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
module ShiftString where | |
import Data.Char | |
data CharacterNumber | |
= Lower Int | |
| Upper Int | |
add' :: CharacterNumber -> Int -> CharacterNumber | |
add' (Lower a) b = Lower (a + b) |
This file contains hidden or 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 { propOr, identity } from 'ramda' | |
const createReducer = (initialState, handlers) => | |
(state = initialState, action) => | |
propOr(identity, action.type, handlers)(state, action) | |
export default createReducer |
This file contains hidden or 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 ensureStartsWith = (start, str) => str.startsWith(start) ? str : start + str | |
const setSearchParam = searchStr => | |
(key, value) => { | |
if (!value) return searchStr | |
const searchParams = new URLSearchParams(searchStr) | |
searchParams.set(key, value) | |
const newSearchStr = |
This file contains hidden or 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 { | |
compose, map, ifElse, filter, isEmpty, | |
endsWith, init, identity, join | |
} from 'ramda' | |
const urljoin = compose( | |
join('/'), | |
map(ifElse(endsWith('/'), init, identity)), | |
filter(isEmpty) | |
) |