campoy / justforfunc Goto Github PK
View Code? Open in Web Editor NEWThe repository for the YouTube series JustForFunc
Home Page: https://youtube.com/c/justforfunc
License: Apache License 2.0
The repository for the YouTube series JustForFunc
Home Page: https://youtube.com/c/justforfunc
License: Apache License 2.0
First of all Great episode (#12) about grpc, enjoyed it, just wish you had mentioned you need to install protoc it could be a lil painful to install it.
Thanks for the great videos. At ~7:50, you make a change to the Long description in the root command, run go install, and the code updates accordingly when you execute "todo". I did the same thing and found that my change to the short and long description would not update, even if I deleted my app binary from /bin and reran go install. It wasn't until I ran a go mod init in my app directory that things started to work as expected (i.e. code changes in the root command appeared after a go install...). Any idea why you were getting this to work without a go.mod file but I wasn't? Very perplexed.
Greetings!
I watched the episode about Gonum, but I don't understand how to create a time-based plot ..
I need to plot it:
2020/09/11,1336.44 2020/10/20,1936.44 2020/11/01,2005.11 2020/11/01,2005.24 2020/11/25,1994.25 2020/12/04,2594.25 2020/12/04,3194.25 2020/12/14,3185.49 2020/12/21,3172.35 2020/12/22,3342.35 2020/12/22,3172.35 2020/12/30,3161.34 2020/12/31,3011.34 2021/01/01,3078.34 2021/01/20,3038.34 2021/01/22,3028.34 2021/01/25,3328.34 2021/01/25,3628.34 2021/02/01,3758.34 2021/02/02,3733.26 2021/02/16,3709.38 2021/02/16,3859.38 2021/02/16,3709.38 2021/02/22,3673.38 2021/02/24,3619.38
I'm trying:
package main
import (
"bufio"
"fmt"
"image/color"
"log"
"os"
"strconv"
"strings"
"time"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/vg/draw"
)
func main() {
xys, err := readData("test.txt")
if err != nil {
log.Fatalf("could not read data.txt: %v", err)
}
_ = xys
err = plotData("out.png", xys)
if err != nil {
log.Fatalf("could not plot data: %v", err)
}
}
func readData(path string) (plotter.XYs, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var xys plotter.XYs
s := bufio.NewScanner(f)
s.Split(bufio.ScanLines)
var txtlines []string
for s.Scan() {
txtlines = append(txtlines, s.Text())
}
for _, eachline := range txtlines {
lines := strings.Split(string(eachline), ",")
var x float64
var y float64
t := strings.Split(lines[0], "/")
year, _ := strconv.Atoi(t[0])
month, _ := strconv.Atoi(t[1])
day, _ := strconv.Atoi(t[2])
println(year, month, day, lines[1])
date := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).Unix()
x = float64(date)
fmt.Println(fmt.Sprintf("%f", x))
y, err = strconv.ParseFloat(strings.TrimSpace(lines[1]), 64)
fmt.Println(fmt.Sprintf("%f", y))
xys = append(xys, struct{ X, Y float64 }{x, y})
if err != nil {
fmt.Println(err)
}
}
if err := s.Err(); err != nil {
return nil, fmt.Errorf("could not scan: %v", err)
}
return xys, nil
}
func plotData(path string, xys plotter.XYs) error {
f, err := os.Create(path)
if err != nil {
return fmt.Errorf("could not create %s: %v", path, err)
}
p, _ := plot.New()
s, err := plotter.NewScatter(xys)
if err != nil {
return fmt.Errorf("could not create scatter: %v", err)
}
s.GlyphStyle.Shape = draw.CrossGlyph{}
s.Color = color.RGBA{R: 255, A: 255}
p.Add(s)
var x, c float64
x = 1.2
c = -3
l, points, err := plotter.NewLinePoints(plotter.XYs{
{3, 3*x + c}, {20, 20*x + c},
})
if err != nil {
return fmt.Errorf("could not create line: %v", err)
}
l.Color = color.RGBA{G: 255, A: 255}
points.Shape = draw.CircleGlyph{}
points.Color = color.RGBA{R: 255, A: 255}
p.Add(l, points)
err = p.Save(256, 256, "timeseries.png")
if err != nil {
log.Panic(err)
}
wt, err := p.WriterTo(256, 256, "png")
if err != nil {
return fmt.Errorf("could not create writer: %v", err)
}
_, err = wt.WriteTo(f)
if err != nil {
return fmt.Errorf("could not write to %s: %v", path, err)
}
if err := f.Close(); err != nil {
return fmt.Errorf("could not close %s: %v", path, err)
}
return nil
}
What I'm doing wrong?
Thanks in advance!
after building this out, I tried to run 'desc cities' or 'desc people' like in your part 1 video and get the error
ERROR 1105 (HY000): unknown error: unsupported syntax: &sqlparser.OtherRead{}
I can’t find a tutorial to create multipart mails with a text part and an utf-8 base64 encoded html part by using the standard library. The best I could find is this but it doesn’t seam to produce a valid mime encoding. An example using templates would be great.
My use case is the following. My Go program is doing a batch processing (e.g. backup, data integrity check, ...) and sends a report by mail. I have a python code that run every night and produce a text only report. When the report is long, it’s hard to locate the problems. I would now like to write the code in Go (because I can), and I’m stuck at generating a multipart mail with problems shown in red in the html part.
Another use case could be to send a multipart mail containing markdown text and its html encoding. The user would provide the markdown text.
specially something that writes to google datastore or google database offerings. to be honest the documentation is not the best, there are two versions of everything for google app engine and not appengine, and they don't work ! specially if you wanted to try the db servers locally (using docker)
it would be a great thing if you make an episode of a full example of using google's database offerings in golang.
I'm interested to know how you would now test the command handler functions given you have switched from dependency injection of the client to a package level variable. This appears to go against the principles you mentioned in an earlier episode.
in your post you have:
$ go tool seq.trace
but it should be
$ go tool trace seq.trace
you are missing there the trace. Not in the other code snippets though.
and I like the posts, much easier to follow than the videos 👍
halfway through the video, I build the docker image through the makefile, which works,
but when i try to run docker run -p 8080:8080 campoy/say
I get an error.
standard_init_linux.go:178: exec user process caused "no such file or directory"
It seems he can't find the entrypoint of the dockerfile or something.
I get this error on the latest docker version (ce).
Before I upgraded my docker version, i got almost the same error, but there, the message explicitly pointed to the "/app" that was not found.
Any suggestions?
I'm on ubuntu 16.04
Update
I Tested this with the source code of this github project itself.
Same error, Maybe an OS issue?
Hello, I am using go version go1.10.2 darwin/amd64
. Building the server works with the provided code.
The example isn't working after re-generating the pg.go file using:
protoc -I . todo.proto --go_out=plugins=grpc:.
The error:
$ go build server/main.go
# github.com/campoy/justforfunc/31-grpc/todo
../todo/todo.pb.go:56:26: undefined: proto.InternalMessageInfo
../todo/todo.pb.go:101:30: undefined: proto.InternalMessageInfo
../todo/todo.pb.go:139:26: undefined: proto.InternalMessageInfo
../todo/todo.pb.go:176:26: undefined: proto.InternalMessageInfo
I have done this for the dependencies, although it is not very clear which ones to use:
go get -u -v github.com/golang/protobuf/proto
go get -u -v github.com/gogo/protobuf/proto
maybe use glide
for the proejects in the future in order to clarify?
Is this related to this: https://groups.google.com/forum/#!topic/golang-nuts/F5xFHTfwRnY ?
if it is, how do we move past this?
Thanks
EDIT: Here is the regenerated code
https://gist.github.com/trobert2/d8eb11ba7f1cec92241ba4d079993852
Link to episode 40-csvql code is broken
The body of response for http.Get should close.
justforfunc/16-testing/webserver/main_test.go
Lines 85 to 89 in 90c277a
With the code in the video, if you try and apply a projection to a query, you get this error
mysql> select name from cities;
ERROR 1105 (HY000): unknown error: table "cities" does not have column "name"
I know this isn't demonstrated in the video
Greetings!
I watched the episode about Gonum, but I don't understand how to create a time-based plot ..
I need to plot it:
2020/09/11,1336.44 2020/10/20,1936.44 2020/11/01,2005.11 2020/11/01,2005.24 2020/11/25,1994.25 2020/12/04,2594.25 2020/12/04,3194.25 2020/12/14,3185.49 2020/12/21,3172.35 2020/12/22,3342.35 2020/12/22,3172.35 2020/12/30,3161.34 2020/12/31,3011.34 2021/01/01,3078.34 2021/01/20,3038.34 2021/01/22,3028.34 2021/01/25,3328.34 2021/01/25,3628.34 2021/02/01,3758.34 2021/02/02,3733.26 2021/02/16,3709.38 2021/02/16,3859.38 2021/02/16,3709.38 2021/02/22,3673.38 2021/02/24,3619.38
I'm trying:
func readData(path string) (plotter.XYs, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var xys plotter.XYs
s := bufio.NewScanner(f)
for s.Scan() {
var y float64
var x float64
_, err := fmt.Sscanf(s.Text(), "%f,%f", &x, &y)
if err != nil {
log.Printf("discarding bad data point %q: %v", s.Text(), err)
continue
}
s := fmt.Sprintf("%f", x)
date1, err := time.Parse("2006/02/01", s)
date2, _ := strconv.Atoi(date1.String())
x = float64(date2)
xys = append(xys, struct{ X, Y float64 }{x, y})
if err != nil {
fmt.Println(err)
}
}
if err := s.Err(); err != nil {
return nil, fmt.Errorf("could not scan: %v", err)
}
return xys, nil
}
What I'm doing wrong?
Thanks in advance!
I'd love to see how one would go about manipulating video with Go. For instance adding a simple text overlay to the video to show some captions.
Hi Francesc!
In your talk, you're saying that gRPC still using old context path.
But in the client code, new context path is actually used.
So my question is it ok to use new context path with gRPC?
First of all thanks for your work, your talent and of course thanks for share your videos ( I'm new in Go and it's been quite helpful)
Watching them I saw you a lot of times using this expression:
if err != nil {log.Errorf(...)} }
or
if err != nil {return "", err}
or
if err != nil {return nil, fmt.Errorf(...)}
So I'm wondering if it will be a good solution create a function/s which gets the error and return it if it's needed, it's more about the reduction of lines and try to apply the DRY methodology.
It could be someting like this:
func myErr (err error) error{ if err != nil { return fmt.Error(...) } }
An then you can call it in just one line: myErr(err)
Thanks for your time!
Would be great to see a video on a performant way of taking one channel of events and then fanning those events from that channel to n channels.
Obviously would be important to cover how to gracefully handle the shutdown of those channels without losing a event that is in flight.
Something like the following
Hi,
I d like to suggest an app for future videos.
An app that runs on mobile, consume video feed to detect and read a qrcode, on the other end, the app can create/manage gpg identities in order to shows their public keys as a qrcode on the screen, so that another user can read it and decode the public key, you see ?
For the qrcode, i know there are several golang libs.
For the public keys, that be cool to introduce golang crypto https://godoc.org/golang.org/x/crypto/ and more specifically maybe https://godoc.org/golang.org/x/crypto/openpgp
For the mobile app, many things,
I have no idea if it is feasible, what do you think about it ?
Do i have to sign cla for suggestions too ? =)
Greetings!
I watched the episode about Gonum, but I don't understand how to create a time-based plot ..
I need to plot it:
2020/09/11,1336.44 2020/10/20,1936.44 2020/11/01,2005.11 2020/11/01,2005.24 2020/11/25,1994.25 2020/12/04,2594.25 2020/12/04,3194.25 2020/12/14,3185.49 2020/12/21,3172.35 2020/12/22,3342.35 2020/12/22,3172.35 2020/12/30,3161.34 2020/12/31,3011.34 2021/01/01,3078.34 2021/01/20,3038.34 2021/01/22,3028.34 2021/01/25,3328.34 2021/01/25,3628.34 2021/02/01,3758.34 2021/02/02,3733.26 2021/02/16,3709.38 2021/02/16,3859.38 2021/02/16,3709.38 2021/02/22,3673.38 2021/02/24,3619.38
I'm trying:
func readData(path string) (plotter.XYs, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var xys plotter.XYs
s := bufio.NewScanner(f)
for s.Scan() {
var y float64
var x float64
_, err := fmt.Sscanf(s.Text(), "%f,%f", &x, &y)
if err != nil {
log.Printf("discarding bad data point %q: %v", s.Text(), err)
continue
}
s := fmt.Sprintf("%f", x)
date1, err := time.Parse("2006/02/01", s)
date2, _ := strconv.Atoi(date1.String())
x = float64(date2)
xys = append(xys, struct{ X, Y float64 }{x, y})
if err != nil {
fmt.Println(err)
}
}
if err := s.Err(); err != nil {
return nil, fmt.Errorf("could not scan: %v", err)
}
return xys, nil
}
What I'm doing wrong?
Thanks in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.