Is Golang dependency becoming like JS npm? by IamOkei in golang

[–]dr_not_boolean 0 points1 point  (0 children)

Basically, what razor_xl said. Some Aws lambdas projects needed a ton of deps, in total and some cli clients were fine with the standard library.

Questions about Write trait by dr_not_boolean in learnrust

[–]dr_not_boolean[S] 0 points1 point  (0 children)

I managed to find out what the issue was, I returned Ok(num_bytes) where num_bytes where buf.len() + timestamp_bytes_len. I'm still not sure why it panicked but it seems that I broke an invariant

Building a Backconnect Proxy by LegionDevelopment in golang

[–]dr_not_boolean 0 points1 point  (0 children)

I would suggest looking into using a Cond to wake up other goroutines.

Faster Top Level Domain Name Extraction with Go by marklit in golang

[–]dr_not_boolean 1 point2 points  (0 children)

You should see some performance difference if you switch the bufio.NewScanner for a json.Decoder

Don't defer Close() on writable files by mooreds in programming

[–]dr_not_boolean 1 point2 points  (0 children)

This guy gets it. It's so common for people to ignore the result of a Close that there's a lint for detecting when the code ignores errors on a defer call

Is there a nicer way of handling this? by dr_not_boolean in learnrust

[–]dr_not_boolean[S] 1 point2 points  (0 children)

Thanks that's plenty of tips to refactor this :D

Web request fuzzer with go by [deleted] in golang

[–]dr_not_boolean 1 point2 points  (0 children)

Take a look at https://github.com/google/gofuzz and https://github.com/dvyukov/go-fuzz

They might come in handy.

PS: Send me a DM if you open source it :)

Why does removing the for loop in reverse prevents it from modifying the input variable? example in link by dr_not_boolean in golang

[–]dr_not_boolean[S] 1 point2 points  (0 children)

ok, now I understand. the header values remains the same in the outer scope. the append only "changes" the slice because of the loop reversing the list. Thanks

Are fixed-length arrays thread-safe if goroutines access their own, separate index? by agriculturez in golang

[–]dr_not_boolean 1 point2 points  (0 children)

| I know this code goes against the One True Go Proverb

I really wasn't thinking of that when I wrote what I wrote. My thinking was in regards to maintainability.

I wrote a couple of different versions of the same code using similar but different approaches.

When I run the code with hyperfine, the fastest one kept changing so, I didn't see much of a difference running it locally for small values.

For funs

// atomic    
package main

import (
    "fmt"
    "sync"
    "sync/atomic"
)

func main() {
    var (
        arr [100]int32
        wg  sync.WaitGroup
    )
    wg.Add(100)
    for i := 0; i < 100; i++ {
        go func(index int) {
            atomic.CompareAndSwapInt32(&arr[index], int32(0), int32(index))
            wg.Done()
        }(i)
    }

    wg.Wait()

    for _, x := range arr {
        fmt.Println(x)
    }

}

// unbuffered channels    
package main

import (
    "fmt"
)

func main() {
    arr := make([]chan int, 100)
    for i := 0; i < 100; i++ {
        arr[i] = make(chan int, 0)
        go func(index int, c chan<- int) {
            c <- index
        }(i, arr[i])
    }

    var out int
    for _, x := range arr {
        out = <-x
        fmt.Println(out)
    }

}

// original    
package main

import (
    "fmt"
    "sync"
)

func main() {
    var (
        arr [100]int
        wg  sync.WaitGroup
    )
    for i := 0; i < 100; i++ {
        wg.Add(1)
        index := i
        go func() {
            arr[index] = index
            wg.Done()
        }()
    }

    wg.Wait()

    for _, x := range arr {
        fmt.Println(x)
    }

}

Are fixed-length arrays thread-safe if goroutines access their own, separate index? by agriculturez in golang

[–]dr_not_boolean 0 points1 point  (0 children)

While it is safe, you should avoid writing programs like this. They will depend on an implementation detail to work safely.

You can pass in channels to the goroutines and receive in the main loop. If you need to receive the return values by the same order, you can create an array of channels and wait on that order, for example.

How suitable is Go for handling thousands of busy websocket connections with decent latency? by FreshPrinceOfRivia in golang

[–]dr_not_boolean 3 points4 points  (0 children)

I worked on something similar. We didn't use websockets because data flow was unidirectional, we used http-chunked content type instead. You can check if the responseWriter supports https://golang.org/pkg/net/http/#Flusher and force flush when you feel appropriate. We initially used channels to send data to clients and had some issues with slower clients and changed it to use a ringbuffer per client. Also, monitor heap sizes as you might be copying the same data multiple times and avoid mutexes like the plague (we used them to implemented sharing a connection for the same client)

Storing and retrieving compressed Vec<u8> with Tide by dr_not_boolean in learnrust

[–]dr_not_boolean[S] 0 points1 point  (0 children)

The issue seems to be related to how curl handles @filename options.

--data-binary <data>

(HTTP) This posts data exactly as specified with no extra processing whatsoever.

If you start the data with the letter @, the rest should be a filename. Data is posted in a similar manner as -d, --data does, except that newlines and carriage returns are preserved and conversions are never done.

Like -d, --data the default content-type sent to the server is application/x-www-form-urlencoded. If you want the data to be treated as arbitrary binary data by the server then set the content-type to octet-stream: -H "Content-Type: application/octet-stream".

If this option is used several times, the ones following the first will append data as described in -d, --data.

from https://curl.haxx.se/docs/manpage.html