-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
- Loading branch information
Showing
5 changed files
with
252 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
adventurous | ||
affectionate | ||
ambitious | ||
amiable | ||
blissful | ||
brave | ||
brilliant | ||
caring | ||
cheerful | ||
confident | ||
courageous | ||
creative | ||
delightful | ||
eager | ||
elegant | ||
energetic | ||
enthusiastic | ||
excited | ||
exuberant | ||
friendly | ||
generous | ||
gentle | ||
grateful | ||
happy | ||
harmonious | ||
hopeful | ||
inspirational | ||
intelligent | ||
jovial | ||
joyful | ||
kind | ||
lively | ||
loving | ||
magical | ||
mindful | ||
optimistic | ||
passionate | ||
peaceful | ||
positive | ||
radiant | ||
resilient | ||
sincere | ||
spirited | ||
strong | ||
thankful | ||
thriving | ||
tranquil | ||
uplifting | ||
vibrant | ||
vivacious | ||
warm | ||
wise | ||
wonderful | ||
zealous | ||
admirable | ||
blissful | ||
bountiful | ||
charming | ||
cheerful | ||
compassionate | ||
confident | ||
dazzling | ||
effervescent | ||
empathetic | ||
engaging | ||
enlightened | ||
fascinating | ||
gracious | ||
gregarious | ||
inspiring | ||
jubilant | ||
kindhearted | ||
motivated | ||
nurturing | ||
passionate | ||
radiant | ||
remarkable | ||
spirited | ||
stellar | ||
thrilling | ||
vibrant | ||
wholesome | ||
zealous |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod commands; | ||
mod opts; | ||
mod random_name; | ||
mod spin; | ||
|
||
use anyhow::{Error, Result}; | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
cat | ||
dog | ||
bird | ||
lion | ||
tiger | ||
elephant | ||
monkey | ||
snake | ||
bear | ||
rabbit | ||
fish | ||
horse | ||
cow | ||
sheep | ||
pig | ||
frog | ||
kangaroo | ||
giraffe | ||
zebra | ||
dolphin | ||
turtle | ||
whale | ||
gorilla | ||
penguin | ||
hippo | ||
crocodile | ||
jaguar | ||
octopus | ||
koala | ||
rhino | ||
squirrel | ||
otter | ||
lobster | ||
parrot | ||
peacock | ||
panther | ||
cheetah | ||
panda | ||
buffalo | ||
goat | ||
ostrich | ||
camel | ||
raccoon | ||
hedgehog | ||
chimpanzee | ||
elephant | ||
snail | ||
deer | ||
fox | ||
badger | ||
apple | ||
orange | ||
strawberry | ||
grape | ||
watermelon | ||
mango | ||
pear | ||
peach | ||
pineapple | ||
kiwi | ||
coconut | ||
blueberry | ||
lemon | ||
lime | ||
cherry | ||
plum | ||
apricot | ||
raspberry | ||
blackberry | ||
pomegranate | ||
fig | ||
avocado | ||
melon | ||
guava | ||
lychee | ||
mangosteen | ||
durian | ||
persimmon | ||
quince | ||
pawpaw | ||
jackfruit | ||
rambutan | ||
mulberry | ||
gooseberry | ||
cranberry | ||
date | ||
nectarine | ||
cantaloupe | ||
honeydew | ||
tangerine | ||
grapefruit | ||
rhubarb | ||
tomato | ||
boson | ||
quark | ||
moon | ||
sun | ||
earth | ||
planet | ||
squash |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::collections::HashSet; | ||
|
||
use rand::seq::SliceRandom; | ||
|
||
const ADJECTIVES: &str = include_str!("adjectives.txt"); | ||
const NOUNS: &str = include_str!("nouns.txt"); | ||
|
||
pub struct RandomNameGenerator { | ||
adjectives: Vec<&'static str>, | ||
nouns: Vec<&'static str>, | ||
} | ||
|
||
impl RandomNameGenerator { | ||
pub fn new() -> Self { | ||
let adjectives = ADJECTIVES.split("\n").collect(); | ||
let nouns = NOUNS.split("\n").collect(); | ||
Self { adjectives, nouns } | ||
} | ||
|
||
pub fn generate(&self) -> String { | ||
let mut rng = rand::thread_rng(); | ||
let adjective = self.adjectives.choose(&mut rng).unwrap(); | ||
let noun = self.nouns.choose(&mut rng).unwrap(); | ||
format!("{adjective}-{noun}") | ||
} | ||
|
||
pub fn generate_unique(&self, existing: HashSet<&str>, max_attempts: usize) -> Option<String> { | ||
let mut i = 0; | ||
while i < max_attempts { | ||
let name = self.generate(); | ||
if !existing.contains(name.as_str()) { | ||
return Some(name); | ||
} | ||
i += 1; | ||
} | ||
None | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn can_produce_name() { | ||
let generator = RandomNameGenerator::new(); | ||
assert!(generator.generate_unique(Default::default(), 10).is_some()); | ||
} | ||
} |