Skip to content

Instantly share code, notes, and snippets.

View Shuumatsu's full-sized avatar

为世人降下祝福 Shuumatsu

View GitHub Profile
<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>
@Shuumatsu
Shuumatsu / parse-es6-template.js
Created July 24, 2017 15:19 — forked from smeijer/parse-es6-template.js
ES6 template string parser
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);
});
}
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)
import {
compose, map, ifElse, filter, isEmpty,
endsWith, init, identity, join
} from 'ramda'
const urljoin = compose(
join('/'),
map(ifElse(endsWith('/'), init, identity)),
filter(isEmpty)
)
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 =
import { propOr, identity } from 'ramda'
const createReducer = (initialState, handlers) =>
(state = initialState, action) =>
propOr(identity, action.type, handlers)(state, action)
export default createReducer
module ShiftString where
import Data.Char
data CharacterNumber
= Lower Int
| Upper Int
add' :: CharacterNumber -> Int -> CharacterNumber
add' (Lower a) b = Lower (a + b)
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
module ChurchNumberals where
type ChurchNumberals a = (a -> a) -> a -> a
one :: ChurchNumberals a
one f = f
two :: ChurchNumberals a
two f = f . f
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 {