[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-02 Thread Florin Pățan
Since everyone thinks it but nobody bothers to reply to it: this whole thing 
you propose can be currently done with a for loop, which not only is explicit 
about what it doing, but it also lets you control if you want to exit early 
from it and so on. Complicating the whole language because something is cool 
(yet looks like a really complex thing that you need to think about while 
reading the code) is in no one's benefit. Stop trying to avoid a couple of 
extra rows of for {} (where the third row is literally just an "}")  and start 
embracing the fact that you can understand the code by looking at it and not 
apply any complex mental acrobatics to figure out what those three lines of 
code are doing. Your future self/person after you will thank you for that. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-02 Thread mhhcbon
Sorry for this crime of thought, i was thinking it was a chance to talk 
about it and explore different paths.
That, this, is the only answer, well, life is hard.

Just for the records, i did stop thinking like that when i started golang, 
its not like you are given the choice.

Psst ... I must ask you about the address of the shop where you bought this 
wonderful magical crystal bowl you use to read in the future.
I kind of fail to find one for my current self.
thanks ;)

On Friday, June 2, 2017 at 10:17:54 AM UTC+2, Florin Pățan wrote:
>
> Since everyone thinks it but nobody bothers to reply to it: this whole 
> thing you propose can be currently done with a for loop, which not only is 
> explicit about what it doing, but it also lets you control if you want to 
> exit early from it and so on. Complicating the whole language because 
> something is cool (yet looks like a really complex thing that you need to 
> think about while reading the code) is in no one's benefit. Stop trying to 
> avoid a couple of extra rows of for {} (where the third row is literally 
> just an "}")  and start embracing the fact that you can understand the code 
> by looking at it and not apply any complex mental acrobatics to figure out 
> what those three lines of code are doing. Your future self/person after you 
> will thank you for that. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: How to parallelize text/template long running functions?

2017-06-02 Thread roger peppe
Here's a proof-of-concept of a somewhat general mechanism
for making template functions concurrent. It involves some
fun reflection code (first time I've used FuncOf, MakeFunc,
StructOf and MapOf for real).

 https://play.golang.org/p/7qXx5pCh9N

On 1 June 2017 at 07:02, Michael Brown  wrote:
> Great! If I had checked this thread when you posted this I (probably) could
> have saved myself 3 hours of work.
>
> I got it working with a two-pass scheme using text/template and some
> channels.
>
> Here is what I came up with:
>
> package main
>
>
> import (
>
> "text/template"
>
> "bytes"
>
> "context"
>
> "fmt"
>
> "github.com/google/uuid"
>
> "time"
>
> )
>
>
> type resultpair struct {
>
> key   string
>
> value string
>
> }
>
>
>
> func getFuncMap(ctx context.Context, resultsQueue chan resultpair) (*int,
> template.FuncMap) {
>
> totalJobs := 0
>
> var funcMap = template.FuncMap{
>
> "sleep": func() string {
>
> totalJobs = totalJobs + 1
>
> token := uuid.New()
>
> go func() {
>
> time.Sleep(1 * time.Second)
>
> resultsQueue <- resultpair{token.String(), "REAL_VALUE!"}
>
> }()
>
> return "{{ getOutput \"" + token.String() + "\" }}"
>
> },
>
> }
>
>
> return &totalJobs, funcMap
>
> }
>
>
> func getFuncMapNested(ctx context.Context, output map[string]string)
> template.FuncMap {
>
> var funcMapNested = template.FuncMap{
>
> "getOutput": func(input string) string { return output[input] },
>
> }
>
> return funcMapNested
>
> }
>
>
> func main() {
>
> initial := "{{sleep}} {{sleep}} {{sleep}}"
>
>
> resultsQueue := make(chan resultpair)
>
> outputQueue := make(chan map[string]string)
>
> // totalJobs is decieving: only ever accessed by one thread at a time,
> so shouldn't need locking (I think)
>
> totalJobs, funcMap := getFuncMap(context.TODO(), resultsQueue)
>
>
> fmt.Printf("About to execute first template: %s\n", initial)
>
> fmt.Printf("TOTAL JOBS: %d\n", *totalJobs)
>
> tmpl, _ := template.New("test").Funcs(funcMap).Parse(initial)
>
> var buf bytes.Buffer
>
> tmpl.Execute(&buf, nil)
>
> fmt.Printf("Got translated template: %s\n", buf.String())
>
> fmt.Printf("TOTAL JOBS: %d\n", *totalJobs)
>
>
> go func(totalJobs *int) {
>
> var results map[string]string
>
> results = make(map[string]string)
>
>
> for i := 0; i < *totalJobs; i++ {
>
> res := <-resultsQueue
>
> results[res.key] = res.value
>
> }
>
> outputQueue <- results
>
> close(outputQueue)
>
> }(totalJobs)
>
>
> output := <-outputQueue
>
> close(resultsQueue)
>
> fmt.Printf("Output of the goroutine: %s\n", output)
>
>
> funcMapNested := getFuncMapNested(context.TODO(), output)
>
> tmpl2, _ :=
> template.New("nested").Funcs(funcMapNested).Parse(buf.String())
>
> var buf2 bytes.Buffer
>
> tmpl2.Execute(&buf2, nil)
>
>
> fmt.Printf("results: %s\n", buf2.String())
>
> }
>
>
> OUTPUT:
>
>
> $ time go run ./commands/try.go
>
> About to execute first template: {{sleep}} {{sleep}} {{sleep}}
>
> TOTAL JOBS: 0
>
> Got translated template: {{ getOutput "bc7dcfa0-89d9-45e9-bd40-eb2db6f51db0"
> }} {{ getOutput "f2539f15-378b-408d-8c6e-d3822e985a6b" }} {{ getOutput
> "56c9d239-d08d-43e8-80de-dd97ef157b6a" }}
>
> TOTAL JOBS: 3
>
> Output of the goroutine:
> map[bc7dcfa0-89d9-45e9-bd40-eb2db6f51db0:REAL_VALUE!
> f2539f15-378b-408d-8c6e-d3822e985a6b:REAL_VALUE!
> 56c9d239-d08d-43e8-80de-dd97ef157b6a:REAL_VALUE!]
>
> results: REAL_VALUE! REAL_VALUE! REAL_VALUE!
>
>
> real0m1.319s
>
> user0m0.278s
>
> sys 0m0.098s
>
>
> On Wednesday, May 31, 2017 at 9:09:51 PM UTC-5, robfig wrote:
>>
>> We do this exact thing except using closure templates
>> https://blog.gopheracademy.com/advent-2014/soy-programmable-templates/
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: How to parallelize text/template long running functions?

2017-06-02 Thread roger peppe
On 2 June 2017 at 10:35, roger peppe  wrote:
> Here's a proof-of-concept of a somewhat general mechanism
> for making template functions concurrent. It involves some
> fun reflection code (first time I've used FuncOf, MakeFunc,
> StructOf and MapOf for real).
>
>  https://play.golang.org/p/7qXx5pCh9N

Note that it won't work correctly if you pass any functions whose results
are used in template expressions to Execute.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-02 Thread Egon
On Friday, 2 June 2017 12:06:54 UTC+3, mhh...@gmail.com wrote:
>
> Sorry for this crime of thought, i was thinking it was a chance to talk 
> about it and explore different paths.
> That, this, is the only answer, well, life is hard.
>

Thinking and discussion is helpful, but I think the format here could be 
improved.

The problem in this thread is that these comments are "random thoughts" 
instead of "organized thoughts" about different aspects, without 
referencing any prior art.

Organizing these thoughts and points works for these things much, much 
better. Even better is a article / blog-post for something bigger.

E.g. I would consider this form:

1. real-world problem (no "animal" or "bunny" examples)
1.1. where it exists
1.2. how frequent
2. Current solutions
2.1. current solution 1 (pros/cons)
2.2. current solution 2 (pros/cons)
2.3. current solution 3 (pros/cons)
3. Alternative approaches
3.1 alternative approach 1 (pros/cons/prior-art)
3.2 alternative approach 2 (pros/cons/prior-art)
3.3 alternative approach 3 (pros/cons/prior-art)
4. Comparison between solutions.
5. Cost / benefit discussion.

*Each of these around 1-3 paragraphs.*

This has a good basis for a good discussion, whereas random thoughts often 
don't. Also there's always room for a middle-ground.

Thinking aloud and random thoughts work somewhat in chats, but often 
doesn't end-up in something tangible that can be used later on.

+ Egon


> Just for the records, i did stop thinking like that when i started golang, 
> its not like you are given the choice.
>
> Psst ... I must ask you about the address of the shop where you bought 
> this wonderful magical crystal bowl you use to read in the future.
> I kind of fail to find one for my current self.
> thanks ;)
>
> On Friday, June 2, 2017 at 10:17:54 AM UTC+2, Florin Pățan wrote:
>>
>> Since everyone thinks it but nobody bothers to reply to it: this whole 
>> thing you propose can be currently done with a for loop, which not only is 
>> explicit about what it doing, but it also lets you control if you want to 
>> exit early from it and so on. Complicating the whole language because 
>> something is cool (yet looks like a really complex thing that you need to 
>> think about while reading the code) is in no one's benefit. Stop trying to 
>> avoid a couple of extra rows of for {} (where the third row is literally 
>> just an "}")  and start embracing the fact that you can understand the code 
>> by looking at it and not apply any complex mental acrobatics to figure out 
>> what those three lines of code are doing. Your future self/person after you 
>> will thank you for that. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] AI-first?

2017-06-02 Thread Rudi


On Thursday, June 1, 2017 at 11:17:42 PM UTC+2, Ian Lance Taylor wrote:
>
> On Thu, Jun 1, 2017 at 7:20 AM,  > 
> wrote: 
> > 
> > I have a general question: 
> > 
> > I'd like to talk a little bit about how AI might be used to create 
> better 
> > computer programs. Some years ago there used to be a lot of interesting 
> > conceptual discussions in this forum, I don't know if its the right 
> place 
> > for that kind of talk and out-loud-thinking. 
> > 
> > So I'm just asking: anybody else thinking hard about this and want to 
> talk 
> > about it here? Or is there a better place and where would that place be? 
>
> The golang-nuts mailing list is a good place to talk about Go-first 
> (or Go-second or Go-last).  It's not a good place to talk about AI. 
> Thanks. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Which Go client for ElasticSearch?

2017-06-02 Thread Lee Rick
i choose https://github.com/olivere/elastic, it works fine.


在 2015年11月5日星期四 UTC+8上午8:21:29,Peter Kleiweg写道:
>
> The website of ElasticSearch lists three Go clients:
>
> https://github.com/mattbaird/elastigo
>
> https://github.com/belogik/goes
>
> https://github.com/olivere/elastic
>
> Does anyone have experience with these? Which of these three would be the 
> best?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Golang, SQL and ORM avoidance techniques

2017-06-02 Thread brylant

I've been trying hard (well.. as much as I can considering my lack of 
in-depth go knowledge or - to be perfectly honest - lack of in-depth 
knowledge of anything) to find suitable go+sql technique that would not 
require a lot of code repetition, not use reflection and not use ORMs of 
any sort... Could somebody please tell me if there's anything particularly 
wrong with the following:


type ScannerFunc func() []interface{}

func (db *DB) ScanSome(stmt string, sf ScannerFunc, params ...interface{}) 
error {
 rows, err := db.Query(stmt, params...)
 if err != nil {
 return err
 }
 defer rows.Close()
 for rows.Next() {
 err = rows.Scan(sf()...)
 if err != nil {
 return err
 }
 }
 if err = rows.Err(); err != nil {
 return err
 }
 return nil
}

Having the above I could then implement the following for each of my 
'models' (User being an example below). This could easily be 'go 
generate'-d for each model


type User struct {
UserID  int64
Namestring
Roleint
// (...)
}

func ScanUsersFunc(users *[]*User) ScannerFunc {
return ScannerFunc(func() []interface{}) {
u := User{}
*users = append(*users, &u)
var r []interface{} = []interface{}{&u.UserID, &u.Name, &u.Role, (more 
properties)}
return r
}
}


and finally use it like this: 


const (
sqlUsersByRole = "SELECT user_id,name,role, (more if needed) FROM user 
WHERE role=?"
sqlAllUsers= "SELECT user_id,name,role FROM user"
)

func (db *DB) UsersByRole(role int) ([]*User, error) {
users := make([]*User, 0)
err := db.ScanSome(sqlUsersByRole, ScanUsersFunc(&users), role)
if err != nil {
return nil, err
}
return users, nil
}

func (db *DB) AllUsers() ([]*User, error) {
users := make([]*User, 0)
err := db.ScanSome(sqlAllUsers, ScanUsersFunc(&users))
if err != nil {
return nil, err
}
return users, nil
}


Alternatively (to avoid scanning/returning all results) a callback could be 
provided to ScanSome and called after each scan.

Obviously I could also implement ScanOne for situations where I only expect 
one row of results...


So - any obvious issues with the above 'technique'...?


Thanks,

adam



-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] AI-first?

2017-06-02 Thread Rudi
Well,  I deleted my original post before Ian replied because I anticipated 
his answer in advance. 

However, since you mentioned "confusion",  I feel I want to clarify a bit 
what I am getting at: 
there is already a project out there called Milepost GCC, they do compiler 
optimizations using machine learning and neural nets. Garbage collector 
optimization also comes to mind. Any kind of optimization with any kind of 
potential will do,

However, there are other applications that come to mind that are far less 
obvious. A binary computer program is just another image,  Machine learning 
is very well suited to work on images, so why not train some neural nets to 
detect certain patterns in your binaries as a starting point and go deeper 
from there? This is could be very useful, it could potentially help you 
find bugs and other very interesting things that normally stay hidden in 
the binary.  

There is also machine translation based on machine learning (EBMT), if you 
can train an AI to translate English to German, then why not train it to 
translate for example x86 machine code to another perhaps far more useful 
representation? If the neural net is trained well,  it can even do the 
translation both ways... thats a bit of a moonshot I know, but just think 
of the potential.  

I don't know if any of this has anything to do with Go Language, but maybe 
someone will find it inspiring and fun to think about anyway. Cheers :-)


On Friday, June 2, 2017 at 7:46:23 AM UTC+2, Nigel Tao wrote:
>
> On Fri, Jun 2, 2017 at 7:17 AM, Ian Lance Taylor  > wrote: 
> > The golang-nuts mailing list is a good place to talk about Go-first 
> > (or Go-second or Go-last).  It's not a good place to talk about AI. 
> > Thanks. 
>
> In case there is any confusion, this list is about Go the programming 
> language. There's also interesting news about Artificial Intelligence 
> and Go the board game, but as Ian said, this list is not the right 
> place to discuss that, unless of course it also involves Go the 
> programming language. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-02 Thread gary . willoughby
Generics enable more than just replacing loops. For example, they can 
enable libraries of generic algorithms to be used with any type of array. 
Here's an example:

foo := GetArray()
result := foo.Take(10).map(...).Sort(...).Reduce(...)

That is simple to understand and in one line of code. Imagine the 
acrobatics (and lines of code) needed to do this using Go's loops!

You can read my full article on why Go needs generics 
here: 
http://nomad.so/2015/03/why-gos-design-is-a-disservice-to-intelligent-programmers/

On Friday, 2 June 2017 09:17:54 UTC+1, Florin Pățan wrote:
>
> Since everyone thinks it but nobody bothers to reply to it: this whole 
> thing you propose can be currently done with a for loop, which not only is 
> explicit about what it doing, but it also lets you control if you want to 
> exit early from it and so on. Complicating the whole language because 
> something is cool (yet looks like a really complex thing that you need to 
> think about while reading the code) is in no one's benefit. Stop trying to 
> avoid a couple of extra rows of for {} (where the third row is literally 
> just an "}")  and start embracing the fact that you can understand the code 
> by looking at it and not apply any complex mental acrobatics to figure out 
> what those three lines of code are doing. Your future self/person after you 
> will thank you for that. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-02 Thread Egon
On Friday, 2 June 2017 15:59:41 UTC+3, gary.wi...@victoriaplumb.com wrote:
>
> Generics enable more than just replacing loops. For example, they can 
> enable libraries of generic algorithms to be used with any type of array. 
> Here's an example:
>
> foo := GetArray()
> result := foo.Take(10).map(...).Sort(...).Reduce(...)
>

Why stop there? It also could be:

*result := average wage by country*

This is much more readable than the map/reduce stuff.


> That is simple to understand and in one line of code. Imagine the 
> acrobatics (and lines of code) needed to do this using Go's loops!
>
> You can read my full article on why Go needs generics here: 
> http://nomad.so/2015/03/why-gos-design-is-a-disservice-to-intelligent-programmers/
>  
> 
>
> On Friday, 2 June 2017 09:17:54 UTC+1, Florin Pățan wrote:
>>
>> Since everyone thinks it but nobody bothers to reply to it: this whole 
>> thing you propose can be currently done with a for loop, which not only is 
>> explicit about what it doing, but it also lets you control if you want to 
>> exit early from it and so on. Complicating the whole language because 
>> something is cool (yet looks like a really complex thing that you need to 
>> think about while reading the code) is in no one's benefit. Stop trying to 
>> avoid a couple of extra rows of for {} (where the third row is literally 
>> just an "}")  and start embracing the fact that you can understand the code 
>> by looking at it and not apply any complex mental acrobatics to figure out 
>> what those three lines of code are doing. Your future self/person after you 
>> will thank you for that. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-02 Thread gary . willoughby
Right, now show me the contents of the *average wage by country *function! 
It's not going to be one line or as readable is it?!?!

On Friday, 2 June 2017 14:26:47 UTC+1, Egon wrote:
>
> On Friday, 2 June 2017 15:59:41 UTC+3, gary.wi...@victoriaplumb.com wrote:
>>
>> Generics enable more than just replacing loops. For example, they can 
>> enable libraries of generic algorithms to be used with any type of array. 
>> Here's an example:
>>
>> foo := GetArray()
>> result := foo.Take(10).map(...).Sort(...).Reduce(...)
>>
>
> Why stop there? It also could be:
>
> *result := average wage by country*
>
> This is much more readable than the map/reduce stuff. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-02 Thread Henrik Johansson
I have seen syntactic sugar like that in Scala. It can be very powerful but
at the same time very confusing when you need to fix a bug since you have
the mental overhead of the dsl to actual code to worry about as well.


fre 2 juni 2017 kl 16:16 skrev :

> Right, now show me the contents of the *average wage by country *function!
> It's not going to be one line or as readable is it?!?!
>
>
> On Friday, 2 June 2017 14:26:47 UTC+1, Egon wrote:
>>
>> On Friday, 2 June 2017 15:59:41 UTC+3, gary.wi...@victoriaplumb.com
>> wrote:
>>>
>>> Generics enable more than just replacing loops. For example, they can
>>> enable libraries of generic algorithms to be used with any type of array.
>>> Here's an example:
>>>
>>> foo := GetArray()
>>> result := foo.Take(10).map(...).Sort(...).Reduce(...)
>>>
>>
>> Why stop there? It also could be:
>>
>> *result := average wage by country*
>>
>> This is much more readable than the map/reduce stuff.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-02 Thread Egon
On Friday, 2 June 2017 17:16:09 UTC+3, gary.wi...@victoriaplumb.com wrote:
>
> Right, now show me the contents of the *average wage by country *function! 
> It's not going to be one line or as readable is it?!?!
>

You can try http://www.wolframalpha.com/, which is somewhat close to the 
principle.
 

>
> On Friday, 2 June 2017 14:26:47 UTC+1, Egon wrote:
>>
>> On Friday, 2 June 2017 15:59:41 UTC+3, gary.wi...@victoriaplumb.com 
>> wrote:
>>>
>>> Generics enable more than just replacing loops. For example, they can 
>>> enable libraries of generic algorithms to be used with any type of array. 
>>> Here's an example:
>>>
>>> foo := GetArray()
>>> result := foo.Take(10).map(...).Sort(...).Reduce(...)
>>>
>>
>> Why stop there? It also could be:
>>
>> *result := average wage by country*
>>
>> This is much more readable than the map/reduce stuff. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] golang regex question

2017-06-02 Thread Sankar
I have a go string

dbConnStr1 := "user=someone password=something host=superduperhost 
sslmode=something"

the k=v pair in this string may be in any order, for example:

dbConnStr2 := "host=superduperhost user=someone password=something"


Notice the difference in the key order and also the missing "sslmode" key 
in the second instance.

Also, it is possible that instead of whitespace, the individual k,v pairs 
may be separated by newline too.

It is safe to assume that the values may not contain '=' as a content.

Given all these constraints:

Now I want to extract the unique keys and their corresponding values from 
the given string, using regexp. If it will help, I can give a list of all 
the possible keys that may come (username, password, host, sslmode), but I 
would ideally like a regex solution that works with any list of keys and 
values.

How to do this ? I understand that it may be possible with 
regexp.FindStringSubmatch but not able to wrap my head around writing the 
regexp.

P.s: I know that instead of using regexp, I can write strings.Split call 
and do it normally, but I want a regexp based solution.

Any help ?

Thanks.

PS: I have asked the same question in stackoverflow too and if you want to 
answer there, please 
see: 
https://stackoverflow.com/questions/44321199/golang-extract-unique-key-value-from-a-key-value-pair-string-using-regex

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: How to parallelize text/template long running functions?

2017-06-02 Thread Michael Brown
Your solution is certainly nice. It has the same limitation that mine does. 
I'll take a look, I like how you don't have to modify the funcmap in yours.
--
Michael

On Friday, June 2, 2017 at 4:41:14 AM UTC-5, rog wrote:
>
> On 2 June 2017 at 10:35, roger peppe > 
> wrote: 
> > Here's a proof-of-concept of a somewhat general mechanism 
> > for making template functions concurrent. It involves some 
> > fun reflection code (first time I've used FuncOf, MakeFunc, 
> > StructOf and MapOf for real). 
> > 
> >  https://play.golang.org/p/7qXx5pCh9N 
>
> Note that it won't work correctly if you pass any functions whose results 
> are used in template expressions to Execute. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: golang regex question

2017-06-02 Thread pierre . curto

Hello,

Try something like this:
https://play.golang.org/p/xSEX1CAcQE

Le vendredi 2 juin 2017 16:26:24 UTC+2, Sankar a écrit :
>
> I have a go string
>
> dbConnStr1 := "user=someone password=something host=superduperhost 
> sslmode=something"
>
> the k=v pair in this string may be in any order, for example:
>
> dbConnStr2 := "host=superduperhost user=someone password=something"
>
>
> Notice the difference in the key order and also the missing "sslmode" key 
> in the second instance.
>
> Also, it is possible that instead of whitespace, the individual k,v pairs 
> may be separated by newline too.
>
> It is safe to assume that the values may not contain '=' as a content.
>
> Given all these constraints:
>
> Now I want to extract the unique keys and their corresponding values from 
> the given string, using regexp. If it will help, I can give a list of all 
> the possible keys that may come (username, password, host, sslmode), but I 
> would ideally like a regex solution that works with any list of keys and 
> values.
>
> How to do this ? I understand that it may be possible with 
> regexp.FindStringSubmatch but not able to wrap my head around writing the 
> regexp.
>
> P.s: I know that instead of using regexp, I can write strings.Split call 
> and do it normally, but I want a regexp based solution.
>
> Any help ?
>
> Thanks.
>
> PS: I have asked the same question in stackoverflow too and if you want to 
> answer there, please see: 
> https://stackoverflow.com/questions/44321199/golang-extract-unique-key-value-from-a-key-value-pair-string-using-regex
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: golang regex question

2017-06-02 Thread Sankar P
This is brilliant. I just never had the idea to split by words and
accumulate them. Thanks. Please update the stackoverflow also with this
answer if you have an account. Otherwise I will update it in stackoverflow
tomorrow, crediting this mail thread as the source.

2017-06-02 21:39 GMT+05:30 :

>
> Hello,
>
> Try something like this:
> https://play.golang.org/p/xSEX1CAcQE
>
>
> Le vendredi 2 juin 2017 16:26:24 UTC+2, Sankar a écrit :
>>
>> I have a go string
>>
>> dbConnStr1 := "user=someone password=something host=superduperhost
>> sslmode=something"
>>
>> the k=v pair in this string may be in any order, for example:
>>
>> dbConnStr2 := "host=superduperhost user=someone password=something"
>>
>>
>> Notice the difference in the key order and also the missing "sslmode" key
>> in the second instance.
>>
>> Also, it is possible that instead of whitespace, the individual k,v pairs
>> may be separated by newline too.
>>
>> It is safe to assume that the values may not contain '=' as a content.
>>
>> Given all these constraints:
>>
>> Now I want to extract the unique keys and their corresponding values from
>> the given string, using regexp. If it will help, I can give a list of all
>> the possible keys that may come (username, password, host, sslmode), but I
>> would ideally like a regex solution that works with any list of keys and
>> values.
>>
>> How to do this ? I understand that it may be possible with
>> regexp.FindStringSubmatch but not able to wrap my head around writing the
>> regexp.
>>
>> P.s: I know that instead of using regexp, I can write strings.Split call
>> and do it normally, but I want a regexp based solution.
>>
>> Any help ?
>>
>> Thanks.
>>
>> PS: I have asked the same question in stackoverflow too and if you want
>> to answer there, please see: https://stackoverflow.com
>> /questions/44321199/golang-extract-unique-key-value-from-a-
>> key-value-pair-string-using-regex
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/HiLDX9qApDI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Copy map with empty interfaces

2017-06-02 Thread Chun Zhang
I am trying to store some complicated data structure with a map, and 
eventually search and use it. 
Since the structure can change with different applications, and it has to 
work with multiple thread, I defined a generic map like follows

type IndexedMap struct {
sync.RWMutex
DataNode  map[interface{}]interface{}
}

Insert is defined as 

func (m *IndexedMap) Insert(dataIndex interface{}, data interface{}) error {

   var err error

   m.Lock()

   //if the node exist
   if _, ok := m.DataNode[dataIndex]; ok {
  m.Unlock()
  return m.Update(dataIndex, data)
   } else {
  //insert new node
  m.DataNode[dataIndex] = data
   }

   m.Unlock()

   return err
}


** For now, the data being inserted is a structure, not the pointer to the 
structure and the key/index is a string.**


Then when I need to find a piece of data, I tried to get a snapshot of the 
database first and then look for it

v, ok : = m.SnapShotData()[key] where

func (m *IndexedMap) SnapShotData() map[interface{}]interface{} {

   ret := make(map[interface{}]interface{})

   m.Lock()
   for k, v := range m.DataNode {
  ret[k] = v
   }
   m.Unlock()

   return ret
}


Then the data v is used to do other things, never modified though. 

This works but the performance is abysmal when the database getting large. 
So, I tried to search without copying 

v, ok := m.DataSearch(key)

func (m *IndexedMap) DataSearch(dataIndex interface{}) (interface{}, bool) {

   var data interface{}
   var ok bool

   m.Lock()

   data, ok = m.DataNode[dataIndex]

   m.Unlock()

   return data, ok
}



However, with this implementation, I always get crash after running the 
program just a little bit with the following error

*** Error in `./colordecoder': double free or corruption (fasttop): 
0x7f943c26f590 ***
SIGABRT: abort
PC=0x7f946c2eac37 m=4
signal arrived during cgo execution

I guess somewhere along the line the copy is a not a hard copy but just a 
reference copy. However, I couldn't understand the difference between above 
two approaches, seems that in SnapShotData I did exactly the same thing, 
but no crash ever. 

Can somebody tell me where I did wrong? Thanks!!


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] [ANN] HTTP/2 Plaintext Server

2017-06-02 Thread Carl Mastrangelo
Hi all, 

If you have ever wanted to use the Go httputil.ReverseProxy with HTTP/2, or 
do HTTP/2 over Unix Domain Sockets, or do gRPC over plaintext, I made a 
package that makes it easy to do:

https://github.com/carl-mastrangelo/h2c

I added some examples to show how to do it, comments welcome!

(Still to do is http/1.1 upgrade, but so far I don't know any clients that 
do that) 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Minio cloud storage?

2017-06-02 Thread Jim Robinson
The https://www.minio.io/ project looks very interesting.  

It's an S3 compatible cloud storage server (and associated apis and command 
line clients), written in Go.

Have any of you folks made use of it?

Jim

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Minio cloud storage?

2017-06-02 Thread Christian von Pentz
On 06/02/2017 11:36 PM, Jim Robinson wrote:
> Have any of you folks made use of it?

Indeed I have. So far only on a single node in the non-cluster mode but
it worked very well and was a pleasure to setup and use.
In fact it worked so well that I'll be moving a 16TB cluster from
Riak-CS to minio in the next days. Had a lot of trouble with it lately
and if the distributed mode of minio works just as good as the single
node mode this should untangle things quite a bit.


Cheers,
chris

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] CGO & Plugins

2017-06-02 Thread dc0d
Assuming we have some *cgo* packages, is it fine to place them inside a 
plugin (added in Go 1.8)?

It seems to ease deployment (on the same platform) and save some 
compilation time. But I'm not sure if it's safe to do so, mixing cgo & 
plugins.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Is there any golang package available for building mongodb query from plain logic expression string or URL?

2017-06-02 Thread Ray Yang
Googled around for a while and found some libs in node.js for the same 
purpose, e.g.

https://www.npmjs.com/package/query-to-mongo
https://www.npmjs.com/package/mongo-querystring

Is there anything similar available in golang?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] CGO & Plugins

2017-06-02 Thread Ian Lance Taylor
On Fri, Jun 2, 2017 at 3:55 PM, dc0d  wrote:
>
> Assuming we have some cgo packages, is it fine to place them inside a plugin
> (added in Go 1.8)?
>
> It seems to ease deployment (on the same platform) and save some compilation
> time. But I'm not sure if it's safe to do so, mixing cgo & plugins.

I can't think of a reason why it wouldn't work, but clearly the
current plugin approach is rather fragile.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] CGO & Plugins

2017-06-02 Thread Michael Brown
Do you have any references on the stability of the current plugin system 
that I can use for reference? I'm building a system now that I contemplate 
using with some plugins and I'd like to know up front the challenges.

On Friday, June 2, 2017 at 7:39:40 PM UTC-5, Ian Lance Taylor wrote:
>
> On Fri, Jun 2, 2017 at 3:55 PM, dc0d > 
> wrote: 
> > 
> > Assuming we have some cgo packages, is it fine to place them inside a 
> plugin 
> > (added in Go 1.8)? 
> > 
> > It seems to ease deployment (on the same platform) and save some 
> compilation 
> > time. But I'm not sure if it's safe to do so, mixing cgo & plugins. 
>
> I can't think of a reason why it wouldn't work, but clearly the 
> current plugin approach is rather fragile. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] filago: Monitor a Linux process' opening and closing of files, including Unix pipes and sockets

2017-06-02 Thread Glen Newton


Monitor open files (via /proc/pid) of a process. Lists time when it first 
sees the file open (which may be later than when the file actually opened, 
especially at startup of filago), and when it is no longer open. Stop 
running when target process ends.

This includes anon_inode and tcp and unix sockets.


*Only works on Linux or OSes supporting /proc in this manner.*


Usage of ./filago:
  -d uint
Time granularity for checking files, in milliseconds (default 100)
  -jOutput json (complete json per line)
  -lTurn on hostname lookup (default is a "-"
  -rShow only real files, i.e. no pipes, sockets, etc.


Default simple text output as well as json output containing more extensive 
information.


Example text output on Firefox process:


$ ./filago -l -j 3737

2017-05-07T12:40:40.663016-04:00 open socket:[416916] tcp 
198.252.206.25:443 stackoverflow.com. 
2017-05-07T12:40:40.663016-04:00 open anon_inode:[eventpoll] 
2017-05-07T12:40:40.663016-04:00 open socket:[511791] unix - 
2017-05-07T12:40:40.663016-04:00 open 
/home/bsmith/.cache/event-sound-cache.tdb.9bf539dba0e34f7aaf456bd844b6826e.x86_64-redhat-linux-gnu
 

2017-05-07T12:40:40.663016-04:00 open socket:[1265977] unix - 
2017-05-07T12:40:40.663016-04:00 open socket:[1574737] tcp 
173.194.175.189:443 qs-in-f189.1e100.net. 
2017-05-07T12:41:21.110231-04:00 close socket:[1630334] tcp 
52.84.139.212:80 server-52-84-139-212.yto50.r.cloudfront.net. 
2017-05-07T12:42:35.083678-04:00 open socket:[1635598] 
2017-05-07T12:42:35.155006-04:00 close socket:[1635598] 
2017-05-07T12:42:35.155006-04:00 open socket:[1630691] tcp 
172.217.6.229:443 lga25s55-in-f5.1e100.net.


Example json output (complete json per line) on Firefox process:


$ ./filago -l -j 3737
{"filename":"socket:[95066]","type":"unix","socket_info":{"unix_socket":{"num":"8803e6c99f80","refcount":"0003","protocol":"","flags":"","type":"0001","st":"03","inode":95066}},"status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
{"filename":"socket:[95067]","type":"unix","socket_info":{"unix_socket":{"num":"8803e6c99c00","refcount":"0003","protocol":"","flags":"","type":"0001","st":"03","inode":95067}},"status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
{"filename":"pipe:[95068]","type":"pipe","status":"open","mod_time":"2017-06-02T23:20:10.616170585-04:00"}
{"filename":"/home/bsmith/install/firefox/omni.ja","type":"file","status":"open","mod_time":"2017-05-27T23:24:59.740556075-04:00"}
{"filename":"/home/bsmith/install/firefox/browser/omni.ja","type":"file","status":"open","mod_time":"2017-05-27T23:25:00.173556279-04:00"}
{"filename":"pipe:[95069]","type":"pipe","status":"open","mod_time":"2017-06-02T23:19:57.685144488-04:00"}
{"filename":"pipe:[110949]","type":"pipe","status":"open","mod_time":"2017-06-02T23:19:57.685144488-04:00"}
{"filename":"socket:[95070]","type":"other","status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
{"filename":"pipe:[102268]","type":"pipe","status":"open","mod_time":"2017-06-02T23:20:13.688176034-04:00"}
{"filename":"/home/bsmith/.mozilla/firefox/uqsr6u0q.default/extension-data/ublock0.sqlite","type":"file","status":"open","mod_time":"2017-06-02T23:19:09.638842227-04:00"}
{"filename":"socket:[110951]","type":"unix","socket_info":{"unix_socket":{"num":"880403259c00","refcount":"0003","protocol":"","flags":"","type":"0001","st":"03","inode":110951}},"status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
{"filename":"anon_inode:[eventfd]","type":"anon_inode","status":"open","mod_time":"2017-06-02T22:20:43.18337-04:00"}
{"filename":"anon_inode:inotify","type":"anon_inode","status":"open","mod_time":"2017-06-02T22:20:43.18337-04:00"}

{"filename":"socket:[109319]","type":"tcp","socket_info":{"inode":109319,"tcp_socket":{"rem_hostname":"a23-63-227-177.deploy.static.akamaitechnologies.com.","sl":4,"local_port":58795,"remote_port":80,"st":1,"tr":1,"uid":1000,"tx_queue":296,"tm_when":21,"extra":"3","rem_address":"23.63.227.177","local_address":"192.168.0.101"}},"status":"close","mod_time":"1969-12-31T19:00:00-05:00"}
{"filename":"socket:[106227]","type":"tcp","socket_info":{"inode":106227,"tcp_socket":{"rem_hostname":"a23-63-227-177.deploy.static.akamaitechnologies.com.","sl":1,"local_port":58796,"remote_port":80,"st":1,"tr":1,"uid":1000,"tx_queue":296,"tm_when":21,"extra":"3","rem_address":"23.63.227.177","local_address":"192.168.0.101"}},"status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
{"filename":"socket:[106227]","type":"tcp","socket_info":{"inode":106227,"tcp_socket":{"rem_hostname":"a23-63-227-177.deploy.static.akamaitechnologies.com.","sl":1,"local_port":58796,"remote_port":80,"st":1,"tr":1,"uid":1000,"tx_queue":296,"tm_when":21,"extra":"3","rem_address":"23.63.227.177","local_address":"192.168.0.101"}},"status":"close","mod_time":"1969-12-31T19:00:00-05:00"}
{"filename":"socket:[111430]","type":"tcp","socket_info":{"inode":111430,"tcp_socket":{"rem_hostname":

[go-nuts] Copy map with empty interfaces

2017-06-02 Thread Tamás Gulácsi
How is cgo involved here? What kind of keys are you using?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.