[go-nuts] Go generic set with interesting real world applications

2021-01-03 Thread Andrew Phillips
I am an avid user of Go who loves how it makes my life so much easier due to its amazing simplicity. I am thrilled to find that a great deal of progress has been made in adding (simple) generic types and functions to the language, which will make my life even simpler! When I discovered the go2

Re: [go-nuts] sql string not interpolated as expected

2021-01-03 Thread Marcin Romaszewicz
Don't use fmt.Sprintf for the actual values, generate the positional arguments yourself. Something like: q := "SELECT x FROM t WHERE y IN (%s)" labelName := []string{'carnivore', 'mammal', 'vertebrate'} var arrayArgs []string for i := range labelName { arrayArgs = append(arrayArgs, fmt.Sprint

Re: [go-nuts] sql string not interpolated as expected

2021-01-03 Thread Alexander Mills
here is a question I posted on dba.stackexchange: https://dba.stackexchange.com/questions/282501/variable-number-of-arguments-with-golang On Sun, Jan 3, 2021 at 2:20 PM Alexander Mills wrote: > labels are variable arguments, so I don't know how to do it..i solved it > for the time being usin

Re: [go-nuts] sql string not interpolated as expected

2021-01-03 Thread Alexander Mills
labels are variable arguments, so I don't know how to do it..i solved it for the time being using `fmt.Sprintf` but that leaves me vulnerable to sql injection I suppose. On Sun, Jan 3, 2021 at 8:58 AM 'Brian Candler' via golang-nuts < golang-nuts@googlegroups.com> wrote: > I think the nearest is

Re: [go-nuts] sound level from sample of a wav file

2021-01-03 Thread Francisco Dalla Rosa Soares
Hi there If I got it right, all you wanna do is calculate the decibels of an audio file and trigger an an alert in case it goes over a certain threshold. I found this great answer on Stack overflow, really recommend the whole read but I'll add here the TL;DR, however I do recommend the full read

[go-nuts] sound level from sample of a wav file

2021-01-03 Thread Jeff Mangan
I am able to open a wav file and iterate through samples of it. I am trying to figure out the level of sound (loud vs low talking) and I believe it's a matter of getting some value from the sample and then running some math formulas. Anyone have any ideas or references on this, prefer not some hea

Re: [go-nuts] Generics - please provide real life problems

2021-01-03 Thread robert engels
I do believe (hope) David was kidding. Anonymous product types (and similar constructs) are the root of all evil. > On Jan 3, 2021, at 11:32 AM, roger peppe wrote: > > FWIW I'm certain that the lack of tuples in Go was a very deliberate decision > - one of Go's more significant ancestors, Limb

Re: [go-nuts] Generics - please provide real life problems

2021-01-03 Thread roger peppe
FWIW I'm certain that the lack of tuples in Go was a very deliberate decision - one of Go's more significant ancestors, Limbo, had tuples. Anonymous product types have their disadvantages too (you don't get to name the members, so code can end up significantly harder to understand), which I suspect

Re: [go-nuts] sql string not interpolated as expected

2021-01-03 Thread 'Brian Candler' via golang-nuts
I think the nearest is: labelStrs := []interface{}{"carnivore", "mammal", "vertebrate"} rows, err := c.Database.Db.Query(` select id from mbk_user_label where label_name in (?,?,?) `, labelStrs...) Of course, you may need to change the number of question-marks to match len(labelS

Re: [go-nuts] Generics - please provide real life problems

2021-01-03 Thread Jesper Louis Andersen
On Thu, Dec 31, 2020 at 9:45 PM da...@suarezhouse.net wrote: > Real use cases have been provided it appears for both why generics can be > good and how they can be used negligently (love the sextuple example BTW). Some future language will invent the idea that you should be able to create anony

Re: [go-nuts] sql string not interpolated as expected

2021-01-03 Thread Reto
On Sun, Jan 03, 2021 at 12:53:03AM -0800, Alexander Mills wrote: > rows, err := c.Database.Db.Query(` > > select *, ( > select count(*) from mbk_file_label > where file_id = mbk_file.id and label_id IN ( > select id > from mbk_user_label > where label_name IN ( > $2 > ) > ) > ) as xxx > fro

[go-nuts] sql string not interpolated as expected

2021-01-03 Thread Alexander Mills
I have this: rows, err := c.Database.Db.Query(` select *, ( select count(*) from mbk_file_label where file_id = mbk_file.id and label_id IN ( select id from mbk_user_label where label_name IN ( 'carnivore', 'mammal', 'vertebrate' ) ) ) as xxx from mbk_file where user_id = $1 order by xxx DESC `