Created
October 1, 2022 18:10
-
Star
(120)
You must be signed in to star a gist -
Fork
(3)
You must be signed in to fork a gist
-
-
Save aileftech/dd4f5598b1f3837651fdf16e5abc3ffb to your computer and use it in GitHub Desktop.
A Bash one-liner to produce a list of HEX color codes that read like (supposedly) valid English words
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
$ grep -P "^[ABCDEFabcdefOoIi]{6,6}$" /usr/share/dict/words | tr 'OoIi' '0011' | tr '[:lower:]' '[:upper:]' | awk '{print "#" $0}' | |
#ACAD1A | |
#B0BB1E | |
#DEBB1E | |
#AB1DED | |
#ACAC1A | |
#ACCEDE | |
#AC1D1C | |
#BAB1ED | |
#BA0BAB | |
#BEADED | |
#BEDDED | |
#BEEFED | |
#B0BBED | |
#B0D1CE | |
#B00BED | |
#CABBED | |
#CABB1E | |
#CADD1E | |
#C1CADA | |
#C0DDED | |
#C0FFEE | |
#C01FED | |
#DABBED | |
#DECADE | |
#DEC1DE | |
#DEC0DE | |
#DEEDED | |
#DEFACE | |
#DEF1ED | |
#DE1CED | |
#D0FFED | |
#D00DAD | |
#EDD1ED | |
#EFFACE | |
#FACADE | |
#F1BBED | |
#F0BBED | |
#0FF1CE |
Where is #BADA55 (or this is clean version)?
@dainiuxt it's on the "enable" list that my script uses
What if you take into account hex codes with 3 characters?
#AAA
#ABC
#ABE
#ACE
#ADA
#ADD
#AD0
#A1D
#A55
#BAD
#BBC
#BED
#BEE
#B1B
#B1D
#B0A
#B0B
#B00
#B5C
#CAB
#CAD
#CB1
#C1D
#C0B
#C0D
#C00
#C05
#DAB
#DAD
#DEB
#DFC
#D1D
#D1E
#D0C
#D0E
#D5C
#EBB
#E5C
#E5E
#FAD
#FED
#FEE
#F1B
#F0B
#F0E
#1B1
#1CE
#1DA
#111
#0AF
#0DD
#0DE
#0ED
#0FF
#5AD
#5EA
#5EC
#5EE
#51C
#50B
#50D
#55E
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty gosh darn happy with this now c:
Not pure bash, I think that the
coreutils
's conciseness (tr
,fold
,xargs
) is indispensable and grep is just so much faster (something does feel a little slow, donno if it's the sub-shells, or the arrays, haven't put my finger on it). I think it's concise, and clear... so long as one knows<<<
,<()
,IFS
, and overlooks the entireBG_RGB
pipeline (for which one ought to know a relatively obscure feature ofprintf
,xargs
, and (new to me)fold
). Gotta love shell.Edit:
It was
xargs
, 'bout 50% faster without it (specifically not because of any other change I made to refactor it out, though most tweaks do push it overreal 0m4s
).Edit:
sed
is slightly faster thangrep
orawk
(for matching words, on my machine), and dropping the nested while loop into what is nowsed
's pipeline saves a ton of time. This is as fast as I think it gets, at least without usingawk
orsed
for more than just whatgrep
can do.Edit: I gotta go to bed :c
But just as a quick and dirty point of comparison, has an (extra) advantage bc the loop is unrolled (not that it makes a difference):