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
| // You should probably use Vorpal.js instead of this. | |
| // usage demo down at the bottom of the file... | |
| const Repl = require('repl'); | |
| const util = require('util'); | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| // Don't be a repli-can't, be a... | |
| class Replican { |
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 line = '"" "a b" "a b c" "a \\" marvellous" \'we like\'a"b a""b abab abb "hi"'; | |
| const gre = /\s*(?:(?:"((?:\\"|[^"])*)")|(?:'((?:\\'|[^'])*)')|([^\s]+))/g; | |
| function split(str) { | |
| const result = []; | |
| str.replace(gre, (part, dquoteMatch, squoteMatch, wsMatch, offset, fullString) => { | |
| result.push(dquoteMatch !== undefined ? dquoteMatch : squoteMatch !== undefined ? squoteMatch : wsMatch) | |
| }); | |
| return result; | |
| } |
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 fetch = require('node-fetch'); | |
| const lotteries = { | |
| lotto: { | |
| balls: [ | |
| {number: 6, from:1, to: 59} | |
| ] | |
| }, | |
| euromillions: { | |
| balls: [ |
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
| <html> | |
| <head> | |
| <title>React</title> | |
| <script type="application/javascript" crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> | |
| <script type="application/javascript" crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> | |
| </head> | |
| <body> | |
| <div id="root"></div> | |
| <script type="application/javascript"> |
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
| <html> | |
| <head> | |
| <style> | |
| body { | |
| background-color: turquoise; | |
| } | |
| #age { | |
| color: white; | |
| font-size: xxx-large; |
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
| <html> | |
| <head> | |
| <style> | |
| body { | |
| background-color: turquoise; | |
| } | |
| #age { | |
| color: white; | |
| font-size: xxx-large; |
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 min = (a,b) => (a < b) ? a : b // this works on big ints too, unlike Math.min | |
| const err = message => {throw new Error(message)} // useful if you want to throw an error in an expression | |
| const castToNumber = bigInt => (BigInt(bigInt) <= Number.MAX_SAFE_INTEGER) ? Number(bigInt) : err(`Number too big: ${bigInt} > MAX_SAFE_INTEGER`) | |
| const prefixTo = (array, length) => (array.length >= length) ? array : [...Array(length - array.length).fill(0), ...array] | |
| const factorial = (() => { | |
| const lookupTableSize = 20 | |
| let lastVal = 1n | |
| const lookUp = Array.from({length: lookupTableSize}, (_,i) => lastVal = i === 0 ? lastVal : BigInt(i) * lastVal) | |
| return function factorial(n) { |
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
| class Op { | |
| constructor(symbol, precedence, leftAssociate, apply) { | |
| Object.assign(this, {symbol, precedence, leftAssociate, apply}) | |
| } | |
| process(stack) { | |
| if (this.apply === null) return | |
| const args = [] | |
| for (let i = 0; i < this.apply.length; i++) { | |
| const arg = stack.pop() | |
| if (arg === undefined) { |
OlderNewer