Skip to content

Instantly share code, notes, and snippets.

@ip-rw
Created October 22, 2023 09:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ip-rw/e687f4c5b9d7ef3242817d4951101b3c to your computer and use it in GitHub Desktop.
Save ip-rw/e687f4c5b9d7ef3242817d4951101b3c to your computer and use it in GitHub Desktop.
Ajam: exhausting.
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