[go-nuts] Re: Template function arguments from JS

2018-10-18 Thread howardcshaw
I have not done much with golang on the web, so take this with a grain of 
salt.

You are right in judging why it does not work - by the time the Javascript 
runs, the template generation is long over with.

That said, I think you have two basic options:

Option 1: Front-load the data into Javascript

That is, the template needs to write ALL the data necessary for the 
sub-region into Javascript (i.e. have the Template produce a bit of JSON 
assigned to a variable in the script region), then have more Javascript 
that uses that data to render the sub-region on the fly on the basis of the 
selection.

Option 2: Use AJAX to pull a smaller template from your Go server, passing 
in the parameter gathered from Javascript, and replacing the sub-region in 
the DOM. So basically, you'd have more Javascript in the first template, 
and the sub-region would get pulled out into a second template on the Go 
side.

https://stackoverflow.com/questions/41136000/creating-load-more-button-in-golang-with-templates
https://stackoverflow.com/questions/36251743/render-a-partial-template-with-passed-parameters

-- 
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: navigating through interface calls

2018-12-07 Thread howardcshaw
It is rather the point of interfaces that there IS no fixed definition of 
an instance of an Interface call. The definition could be that of ANY 
struct that matches that interface, depending on what is passed.

So yes, you have to find AN instance of a call to the function that accepts 
an interface, to find out what it is calling. Because if you call it with a 
different struct, it calls that struct's implementation. Kind of the point. 
And finding that implementation for that call does not guarantee that the 
next call may not be calling a different implementation, because it is 
being passed a different struct.

Your steps after 5 seemed a bit unnecessary - just go to the definition of 
xooConn, your step 5, and search for Close. While it is possible to 
implement a function on a struct elsewhere, the likelihood is pretty low, 
and if you don't find it, then you can go on to your other steps. 

-- 
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] Homoiconic metaprogramming in Go

2018-12-14 Thread howardcshaw
Not sure where you got this impression - commands run by go generate have 
only the OS environment. They are just ordinary commands, as might be run 
by any shell script, just the calls to them are integrated into the Go 
tooling.

Tools that seem to access go syntax trees and the like? They are simply 
using the parser and AST tools made available by Go to parse go code, and 
that can be done at any time, not just during go generate.

Howard

On Friday, December 14, 2018 at 3:40:40 AM UTC-6, rog wrote:
>
> To answer your original question, yes, it is possible to do 
> metaprogramming in Go, although not at compile time.
>
> That's essentially what the go generate command is about - a command run 
> by go generate has access to parsed syntax trees, type information and 
> anything else it likes (bar actual compiler internals), and can generate 
> whatever code it likes.
>
> For example, I think it's pretty clear that what the Wire project does 
> (see https://github.com/google/wire/blob/master/docs/guide.md) is 
> metaprogramming, to some degree or other.
>
>   cheers,
> rog.
>
>> -- 
>>
>>

-- 
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] Homoiconic metaprogramming in Go

2018-12-17 Thread howardcshaw
I was not responding to it being or not being metaprogramming, just the 
implication that go generate commands were provided some sort of special 
access. They do not have any access to parsed syntax trees - they can 
themselves parse source files and thus create syntax trees. On re-reading, 
I can see how your description still fits, I was reading an implication 
into it that is not actually stated in the text. Mea culpa.

Howard

-- 
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: Algorithm question: reversing text/template.Template.Execute efficiently

2019-01-17 Thread howardcshaw
I don't think the problem is well-defined or single-solution. Surely the 
simplest solution, given a single output and the data that produced it is 
to simply encode the entire output text in the template and ignore the data.

Instead, I think you need a matching corpus - i.e. a list of pairs of 
output and input. Once you have that, I expect you would basically run a 
diff-type algorithm across pairs of outputs looking to build an invariant 
list (i.e. the elements of the template that never change) paired with a 
variant list (the elements that change), to be interleaved in the template. 

I don't think there is any simple or valid path to go from there to a fully 
worked out template, given the level of coding permissible in templates. 
But you could do a series of heuristics to match clear elements. For 
example, having your list of variants, you would run a match against the 
content of that variant in each output against all the inputs looking for 
simple matches that hold true across the entire corpus, and replace these 
with simple substitutions in the template, marking them completed in your 
list of variants.

Then you would run the same comparison looking for substring matches (to 
attempt to capture simple substitutions that are chained (e.g. 
{{.Salutation}} {{.FirstName}} {{.LastName}} in a naive name implementation 
is going to show up as a single variant block in the analysis, so your 
first heuristic will fail to find a match). 

Finding repeated complex sub-elements of a template and matching them; or 
matching summary values such as subtotals and grand totals or worse, 
averages that have been formatted to less than the default number of 
digits? I suspect you are going well off the end of what is achievable with 
simple pattern matching, so if that is your normal interview fare, I pity 
your interviewees.

-- 
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] I found a very strange code that would cause deadlocks and blocking,why???

2019-02-28 Thread howardcshaw
Sameer is correct, but to be clear - The *block* happens because the 
channel is empty, so the receive operation blocks forever. This happens in 
both of the cases you show.

The *deadlock* happens because *all* goroutines are blocked and none can 
continue. So if you start some other goroutine that is not blocked, you 
won't have a deadlock, even though your main routine is blocked forever, 
which you are inadvertently doing by that import. Or, more to the point, 
you have a deadlock that Go can't detect as such - because technically, 
there is a goroutine running that could at some point read from that 
channel and your main routine would be unblocked and continue. It won't, 
because it has no reference to it, but the compiler is not currently able 
to detect that.

Again, both cases actually block. It is merely that in the first case the 
compiler can detect that it is a 'forever-blocked' situation and kills the 
program with a warning that it was deadlocked.

Howard

-- 
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] why slice[len:len] okay, but slice[len] fail?

2019-03-08 Thread howardcshaw
> Could you please explain, why primes[6:6] okay, but primes[7:7] not?

Here you go: 
Given this as a slice:
[2:3:5:7:11:13]

consider primes[6:6]'s meaning.
[2:3:5:7:11:13]
  [
  ]

'return the slice starting after the last element of primes and ending 
after the last element of primes'

Now consider prime[7:7]'s meaning.
[2:3:5:7:11:13]
   [
   ]

'return the slice starting after the next position beyond the end of the 
slice, and ending after the next position beyond the end of the slice'. It 
fails on the first entry - there is no concept of a next position beyond 
the end of the slice. 

Think of it like a queue of students standing in line, and the positions a 
teacher might reference when telling a new student or students where to 
stand. 
"Go stand at the head of the line." primes[0:0]
"Go stand in place of the first student and send them back to me." primes[0]
"Go stand right after the first student." primes[1:1]
"Go stand in place of the last student and send them back to me." 
primes[5:6]
"Go stand at the end of the line." primes[6:6]

What does primes[7:7] mean at that point? "Go stand behind the person who 
would be standing at the end of the line if there was one more person 
there."

Nothing conceptually wrong with that - but not supported. But if you had 
sent a person to stand at the end of the line already, then it would be 
fine.

-- 
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] Accessing *[]uint64 from assembly - strange memory corruption under heavy load - any ideas?

2019-03-22 Thread howardcshaw
On Friday, March 22, 2019 at 12:27:37 AM UTC-5, Tom wrote:
>
> The allocation is in go, and assembly never modifies the size of the 
> backing array. Assembly only ever modifies len, which is the len of the 
> slice and not the backing array.
>
>
Can the assembly ever modify len to a size greater than the length of the 
backing array? When that happens within go, a new, larger array gets 
allocated and the backing array gets copied to it. If it happens in your 
assembly?

Howard

-- 
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: Have Any One Experience With Print CSS Modules Using in Golang

2019-03-22 Thread howardcshaw
That is just a wrapper for wkhtmltopdf - I'd suggest looking into that 
library and tool https://wkhtmltopdf.org/ first. If you can get the 
wkhtmltopdf command line tool to convert your file happily, then getting 
the Go wrapper to do the same is probably possible. But if the command line 
tool can't do it, then adding Go is not going to change that. As the 
webpage for it says, it uses a patched Qt. https://wiki.qt.io/Handling_HTML 
says, about Qt apps handling html, 
"However, it only supports a limited subset of static HTML 4 / CSS 2.1"

https://www.w3.org/TR/CSS2/page.html

My suggestion, then, would be to try the approach described 
here: 
https://medium.com/compass-true-north/go-service-to-convert-web-pages-to-pdf-using-headless-chrome-5fd9ffbae1af
which uses a headless Chrome instance to do the rendering. I don't know 
that Chrome has better support, but that should be easy enough to test - 
just load your HTML+CSS doc in Chrome directly and save to PDF - if it 
looks good, then the above method might get the same result in Go.

Again, nothing about this is really Go related - just dependent on what 
backend is actually doing the HTML+CSS rendering.

Howard

On Thursday, March 21, 2019 at 10:24:29 AM UTC-5, nafisf...@gmail.com wrote:
>
> I try to make a pdf from my HTML and CSS. In CSS file there have 
> some Paged Media Models. 
> https://github.com/SebastiaanKlippert/go-wkhtmltopdf/ I use this library 
> to generate my pdf but the problem is the Print CSS didn't work well. I am 
> searching for some idea and feel free to suggest me if you have any 
> solution. Thank you for your time.
>
>
>

-- 
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] encoding/csv: Is this a bug?

2017-07-24 Thread howardcshaw
encoding/csv uses the io.Reader interface, so wouldn't you just need a 
CR->CR/LF filter that fulfills that interface?

Something like https://github.com/andybalholm/crlf should do the trick. 
Though it would be annoying to deal with when writing a generic program for 
handling arbitrary input, if you are dealing with an internal program and 
your own files and you know they are going to be generated that way...

f, err := os.Open("myfile.csv")
// handle error, defer close, etc
c := csv.NewReader(f)
// do stuff

would just become

f, err := os.Open("myfile.csv")
// handle error, defer close, etc
c := csv.NewReader(crlf.NewReader(f))
// do stuff

Howard

On Monday, July 17, 2017 at 10:07:43 PM UTC-5, Matt Harden wrote:
>
> I suspect that this has to do with the line-ending characters on a Mac. I 
> think Excel is writing the file with each line ending with a CR character. 
> The encoding/csv package expects RFC 4180 format (each line terminated with 
> CRLF), which is what Excel writes when you select "Windows Comma Separated".
>
> I don't know a super-easy way to make encoding/csv accept the first format.
>
> On Mon, Jul 17, 2017 at 4:42 PM Dat Huynh  > wrote:
>
>> Hi all,
>>
>> I have a problem with parsing a .csv file using the library 
>> "encoding/csv".
>>
>> I wonder if that is the problem of Microsoft Excel or the Go library.
>>
>> I am using Microsoft Excel version 14.2.2 on MacOS and go1.8.3 
>> darwin/amd64
>>
>> What did I do?
>>
>> Firstly I input the below values into an Excel sheet, and save as a .csv 
>> file.
>> value 11 value 12 
>> value 21 value 22 
>> value 31 value 32 
>>
>> If I choose "Comma Separated Values (.csv)" in the option "Format", type 
>> the file name "data.csv", and run my Go app, it returns:
>>
>> $ go run demo.go 
>> value 31 value 32]12
>>
>> If I choose "Window Comma Separated (.csv)" in the option "Format", type 
>> the file name "data.csv", and run my Go app, it works well.
>>
>> $ go run demo.go 
>> 0 [value 11 value 12]
>> 1 [value 21 value 22]
>> 2 [value 31 value 32]
>>
>> Could you please confirm if this is a bug of the library or MS Excel?
>>
>> Below is my code.
>>
>> package main
>>
>> import (
>> "encoding/csv"
>> "fmt"
>> "os"
>> )
>>
>> func main() {
>> file, _ := os.Open("data.csv")
>> defer file.Close()
>> csvReader := csv.NewReader(file)
>> records, _ := csvReader.ReadAll()
>> for index, record := range records {
>> fmt.Println(index, record)
>> }
>> }
>>
>> Thank you very much.
>>
>> Regards,
>> Dat Huynh.
>>
>> -- 
>> 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.


Re: [go-nuts] Alternative to reflect.DeepEqual that considers "shape" of cycles?

2017-07-27 Thread howardcshaw
https://golang.org/pkg/reflect/#DeepEqual

"Pointer values are deeply equal if they are equal using Go's == operator 
or if they point to deeply equal values."

By the rules described here, the fact that both pointers have the same 
value means it does not even NEED to check what they point to, so I don't 
think it ever even sees the cycle.

So yeah, you would have to write your own implementation, or find one.

https://github.com/google/go-cmp is an example of a custom DeepEqual 
implementation that allows overriding of the comparison basis by 
implementing an interface (it was designed for equality testing in tests).

>From a programmatic perspective, there are two basic ways of comparing two 
objects for equality - you either walk both objects, returning false the 
first time you find a mismatch; or you render both objects into a more 
directly comparable form, and then compare those.

For objects that contain directed or cyclic graphs, going the latter route 
(which *must* include cycle-breaking to avoid infinite loops) provides the 
opportunity of applying a 'canonicalization' pass on the intermediate form 
before the comparison. As an example, if you had two List pointers of the 
sort you used in your example, that *did* have the same structure, they 
would be unequal under DeepEqual (if they carried any comparable, non-equal 
information *aside* from the next pointer), but if canonicalized in a 
consistent manner that rotated each cycle to have the same starting point 
in a resulting acyclic graph subsequent to cycle-breaking, could then be 
compared equal. This requires general graph manipulations, though, and 
could greatly increase the cost to compare on complicated objects. (After 
all, it is effectively the same as asking whether two mathematical objects 
share the same topology, and that is the sort of question that can provide 
someone a PHD thesis!) But while a *general* solution may be quite 
expensive, for a specific case where you have control over the objects, it 
could be as simple as always walking a list until you find the node marked 
with a head flag before comparing them.

-- 
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: How to convert byte slice to UUID?

2017-10-18 Thread howardcshaw
I don't know if you are going to get very far on that, as it seems to have 
been a deliberate change:

" It differs from these earlier packages in that a UUID is a 16 byte array 
rather than a byte slice." 

Looks from here: https://github.com/pborman/uuid/issues/3 like being able 
to use them as map keys may have influenced the shift.

Howard

-- 
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: Mermaid parser

2017-10-27 Thread howardcshaw
There is not one currently that I've seen; there are reasonably good SVG 
libraries for Go though, and it might be possible to take the Javascript 
code and convert it to Go fairly mechanically to make a start on one.

https://github.com/blampe/goat appears to do something like that for the 
charting parts of Markdeep, which is an alternative way of doing charting 
in Markdown.



-- 
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: Handling dynamic and unknown number of wait groups?

2017-11-02 Thread howardcshaw
You absolutely can use goroutines without waitgroups! It all depends on 
what you are doing with them. Where waitgroups come in is when you need to 
something only after *all* of the goroutines on a specific task are done.

Chances are that if you are not using waitgroups, you are either using 
channels or you are only interested in the side-effects of the goroutines 
and are running a long-running service that does not need to have a clear 
end-point.

For example, there is a spot in one of my code-bases where I fire off a few 
optimization routines in parallel - each one takes a channel to feed a 
result in, and I know going in exactly how many results there will be. I am 
going to be comparing and keepign the best, so I don't care which routine 
returns its result first, last, etc - I simply pull the known number of 
results out of the channel - knowing that it will block until that number 
of goroutines has returned. This is a known number of routines though, and 
a waitgroup would be a viable alternative here.

I also have two other kinds of programs that don't use waitgroups - one 
sort of them builds a chain of channels with a goroutine pushing data 
through, and all the other goroutines just flow data through the channel 
using range until the channel closes, then they evaporate. Doesn't need a 
waitgroup because they aren't working on 'pieces of the data that have to 
be put back together at the end' but instead are each operating on *all* 
the data as it flows through them. And the others fire off a goroutine in 
response to an incoming connection, handle that connection, and then go 
away. No need for waitgroups there, unless they in turn fire off a 
collective operation.

A waitgroup is just a way of saying, "I need to be able to wait until all 
these goroutines have done there stuff and finished." If you don't need to 
wait for a group of them to finish, you don't need a waitgroup.

-- 
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: How to convert from []byte to []uint32?

2017-11-13 Thread howardcshaw
The hack would be to use unsafe after converting it to a byte slice to cast 
to a Pointer and cast that back to a uint32 slice. This is bad. Do not do 
this.

Go's ethos is pretty strongly against 'super cool hacks' or 'code golf' 
style statements that perform magic to stuff a lot of code into one 
instruction. Indeed, Go is pretty much the opposite - plain code that does 
what it appears to do with minimal magic, for maximum long-term and 
large-group maintainability of the codebase.

This StackOverflow answer provides an example of the unsafe 
way: 
https://stackoverflow.com/questions/11924196/convert-between-slices-of-different-types

As it also says, this is strongly not recommended.

-- 
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: How to returns the index of the first instance in uint32 slice?

2017-11-14 Thread howardcshaw
You certainly can implement such a thing. The source to the bytes Index 
function is in the bytes_platform.go files, as it is optimized per 
platform: https://golang.org/src/bytes/bytes_amd64.go is the amd64 one, for 
example. Looking at it is a good way to see how such a thing is implemented.

A naive implementation would be something like 
this: https://play.golang.org/p/75H1DSWryQ

But actually looking at the rest of the bytes implementation will give some 
insight into more efficient ways to do it

On Tuesday, November 14, 2017 at 9:21:35 AM UTC-6, Christian LeMoussel 
wrote:
>
> bytes package implements Index  function 
> (func Index(s, sep []byte) int) that returns the index of the first 
> instance of sep in s, or -1 if sep is not present in s. 
> Do you think it's possible to do the same thing with uint32 slice (func 
> Index(s, sep []uint32) int)?
>
> eg: https://play.golang.org/p/kSu3lqsbRH
> buffer := "83f9eed5fb46f700c1caca"
> searchByte := []byte{0x65, 0x65, 0x64, 0x35, 0x66, 0x62, 0x34, 0x36, 
> 0x66, 0x37} // eed5fb46f7
> if bytes.Index([]byte(buffer), searchByte) != -1 {
> fmt.Println("OK")
> }
> 
> 
>

-- 
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 and http2

2017-11-15 Thread howardcshaw
See
https://github.com/golang/go/issues/14141 - for discussion of the issue; 
and 
https://github.com/hkwi/h2c for a way to use the in 
stdlib-but-not-linked-together support for h2c (http/2 over non-TLS).

Howard

-- 
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: Union types mindset

2017-11-21 Thread howardcshaw
In addition to Joshua's suggestion, I would point to Composition. Something 
like this:



// Anything with a GetComment implicitly implements this Interface
type AsmComment interface {
  GetComment() string // presuming any line could have a comment
}


type AsmEntry interface {
  GetEntry() string // renders the full line as it would be in the 
file, maybe
}


type Comment struct {
  Comment string
}


func (c *Comment) GetComment() string {
 return c.Comment;
}


// Can labels have comments as well? This implementation says no, but it 
does implement AsmEntry
type Label string


func (l Label) GetEntry() {
  return l
}


type Instruction interface {
GetMnemonic() string
GetArgsLen() int
GetArg(int) string
}


// By including Comment without a name, it is 'embedded', composed into the 
IntelInstruction struct, which means that IntelInstruction fulfills the 
// AsmComment interface automatically
type IntelInstruction struct {
Comment
Mnemonic string
Args []string
}


...GetMnemonic...
...GetArgsLen...
etc


// The presence of this function fulfills the AsmEntry interface.
func (i IntelInstruction) GetEntry() string {
//Do stuff here
}



-- 
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: Calculation of the combinations between an unlimited number of slices

2017-12-08 Thread howardcshaw
When you use append, two different things can happen:

1. There is enough capacity in the original slice to which you are 
appending to add the additional values. You get a slice that points to the 
same backing memory.
2. There is not enough capacity in the original slice to which you are 
appending. You get a slice that points to a newly allocated chunk of 
backing memory.

This blog talks specifically about append: https://blog.golang.org/slices

Now, looking at your code:

  
c1 := append(c, s)
temp = append(temp, c1)
fmt.Println(i,j,k, "- temp =", temp, " c=", c)

The key thing to see here, is that s is going to be added to c, and *c* is 
going to end up in c1, IF there is enough room for s in c. So, sometimes c1 
is pointing to the same bit of memory as c, sometimes a different bit.

I think, rather than making a copy of the temp variable c1, you should be 
doing the same thing at the step where you create c1.

In other words, something like
c1 := append([]int{}, c..., s)

-- 
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: Go Generate Vs Go Build!

2017-12-20 Thread howardcshaw
Go generate is not needed in your example. Go build is what is producing 
the hello executable.

Go generate is used to run special commands specified by comments in the 
.go files - these commands could produce new .go files, package binaries 
into binhex or base64 encoded strings in .go files for inclusion in the 
executable, produce inter-process communication interface descriptions from 
go structs, embedding version numbers without having to remember to set 
-ldflags, automating the collection of API information from the internet, 
etc.

When it is run and there are no .go files containing generate commands, it 
is doing nothing but scanning the files and exiting. In general, pretty 
much anything you 'go get' should have included any generated files in the 
downloaded data, so running it again is usually not needed, unless the 
README indicates that it is.

Howard

-- 
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: XML Pretty Print

2017-12-20 Thread howardcshaw
One thing to consider is what level of change to the file is acceptable? If 
it is just to be human read, than the suggestions already given may do what 
you want; but it you want to take that result and preserve it for future 
use, then the mxj and the encoding/xml based methods may produce unwanted 
alterations, in which case a package 
like https://github.com/go-xmlfmt/xmlfmt , which doesn't actually parse the 
xml properly at all, just tries to push it back and forth to line up and 
look pretty using regular expressions might be more to your taste. As far 
as I can see, it won't change anything other than whitespace, where a 
parse/pretty-print cycle may have effects such as replicating namespace 
entries or prefixes throughout, changing self-closing tags to tag-pairs or 
vice-versa, etc.

Regexps are pretty cringe-worthy when you see them being used in code that 
is trying to parse HTML or XML and operate on it, but for this use-case, 
they might handle pretty-printing potentially invalid XML data more readily 
than a parser. I.e. the regexp is not going to care if the xml file you got 
has unbalanced tags, etc, and will probably nicely format the first half of 
an XML file that got the latter half replaced with garbage from 
cross-linking or the like.

-- 
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: static analysis tool for detecting unclosed io.Closer's

2017-12-20 Thread howardcshaw
In the absence of an affirmative, I'll just say that I did a search of my 
own. 

This site:
https://github.com/mre/awesome-static-analysis
lists a bunch of static analysis tools for go.

https://github.com/alecthomas/gometalinter has another list, and will run 
them for you. They have binary packages now 
at https://github.com/alecthomas/gometalinter/releases that include the 
linters they can run.

I wrote a minimal program that has the condition of opening an os.File, 
which is an os.Closer, and not explicitly closing it. None of them 
complained about this minimal program, so it is reasonable to assume that 
none of the static analysis tools on the gometalinter list check 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: [ANN] A blog post series on serving big satellite imagery with Go

2017-12-21 Thread howardcshaw
To consider for your series, at some point down the line: 

There are standards for serving geo-located tiles, and if you match one of 
them, your little Go program can serve tiles to already existing map 
browsers, from Javascript based slippy-maps, to Android or iOS street-map 
viewers, to full GIS systems, depending to some degree to which standard 
you match.

Also worth considering is serving tiles at different scales from that 
original dataset (which would be needed for the above tile-serving to work 
at any zoom level, rather than being fixed to one level). While serving at 
a scale finer than that of the Blue Marble is pointless from the BM 
dataset, it is certainly possible to write software that takes your 
existing tile set, and rolls across it, composing 4x4 sets of tiles into an 
image, scaling that down, and saving it as a new tile for a higher level, 
and then repeating that until you finally have a single tile-sized view of 
the whole world. (Would require lossless compression be used for the 
starter tiles and during the creation process, but you could then go back 
and run over them a second time switching them to lossy compression).

You can show composition and decomposition of tasks in rendering and 
serving - instead of a one-time run program to generate the tiles, create a 
rendering daemon to create the tiles on demand into a cache, with a second 
service that serves from the cache and calls the renderer when a tile is 
not found. 

You might also do an overlay service, demonstrating the ability to take a 
tile, render a geographically aligned overlay that matches the tile's 
location, then apply the overlay to the tile before returning the tile to 
the user (for example, using a world boundaries to add country lines onto 
the Blue Marble image, or rendering an end-user's KML file onto the tiles.

Howard

-- 
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: If Go is using libc instead of syscalls on macOS now, why is it not shown via otool -L?

2019-05-03 Thread howardcshaw
I believe that by default, Go programs are statically linked.

>From the man page for otool:

*-L* Display the names and version numbers of  the  shared  libraries
  that  the  object file uses, as well as the shared library ID if
  the file is a shared library.


This is listing what is dynamically linked, not statically linked, so it does 
not show up.

-- 
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: Web access to golang-dev is down

2019-05-07 Thread howardcshaw
I get the error online as well, using groups.google.com/forum/#!golang-dev

Refreshing the page has no effect. Incognito mode, not logged in, gives the 
same error.

Google Chrome 74.0.3729.131 (Official Build) (64-bit) (cohort: Stable)

IP is in the 104.182.104.255 block.

Firefox Version 67.0b12 Build ID 20190418160535 - gives same error.
Microsoft Edge 42.17134.1.0 - same error

All show the grey box in the bottom right saying, "An error (#401) 
occurred  while communicating with the server.
Reload"

Howard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4953ba9e-ec95-4744-972b-c5c7a38ee36d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Web access to golang-dev is down

2019-05-07 Thread howardcshaw
Sorry, forgot to include: Yes, I can access golang-nuts, no errors. 
Golang-announce works fine, neovim gives the error. Clojure works fine.

Howard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b07035fe-d96d-4606-9f15-d9a8a0e16824%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: io.Copy and Writer

2019-05-21 Thread howardcshaw
Excuse me if I am misunderstanding something - but it certainly looks to me 
like you are not at any point closing the bufio.Writer (because it is not a 
WriteCloser and does not support Close function). That is why you need to 
flush it! What you are closing is the underlying file/stream/WriteCloser, 
but it is the bufio.Writer that has the data in its buffer, *not* the file. 
This is not the same thing as flushing a file descriptor, which happens on 
close.

"After all data has been written, the client should call the Flush method 
to guarantee all data has been forwarded to the underlying io.Writer."

IF the bufio.Writer had been implemented as a WriteCloser, then closing it 
would probably flush as well - here is a discussion where they talk about 
how that could be implemented: 
https://stackoverflow.com/questions/43115699/how-to-get-a-bufio-writer-that-implements-io-writecloser

Howard

On Tuesday, May 21, 2019 at 8:42:51 AM UTC-5, Subramanian Sridharan wrote:
>
> I don't think so.
>
> When I close the file and don't explicitly flush:
>
> package main
>
> import (
> "bufio"
> "fmt"
> "io"
> "os"
> )
>
> func main() {
> sourceFilename := "MozillaFirefox-66.0.5-741.4.x86_64.rpm"
> sourcef, err := os.Open(sourceFilename)
> if err != nil {
> fmt.Println("Error while opening source file:", err)
> return
> }
> defer sourcef.Close()
>
> destinationFilename := "CopiedMozillaFirefox-66.0.5-741.4.x86_64.rpm"
> os.Create(destinationFilename)
> destf, err := os.OpenFile(destinationFilename, os.O_APPEND|os.O_WRONLY, 
> os.ModeAppend)
> if err != nil {
> fmt.Println("Error while opening destination file:", err)
> return
> }
> defer func() {
> fmt.Println("Closing file.")
> destf.Close()
> }()
>
> fReader := bufio.NewReader(sourcef)
> fWriter := bufio.NewWriter(destf)
>
> n, err := io.Copy(fWriter, fReader)
> if err != nil {
> fmt.Println("Error while copying:", err)
> return
> }
>
> fmt.Println("Copied", n, "bytes.")
> }
>
>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/24d5242a-3e5a-4b83-a6f2-1ca7e29cfe0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: io.Copy and Writer

2019-05-22 Thread howardcshaw
Except that as the example I gave showed, it is fairly trivial to wrap the 
bufio.Writer into a WriteCloser that retains that reference and performs 
the pass-through Close as expected. So if you have a situation that needs a 
WriteCloser, you can manage that. Meanwhile, the bufio classes provide 
valuable functionality to Writers and Readers, whether or not they have a 
Close function, at the cost of a simple requirement to call Flush after 
writes finish.

The current implementation *is* the more general one. So perhaps what would 
be better would be to add a bufio.WriteCloser that requires a WriteCloser 
to wrap, so that we don't have to implement one of our own in those cases.

Howard

On Wednesday, May 22, 2019 at 8:02:34 AM UTC-5, Robert Engels wrote:
>
> The more I think about this, the more I believe that this is a horrible 
> situation that breaks all rules of encapsulation. This requires the creator 
> to maintain references to the underlying Writer. It also requires the 
> creator to be the sole decider of when the Writer is closed, or the creator 
> must pass the concrete class to subordinates so they can close, or the 
> subordinates must do type casting. 
>
> The bufio.Writer is badly broken and should be changed to declare Close 
> and pass this to the contained Writer if it is a WriterCloser. 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/da01596f-d958-46f0-9bca-18b768e49a35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Any alternative to go-bindata that supports dynamic assets?

2019-05-29 Thread howardcshaw
Just a suggestion, Mark - instead of L.DoString(string(file)) in response 
to a failure on L.DoFile (is there no other error that can occur there 
other than the file being missing?), do an explicit test for the file 
existing, and if it does not exist, grab the asset from bindata and *write 
it out* - then do your L.DoFile.

While it may not seem much of a change, it means that as soon as your 
program runs, whatever scripts it needs get punted out onto the file system 
where your end user can see and fiddle with them.

Depending on your intentions, your way may be more appropriate (e.g. you 
only want the dynamicism to support updates rather than end-user 
tinkering), but this method is more discoverable if end-user tweaking is 
permissible.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/58faabde-82a0-43da-b88d-cda4a94bdb36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Question re fcns that return multiple values

2019-08-07 Thread howardcshaw
On Wednesday, August 7, 2019 at 8:45:18 AM UTC-5, lgo...@gmail.com wrote:
>
> f( g() ) compiles  when g returns exactly the number of args that f() 
> requires, but if g() returns only 1/2 that number  f (g(), g() ) wont 
> compile !! ...Is this not a Golang absurdity  ?? 
>
>>
>>
Eh. Certainly absurd from the perspective of a lot of languages, and 
frustrating when put up against the otherwise good support for duck-typing. 
But the sharp limitation of 'magic' in syntax and the emphasis on being 
explicit where there might be  ambiguity seems in line with Go's ethos to 
me.

At any rate, you can do almost this, if you really, really want to for some 
reason.
https://play.golang.org/p/90gx-tHXwq5

It would be f(h(g,g)) instead of f(g(),g()), but if you had some situation 
where you legitimately needed to make the call a lot, maybe it might be 
worth it over putting the variable collection in each call site.

On the whole, though, it really seems like trying to shoehorn a different 
language's behavior into Go, and maybe you might be better off just finding 
a different way to express the pattern.

For example, instead of returning x and y from your scalarmult(scale, x, y) 
function, you could use a Point struct.

https://play.golang.org/p/V1Iw5HUK4e_-

type Point struct {
x, y int
}

func scalarMult(scale int, a Point) Point {
return Point{a.x*scale,a.y*scale}
}

func add(a Point, b Point) Point {
return Point{a.x+b.x,a.y+b.y}
}

func main() {
m1 := scalarMult(16,Point{28,33})  
m2 := scalarMult( 1,Point{28,33})
r := add(m1, m2)
fmt.Println(r)
}

{476 561}


Howard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9efbd578-8258-4d5f-a47a-5ac72ea609aa%40googlegroups.com.


[go-nuts] Re: SSA-able and canSSA meaning in Go compiler's SSA backend?

2019-09-19 Thread howardcshaw
Read this wiki page to understand what the goal is:
https://en.wikipedia.org/wiki/Static_single_assignment_form

Basically, SSA-form allows certain optimizations that are harder without 
it, but SSA is also itself hard to apply. SSA examples are often posed in 
the form of simple variables, but real code has structs and arrays and maps 
and slices. So they mark things that are worth the effort of applying SSA 
to and things they've (the compiler writers, that is) have decided are not 
worth of pushing down to an SSA form.

So, the special purpose it serves is to enable a class of optimizations. 
And the difference from non-SSA-able values is simply one of cost/benefit. 
Non-SSA-able values are actually those where implementing SSA was deemed 
either not possible or too expensive (either in terms of time, or code, or 
just the compiler author's brainspace).

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/24f48b18-3bd8-4796-bfac-6deb965da99b%40googlegroups.com.


[go-nuts] Re: SSA-able and canSSA meaning in Go compiler's SSA backend?

2019-09-19 Thread howardcshaw
Read this wiki page to understand what the goal is:
https://en.wikipedia.org/wiki/Static_single_assignment_form

Basically, SSA-form allows certain optimizations that are harder without 
it, but SSA is also itself hard to apply. SSA examples are often posed in 
the form of simple variables, but real code has structs and arrays and maps 
and slices. So they mark things that are worth the effort of applying SSA 
to and things they've (the compiler writers, that is) have decided are not 
worth of pushing down to an SSA form.

So, the special purpose it serves is to enable a class of optimizations. 
And the difference from non-SSA-able values is simply one of cost/benefit. 
Non-SSA-able values are actually those where implementing SSA was deemed 
either not possible or too expensive (either in terms of time, or code, or 
just the compiler author's brainspace).

Here is a link to a talk from a Go developer about adding SSA to the 
compiler:
https://about.sourcegraph.com/go/generating-better-machine-code-with-ssa

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d9505d32-c90f-4218-8d51-4cc57ba91745%40googlegroups.com.


[go-nuts] Re: SSA-able and canSSA meaning in Go compiler's SSA backend?

2019-09-19 Thread howardcshaw
Read this wiki page to understand what the goal is:
https://en.wikipedia.org/wiki/Static_single_assignment_form

Basically, SSA-form allows certain optimizations that are harder without 
it, but SSA is also itself hard to apply. SSA examples are often posed in 
the form of simple variables, but real code has structs and arrays and maps 
and slices. So they mark things that are worth the effort of applying SSA 
to and things they've (the compiler writers, that is) have decided are not 
worth of pushing down to an SSA form.

So, the special purpose it serves is to enable a class of optimizations. 
And the difference from non-SSA-able values is simply one of cost/benefit. 
Non-SSA-able values are actually those where implementing SSA was deemed 
either not possible or too expensive (either in terms of time, or code, or 
just the compiler author's brainspace).

Here is a link to a talk from a Go developer about adding SSA to the 
compiler:
https://about.sourcegraph.com/go/generating-better-machine-code-with-ssa

(P.S. if this ends up posting multiple times, I apologize. It has told me 
there was an error communicating with the server twice now.)

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6e1cc086-31ca-4dd8-bce1-3e0cdf14af5a%40googlegroups.com.


[go-nuts] Re: Adding dimension to 2d slice loses dimension order

2019-10-16 Thread howardcshaw
https://play.golang.org/p/Q7otoSJBD5g

As you can see here, wrapping a 2d slice inside of a 3d slice does not 
affect the ordering. Look to see if you use a map anywhere - the order of 
map keys is not preserved, and indeed is deliberately randomized. Beyond 
that, add tests and printfs to narrow down where the change happens. I 
don't think it would be coming simply from the wrapping.

Howard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c08d4e7c-fac5-4881-88a7-d28d4bd5b7a0%40googlegroups.com.


[go-nuts] ANNOUNCE: renderview

2016-08-27 Thread howardcshaw
I mentioned this on the list a little while back in a discussion on Shiny, 
and now it is finally up and available.

https://github.com/TheGrum/renderview

So... what is it? RenderView is a simple GUI wrapper that makes it easy to 
wrap any image generation function and make it interactive. 

It is NOT a replacement for writing full graphical interfaces. This is not 
for front-end developers, this is for the more general Go crowd, the people 
writing back-end code, micro-services, web services, composable 
applications and the like, who don't *want* to have to learn the 
nitty-gritty of a particular graphical toolkit, but would like to be able 
to have a rapid-turnaround way to test/view the graphical outputs of their 
work.

My own intention in writing this came after writing a tool to parse some 
log files, and another to render them as visualizations saved as PNGs, 
produced several gigabytes of data. I want to be able to peek into some of 
my algorithms as they are running, to confirm their behavior is as desired, 
not merely their final output, but I don't want to fill up my disks to do 
it.

I've included several examples of various levels, but basically, given a 
function that produces an image.Image:

func DrawSomething(bounds image.Rect, input1 int, input2 float64, input3 
etc) image.Image {
}

RenderView asks you to provide a RenderModel that simply wraps this image 
generation function, a bag of parameters, and your code for setting up 
those parameters to feed into your drawing function, and it gives you a 
graphical application with various interactive features. Which features you 
get depends on what parameters you use, and which you pay attention to. If 
using a backend that can produce editable widgets (at the moment, this is 
only go-gtk), you can add arbitrary additional parameters to be exposed to 
the user for editing.

The Maze example provides an illustration of how simple it can be. Aside 
from the functions to generate, and to draw the maze, both of which are 
ordinary Go code, the added work is this:

func main() {
sig := ""
rand.Seed(time.Now().UnixNano())
m := rv.NewBasicRenderModel()
m.AddParameters(
rv.SetHints(rv.HINT_HIDE,
rv.NewIntRP("width", 0),
rv.NewIntRP("height", 0),
)...)
m.AddParameters(
rv.NewIntRP("page", 0),
rv.NewIntRP("linewidth", 1),
rv.NewIntRP("cellwidth", 5),
rv.NewIntRP("mazewidth", 100),
rv.NewIntRP("mazeheight", 100))
m.InnerRender = func() {
z := NewDepthFirstMaze(m.Params[5].GetValueInt(), m.Params[6].GetValueInt())
m.Img = RenderMaze(m, z)
m.RequestPaint()
}
}
driver.Main(m)
}

The mandelbrot example, specifically, is code by Sonia Keys taken from 
RosettaCode, used by permission, and shows a concrete instance where I took 
code that literally produced a single, static png, elevated a few constants 
and variables to parameters, had it return the image instead of saving it, 
wrapped it in a simple model - the actual executable for it is in cmd/demo.

The intention is that your library or backend code could live unchanged and 
uncontaminated, while you add a cmd/gui/ folder, drop in a model and a main 
and produce a GUI that lets you exercise your code dynamically. Or, for 
that matter, your GUI could live in its own package, just importing your 
backend code, never to even visit your production environment.

If you look at this and think, you know, with just a little work you could 
do this in any language wrapped around an executable in Go that produced 
the images, well, you're right. There is no reason the frontend code has to 
be in Go. But by the same token, there is no reason the backend code has to 
be in Go either! In cmd/cmdgui, cmdgui is a utility that does just this, 
wrapping a command-line call, with parameters passed both in the 
environment, and optionally interpolated into the arguments using Go 
Templates. The examples show taking a simple Python script for quickly 
generating a function plot, and making it interactive, and using curl to 
call a webservice to make it interactive.

Give it a try with 

go get github.com/TheGrum/renderview

and let me know what you think. Have fun!


Howard C. Shaw III, the Grum

P.S. I guess I have not documented the default parameters it cares about 
yet, I should do that:

left,top,right,bottom - these can be either int or float64, and when 
available, operate panning, and if float64, zooming. - two way, you can 
change these in your code to move the viewport if you are paying attention 
to them
width,height - these get populated with the window width and height - 
changing these in your code has no effect.
options - maybe more later, right now these just control the zooming (done 
with the scroll-wheel)
const (
OPT_NONE= iota  // 0
OPT_CENTER_ZOOM = 1 << iota // 1
OPT_AUTO_ZOOM   = 1 << iota // 2
)
zoom - int or float64, this gets incremented/decremented when the 
scroll-wheel is turned, and can be used to implement your own zoom.
mouseX, mouseY - float64, these get populated with the curre

Re: [go-nuts] Re: ANNOUNCE: renderview

2016-08-27 Thread howardcshaw
Thanks, Nigel. I've updated as you recommended.

Remember to use -u to tell go get to fetch it fresh from github.

go get -u github.com/TheGrum/renderview

On Saturday, August 27, 2016 at 7:21:12 PM UTC-5, Nigel Tao wrote:
>
>
> Yeah, all of the "renderview" imports need to be 
> "github.com/TheGrum/renderview" to play well with "go get". 
>

-- 
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: ANNOUNCE: renderview

2016-08-28 Thread howardcshaw
I still have not tested on Windows; I did look up and find some 
documentation on how to get go and gtk installed and working together on 
Windows, and it basically boils down to installing the linux version of go 
under mingw.

https://github.com/conformal/gotk3/wiki/Installing-on-Windows
http://stackoverflow.com/questions/16999498/how-to-set-up-gtk-for-go-on-win-7

You might say, "but Howard, you posted links for go-gtk and gotk3, what's 
up with that?"

Well, other update, I added preliminary gotk3 support last night. So now we 
have three backends, two of which are partially broken. Fun. Shiny = 
framebuffer, eventloop, no widgets. go-gtk = framebuffer, eventloop, 
widgets. gotk3 = eventloop, widgets, no framebuffer. That is too say, even 
though as far as I can tell the code is correctly asking a GtkImage to set 
its image from the pixbuf I'm passing it, I get nothing. 

So, hey, Joe Blue from the Shiny convo earlier, if you want to showcase 
examples in the various toolkits, you could contribute some more backends! 
:-P

I tried to set it up so that gotk3 would not try to compile by default, to 
limit the introduction of new build headaches. To build it, add -tags gotk3 
nogtk2 to the build line. If on Ubuntu 14.04 like me, or a different distro 
with an early gtk3, you may need to add gtk_3_10 as well. I am slowly 
marking the example as such in the build tags so they don't auto-build, so 
in the example folder use example tag to build them.

go build -tags 'gtk_3_10 gotk3 nogtk2 example'

lsystem example compiled with the above... 18 M

go build -tags 'example'
lsystem example compiled with the above (uses go-gtk)... 7M

Hopefully the gotk3 rendering issue will be resolved shortly - if anyone 
has experience going from a golang image.Image to a rendered image on a 
GTK3 Cairo surface, I'll gladly listen.

Howard

-- 
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: ANNOUNCE: renderview

2016-08-28 Thread howardcshaw
Alright, gotk3 appears to be working properly now. I found the right 
function - I had found set_surface_pixbuf in the GTK3 docs, but thought it 
missing from the gotk3, until a helpful page pointed out that it was *not* 
a Cairo function, and took the Cairo context as a parameter instead.

So, one partial and two working backends. Excellent. All is proceeding as 
planned.

-- 
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: [ANN] A terminal based search engine for bash commands, built with Go

2016-09-11 Thread howardcshaw
Taking a quick look; you've got some Vim style .swp files in your git 
repository that should be removed.

Next, in main.go (anyone else start thinking of tropical fruits at this 
point?) you use 'break Loop' when the number of lines exceeds 10, which 
means one long solution can crowd out less wordy ones; maybe have an option 
to print again with no limit? Then again, as you mentioned in the README, 
once you've added some form of recommendation system, you can sort by that 
to push the more highly recommended answers first.

Finally, have a look at http://www.tldp.org/LDP/abs/abs-guide.pdf

This is a BASH cookbook-style guide that has been explicitly donated to the 
public domain, and should be a fertile resource for populating your library.

Howard

On Sunday, September 11, 2016 at 12:52:12 PM UTC-5, johnny-john wrote:
>
> Hi all!
>
> Just thought about dropping this link here, the codebase is VERY small, so 
> if you are a newbie looking for a project to get into, have a look: 
> https://github.com/crufter/borg
>
> 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] Re: [ANN] (GUI) Qt binding which supports Windows / macOS / Linux / Android / iOS / Sailfish OS / Raspberry Pi

2016-11-15 Thread howardcshaw
therecipe, is there a means available to render image.Image or draw.Image 
(go Image) objects to Qt images/buffers/etc?

I was not able to locate such a facility in several other libraries. In the 
end I got fed up and wrote my own for converting a draw.Image to a 
GdkPixBuf to get gtk2 and gotk3 working. Is there a similar raw in-memory 
image format for Qt that is accessible in a way I could manually create it 
from an image.Image? (In other words, one where the raw bytes are 
accessible for setting, as an array, etc?)

Howad

-- 
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: [ANN] (GUI) Qt binding which supports Windows / macOS / Linux / Android / iOS / Sailfish OS / Raspberry Pi

2016-11-17 Thread howardcshaw
What version of QT is it intended to be built against? I get
therecipe/qt/core/core.cpp:9:30: fatal error: QAbstractAnimation: No such 
file or directory
when I try to build against it, or when trying to build the renderer 
example.

qt5-default says it is 5.5.1+dfsg-16ubuntu7.2 and qtdeclarative5-dev 
is 5.5.1-2ubuntu6

I am building on Ubuntu 16.04.1 LTS.

Howard

-- 
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: Why is src modified when concatenating slices with dst = append(dst, src[:i])

2016-11-21 Thread howardcshaw
Your solution certainly works - but because you allocate a smaller slice 
than you need in the end, it is going to allocate and copy *again* as soon 
as you hit your second append.

You could instead use the other form of make (three parameter) to create an 
*empty* slice with the full length needed pre-allocated, then append thrice 
to get your desired result.

func make([]T, len, cap) []T

If you also use a simple helper function, you can make the result (in my 
opinion, anyway), much more readable. It does carry a performance penalty, 
though, as it involves iterating a loop. Whether that's worth it depends on 
how much speed matters over readability and maintainability.

https://play.golang.org/p/-KOVGMP8KB

Howard

On Sunday, November 20, 2016 at 12:14:31 PM UTC-6, Bogdan Katyński wrote:
>
> Thank you very much for the replies.
> I've read the blog about slices again and I'm pretty sure I know what is 
> happening in my example and how are dst and src interconnected.
>
> I've started thinking how I can achieve what I'm looking for in the nicest 
> way, and after some trial and error, I've come up with this solution:
> https://play.golang.org/p/F3GWDKCrLo
>
> Not sure if it's the nicest way but it was the smallest change and works.
>
> Thanks again for the answers and inspiring me to dig deeper :)
> Bogdan
>
>
>
> W dniu niedziela, 20 listopada 2016 09:52:59 UTC użytkownik Val napisał:
>>
>> Hello Bogdan
>> You're asking a very legit question. Slices are powerful but using 
>> combinations of append and reslicing can be surprisingly subtle.
>>
>> Step1 is easy: slicing is basically creating a new header referencing a 
>> position in an existing array, it does NOT by itself modify src.
>>
>> Step3 is more difficult: dst and src don't share any overlapping memory 
>> location anymore, though they did in Step1 and Step2. This is what happens 
>> when appending elements beyond capacity (beyond last slot of underlying 
>> array): then a fresh new array is allocated and returned, now independent 
>> from src. To understand why there is an overflow at all (even if dst has no 
>> more than 8 items), you must consider that after Step1, the fist slot of 
>> dst is the seond slot of the underlying array.
>>
>> Hope this helps.
>> Same sort of puzzle here: https://go-traps.appspot.com/#append
>>
>>

-- 
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: Merging Data Structures in Go

2016-11-21 Thread howardcshaw
What is the intended use-case for this? Depending on the purpose, you might 
have a look at mergo, https://github.com/imdario/mergo as it does something 
similar, mostly for pulling configuration settings from multiple places and 
combining them with defaults.

For JSON maps, there is https://github.com/peterbourgon/mergemap , and for 
simpler situations (i.e. merging JSON structs without merging embedded 
slices or maps), this solution https://play.golang.org/p/8jlJUbEJKf from 
rog in this 
post https://groups.google.com/forum/#!topic/golang-nuts/nLCy75zMlS8.

As to the code itself, let's see...

I do find it a little odd that when asked to merge A, and B, passed in that 
order, it returns B, A when both items are ints or strings, but if A is a 
slice, then B is appended to A's slice.

So mergeDataStructures("A", "B") = ["B", "A"], while 
mergeDataStructures([]interface{}{"A"},"B") = ["A", "B"]

Just looks like an accidental flipping of b and a to me, easily fixed.

Meanwhile mergeDataStructures("A",[]interface{}{"B"}) panics. (i.e. case 
string: case []interface{}), and even if that code did work, it only 
references a, so it would be returning an incomplete result even if it did 
work.

When handed two similar items on the same level - two strings or two ints 
or an int and a string, it promotes the return object to a slice, whereas 
when the same key with different values appears in two maps being merged, 
one overwrites the other instead of being promoted. It can't handle structs 
apparently at all (just a suggestion: many structs can be JSON marshaled 
and unmarshaled to an map[string]interface{}, which might let them be 
incorporated fairly simply).

Moving on to the question of elegance:

To my knowledge, there is no simpler way in Go to merge two maps other than 
to iterate over one, settings the keys and values into the other 
(obviously, the one being iterated over effectively has precedence, 
overwriting the corresponding values in the other). As to merging slices as 
you have done, well, that rather depends on the intended semantics, so I'm 
not sure you can do it generically without being wrong for at least some 
cases. After all, a slice in an arbitrary data structure or document might 
be sorted or unsorted, or it might be being used as a set and so need to 
reject duplicate items.

So while it might need a few cases tweaked, I think in general you have a 
reasonably workable solution. I do see that this code does not handle 
hierarchical maps - it assigns all of a's map values to a map, then all of 
b's to the same map, without regard for whether they are duplicated.

Howard

-- 
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: rosarygen 1.0

2017-01-03 Thread howardcshaw
This will probably have a very narrow audience (intersection of golang-nuts 
readers and Catholics), but may serve as an example of functional 
audio-processing in Go.

For those unaware, in the Catholic faith, the Rosary is a collection of 
prayers meant to be said while meditating, often with the use of a physical 
rosary, a set of prayer beads in a particular pattern. While nominally 
fairly simple, there have been various alterations and additions adopted by 
various groups that mean that the Rosary as prayed by one group may differ 
in a number of details from that prayed by another.

The next relevant fact is that there are a number of recorded rosaries 
available, some commercially, some public-domain, some on cd, some online, 
generally with the intention that the person listening to the audio would 
be praying along with it. Because of the differences in regional 
pronunciation, word choice (Holy Ghost vs Holy Spirit, for example), 
speaking speed, choice of additions and the like, it can be difficult to 
find a rosary that is completely suited to one's prayer style.

RosaryGen combines a couple of TOML files describing the constituent 
prayers, mysteries, and the structure of the rosary desired, and renders 
out a variable number of audio files by combining the files in the desired 
pattern. It accepts a list of directories and searches them in the given 
order, using the file from the first location found, making it easy to 
layer personal changes over audio drawn from other sources.

https://github.com/TheGrum/rosarygen

Have a look. At the very least, processor.go may be of some interest - it 
builds on azul3d.org's audio.Slices to build a stack of effects and run the 
audio files through it. This is largely unused by the current code, as 
processor.go is actually pulled out of a different project, swarmvoice, as 
yet unfinished and unreleased, but I'll probably use it to add support for 
laying intro and outro music.

On a different note, we have here a grand example of motivated programmer 
laziness. I built a rosary for my mother by grabbing YouTube videos and 
carefully carving them up into cd tracks, replaced some missing prayers, 
fought with Audacity crashing frequently... and then she wanted something 
tweaked, and I looked at Audacity... and instead I went and spent a week 
writing a program to take audio files and stitch them together into a 
proper set of rosary tracks.

Gave her a rosary Sunday morning, she asked for changes, and I went through 
four revisions that same day, ending up with something that has made her 
quite happy. Yep, I spent an entire week of free time, during which I 
surely could have finished the revamp of the rosary I had hand-done for 
her. But each subsequent change she needed (including re-recording audio 
with different words, swapping the order of prayers that recur 20 times in 
the rosary, and the like) took minutes to a half-hour at the most, and now 
she has a CD with *all* the prayers she likes to say, with timing that does 
not leave her gasping for breath or champing at the bit for the next prayer 
to start, in the order she prefers. And she wants copies for her friends. 
Success achieved!

-- 
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] Disadvantage of Go

2017-01-13 Thread howardcshaw
Ehrmm, well, you can do that. The bit that you can't do without it being 
implemented in language is having it behave as a properly type-safe 
expression all the way through.

Here is an example of a ternary function and its use that correctly 
triggers side-effects down only its true path and never calls functions or 
triggers side-effects on the other paths. It is quite a bit more verbose 
than a simple ternary, and I would definitely not recommend its use, but it 
is an interesting example of the use of first-class functions.

https://play.golang.org/p/0PVSeTsQZr

There are two forms there, one that is nestable but is only a statement, 
and can't be used in expression context (but is more compact to write, and 
type-safe). The other is nestable and works as an expression, but uses 
interface{} and so needs casting depending on the use context.

Howard

On Friday, January 13, 2017 at 8:41:54 AM UTC-6, Michael Jones wrote:
>
> One minor point is that you cannot fake the ternary operator with a 
> function. In the function call the two alternates are evaluated before the 
> call so this breaks ... everything else with side effects such as function 
> calls.
>

-- 
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: Marshal more than one XML line?

2017-01-17 Thread howardcshaw
If you actually run that example (click Run below it), you will see it is 
actually writing out eleven lines of XML.
If you had two persons, then you would not be marshalling each 
individually, generally. Instead, you would marshal a slice or array of 
persons.

See this example:
https://play.golang.org/p/OS3hgzCBdN

-- 
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: Marshal more than one XML line?

2017-01-18 Thread howardcshaw
On Tuesday, January 17, 2017 at 11:07:00 PM UTC-6, Tomi Häsä wrote:
>
> What is the difference between Encoder and MarshalIndent? They both write 
> to a stream. When do you use Encoder?
>

I think julian.klode already answered this, not sure why it has not shown 
up here. 

First, they do *not* both write to a stream. Encoder writes to a stream. 
Marshal and MarshalIndent *return* a byte slice.

They are utility wrapper functions around the Encoder; Marshal sets up an 
encoder, encodes the item to a bytes.Buffer, and returns the byte slice. 
MarshalIndent does exactly the same, but calls the Encoder's Indent 
function with the prefix and indent values first.

So the general answer would be, if you have a stream you are writing to, 
use Encoder. If you need to pass around byte slices or munge them in a way 
that is uncomfortable with streams, use Marshal.

The example for Marshal sends the data to the output stream to get results 
visible when you click Run - it is showing *how* to use Marshal, rather 
than *when* to use Marshal.

-- 
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: Shiny

2016-08-16 Thread howardcshaw
I've been working with it lately. I got fairly far in writing a drop-in 
visualizer for my algorithms, but I ran into a snag when I went to add 
dynamically generated editing for parameter values. The widget.NewText(), 
in spite of being used in an Example called TextEdit, does not appear to 
actually have any GUI support for editing yet.

It is also slightly unclear what version of the language it is built for. I 
think they have been advancing with Go, and have not made efforts towards 
backwards compatibility, and I had to make several hand-edits after 
updating, to get it to compile under Go 1.5.

So, from my examination, the event handling/mainloop is fine (at least on 
Linux using X11 driver), painting is fine, widget layout is acceptable-ish, 
but widget depth is exceedingly poor. Basically has image rendering 
widgets, labels, and text widgets with automatic text layout, and that is 
it.

No buttons (though they aren't hard to implement from a label), no radio 
boxes, no built-in scrollbars that I could find, no actual text editors, no 
lookups/drop-downs/choosers, no listboxes. And certainly nothing akin to a 
grid/spreadsheet control with embeddable widgets.

So, right now, as Dave MacFarlane's suggestion also shows, it is viable for 
creating renderers/viewers.

Howard

On Tuesday, August 16, 2016 at 6:35:55 AM UTC-5, Joe Blue wrote:
>
> Shiny looks OK for building desktop apps.
>
> A tone built anything useful with it ?
>

-- 
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: Shiny

2016-08-16 Thread howardcshaw
On Tuesday, August 16, 2016 at 12:19:13 PM UTC-5, Dave MacFarlane wrote:
>
> What do you mean "no actual text editors"? By my count of the 
> importers that GoDoc knows about 3 out of 8 of the projects that are 
> using it are text editor apps. 
>
> - Dave 
>

Go to exp/shiny/examples/textedit. 
go run main.go

Try to edit. Nothing happens. Click - no caret appears. Type, nothing 
happens. Try to select text, nothing happens. 

Look at the list of GoDoc projects:

go-vu: not clear what this is, but it looks like a GUI implementation of 
its own, resting on top of Cocoa, mobile, or Shiny, 
but https://github.com/achille-roussel/go-vu/blob/master/text.go looks like 
his custom implementation of a text edit.

view-fits: image viewer for specific file type.

de: programmer's text editor - uses the Shiny screen as an image window, 
renders text and line numbers into that on its own, does not use any Shiny 
widgets (hardly surprising - this is a VI style mode-based editor, so a 
traditional text edit would hardly be a viable basis). See 
https://github.com/driusan/de/blob/master/kbmap/insertmode.go for basic 
implementation of text editing

T: T text editor. https://github.com/eaburns/T/blob/master/ui/textbox.go - 
this is his own textbox implementation - presumably because Shiny does not 
have a usable one yet.

hplot: histogram and function plotter.

linedrawer: draws steps from 1-dimensional cellular automata

goapple2: apple II emulator, using Shiny as a framebuffer/eventloop, 
basically. Again, not using built-in text widgets, doing its own rendering 
and text handling.

graphics/cmd/edit: popping up a couple of levels, to graphics, here is a 
line from their readme: "editor provides a graphical, editable text area 
widget." Again, their own implementation of a text editor widget.

So, again, not one of these programs uses the Shiny text widget. 
"sigint.ca/graphics/editor" looks like an interesting implementation that I 
may try to use, as it appears on the face of it to have been designed as a 
drop-in usable widget with minimal dependency contamination.

But my basic point stands - the exp/shiny implementation lacks the basic 
widgets to implement the average desktop application, particularly of the 
data entry variety, but is suitable as a backing framebuffer/eventloop. 
Expanding your dependencies may gain you a text editor widget, but you 
would still be on your own for implementing buttons, radio-buttons, 
drop-down/lookup/choosers, list selectors, tree controls, grid controls. 
Unless it is your *goal* in the first place to write such a set of widgets, 
then currently you are probably better off implementing back-end logic in 
Go and front-end interfaces in something else, or looking into alternative 
more feature-complete GUI packages for Go.

The text widget itself was only added to Shiny on June 12, and there is 
still a comment in the file that reads "// TODO: cursors + editing (not 
just viewing) text, key + mouse events, // scrolling, load/save, 
clipboard." so I don't think I am making any claims the developers would 
not acquiesce to. Surely this will change over time, and the 
implementations above are evidence enough that Shiny is a viable platform 
on which to build complex widgets. I am not at all meaning to disparage the 
project, just trying to offer a bit of my own experience.

Howard

-- 
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] Shiny

2016-08-18 Thread howardcshaw
Thanks Joe. I've got some samples already for testing what I'm working 
on... but right now, I'm hitting a wall. The Shiny docs say that 
OnInputEvent on widgets gets called on keyboard events:
>
>
// OnInputEvent handles a key, mouse, touch or gesture event.

but in my testing trying to integrate "sigint.ca/graphics/editor" as a 
temporary replacement for the nonfunction Text widget, a simple 
log.Printf("Handling event (%v)\n", e) on a widget reports mouse movement, 
clicks, mousewheel, but no keyboard events at all (aside from the 
key.Modifiers() state on mouse events - i.e. whether Ctrl is held while 
dragging). Which makes passing those events through to the sigint control 
impossible. 

If I had to guess, it looks to me like this is due to lines 117, 118 in 
widget.go:
case gesture.Event, mouse.Event:
root.OnInputEvent(e, image.Point{})

When I change it to 
case gesture.Event, mouse.Event, key.Event:

then I can make the sigint.ca text editor work in the widget tree, but 
obviously, requiring hand-editing of dependencies is not a viable path, nor 
is vendoring in a customized shiny. Well, the vendored one would work for 
me... but I'm trying to build something that people would willingly drop in 
as a lightweight means of getting a quick dev gui, and including a frozen 
snapshot of a rapidly cycling experimental dependency doesn't seem like a 
good way to do that. Hopefully I can get the change into upstream and not 
worry about it.

On a different note, I will throw in that if you try anything with the 
Widgets and get no visual output, and testing shows your paint functions 
are never called, you probably have not included a widget.NewSheet() call 
wrapping your widgets. You can have more than one of these (to represent 
regions that will be independently scrollable, when scrolling is 
implemented), but most of the built-in widgets assume you have at least 
one. 

-- 
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] Shiny

2016-08-18 Thread howardcshaw
My poor brain is melting. I was just worried about vendoring shiny and the 
effect of that on producing something to be easily embedded in other 
people's programs... while writing a (successful, mind!) wrapper of 
sigint.ca/graphics/editor that makes it fit the Widget node.LeafEmbed model 
of shiny... 

And when I tried to pass in mouse events as well as the keyboard events I 
was already passing, I got this error:
./textedit.go:65: cannot use e (type 
"golang.org/x/mobile/event/mouse".Event) as type 
"sigint.ca/graphics/vendor/golang.org/x/mobile/event/mouse".Event in 
argument to t.editor.SendMouseEvent

Sooo the library I am adding to extend the missing functionality in 
shiny, already vendors shiny and mobile. o_O
Though, only mobile/event/mouse/mouse.go, which based on its alterations, I 
assume fits with modifications to their vendored shiny, as otherwise I 
can't see how it could be filled out. But which means that when embedding 
in un-vendored shiny, you can't send them any mouse events... as far as I 
can see, you can't even manually repackage events in the format they want, 
because you can't import the vendored package from another package.

I also can't just vendor sigint.ca and add a WrapMouseEvent(e 
unvendoredevent) type call, since the new 1.7 vendoring stuff does 
automatic rewriting, so I can't get at *both* the vendored *and* the 
unvendored on either side. I could possibly pass it through as an 
interface{} and unpack it with reflection (bleh!), or create yet a third 
mouse.Event that is actually on a different path, so is accessible to both, 
and convert it twice (ick, but less so). Not really sure where to go with 
this, but I guess mouse interaction is not critical to my primary intended 
use... so back to what I was trying to accomplish.

-- 
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] Why do these Printfs output different things?

2017-01-24 Thread howardcshaw
Actually, the explanation is a little further down in the docs, 
specifically, this paragraph:

For floating-point values, width sets the minimum width of the field and 
precision sets the number of places after the decimal, if appropriate, 
except that for %g/%G precision sets the total number of significant 
digits. For example, given 12.345 the format %6.3f prints 12.345 while %.3g 
prints 12.3. The default precision for %e and %f is 6; for %g it is the 
smallest number of digits necessary to identify the value uniquely.

// These print the same
fmt.Printf("%f\n", a+b)
fmt.Printf("%.6f\n", a+b)
// and these print the same *for this number! - not for all numbers*
fmt.Printf("%g\n", a+b)
fmt.Printf("%.15f\n", a+b) 

So, again, the primary point is that for %g, the *default* precision is the 
smallest number of digits necessary to identify the value uniquely, *not* a 
pre-specified value. For 'a' alone, (i.e. 23.61), 
fmt.Printf("%f\n", a) prints '23.61'
and

fmt.Printf("%g\n", a) prints '23.61'


So this is documented behavior, just lacking the precision caveat on the bullet 
point description of %g.

-- 
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: XML unmarshal woes

2017-02-02 Thread howardcshaw
Here is a playground link: https://play.golang.org/p/_wJEBd1L9x

ABStuff string `xml:",innerxml"`

You can capture the innerxml with an appropriate tag; you can also, as my 
third example in the above link demonstrates, capture multiple repeated 
tags like that to a list of values. If, as I think your comment implies, 
you need to preserve the order of a's and b's AND their order relative to 
each other, that obviously does not help, so the first example demonstrates 
the ,innerxml capture

-- 
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: Pass variables to bash

2017-02-02 Thread howardcshaw
I don't think you can do what you want to do, precisely.

But, I do think you can solve your problem!

Instead of actually writing to your environment in the Go code (which can 
only be seen by *child* processes *of the Go program*!), just print to 
stdout.

That is, instead of os.Setenv("MyPass","Abc.1234"), you would just do 
fmt.Printf("export %s=%s\n", envVarName, envVarValue),

so the output of the program is lines like 

export MyPass=Abc.1234
export somethingelse=thisotherthing

Then take that output and eval it in the shell script.

Example:

osm@Beast:~/test$ echo "#!/bin/sh
> echo export TEST=TRUE
> echo export TEST2=FALSE" > test.sh

osm@Beast:~/test$ cat test.sh
#!/bin/sh
echo export TEST=TRUE
echo export TEST2=FALSE

osm@Beast:~/test$ env | grep TEST
osm@Beast:~/test$ ./test.sh
export TEST=TRUE
export TEST2=FALSE
osm@Beast:~/test$ env | grep TEST
osm@Beast:~/test$ eval "$(./test.sh)"
osm@Beast:~/test$ env | grep TEST
TEST=TRUE
TEST2=FALSE

-- 
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: Does my gofmt work wrongly or I don't understand something ?

2017-02-05 Thread howardcshaw
What were you expecting to happen?

The documentation says: 

   Both  pattern and replacement must be valid Go expressions. In the 
pat‐
   tern, single-character lowercase identifiers serve as wildcards 
 match‐
   ing  arbitrary  sub-expressions;  those expressions will be 
substituted
   for the same identifiers in the replacement.

So if 'h' had shown up in the replacement, it would get replaced with the 
original identifier - but it did not appear, instead H did.

It *looks* like you were expecting it to change the "hello, world\n" to 
"Hello, world\n"? But gofmt's -r requires that both pattern and replacement 
be valid Go expressions. 

This:
gofmt -r "\"hello, world\\n\" -> \"Hello, world\\n\""

Has the effect I think you might have been going for. I'm not certain what 
you were intending though, so I'm not sure of 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: how to parse script expression with go and run the script

2017-02-15 Thread howardcshaw
The go/parse package is not really going to help much, as Go is a compiled 
language. What you are wanting is something akin to a scripting language, 
something with an 'eval' type function. While it is just barely feasible 
that you could accomplish something directly with Go using on-the-fly 
compilation, dynamic object loading, and plugins, it is going to be a lot 
of work and not likely to be a comfortable fit.

My recommendation would be to look at simply embedding a script engine in 
your Go program. There are several Lua implementations for Go, for example.

Have a look at http://awesome-go.com/#embeddable-scripting-languages and 
see if one of them might work for your situation. 

-- 
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: Returning an interface using a concrete type?

2017-02-15 Thread howardcshaw
It can, as I see you've already discovered - but at the same time, should 
it? I think the current 'received Go wisdom' in the community seems to be 
'Accept interfaces, return structs' 
- 
https://medium.com/@cep21/what-accept-interfaces-return-structs-means-in-go-2fe879e25ee8#.g2jxv9wgv

So you might consider if it is actually helpful there to return the 
interface (I'm not saying it definitely isn't - there may be a valid reason 
to return an interface. I'm just suggesting it might be worth questioning 
whether it is or not.)

-- 
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] CodeReviewComments: Recommendation of gofmt

2017-02-15 Thread howardcshaw

>
>
> > Side-note: I don't think goimports can actually do what you are saying, 
> can it? Because, if you run goimports on a valid program, it won't actually 
> *change* any imports, it might just reformat it. For goimports to change 
> anything semantically, the program would need to have missing imports to 
> begin with.
>
> Of course, you're right. I should have said: It can silently turn an 
> invalid program into a valid one with different than intended/assumed 
> semantics. Security implications, however, remain.
>
>
I've experienced this (not in the sense of a security hole, but 
unintended/expected semantic change) in developing my little toy GUI 
 wrapper. As I was writing in support for gotk3 after previously writing 
support code for go-gtk (GTK2), the similarity in the two code-bases 
several times lead goimports to bring in a mix of modules from the two 
different gtk libraries, causing odd build errors and forcing manual fixes.

-- 
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: Generate string to enum using stringer.

2017-02-15 Thread howardcshaw
It already has been! Álvaro has done this for you. 
https://github.com/alvaroloes/enumer

This is a fork of stringer that has the function you want:

   - A function String(s string) to get the enum value from its 
   string representation. This is useful when you need to read enum values 
   from command line arguments, from a configuration file, or from a REST API 
   request... In short, from those places where using the real enum value (an 
   integer) would be almost meaningless or hard to trace or use by a human.


On Friday, February 10, 2017 at 1:35:57 AM UTC-6, tamal wrote:
>
> Hi,
> We would like to be able to generate string to enum value method using 
> stringer in addition to String() method.
> https://github.com/golang/tools/blob/master/cmd/stringer/stringer.go
>
> Is this something that can be added to Stringer? If yes, what is the 
> process for that?
>
> 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] Re: Compressing 2.5 GB data trims files

2017-02-15 Thread howardcshaw
While it is not clear from the Buffer documentation, the Reader *interface* 
documentation (which Buffer.Read implements implicitly) does state "up to 
len(p) bytes." You are ignoring how many bytes it read and assuming that 
the one read is reading the whole file. I am not sure that this is 
guaranteed with Buffer.Read. 

I would suggest you try to adhere to the Reader interface's documented 
behavior, and continue to call Read until you get EOF, and process the n 
returned bytes each time. Doing this would also make it easier to then move 
a step further and drop your buffer size to something sensible, instead of 
attempting to read the entire 2.5G file into memory before compressing.

Howard

-- 
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: go/types.Typ is a slice-of-pointer-to-struct yet uses map syntax

2017-02-15 Thread howardcshaw
Invalid, Bool, Int, Int8 there are const integers, and they are specifying 
the entry's position in the slice, allowing gaps in the list to be 
implicitly defined.

See this example: https://play.golang.org/p/KVqO40R6mP

-- 
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: [Newbie] Create PNG from 2D Array and Write Over HTTP

2017-02-27 Thread howardcshaw
You could define the colors higher in the package - right now you are 
allocating them every time, but they are not changing. You could also also 
retain the image and simply wipe and rewrite it every time as long as it is 
not happening in a goroutine in multiple places - if so, you could retain 
one image per goroutine. When you do png.Encode, the image is only read, 
not modified, and it is fine to hold on to it, change the pixels, and 
Encode it again.

It is possible to access the bytes directly but I can't see any advantage 
to doing that in a 5x5 example. 

Howard

-- 
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: int64 -> []byte writing 9 bytes?

2017-02-27 Thread howardcshaw
You are missing that it is encoding. Specifically, using VarInt is asking 
for Variable integer 
encoding: https://developers.google.com/protocol-buffers/docs/encoding#varints

The important bit here is that the Varint stores 7-bits of data and 1-bit 
of metadata in each byte (the metadata being whether there are more bits). 
Have a look at the value you stored, 1488220019858895600. In binary, that 
is 1 0100 1010 0111 0011 1000 0011 1001 0001  0101  0111 0010  
, which takes 61 bits. Using 7 bits per byte, this takes 8.7 bytes 
to store, in other words, long enough that it takes 9 bytes because the 
encoding does not use partial by

-- 
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: int64 -> []byte writing 9 bytes?

2017-02-27 Thread howardcshaw
Look a little further down - they are documented in the ByteOrder type.

A ByteOrder specifies how to convert byte sequences into 16-, 32-, or 
64-bit unsigned integers.

type ByteOrder interface {
Uint16([]byte ) uint16 

Uint32([]byte ) uint32 

Uint64([]byte ) uint64 

PutUint16([]byte , uint16 
)
PutUint32([]byte , uint32 
)
PutUint64([]byte , uint64 
)
String() string 
}


and the other piece is up near the top:

Variables ¶ 

BigEndian is the big-endian implementation of ByteOrder.

var BigEndian bigEndian

LittleEndian is the little-endian implementation of ByteOrder.
var LittleEndian littleEndian 

-- 
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: Can ServerMux serve two different handler functions on / and a path beyond / ?

2017-03-01 Thread howardcshaw
I think at that point you have to step up to one of the muxers - Gorilla is 
a popular choice in the ecosystem. https://github.com/gorilla/mux

Their example:

func main() {
r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)
r.HandleFunc("/products", ProductsHandler)
r.HandleFunc("/articles", ArticlesHandler)
http.Handle("/", r)
}

httprouter is also popular, and there are others, see Awesome Go for more.

Howard 

-- 
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: After conn.Close, connections is still alive

2017-03-07 Thread howardcshaw
io.Copy is going to read from one stream and write to the other, until the 
read stream is closed. "Copy copies from src to dst until either EOF is 
reached on src or an error occurs." So until you close the stream on your 
side (i.e. end the telnet session), your Go code is still sitting at that 
io.Copy line, and has not reached the io.Close.

Howard

-- 
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: RTP/RSTP and OVNIF?

2017-05-03 Thread howardcshaw
https://golanglibs.com/top?q=rtsp lists several for rstp. I have not used 
any, so I cannot recommend one over another. As for ONVIF, I don't know of 
any implementations, but it is just a SOAP api, so generic SOAP programming 
should be enough to interact with it, I believe. Here is a SOAP/WSDL 
library for golang: https://github.com/justwatchcom/goat

Howard

-- 
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: [ANN] Gobot v1.5.0 released

2017-05-10 Thread howardcshaw
Might want to mention what that IS so people know whether they care to 
click link.

Gobot is 'Next generation robotics/IoT framework with support for 29 
different platforms' according to their website. (IoT is Internet of 
Things, meaning internet-connected appliances/tools/non-traditional 
computers - refrigerators, mirrors, shoes, arduinos, raspberry pi's, etc.).

"Gobot provides drivers and adapters for controlling a wide variety of 
physical devices from low-level Arduino and Raspberry Pi, as well as 
drones, toys, and other complete devices that themselves have APIs."

-- 
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: map[X]Y or map[X]*Y ?

2017-05-12 Thread howardcshaw

>
> type Y struct {
> //some fields
> }
>
> This rather depends on what those some fields ARE, and whether type Y is 
conceptually mutable or immutable.

For example, I might make a lightweight struct just to group a pair of 
values; X/Y coordinates, or Latitude and Longitude:

type LatLon struct {
  Latitude, Longitude float64
}

or the like, and in that case, I might treat it as immutable, and just make 
a new one if I needed changes, in which case doing a map[string]LatLon 
would be fine. 

If the struct is larger or is mutable, then a pointer makes more sense.

BUT! There is one *critical* case to consider.

type Something struct {
   guard sync.Mutex
   ... guarded things
}

This one MUST be done as a pointer, otherwise you are copying the mutex 
when you assign to the map, or assign from the map to a variable. As the 
docs say, "A Mutex must not be copied after first use."

So if you have mutexes or mutable values in the struct, best to use *. 
"Only use the non-pointer map when your structs are simple, small, and 
immutable" is probably a reasonable rule of thumb.

-- 
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: issue with yaml processing

2019-12-26 Thread howardcshaw
You want to add the flow directive to the struct's attributes. From the 
docs:

flow Marshal using a flow style (useful for structs,
 sequences and maps).

type Config struct {
 Contents []string `yaml:"contents,flow"`
}

Howard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/65141c7b-c39d-4cd0-af40-d69203e6371d%40googlegroups.com.


Re: [go-nuts] Why isn't there strings.reverse("str") function?

2020-02-18 Thread howardcshaw
My most common use case for reversing strings has not come up in Go yet - 
basically, some languages provide a string search function that finds a 
character or substring starting from the beginning of the string. For 
example, in T-SQL, CharIndex. If they do not provide a corresponding search 
that works from the end towards the beginning, then removing something at 
the end of the string involves either searching to exhaustion then backing 
up to the last found index - this is easy in an imperative language like Go 
but trickier in a set-based language like SQL - or cheating by reversing 
the string, performing the search and modification, and reversing it again.

UPDATE Addresses SET Zip = SUBSTRING(Addr,LEN(Addr)-CHARINDEX(' 
',REVERSE(Addr))+2,99)

Another use-case involves zero-filling a number to right align it (again in 
SQL) and ensure a proper field-size: 
REVERSE(SUBSTRING(REVERSE('' + UPC),1,12))

These are janky solutions that only work because I know the data being 
operated on is ASCII and just save doing some fiddly math instead. 

I guess this is neatly reflected by the fact that I only managed to find 
examples when I was searching the folder where I did my data conversions 
for customers - a search in the actual code found no instances.

I have not needed it in Go code so far.


-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/81d73b9b-a234-460a-a415-fb828b692dc9%40googlegroups.com.


[go-nuts] [ANN] Renderview v0.1.0 with go mod, Gio, and Fyne support

2020-02-21 Thread howardcshaw
Four years ago I posted Renderview, a simple GUI wrapper that lets you take 
any image generation function in your code and turn it into an interactive 
GUI program with panning, optional zooming, and depending on backend 
choice, parameter editing.

https://github.com/TheGrum/renderview

I have updated it to support go modules, and added support for the recently 
appearing Gio and Fyne GUI toolkits. They are both operational, if a bit 
oddly. I tested Gio on Windows yesterday when I had a chance, and it did 
build, but for some reason, did not respond to mouse movements, only mouse 
scrolling, and I have not resolved that issue yet.

So now, in addition to serving as a quick and dirty tool for exercising 
your image generating or algorithm visualizing code, the code-base itself 
serves as a comparative implementation of the same task in Shiny,  go-gtk, 
GoTK3, Gio, and Fyne.

I did attempt implementations in a few other environments with no success - 
I need some path to go from an image.Image to a displayed image onscreen, 
and could not find a mechanism to do this in a few of the libraries. 
(Granted, I didn't find a way to do it in go-gtk or GoTK3 either - I brute 
forced it since they at least gave access to the memory backing an onscreen 
image. So the source also provides an example of converting from an 
image.RGBA and an image.NRGBA to the internal format of GTK images.)

I still need to go back through and fix-up the interactions to remove data 
races, but they don't seem to have affected the performance or behavior so 
far.

Howard C. Shaw III

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0be68b05-88da-4b8d-a186-aec9099f8530%40googlegroups.com.


[go-nuts] Re: [ANN] Renderview v0.1.0 with go mod, Gio, and Fyne support

2020-02-22 Thread howardcshaw
As far as Windows goes, the Shiny backend works fine to draw a pannable, 
zoomable image with Renderview on Windows, and as far as I am aware, 
requires no further dependencies. But there is still not an editable text 
widget in Shiny, and while I was able to find a third-party multi-line text 
editor, I was not able to find a single-line one suitable for using as a 
generic data entry field. 

So currently only the other four backends support editable widgets on 
Windows. They all require additional work on Windows to operate, however. 
For example, with Gio, I had to download a set of .DLL files and extract 
them into the root folder of my Go build, as documented on the Gio website.

Meanwhile Fyne appears to require installation of a C compiler on Windows, 
go-gtk and gotk3 need a working GTK environment, etc.

Howard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ecd3257a-7dba-491b-a072-0164fe98648f%40googlegroups.com.


[go-nuts] Re: [ANN] Renderview v0.1.0 with go mod, Gio, and Fyne support

2020-02-25 Thread howardcshaw
I worked it out, will update the programs later. It was not that the events 
were missing - once I enabled the good old Printf debugger, I saw that the 
events are flowing fine. The issue is that on Linux, every Move Mouse event 
reflected what buttons were pressed the entire time they were pressed. On 
Windows, only the Press Mouse event included a value for the Button that 
was pressed (i.e. pointer.ButtonLeft).  

mouse pos({Move Mouse 0 Shared 863h55m54.282s  false {637 369} {0 0} }) 
false
mouse pos({Press Mouse 0 Shared 863h55m54.425s ButtonLeft false {637 369} 
{0 0} }) true
mouse down left({Press Mouse 0 Shared 863h55m54.425s ButtonLeft false {637 
369} {0 0} })
mouse pos({Move Mouse 0 Shared 863h55m54.515s  false {638 369} {0 0} }) 
false
mouse pos({Move Mouse 0 Shared 863h55m54.535s  false {639 369} {0 0} }) 
false
mouse pos({Move Mouse 0 Shared 863h55m54.555s  false {642 369} {0 0} }) 
false
Dragging.
mouse pos({Move Mouse 0 Shared 863h55m54.572s  false {645 370} {0 0} }) 
false
mouse pos({Move Mouse 0 Shared 863h55m54.59s  false {648 370} {0 0} }) false

My code was detecting the return to 0 as the mouse button no longer being 
pressed.

Howard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cd2a324e-e8e9-4c32-b5ab-e96ff6842fff%40googlegroups.com.


[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-11 Thread howardcshaw
I've no relevant experience, but I can recommend a couple of projects to 
look at in the absence of anyone chiming in with actual experience:

https://agniva.me/wasm/2018/06/18/shimmer-wasm.html
https://github.com/agnivade/shimmer
This is a play-project that involves loading images. It appears to be using 
a side-load method of converting the image to Base64 and assigning it to 
the image's src attribute - so it is not using the canvas directly, but if 
a call to the canvas can draw an image from a URL, this might work - have a 
look at

// updateImage writes the image to a byte buffer and then converts it to 
base64.
// Then it sets the value to the src attribute of the target image.
func (s *Shimmer) updateImage(img *image.RGBA, start time.Time) 

in https://github.com/agnivade/shimmer/blob/master/shimmer.go

Here is another project that also went with the Base64 method of passing 
the array, look for the section labeled "Pixels are Pixels": 
https://blog.jeremylikness.com/blog/2019-03-03_gopher-meet-plasma-a-webassembly-experiment/

His final verdict was that the pure Javascript version performed better 
than the Go-WASM+JS version.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3b8de1e9-f54a-4571-b14c-8d889e88bc6d%40googlegroups.com.


[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-03-12 Thread howardcshaw

>
>   let blob = new Blob([buf], {'type': imageType});
>>   document.getElementById('targetImg').src = URL.createObjectURL(blob);
>> } 
>>
>
> I see.  In your case, targetImg is an , right?  Do you know how I 
> could use this same technique with a ? 
>
>
If the  was off-screen or hidden, couldn't you still reference it to 
get the data into the canvas like:
  var img = document.getElementById('targetImg');
  ctx.drawImage(img, 10, 10);

Might not be the most efficient way, but it seems like it should work.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8dbab1d3-fc01-471c-9dbd-b0132b613c5f%40googlegroups.com.


[go-nuts] Re: Does os.exec work ?

2020-03-25 Thread howardcshaw
What you are really wanting there is to run xsel --clipboard and pipe data 
into it. Talk to your cmd.Stdin!
This is mostly straight from the StdinPipe example in the go docs:

cmd := exec.Command ("xsel","--clipboard" )
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
}

go func() {
defer stdin.Close()
io.WriteString(stdin, "values written to stdin are passed to cmd's standard 
input and in this case end up on the X clipboard")
}()

out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/07f0c9dc-b68b-4868-b88d-7f3cd4aff21a%40googlegroups.com.


Re: [go-nuts] Go has confusing pointers

2020-06-19 Thread howardcshaw
c is of type *Count (pointer to Count), surely? It is (*c) that is of type 
Count, which has to be cast to int to be returned as such because Go 
requires explicit casts. Agree with the rest.

On Friday, June 19, 2020 at 12:44:26 PM UTC-5, Tyler Compton wrote:
>
> In this case, c is of type Count, not int. When you define a type in Go, 
> you're defining a new distinct type, not an alias to the underlying type. 
> The Count type is distinct from int, even though it's based on int.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3f2b4f42-7ece-427e-b399-22b2d0145234o%40googlegroups.com.


[go-nuts] Re: [generics] I think it's better have higher perfomance than lower compiling time

2020-06-19 Thread howardcshaw
I think in general this is not the attitude of the Go developers, nor the 
Go community - fast compilation was an explicit design goal of the original 
creation of Go (as a reaction to slow compile times with C++), and has 
remained a concern.

>From the FAQ, https://golang.org/doc/faq#creating_a_new_language , 
" Finally, working with Go is intended to be fast: it should take at most a 
few seconds to build a large executable on a single computer."

It is certainly not their only concern or focus, they also mention "One had 
to choose either efficient compilation, efficient execution, or ease of 
programming; all three were not available in the same mainstream language."

We have seen performance decreases in some language versions, but we have 
also seen performance increases. Efficient execution is a project goal, but 
efficient compilation is as well, so I would not recommend hoping for or 
expecting that performance issues in execution would be resolved via 
additional passes in or excessive time added to compilation.

However, if you do see any major performance regression in a new version, 
do report it - they have historically paid attention to these reports and 
often resolved issues in subsequent updates; see 
https://github.com/golang/go/issues/19096 , 
https://github.com/golang/go/issues/16407 , and 
https://go-review.googlesource.com/c/go/+/30163/

Consider also these headlines:

Go 1.7 to Improve Compilation Speed and Generate Faster Code
Google's Go language takes on compilation speed (about Go 1.8)
Faster builds in Docker with Go 1.11

Howard

On Friday, June 19, 2020 at 12:23:46 PM UTC-5, Ronald Davilla wrote:
>
> Just if perfomance will decrease with every release/version, it'd be not 
> really good, and it's might be necessary to pay more attention to this
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f28b16cb-d0d5-4f3f-8b1f-b6a5d42654eco%40googlegroups.com.


[go-nuts] Re: Why the user variable isn't getting printed when the query is alright

2020-06-24 Thread howardcshaw
First, please post plain text.
Second, you are not capturing the error from the query; capture and print 
that error and it will likely inform you what the issue is. (On the 
row.Scan.)
Third, perhaps the issue is your use of $1 instead of ?. 

This is regarding sqlx, but the issue they describe seems to be postgres 
vs. mysql issue rather than sqlx specific: 
https://github.com/jmoiron/sqlx/issues/78

So perhaps the error you would find after dealing with my second issue 
above would be something like the error the above person was getting, "Error 
1054: Unknown column '$1' in 'where clause'"

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/924da652-961b-4b2d-80f6-50b06710403ao%40googlegroups.com.


[go-nuts] Re: Speed up png.Decode

2020-06-26 Thread howardcshaw
I don't know if the CGo transitions for 16 million images will completely 
swamp the speed gains, or how much post-processing you need to do to these 
images, but you might try https://github.com/h2non/bimg and see if it gives 
you any wins. It claims 'typically 4x faster' then the Go Image package. It 
is a CGO interface to libvips, which is an experimental branch of libspng, 
which is a performance focused alternative to libpng.

Howard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9f8d3086-75f4-47e1-b49a-4dce057258cco%40googlegroups.com.


Re: [go-nuts] Slices and inconsistency

2020-06-26 Thread howardcshaw
"If the capacity of s is not large enough to fit the additional values, 
append allocates a new, sufficiently large underlying array that fits both 
the existing slice elements and the additional values. Otherwise, append 
re-uses the underlying array."

That seems pretty explicit to me? That's from the spec, the other link 
above, the blog, is even more explicit, by straight up showing the 
implementation before introducing the built-in. 

The tour also says it: https://tour.golang.org/moretypes/15 
"If the backing array of s is too small to fit all the given values a 
bigger array will be allocated. The returned slice will point to the newly 
allocated array."

It also links to this documentation: https://blog.golang.org/slices-intro 
"The append function appends the elements x to the end of the slice s, and 
grows the slice if a greater capacity is needed." - this is the only one 
that seems less than explicit about the semantics, and in the sense that it 
does not make explicit that 'grows the slice' means 'returns a copy of the 
slice with greater capacity.' 


The latter link then links further to this documentation: 
https://golang.org/doc/effective_go.html#slices
and just like the blog, it starts by introducing the implementation, where 
it is clear that only one path includes a copy function, and it explicitly 
says "If the data exceeds the capacity, the slice is reallocated." A bit 
later where it covers append directly, it says "The result needs to be 
returned because, as with our hand-written Append, the underlying array may 
change." 

4 bits of official documentation, all of which mention the 'gotcha' more or 
less directly. And in most of those cases, discussion of append directly 
follows discussion of 'copy', which should make it clear how to get copies 
of slices.

I think maybe where it gets missed is from people learning the language by 
example, by coping code from StackOverflow, reading code in GitHub, etc. Go 
is pretty surprisingly easy to pick up by example like that, but it does 
mean those corner cases can bite - however, the actual documentation is 
pretty clear and up-front about the gotchas.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f98d538e-55d5-4a61-b7d2-1ab9497d3cd5o%40googlegroups.com.