beginner – 2 Weeks into Go: Golang Tour WebCrawler Exercise

I’m on week 2 of learning go. I just completed the golang.org exercise on creating web crawler (https://tour.golang.org/concurrency/10) and I would please like feedback on my code. It feels overly complicated but I’m a noob so I don’t know.

I came across this post on the same exercies a few minutes ago while writing up this question. The only posted feedback there is one that I already implemented, so I’m hoping to get something different.

I also am not a fan of that implementation because it relies on knowing exactly how many urls will need to be fetched, which works with the fake data but wouldn’t work with real data.

type Fetcher interface {
    // Fetch returns the body of URL and
    // a slice of URLs found on that page.
    Fetch(url string) (body string, urls ()string, err error)
}

type FetchState struct {
    sync.Mutex
    fetchedUrls map(string)bool
}

// Crawl uses fetcher to recursively crawl
// pages starting with url, to a maximum of depth.
func Crawl(url string, depth int, fetcher Fetcher, state *FetchState) {
    if depth <= 0 {
        return
    }

    state.Lock()

    if _, ok := state.fetchedUrls(url); ok {
        state.Unlock()
        return
    }

    state.Unlock()
    body, urls, err := fetcher.Fetch(url)

    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Printf("found: %s %qn", url, body)
    state.Lock()
    state.fetchedUrls(url) = true
    state.Unlock()

    var wg sync.WaitGroup

    for _, u := range urls {
        wg.Add(1)
        go func(urlToCrawl string, group *sync.WaitGroup) {
            Crawl(urlToCrawl, depth-1, fetcher, state)
            group.Done()
        }(u, &wg)
    }

    wg.Wait()

    return
}

func main() {
    state := &FetchState{
        fetchedUrls: make(map(string)bool),
    }

    Crawl("https://golang.org/", 4, fetcher, state)
}

// fakeFetcher is Fetcher that returns canned results.
type fakeFetcher map(string)*fakeResult

type fakeResult struct {
    body string
    urls ()string
}

func (f fakeFetcher) Fetch(url string) (string, ()string, error) {
    time.Sleep(1000 * time.Millisecond)

    if res, ok := f(url); ok {
        return res.body, res.urls, nil
    }
    return "", nil, fmt.Errorf("not found: %s", url)
}

// fetcher is a populated fakeFetcher.
var fetcher = fakeFetcher{
    "https://golang.org/": &fakeResult{
        "The Go Programming Language",
        ()string{
            "https://golang.org/pkg/",
            "https://golang.org/cmd/",
        },
    },
    "https://golang.org/pkg/": &fakeResult{
        "Packages",
        ()string{
            "https://golang.org/",
            "https://golang.org/cmd/",
            "https://golang.org/pkg/fmt/",
            "https://golang.org/pkg/os/",
        },
    },
    "https://golang.org/pkg/fmt/": &fakeResult{
        "Package fmt",
        ()string{
            "https://golang.org/",
            "https://golang.org/pkg/",
        },
    },
    "https://golang.org/cmd/": &fakeResult{
        "Package cmd",
        ()string{
        },
    },
    "https://golang.org/pkg/os/": &fakeResult{
        "Package os",
        ()string{
            "https://golang.org/",
            "https://golang.org/pkg/",
        },
    },
}

worksheet function – Conditional Formatting / Filter out all of past week’s rows in Google Sheets

I have a running calendar in Sheets and I want last week’s rows to disappear all at once every Monday (Sunday night at 11:59 ideally).

I’ve been trying to use conditional formatting to highlight all rows from last week, and then I can filter them out.

Here is a picture of my calender, and I want rows <11 gone
I’ve been able to highlight any past Sundays red using the formula =AND($B1=”Sunday”,$C1<TODAY()), maybe this is a good start.

I’ve been playing around with this for a while and I’m wondering if it’s even possible/curious to see how you’d do it.

Many thanks.

tag removed – Word problem on the odds of being chosen for something over the course of 5 weeks

This is a word problem. There is a game being played among 15 people. Each week, 2 people will get chosen to compete for a prize. The loser of that 2 person competition will be forced to quit the larger game and go home. Therefore, although there are 15 people currently playing the game, after the first week there will only be 14 people playing, then 13, etc. What I would like to know is, if I am playing this game, over the course of 5 weeks, what are my chances (overall) of getting chosen to compete in at least one of these 2 person competitions?

A few key things to note:

  1. Each week someone will be forced to quit the game (the loser of the two person competition), so the number of people in the game will drop each week (increasing my chances of getting picked as the weeks go on)
  2. Each person has an equal chance of being chosen for the two person competition each week (i.e. prior winners are still eligible for the 2 person competition)

air travel – Do Articles 8 and 9 of EC261 not apply to flight cancellations announced 2+ weeks in advance?

Regarding the EC261 regulation, I know Article 7 (compensation) doesn’t apply if the flight is cancelled more than two weeks in advance. However, it’s always been my understanding that Article 8 (right to a choice between a refund and re-routing “at the earliest opportunity”) and Article 9 (right to care) apply regardless, the latter provided I haven’t opted for a refund.

However, the Irish national enforcement body just told me Article 8 and 9 don’t apply either if the flight was cancelled two weeks or more in advance, and that I can only get a refund and am on my own in terms of getting home.

Is this really the case? Some clarification would be appreciated.

google sheets – How Can I Exclude Vacation Weeks From A Week Number Count?

See testSheet

You can put Week count start date in cell B1.
Then you can specify vacation start and end.

Idea is to calculate weeks omitting vacations.

For that purpose we use NETWORKDAYS.INTL() formula and since it will return working days we wrap it with QUOTIENT() formula with divisor of 5.

NETWORKDAYS.INTL counts days between dates and excludes holidays, so here comes vacation start and end.

We use SEQUENCE() formula to generate dates based on vacation start and end.
You may add more vacations adding start and end dates and adding SEQUENCE() formula to array {}.

=QUOTIENT(
 NETWORKDAYS.INTL(
  $B$1,
  TODAY(),
  1,
  {
   SEQUENCE($B$3-$B$2+1,1,$B$2,1);
   SEQUENCE($B$5-$B$4+1,1,$B$4,1)
  }
  ),
 5)+1

php – Why does DateInterval lack weeks, quarters/seasons, as well as decimal/float versions of each property?

This has puzzled and frustrated me for years: https://www.php.net/manual/en/class.dateinterval.php

y

    Number of years.
m

    Number of months.
d

    Number of days.
h

    Number of hours.
i

    Number of minutes.
s

    Number of seconds.
f

    Number of microseconds, as a fraction of a second.

Where are the weeks and quarters/seasons? In particular, the weeks are sorely missing. In turn, I feel as if I am missing something.

You’d call me crazy if you knew how many hours of my life I’ve plowed into trying to manually calculate the weeks and seasons and decimal versions of all of these based on the existing values, without luck.

I don’t want “rough approximations”, because they fall apart as the two dates drift too far away from each other. “Rough approximations” are easy to make, but I’m looking for exact, accurate information.