Skip to content

Instantly share code, notes, and snippets.

@lc
Last active April 4, 2023 21:16
Show Gist options
  • Select an option

  • Save lc/9bfa09ef9bdf593a69f7bbc33dfbd90d to your computer and use it in GitHub Desktop.

Select an option

Save lc/9bfa09ef9bdf593a69f7bbc33dfbd90d to your computer and use it in GitHub Desktop.

Revisions

  1. lc revised this gist Jul 17, 2019. 1 changed file with 9 additions and 22 deletions.
    31 changes: 9 additions & 22 deletions waywords.go
    Original file line number Diff line number Diff line change
    @@ -10,34 +10,21 @@ import (

    func main() {
    // usage: printf "example.com" | waybackurls | waywords
    var words []string
    words := make(map[string]struct{})
    w := bufio.NewScanner(os.Stdin)
    for w.Scan() {
    u, err := url.Parse(w.Text())
    if err != nil {
    continue
    }
    t := strings.Split(u.Path, "/")
    words = append(words, t...)
    }
    final := un(words)
    for _, word := range final {
    if word != "" {
    fmt.Println(word)

    for _, t := range strings.Split(u.Path, "/") {
    if t == "" {
    continue
    }
    words[t] = struct{}{}
    }
    }

    }
    func un(words []string) []string {
    known := map[string]bool{}
    final := []string{}
    for word := range words {
    if known[words[word]] {
    } else {
    known[words[word]] = true
    final = append(final, words[word])
    }
    for word, _ := range words {
    fmt.Println(word)
    }
    return final
    }
    }
  2. lc created this gist Jun 28, 2019.
    43 changes: 43 additions & 0 deletions waywords.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    package main

    import (
    "bufio"
    "fmt"
    "net/url"
    "os"
    "strings"
    )

    func main() {
    // usage: printf "example.com" | waybackurls | waywords
    var words []string
    w := bufio.NewScanner(os.Stdin)
    for w.Scan() {
    u, err := url.Parse(w.Text())
    if err != nil {
    continue
    }
    t := strings.Split(u.Path, "/")
    words = append(words, t...)
    }
    final := un(words)
    for _, word := range final {
    if word != "" {
    fmt.Println(word)

    }
    }

    }
    func un(words []string) []string {
    known := map[string]bool{}
    final := []string{}
    for word := range words {
    if known[words[word]] {
    } else {
    known[words[word]] = true
    final = append(final, words[word])
    }
    }
    return final
    }