Skip to content

Instantly share code, notes, and snippets.

@ifyoumakeit
ifyoumakeit / templatejs.js
Last active March 19, 2018 17:23
Quick JS templating with string template literals
const resolveExpression = exp => {
const resolved = typeof exp === "function" ? exp() : exp;
return Array.isArray(resolved)
? resolved.join("")
: typeof resolved !== "undefined" ? resolved : "";
};
const html = (strings, ...exps) => {
return strings.reduce((acc, str, i) => {
return `${acc}${resolveExpression(exps[i - 1])}${str}`;
@catb0t
catb0t / mypy_json.pyi
Last active October 3, 2020 09:37
Strict no-Any MyPy JSON type
# modified from Original source: https://github.com/python/mypy/issues/731#issuecomment-539905783
from typing import Union, Dict, List
JSONPrimitive = Union[str, int, bool, None]
JSONType = Union[JSONPrimitive, 'JSONList', 'JSONDict']
# work around mypy#731: no recursive structural types yet
class JSONList(List[JSONType]):
pass