Last active
September 10, 2023 18:36
-
-
Save jbhoot/2565a7131511f253ebf40c2f7680de9c to your computer and use it in GitHub Desktop.
A very crude script to check if a domain name consists of 4 characters or less
This file contains hidden or 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
let remove_substr str substr = | |
Str.global_replace (Str.regexp substr) "" str;; | |
let remove_substrs str substrs = | |
List.fold_left remove_substr str substrs;; | |
let get_domain_name str = | |
let trimmed = remove_substrs str ["https://"; "http://"; "www"] in | |
let domain_frags = String.split_on_char '.' trimmed in | |
List.find (fun frag -> String.length frag > 0) domain_frags;; | |
let is_four_chars_or_less url = | |
let name = get_domain_name url in | |
(String.length name) <= 4;; | |
List.filter is_four_chars_or_less ["www.google.com"; "https://stfj.net"] |
This file contains hidden or 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
#lang racket | |
(define (remove-substr substr str) | |
(string-replace str substr "")) | |
(define (remove-substrs substrs str) | |
(foldl remove-substr str substrs)) | |
(define (get-domain-name url) | |
(define trimmed (remove-substrs '("https://" "http://" "www") url)) | |
(define domain-frags (string-split trimmed ".")) | |
(car domain-frags)) | |
(define (4-chars-or-less? url) | |
(define name (get-domain-name url)) | |
(<= (string-length name) 4)) | |
(filter 4-chars-or-less? '("www.google.com" "https://stfj.net")) |
This file contains hidden or 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
def removeSubstr(str: String, substr: String) = | |
str.replaceAll(substr, "") | |
def removeSubstrs (str: String, substrs: List[String]) = | |
substrs.foldLeft(str)(removeSubstr) | |
def getDomainName(domain: String) = | |
val trimmed = removeSubstrs(domain, List("https://", "http://", "www")) | |
val domainFrags = trimmed.split("\\.") | |
domainFrags.find(_.length > 0).getOrElse("") | |
def isFourCharsOrLess(url: String) = | |
val name = getDomainName(url) | |
name.length <= 4 | |
List("www.google.com", "https://stfj.net").filter(isFourCharsOrLess) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment