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
<div id="data"></div> | |
<body> | |
<script> | |
const div = document.querySelector('div') | |
const print = arg => div.insertAdjacentText('beforeend', arg) | |
</script> | |
<script src="https://en.wikipedia.org/w/api.php?action=opensearch&format=json&callback=print&search=google"></script> |
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
function get(path, obj, fb = `$\{${path}}`) { | |
return path.split('.').reduce((res, key) => res[key] || fb, obj); | |
} | |
function parseTpl(template, map, fallback) { | |
return template.replace(/\$\{.+?}/g, (match) => { | |
const path = match.substr(2, match.length - 3).trim(); | |
return get(path, map, fallback); | |
}); | |
} |
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 { adjust, curryN, length, map } from 'ramda' | |
const globalize = transform => selector => | |
curryN(length(selector), | |
(...args) => selector(...adjust(transform, -1, args)) | |
) | |
export default (localStateTransform, selectors) => | |
map(globalize(localStateTransform), selectors) |
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) | |
) |
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 { 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
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
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 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
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 { |