Skip to content

Instantly share code, notes, and snippets.

@mrhether
Last active November 10, 2015 20:22
Show Gist options
  • Save mrhether/49d33f8b65842ba0f0ca to your computer and use it in GitHub Desktop.
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.
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