Posts by Ainar-G • 227 points
9 posts
-
2
votes4
answers103
viewsA: Extracting json value from page
The fields of the structure should be exported: type Response struct { Proxy string `json:"proxy"` IP string `json:"ip"` Port string `json:"port"` ConnectionType string `json:"connectionType"` ASN…
-
3
votes1
answer80
viewsA: How can a class also be a method in Ruby?
How this is possible in Ruby? Thus: class C attr_accessor :x def initialize(x) @x = x end end # N.B. def C(x) C.new(x) end repl it.: https://repl.it/repls/CurvyTerrificRegister. Where this method is…
-
1
votes1
answer124
viewsA: Why does Illegal Invocation occur in JS?
In Go: store is the method, so we need to use Call. Invoke works only on functions. There is a difference, see below. In JS: a method is not like a normal function because it has this. You can use a…
-
0
votes1
answer253
viewsQ: The period between two dates
How to get a period between two dates? d1, _ := time.Parse(time.RFC3339, "2018-10-27T00:00:00Z") d2, _ := time.Parse(time.RFC3339, "2018-10-28T00:00:00Z") // Não funciona. fmt.Println(d2 - d1)…
-
0
votes1
answer253
viewsA: The period between two dates
You must use the method Sub: fmt.Println(d2.Sub(d1)) // 24h0m0s Playground: https://play.golang.org/p/TEk9bDU0Wz8.…
-
0
votes2
answers115
viewsA: Problem capturing the title of a URL using regular expression
If you want to use regexp: var r = regexp.MustCompile(`(?is)<title>(.*?)</title>`) matches := r.FindStringSubmatch(site) if len(matches) == 2 { fmt.Printf("título: %q\n", matches[1]) }…
-
1
votes1
answer34
viewsQ: Why does JSON or XML not work?
I got this guy: type S struct { a string `json:"a" xml:"a"` b int `json:"b" xml:"b"` c time.Time `json:"c" xml:"c"` } But neither JSON nor XML works: s := S{a: "Olá", b: 42, c: time.Now()}…
-
2
votes1
answer34
viewsA: Why does JSON or XML not work?
To encode or decode data, the identifiers shall be exported. Exported identifiers start with a capital letter: type S struct { A string `json:"a" xml:"a"` B int `json:"b" xml:"b"` C time.Time…
-
0
votes1
answer44
viewsA: Date range by week number
My Portuguese is not good, sorry. You can use time.(Time).Truncate and then change the result: const ( day = 24 * time.Hour sevenDays = 7 * day ) // weekSun returns the beginning and the end of the…