Skip to content

Commit

Permalink
00000015-ea567b02
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Jan 1, 2020
1 parent a284c87 commit 5b3fbd6
Show file tree
Hide file tree
Showing 10 changed files with 251,767 additions and 471 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": true,
"run": true,
"scripts": true,
"src/global.d.ts": true,
"src/react-app-env.d.ts": true,
"tsconfig.json": true,
"yarn": true,
Expand Down
79 changes: 50 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
{
"name": "project",
"version": "0.0.0",
"license": "UNLICENSED",
"private": true,
"engines": {
"node": "14.3.0"
},
"scripts": {
"build": "scripts/build",
"deploy": "yarn install; yarn deploy-gh-pages",
"deploy-gh-pages": "scripts/deploy-gh-pages",
"deploy": "yarn install; yarn deploy:gh-pages",
"deploy:gh-pages": "scripts/deploy-gh-pages",
"name": "scripts/name",
"pretty": "scripts/pretty",
"start": "react-scripts start"
},
"devDependencies": {
"@emotion/core": "^10.0.28",
"@shopify/useful-types": "^2.1.5",
"@types/node": "^14.0.5",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"bip39": "^3.0.2",
"emotion": "^10.0.27",
"fp-ts": "^2.6.1",
"import-sort-cli": "^6.0.0",
"import-sort-parser-typescript": "^6.0.0",
"import-sort-style-module": "^6.0.0",
"io-ts": "^2.2.3",
"io-ts-promise": "^2.0.2",
"io-ts-types": "^0.5.6",
"json-sort-cli": "^1.15.22",
"monocle-ts": "^2.1.0",
"prettier": "^2.0.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "^3.4.1",
"typescript": "^3.9.3",
"word-list-google": "^1.0.1"
},
"type": "module",
"browserslist": {
"development": [
"last 1 chrome version",
Expand Down Expand Up @@ -49,27 +71,26 @@
"proseWrap": "always",
"trailingComma": "none"
},
"type": "module",
"devDependencies": {
"@emotion/core": "^10.0.28",
"@shopify/useful-types": "^2.1.5",
"@types/node": "^14.0.5",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"emotion": "^10.0.27",
"fp-ts": "^2.6.1",
"import-sort-cli": "^6.0.0",
"import-sort-parser-typescript": "^6.0.0",
"import-sort-style-module": "^6.0.0",
"io-ts": "^2.2.3",
"io-ts-promise": "^2.0.2",
"io-ts-types": "^0.5.6",
"json-sort-cli": "^1.15.22",
"lint-staged": "^10.2.6",
"prettier": "^2.0.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "^3.4.1",
"typescript": "^3.9.3"
}
"format-package": {
"order": [
"engines",
"scripts",
"devDependencies",
"dependencies",
"peerDependencies",
"resolutions",
"type",
"...rest",
"format-package",
"private",
"license",
"name",
"version",
"author"
]
},
"private": true,
"license": "UNLICENSED",
"name": "project",
"version": "0.0.0"
}
8 changes: 5 additions & 3 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
set -euo pipefail;

CNAME="${CNAME:-}";
if [ "${CNAME}" = "" ]; then
if [ "${CNAME}" = "" ] || [ "${CNAME}" = "_.otter.academy" ]; then
if [ ! -e ./src/CNAME ]; then
CNAME="$(basename "${PWD}").otter.academy";
echo "${CNAME}" > ./src/CNAME;
CNAME="$(scripts/names.js).otter.academy";
if [ "${CNAME}" = "" ]; then
echo "${CNAME}" > ./src/CNAME;
fi
fi
fi

Expand Down
Empty file modified scripts/deploy-gh-pages
100755 → 100644
Empty file.
130 changes: 130 additions & 0 deletions scripts/names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env node

import fs from "fs";

import bip39 from "bip39";
import dictionary from "word-list-google";

const nameLengthMin = 12;
const nameLengthMax = 12;
const wordLengthMin = 3;
const wordLengthMax = 6;
const overlapMin = 2;
const overlapMax = 4;

Promise.resolve().then(async function main() {
const path = "./scripts/names.txt";
let names;
try {
names = fs
.readFileSync(path, { encoding: "utf8" })
.split("\n")
.filter(Boolean);
const invalidNames = names.filter(
(name) =>
!(
nameLengthMin <= name.length &&
name.length <= nameLengthMax &&
name.match(/^[a-z]+/)
)
);
if (invalidNames.length > 0) {
throw new Error(
`Existing names were invalid (example: ${invalidNames[0]}).`
);
}
if (names.length <= 1000) {
throw new Error(`Too few existing names (${names.length}).`);
}
} catch (error) {
console.error("Regenerating names; ", error);
names = await regenerate();
fs.writeFileSync(path, names.join("\n"), {
encoding: "utf8"
});
}

let n = Number(process.argv[2]);
if (!Number.isInteger(n)) {
n = 1;
}

for (let i = 0; i < n; i += 1) {
console.log(choose(names));
}
});

const words = [
...new Set(
[
...dictionary.englishNoSwears
.filter((word) => word.length >= 4)
.slice(0, 2000),
...bip39.wordlists.english
]
.map((word) => word.toLowerCase())
.filter(
(word) =>
word.match(/^[a-z]+$/) &&
wordLengthMin <= word.length &&
word.length <= wordLengthMax
)
)
].sort();

async function regenerate() {
console.error(
"Generating all names matching",
{
nameLengthMin,
nameLengthMax,
wordLengthMin,
wordLengthMax,
overlapMin,
overlapMax
},
`using a dictionary of ${words.length} words.`
);
const startGenerate = Date.now();
const names = [...new Set(makeNames())].sort();
const elapsedGenerate = (Date.now() - startGenerate) / 1000;

console.error(
`Generated ${names.length} names in ${elapsedGenerate.toFixed(1)}s.`
);

return names;
}

function* makeNames(prefix = "") {
if (nameLengthMin <= prefix.length && prefix.length <= nameLengthMax) {
yield prefix;
}

const clampedOverlapMin = Math.min(overlapMin, prefix.length);
const clampedOverlapMax = Math.max(overlapMax, clampedOverlapMin);

for (
let overlap = clampedOverlapMin;
overlap <= clampedOverlapMax;
overlap += 1
) {
const overlapping = prefix.slice(-overlap);
const preOverlapping = prefix.slice(0, -overlap);
const minWordLength = Math.max(overlap + 1, wordLengthMin);
const maxWordLength = nameLengthMax - prefix.length + overlap;
for (const word of words) {
if (
minWordLength <= word.length &&
word.length <= maxWordLength &&
word.startsWith(overlapping)
) {
yield* makeNames(preOverlapping + word);
}
}
}
}

function choose(array) {
return array[Math.floor(array.length * Math.random())];
}
Loading

0 comments on commit 5b3fbd6

Please sign in to comment.