Created with <3 with dartpad.dev.
Created
October 26, 2022 23:10
-
-
Save halka9000stg/ad6e1ec854533650aef558c111108385 to your computer and use it in GitHub Desktop.
SubDomain Suppling System
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
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