[go-nuts] Re: [ANN] astits: parse and demux MPEG Transport Streams (.ts) natively in GO

2017-11-23 Thread Asticode
Hey guys,

A user in Reddit asked a good question and I'm interested in the answer you 
may have. The question was "Has anyone looked at how this package compares 
to https://github.com/Comcast/gots?;.

Initially I've used this package to parse MPEG transport streams, but I 
didn't really like the way it was built and above all its API. That's why 
I've decided to build go-astits.

I'm really interested in any feedback you guys may have.

Cheers


Le lundi 20 novembre 2017 08:53:01 UTC+1, Asticode a écrit :
>
> Hey guys,
>
> I'm happy to announce go-astits, a Golang library to parse and demux MPEG 
> Transport Streams (.ts) natively: https://github.com/asticode/go-astits
>
> It allows you to either retrieve raw packets or event better retrieve 
> complex data spanning over multiple packets.
>
> Let me know what you think!
>
> Cheers
>

-- 
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] chan chan Job per worker vs. single chan Job

2017-11-23 Thread carsten . orthbandt
Hi!

This should be covered somewhere already but I can't find it. So here's my 
question:

Assume N workers running in a goroutine each and a number of Job tasks 
coming in.

The consensus appears to be to have one dispatcher goroutine collecting all 
jobs, then pulling a ready worker from a single queue of worker channels.
The workers put their individual queue (chan Job) into that single queue 
(chan chan Job) when they are ready to accept new work.

What I don't understand is why this is beneficial compared to the simpler 
approach of having all workers pull their work from one single chan Job 
like this:

func worker(q chan Job) {
  for {
j <-q
   doWork(j)
  }
} 

func dispatch(q chan Job, j Job) {
  q<- j
}

(real world code would obviously select to also cover a quit signal channel)

So what am I missing? In both cases the workers will block when there's no 
work and the "dispatcher" uses whatever worker is available.


Best Regards,
Carsten

-- 
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] Help me MVC golang

2017-11-23 Thread Michael Banzon
Please describe the error you are getting. (I suspect this me yet-another “go 
run”-episode)

It seems you are trying to do MVC the ASP.NET  way in Go - I’m 
quite confident that this will not give a good result.

I’ve been down a similar route (pun intended) when I started programming Go and 
found that going with the least amount of code was the right way. I recommend 
you try using the default HTTP routing from the std lib.

-- 
Michael Banzon
https://michaelbanzon.com/




> Den 23. nov. 2017 kl. 05.37 skrev Teo :
> 
> -- Blog
> -|---Controllers
> ---|---Backend
> ---|index_controller.go
> ---|---Frontend
> ---|index_controller.go
> 
> -|-main.go
> 
> 
> /// file main.go 
> 
> package main
> 
> import (
> "net/http"
> 
> "./controllers/backend"
> "./controllers/frontend"
> "github.com/julienschmidt/httprouter"
> )
> 
> func main() {
> frontend := {}
> backend := {}
> router := httprouter.New()
> 
> router.GET("/", frontend.Index)
> 
> router.GET("/admin", backend.Index)
> 
> http.ListenAndServe("localhost:8080", router)
> }
> 
> // frontend / index_controller.go
> 
> package frontend
> 
> import (
> "fmt"
> "net/http"
> )
> 
> type IndexFrontend struct {
> }
> 
> func (c *IndexFrontend) Index(w http.ResponseWriter, r *http.Request) {
> fmt.Println("frontend")
> }
> 
> // backend / index_controller.go
> 
> package backend
> 
> import (
> "fmt"
> "net/http"
> )
> 
> type Indexbackend struct {
> }
> 
> func (c *Indexbackend) Index(w http.ResponseWriter, r *http.Request) {
> fmt.Println("backend")
> }
> 
> 
> go run main.go ==> error 
> 
> Help me code golang? thanks all
> 
> 
> 
> 
> 
> -- 
> 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: f*ck you, golang

2017-11-23 Thread David Collier-Brown
The PHBs always want FORTRAN IV programmers, in any language. Just lie and 
say Go was written by FORTRAN experts. Lik Kernighan and Pike, for example.

--dave
 

> On Friday, July 24, 2015 at 12:19:29 AM UTC+2, Roberto Zanotto wrote:
>>
>> I have to work on a project for an university exam and the professor 
>> highly recommends doing it in C++ with (his) FastFlow library. Now, because 
>> of Go, I can't stand looking at object oriented code anymore. The way the 
>> code is structured... class hierarchies... you can't even tell what the 
>> program _does_. My eyes cross and I feel like crying.
>>
>> I was meant to be a successful C++/Java programmer, now that is ruined 
>> forever. And nobody listens to me! A friend of mine recently graduated, we 
>> bought him "*Design Patterns: Elements of Reusable Object-Oriented 
>> Software"* and "*Effective Modern C++: 42 Specific Ways to Improve Your 
>> Use of C++11 and C++14".* He wanted those books and said that they are 
>> what he needs to learn for job interviews. And everybody agreed.
>>
>> My life is ruined and it's on you.
>>
>

-- 
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] Introspecting a type

2017-11-23 Thread Hein Meling
That's nice work-around! Thank you Jakob! 

Best regards,
:) Hein

On Wednesday, November 22, 2017 at 11:27:34 PM UTC-8, Jakob Borg wrote:
>
> A variable of type [][]Operation has that type and only that type. Your 
> Concurrent and Sequential types are convertible to []Operation, and this is 
> what happens in the assignment. 
>
> You can probably use interfaces to accomplish what you want.
>
> type Operator interface {
> Operations() []Operation
> }
>
> Make Concurrent and Sequential distinct types that both implement 
> Operations() []Operation. This can be as simple as
>
> type Concurrent []Operation
>
> func (c Concurrent) Operations() []Operation {
> return c
> }
>
> Make your top level thing an []Operator. Use type switching or further 
> interface methods as appropriate.
>
> //jb
>
> On 23 Nov 2017, at 00:39, Hein Meling  
> wrote:
>
> I have code like this:
> type TestCase struct {
> Namestring
> Description string
> OrderOp [][]Operation
> }
>
> type Concurrent []Operation
> type Sequential []Operation
>
> With the intent to do things like this:
> OrderOp: [][]Operation{
> Concurrent{
> {ID: "A", Name: "Read", ArgumentType: "ReadRequest", Value: ""},
> {ID: "B", Name: "Write", ArgumentType: "Value", Value: "7"},
> },
> Sequential{
> {ID: "C", Name: "Read", ArgumentType: "ReadRequest", Value: ""},
> {ID: "D", Name: "Write", ArgumentType: "Value", Value: "8"},
> },
> }
>
> However, it seems that the OrderOp array do not preserve the type 
> information, and I cannot use type assertion or reflect.TypeOf() to recover 
> the types Concurrent and Sequential, that I intended to. For a full 
> example, see link below.
>
> My question is: How can I best work around this problem??
>
> (Preferably without adding a separate field in a struct to discriminate 
> between concurrent and sequential.)
>
> https://github.com/selabhvl/cpnmbt/blob/master/rwregister/table_test.go
>
> Thanks,
> :) Hein
>
> -- 
> 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...@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: various odd, to me, at best undocumented, behaviour of automatic formatting in go doc

2017-11-23 Thread 'simon place' via golang-nuts
what you are describing is what i expected from the start, a form of 
duck-typing, in that if it looks like a Title then format it as a Title, 
fine, simple and efficient.

i don't expect all the cases where the documentation is wrong that could 
easy, simply and usefully not be.

-- 
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: f*ck you, golang

2017-11-23 Thread Juliusz Chroboczek
> I was meant to be a successful C++/Java programmer, now that is ruined 
> forever.

[...]

> My life is ruined and it's on you.

You can only blame yourself.  You should have studied for the exam
rather than doing extra-curricular 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] How to get explicit receiver of a method through reflect?

2017-11-23 Thread Josh Humphries
If you knew the representation of the function, and how captured variables
were stored in this representation, you could use unsafe to reinterpret the
function value as a usable form (pointer, tuple, whatever) and de-reference
this data to read captured variable addresses. In the case you describe,
the receiver would be the only captured variable.

But this is a very bad idea for a couple of reasons:

   1. The Go language spec does not define the representation for a
   function. So if you discovered the representation, the code would not be
   portable to other Go compilers or even across versions of Go.
   2. It is not safe. You have to know apriori the number and types of
   closed variables for this to work. You would not be able to distinguish
   between functions that have the same signature, but with different sets of
   closed variables. So it could be possible you receive a function that does
   not capture a method receiver, and then your interpretation of whatever you
   read using unsafe will likely cause memory corruption and/or a program
   crash.




*Josh Humphries*
jh...@bluegosling.com

On Wed, Nov 22, 2017 at 8:46 PM, Hoping White  wrote:

> Thanks Josh. Yes, a single-method interface can do the job. I just want to
> know the unsafe way for curiosity. could you please explain more?
>
> 2017-11-22 22:12 GMT+08:00 Josh Humphries :
>
>> The reflection package provides no way to do this. Even if it were
>> possible to do with unsafe (not even sure it is, but maybe?), it would be
>> brittle and tied to an undocumented representation of a function and its
>> captured variables.
>>
>> Instead, use a single-method interface. It's easy to create a factory
>> method that takes a function and adapts it to the interface. And then the
>> value can be used both to invoke the logic (by calling the one method of
>> the interface) and for inspecting its concrete type and value.
>>
>>
>> 
>> *Josh Humphries*
>> jh...@bluegosling.com
>>
>> On Wed, Nov 22, 2017 at 8:26 AM, Hoping White 
>> wrote:
>>
>>> Hi, all
>>>
>>> I known that method of a struct can be a function with explicit
>>> receiver, like this
>>>
>>> type Param struct {
>>> v int
>>> }
>>>
>>> func (this *Param) Call() {
>>> println(this.v)
>>> }
>>>
>>> p := {v:10}
>>> t := p.Call
>>> t()
>>>
>>> I wonder how can I get the receiver p from function t through
>>> reflect. Thanks all.
>>>
>>> --
>>> 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: Would someone care to compare Firefox Quantum Rust concurrency features to Go....

2017-11-23 Thread ffm2002
Concurrency in Rust and Go are completely different things. In Rust a 
thread has its own memory space and hence a thread cannot reference data by 
reference of some other thread. The rational behind that is security. Also, 
a thread in Rust is not lightweight, but a full-blown OS thread. So there 
is no CSP in Rust as in Go and therefore there is little to compare between 
Rust and Go concerning concurrency. AFAIK, there is some crate in Rust that 
adds some minimal support for coroutines, but I don't think its used in 
Servo.

Am Donnerstag, 23. November 2017 09:04:09 UTC+1 schrieb Anssi Porttikivi:
>
> How would this look, if implemented in Go? Is there anything to learn from 
> Rust "fearless concurrency"? What are the goals and complexity trade-offs 
> of the two languages? 
> https://blog.rust-lang.org/2017/11/14/Fearless-Concurrency-In-Firefox-Quantum.html
>
> When and why would there be a browser engine in Go? ;-) Some interesting 
> projects to compare to are
> - Servo (rust) https://github.com/servo/servo/
> - 3S (haskell) https://hsbrowser.wordpress.com/3s-functional-web-browser/
> - LURE (lua) https://github.com/admin36/lua-LURE
> - Weasy (python) https://github.com/Kozea/WeasyPrint
>

-- 
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] Help me MVC golang

2017-11-23 Thread Teo
-- Blog
-|---Controllers
---|---Backend
---|index_controller.go
---|---Frontend
---|index_controller.go

-|-main.go


/// file main.go 

package main

import (
"net/http"

"./controllers/backend"
"./controllers/frontend"
"github.com/julienschmidt/httprouter"
)

func main() {
frontend := {}
backend := {}
router := httprouter.New()

router.GET("/", frontend.Index)

router.GET("/admin", backend.Index)

http.ListenAndServe("localhost:8080", router)
}

// frontend / index_controller.go

package frontend

import (
"fmt"
"net/http"
)

type IndexFrontend struct {
}

func (c *IndexFrontend) Index(w http.ResponseWriter, r *http.Request) {
fmt.Println("frontend")
}

// backend / index_controller.go

package backend

import (
"fmt"
"net/http"
)

type Indexbackend struct {
}

func (c *Indexbackend) Index(w http.ResponseWriter, r *http.Request) {
fmt.Println("backend")
}


go run main.go ==> error 

Help me code golang? thanks all




-- 
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: Interest in implementing dual-pivot or 3-pivot quicksort for faster sorting?

2017-11-23 Thread Egon
Did a quick translation of the implementation

https://github.com/egonelbre/exp/tree/master/sorts/qpsort

The implementation seems to fail some Go tests.

--- FAIL: TestSortBM (0.00s)
sort_test.go:168: n=100 m=1 dist=stagger mode=copy: used 840 swaps 
sorting slice of 100
--- FAIL: TestSortBasicBM (0.05s)
sort_test.go:168: n=1023 m=512 dist=sawtooth mode=dither: used 
34100 swaps sorting slice of 1023
--- FAIL: TestAdversary (0.01s)
sort_test.go:316: used 56 comparisons sorting adversary data 
with size 1

Rough measurements and observations:

The interface based version is ~20% slower than std lib.
The specialized version for int is ~20% faster than the std lib.

*The implemented specialized version tries to use similar style as the 
stdlib, which can be optimized further.*

+ Egon

On Wednesday, 22 November 2017 20:03:18 UTC+2, David McManamon wrote:
>
> Sometimes it takes years for great technical papers to be implemented.  As 
> a fun exercise to compare Java's dual-pivot (since so much work went into 
> it) with the 3-pivot described in the paper:
> Multi-Pivot Quicksort: Theory and Experiments 
> downloaded from:
> http://epubs.siam.org/doi/pdf/10.1137/1.9781611973198.6 
> I wrote the 3-pivot quicksort described in the paper and for sorting 10 
> million elements it was about 10% faster than Arrays.sort() and completes 
> in 1 second on my 2013 computer.
> Feel free to run the code if you have any doubts:
>
> https://github.com/dmcmanam/quicksort/tree/master/src
>
> And I wrote a quick blog post for background which also explains why I'm 
> looking for languages like Go to implement this in:
>
>
> https://refactoringlightly.wordpress.com/2017/11/21/multi-pivot-quicksort-aka-3-pivot-quicksort/
>
> Any interest in working with me to write a Go version?  Some discussion & 
> pair programming would be fun since so far I have only written 1 go 
> algorithm - AVL trees since I was surprised to see people using LLRB in Go 
> but I was guessing there is less interest in better balanced binary search 
> trees.  The project would have a few steps, working on benchmarks for edge 
> cases, etc.  
>
> --David
>

-- 
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: f*ck you, golang

2017-11-23 Thread 'Paul' via golang-nuts


On Friday, July 24, 2015 at 12:19:29 AM UTC+2, Roberto Zanotto wrote:
>
> I have to work on a project for an university exam and the professor 
> highly recommends doing it in C++ with (his) FastFlow library. Now, because 
> of Go, I can't stand looking at object oriented code anymore. The way the 
> code is structured... class hierarchies... you can't even tell what the 
> program _does_. My eyes cross and I feel like crying.
>
> I was meant to be a successful C++/Java programmer, now that is ruined 
> forever. And nobody listens to me! A friend of mine recently graduated, we 
> bought him "*Design Patterns: Elements of Reusable Object-Oriented 
> Software"* and "*Effective Modern C++: 42 Specific Ways to Improve Your 
> Use of C++11 and C++14".* He wanted those books and said that they are 
> what he needs to learn for job interviews. And everybody agreed.
>
> My life is ruined and it's on you.
>

'Forever' is a big word, I think things are moving too fast for that.  Once 
General Artificial Intelligence can be used to translate human languages to 
machine languages there will be a seismic shift. If you just think about 
security applications and General AI. Imagine a Deep learning algorithm 
that can detect malicious code by looking at the generated machine code. 
Its not as far fetched as it may seem because its mostly about pattern 
recognition.  Unfortunately not enough is being done to move faster in that 
direction.  

-- 
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: various odd, to me, at best undocumented, behaviour of automatic formatting in go doc

2017-11-23 Thread Volker Dobler
On Wednesday, 22 November 2017 19:09:46 UTC+1, simon place wrote:
>
> trying to work around these issues, i find another undocumented 'feature'
>
> https://play.golang.org/p/dzcq5XKpgG
>
>
It is the same logic:

A heading is a heading to a normal text paragraph. Lines are not
headings by themselves but because the are ahead of the text they
headline.
(Its a bit like preformatted text. No comment by itself is treated as
preformatted: It must be indented to some normal paragraph text
to be rendered as preformatted.)

This is basically the difference to markdown et al. In Markdown
you *mark* a line as headline. The godoc way is different: If it happens
*to be a headline* it is rendered as such. And the rules for being
a headline are a bit like in printing where headlines start with a capital,
has no punctuation and is *properly placed* (according to book printing
typsetting rules): It comes before some actual copy text which it is
headlining. No copy after the headline, no headline. Typesetters typically
do not show figures or tables directly after a headline (at least not
in the main part of a book).

Rule of thumb: If you want a line to be rendered as a heading: Make
it a heading. This includes several formal things like "single line",
"surrounded by newlines", "Capital start", "punctuation free" and some
semantic things like: It must headline actual copy.

V.

-- 
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] Would someone care to compare Firefox Quantum Rust concurrency features to Go....

2017-11-23 Thread Anssi Porttikivi
How would this look, if implemented in Go? Is there anything to learn from 
Rust "fearless concurrency"? What are the goals and complexity trade-offs 
of the two languages? 
https://blog.rust-lang.org/2017/11/14/Fearless-Concurrency-In-Firefox-Quantum.html

When and why would there be a browser engine in Go? ;-) Some interesting 
projects to compare to are
- Servo (rust) https://github.com/servo/servo/
- 3S (haskell) https://hsbrowser.wordpress.com/3s-functional-web-browser/
- LURE (lua) https://github.com/admin36/lua-LURE
- Weasy (python) https://github.com/Kozea/WeasyPrint

-- 
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.