Last active
November 10, 2015 20:22
-
-
Save mrhether/49d33f8b65842ba0f0ca to your computer and use it in GitHub Desktop.
Github names are vital and the smaller they are the better! This tool finds you the smallest github name available.
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
private final Log logger = LogFactory.getLog(getClass()); | |
public void given_i_need_a_github_name() { | |
List<String> names = getNamePerms(6); | |
for (String name : names) { | |
System.out.print('.'); | |
RestTemplate restTemplate = new RestTemplate(); | |
String url = "http://github.com/" + name; | |
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class); | |
if (response.hasBody() && response.getBody().contains("This is not the web page you are looking for")) { | |
logger.info("The name: " + name + "is free!!!"); | |
} | |
} | |
} | |
private List<String> getNamePerms(int maxLength) { | |
if (maxLength == 0) { | |
return Collections.singletonList(""); | |
} | |
List<String> names = new ArrayList<>(); | |
for (String name : getNamePerms(maxLength - 1)) { | |
for (char alphabet = 'a'; alphabet <= 'z'; alphabet++) { | |
String newName = name + alphabet; | |
names.add(newName); | |
} | |
} | |
return names; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment