At an engineering training with Greg Sabo in my first week at Stripe, he showed a cute trick: using a shell command to generate two random words when testing.
For example, every time I reconfigure my mail server, I send a distressing number of emails in this style:
echo "Testing" | mail -s "Mary Test 1" mary
echo "Testing" | mail -s "Mary Test 2" mary
echo "Testing" | mail -s "Mary Test 3" mary
(I usually lose count around Test 4, for the record.)
Likewise, in testing the Stripe create charges API function, one might run this from the documentation:
curl https://api.stripe.com/v1/charges \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
-d amount=400 \
-d currency=usd \
-d source=tok_189fCj2eZvKYlo2CjCzCPbk5 \
-d description="Charge for test@example.com"
Wouldn’t those be both more fun and somewhat easier to find in mailboxes, logs and dashboards as, say, Mary test fan merinos
and Charge for cellular ascendents
respectively? It would be! Thanks Greg!
Implementation-wise, on very recent Ubuntu, the trick is to add something to your bash profile along the times of:
rw () {
cat /usr/share/dict/words | grep -v "'" | grep -v "[A-Z]" | shuf -n 2 | xargs echo
}
Background: shuf
is a command that behaves like head
and tail
, only it returns a selected number random lines. I’m filtering out single quotes (grep -v "'"
) in its input so as to not unduly annoy xargs
, and filtering capital letters (grep -v "[A-Z]"
) as a proxy for filtering out proper names.
From there:
$ rw
newscaster mucky
$ echo Mary test $(rw)
Mary test equitable rough
For systems without shuf
installed, there’s a lot of potential solutions to shuffling a text file at Stack Overflow, this answer has a great roundup.
As a note of caution, you don’t want to run rw
live in front of other people or send them the output unchecked; a random selection of 2 English words has some reasonable chance of being disgusting, offensive, strange, inappropriate, etc. Generate some memorable phrases privately in advance!
Slightly related: xkcd: Password strength.
Change the number of words
Added 28 Sep 2016
A slightly improved version of rw
that allows a variable number of words to be returned, defaulting to 2:
rw () { NUM=$1 if [ -z "$NUM" ] then NUM=2 fi cat /usr/share/dict/words | grep -v "'" | grep -v "[A-Z]" | shuf -n $NUM | xargs echo }
$ rw
reverberations drumming
$ rw 1
bards
$ rw 7
protections proving unfortunately blubbered uninstallers pitchmen locality