logo meditative image

This bash script gave me 3-letter github nickname

,

Serge Osipov

Long story short

One day (18 September 2018) I decided to find a way to choose new original and short Github username for myself.

At that time I already was Developer Program Member, so I could access Github GraphQL API, but I did not thought about it, my bad.

I selected good old brute force. So I opened https://github.com/a in my browser. Meine freunde, schade! It was used by some human called Anton.

How to do this faster? I used curl and grep in shell

# HTTP/2 200 
curl -Is https://github.com/a | grep HTTP

Yes, you could be more precise and use all the power of curl, but it definetely wouldn't be the first idea in an engineer's brain. If you are curious, this would be the most accurate command for this task:

# 200
curl -Is https://github.com/a -o /dev/null -w "%{http_code}" 

But I was in hurry and used my swiss knife, GNU grep, to achieve the same result using the more verbose way.

# 200
curl -Is https://github.com/a \
| grep HTTP \
| grep -oP '[\d]{3}'

If you use macOS, don't try to execute this long pipe, because of lack of -P: PCRE (Perl Compatible Regular Expressions) in BSD derived grep on mac.

Ok, let's continue and add some brute force for one letter, for two letters and even for three letters!

Success!

for var1 in "" a b c d e f g h i j k l m n o p q r s t u v w x y z; do
  for var2 in "" a b c d e f g h i j k l m n o p q r s t u v w x y z; do
    for var3 in "" a b c d e f g h i j k l m n o p q r s t u v w x y z; do
      a=`curl -Is https://github.com/$var1$var2$var3 \
      | grep HTTP \
      | grep -oP '[\d]{3}'`" $var1$var2$var3";
      echo $a;
      echo $a >> git_process_list.txt;
    done;
  done;
done;

This script was ugly duckling but worked as expected.

Voilà! I got around a hundred well-crafted and short account names for Github (the mine is highlighted):

ejp eqf etp fqc fqe fqn fvq gqe gqn gqo
gvq gvw hcz hdl hqe ihv ijq iqj iqk iyb
iyh iyq kbq kov kqo kyg lni nqw nvq nwr
ofq onf oqb oqf oqu qdm qfk qkv rwv ***
ubm ugq uhw ujg ukq upw uqd uqk *** uvh
uvz uwq uwx uwz uxh uyb uyd uyf uyp uyq
uyv uyw uzf uzq *** vfq vfy vhw vjq vpq
vqe vqj *** vqm *** vwh *** vyf vzd wdv
wvn wvp wyv xgv *** *** xvn *** *** zfv
zuv *** *** *** ***

Fun fact: not all of them are in use for now so I hid free three-letter usernames using asterisks.

You could have a chance to find them by yourself.

Final script

It was nothing but awful bash practice from 4 years younger me, so sorry!

Today I'd be less redundant:

for var1 in {a..z}; do
  for var2 in {a..z}; do
    for var3 in {a..z}; do
      echo $(
        curl -Is https://github.com/$var1$var2$var3 -o /dev/null -w "%{http_code}"
      ) $var1$var2$var3 2>&1 | tee -a git_process_list.txt;
    done;
  done;
done;

Or even better, I'd focus more on consistency between different social networks and choose Sherlock Project to find acceptable username.

Also you could find some different ideas how to solve this on Github topic #github-username-checker

Final thoughts

So, the moral of this story?

You need to create programs that lead to results not that are beatiful.

Sometimes it happens.

Ask yourself: "Is this good enough?" more frequently.

, Ä°stanbul