Created
October 22, 2023 09:57
-
-
Save ip-rw/e687f4c5b9d7ef3242817d4951101b3c to your computer and use it in GitHub Desktop.
Ajam: exhausting.
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
package main | |
// Ajam: I might be abrasive but at least I make the effort for people. | |
// I'm surprised you couldn't be bothered to do the 50 lines yourself | |
// after the hour I put in, but I'm a man of my word. | |
// It did indeed take me about 20 minutes to find. It uses a quotient filter. | |
import ( | |
"bufio" | |
"flag" | |
"fmt" | |
"github.com/facebookincubator/go-qfext" | |
"github.com/joeguo/tldextract" | |
"regexp" | |
"strings" | |
log "github.com/sirupsen/logrus" | |
"os" | |
) | |
func init() { | |
flag.Parse() | |
log.SetLevel(log.DebugLevel) | |
} | |
func main() { | |
s := bufio.NewScanner(os.Stdin) | |
q := qf.New() | |
cache := "/tmp/tld.cache" | |
extract, _ := tldextract.New(cache, false) | |
for _, f := range flag.Args() { | |
fi, _ := os.Open(f) | |
if fi != nil { | |
s := bufio.NewScanner(fi) | |
for s.Scan() { | |
q.InsertString(strings.ToLower(strings.TrimSpace(s.Text()))) | |
} | |
} | |
} | |
log.Infof("%d added to filter", q.Len()) | |
var t *tldextract.Result | |
r := regexp.MustCompile("[a-z0-9\\-_\\.]+") | |
for s.Scan() { | |
for _, f := range r.FindAllString(s.Text(), -1) { | |
t = extract.Extract(f) | |
if t != nil { | |
dom := fmt.Sprintf("%s.%s", t.Root, t.Tld) | |
//log.Debugln(dom, f) | |
if q.ContainsString(dom) { | |
fmt.Println(s.Text()) | |
break | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment