Re: [go-nuts] Re: Reading os.Stdin, Unbuffered

2017-11-30 Thread Robert Solomon
Thanks On Nov 28, 2017 8:03 PM, "Robert Solomon" wrote: I trying to learn how to use pseudo-terminal-go. It works fine under Ubuntu 16.04 amd64. But not fine on win10 64 bit. go get github.com/carmark/pseudo-terminal-go/terminal

[go-nuts] net/http 404 error handling

2017-11-30 Thread Nathan Fisher
Hi All, I came across this issue on GitHub relating to 404 handling in which Brad F. said net/http will not implement templating. https://github.com/golang/go/issues/10707 Perhaps a silly question but why not change http.NotFound into a function pointer like this: ``` var NotFound = func(w

Re: [go-nuts] Building a select friendly condition type

2017-11-30 Thread Ian Lance Taylor
On Wed, Nov 29, 2017 at 9:32 PM, Dave Cheney wrote: > > Anyone for a round of code golf? > > I'm working on a piece of code for a streaming gRPC server and have found > myself in the position that I need to wait for a notification event (in this > case that a cache has been

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Steven Harris
On Thursday, November 30, 2017 at 12:32:10 AM UTC-5, Dave Cheney wrote: > > But I'm wondering if others have found themselves in the same position, > and if so, what were your solutions? > I'm not sure if this approach satisfies all of your requirements, but if you want those registering to be

[go-nuts] Re: Sort a huge slice of data around 2GB

2017-11-30 Thread Slawomir Pryczek
It should be very simple if you have additional 2G of memory. You divide the data to X parts where X is power of 2 and X needs to be less than number of cores available. Eg. for 2000MB it can be 250x8. Then you sort it in paralell using built-in sorting function and at the end you just

[go-nuts] Re: How to check if db connection active after database server restarts ?

2017-11-30 Thread Karan Chaudhary
If at any point it is to be checked that connection is active or not, `Ping` can be used as stated by Shawn. And any operation on dirty conn should fail, as the session is corrupt. Though, it seems, auto-reconnection is already done by database/sql. https://github.com/golang/go/issues/5718

[go-nuts] Re: profiling webserver with pprof and router middleware

2017-11-30 Thread Karan Chaudhary
Attaching png: On Thursday, 30 November 2017 19:09:04 UTC+5:30, Karan Chaudhary wrote: > > Are you just trying to see how heap allocation can be seen using >

[go-nuts] Re: profiling webserver with pprof and router middleware

2017-11-30 Thread Karan Chaudhary
Are you just trying to see how heap allocation can be seen using debug/pprof? Maybe you're allocating too less. Try to allocate exponentialy. package main import ( "log" "net/http" "time" _ "net/http/pprof" ) func expalloc() { x := make([]int, 0) for i := 0; i < 10; i++ { x = append(x, i)

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Dan Mullineux
Yes then as it looks correct I am sure I couldn't do any better (fwiw). If you are happy that volumes of waiters vs notifications wouldn't behave as a `leak` then `c.waiters = c.waiters[:0]` is a fair tradeoff vs GC On Thursday, 30 November 2017 12:26:21 UTC, Dave Cheney wrote: > > That is

Re: [go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Artyom Pervukhin
Dave, you’re absolutely right about the possibility of losing channel on lines 43-47, in my use case that was not an issue because of serialized Notify calls. On a second look I see a way to simplify my code essentially to this: https://play.golang.org/p/F8g-ltlXao

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Dave Cheney
thanks for sharing your implementation. I have a few questions. 1. is NewCond needed? Is this sufficient? var c Cond c.Notify() 2. In notify, is the two arg form of the .(*barr) conversion necessary? If the value is not initialised then the assertion to *barr will fail. If it is initiased

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Dave Cheney
That is correct. I should have made this clearer; the intent is to fire a notification when the cache has changed since the last time it was sent to the client, knowing how many times it has changed (for example while it's being transmitted a whole bunch of changes may have been applied) is not

[go-nuts] Re: Building a select friendly condition type

2017-11-30 Thread Dan Mullineux
The for loop in the main goroutine will lose individual notifications between each Register in that loop but it looks guaranteed that each Register will know if at least one Notification happened after it last knew about a Notification. So if that was, and it sounds like it was, the intention,

[go-nuts] Building a select friendly condition type

2017-11-30 Thread Artyom Pervukhin
Hi, Some time ago I had a similar use-case and came up with the following pattern: https://play.golang.org/p/zQglq3ObvH — it's based on guarantee that receive operation on a closed channel always proceeds immediately. -- You received this message because you are subscribed to the Google

[go-nuts] Re: Is there a way omit the the additional allocation when passing []byte to C function?

2017-11-30 Thread Владислав Митов
Thanks a lot. Yeah, that works but that's not actually my code so I'll have to check with the guys that own it if it is feasible to change the C code, otherwise I'll do the wrapper. On Thursday, November 30, 2017 at 1:35:44 AM UTC+2, xingtao zhao wrote: > > /* C code: > > struct PKCS15_Ret { >