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
| let c = Symbol(); | |
| h = (tag, attrs = {}, children = [], node = document.createElement(tag)) => { | |
| node[c] = children; | |
| Object.entries(attrs).map(([k, v]) => | |
| /^on/.test(k) | |
| ? node.addEventListener(k.slice(2), v) | |
| : node.setAttribute(k, v), | |
| ); | |
| return node; | |
| }; |
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 whitespaceSymbol = Symbol('whitespace'); | |
| const whitespace = rawWhitespace.map(() => whitespaceSymbol); | |
| const param = (param) => composeParsers([param, whitespace]); | |
| // const | |
| const sexpr = (fn) => { | |
| const [head, ...tail] = fn(); | |
| const params = sequenceOf([head, ...tail.map(param)]); |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
| <title>Static Template</title> | |
| </head> | |
| <body> | |
| <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
| r=(fn) => { | |
| try { | |
| return fn(); | |
| } catch (e) { | |
| // if (e instanceof ReferenceError) { | |
| if (/^Re/.test(e+[])) { | |
| globalThis[q=e.message.split` `[0]]=q; | |
| return r(fn) | |
| } else { | |
| throw e; |
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 h(tag, attrs = {}, children = []) { | |
| const node = document.createElement(tag); | |
| node.__children = children; | |
| Object.entries(attrs).forEach(([k, v]) => { | |
| /^on/.test(k) | |
| ? node.addEventListener(k.slice(2), v) | |
| : node.setAttribute(k, v); | |
| }); | |
| return node; | |
| } |
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 { | |
| str, | |
| char, | |
| digits, | |
| letters, | |
| sequenceOf, | |
| anythingExcept, | |
| anyOfString, | |
| many, | |
| choice, |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width" /> | |
| <title>Fetti</title> | |
| <style> | |
| div { | |
| left: 50%; | |
| right: 50%; |
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 combineProviders(providers) { | |
| return class Combined extends React.Component { | |
| render() { | |
| return ( | |
| providers.reverse().reduce((acc, Provider) => ( | |
| <Provider>{acc}</Provider> | |
| ), this.props.children) | |
| ); | |
| } | |
| } |
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
| // custom hook: useStore | |
| const ctx = createContext(); | |
| export const Store = ({ children }) => { | |
| const [state, setState] = useState(initialState); | |
| const mergeState = useCallback((obj) => { | |
| setState(state => ({ ...state, ...obj })); | |
| }, []); |
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
| #[derive(Debug, Clone, PartialEq)] | |
| enum Token { | |
| Op(char), | |
| Num(f64), | |
| } | |
| fn prec(op: char) -> usize { | |
| match op { | |
| '*' | '/' => 3, | |
| '+' | '-' => 2, |