Skip to content

Instantly share code, notes, and snippets.

@halka9000stg
Created October 26, 2022 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halka9000stg/ad6e1ec854533650aef558c111108385 to your computer and use it in GitHub Desktop.
Save halka9000stg/ad6e1ec854533650aef558c111108385 to your computer and use it in GitHub Desktop.
SubDomain Suppling System

SubDomain Suppling System

Created with <3 with dartpad.dev.

void main() {
final dp = Domain("dev-pack.org");
print(dp.supply("sorakim"));
print(dp.supply("made.in.apple"));
print(dp.supply("sorakim.made.in.apple"));
}
int maxIntegerOnHex(final int hexLen)=>int.parse("f" * hexLen, radix: 16);
extension on int{
int foldInTo(final int hexLen){
final int max = maxIntegerOnHex(hexLen);
if(this < max){
return this;
}else{
return ((this % max) + (this ~/ max)).foldInTo(hexLen);
}
}
}
class Domain {
String base;
Domain(this.base);
String supply(String name) {
final String hashString = "$name.$name.suppled.$base".hashCode.foldInTo(7).toRadixString(16);
return "$name.$hashString.suppled.$base";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment