Skip to content

Instantly share code, notes, and snippets.

View dxavx's full-sized avatar
🏠
Working from home

dxavx dxavx

🏠
Working from home
View GitHub Profile
@dxavx
dxavx / shadow_method.go
Created March 7, 2020 08:06
shadow method
package main
import (
"fmt"
"image/color"
"math"
)
type Point struct {
X, Y float64
@dxavx
dxavx / method.go
Created March 7, 2020 07:07
method
package main
import (
"fmt"
"math"
)
func main() {
perim := Path{
@dxavx
dxavx / unmarshal.go
Created March 5, 2020 08:01
Unmarshal part of the structure
package main
import (
"encoding/json"
"fmt"
"log"
)
type Move struct {
Title string
@dxavx
dxavx / struct_fields.go
Created March 5, 2020 07:23
anonymous fields in the structure
package main
import "fmt"
// anonymous fields in the structure
type Point struct {
X , Y int
}
@dxavx
dxavx / mutex.go
Created February 28, 2020 14:15
example mutex
package main
import (
"fmt"
"log"
"net/http"
"sync"
)
// минимальный эхо сервер с подсчетом запросов.
@dxavx
dxavx / parallel_requests.go
Created February 28, 2020 13:39
parallel GET requests
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"time"
)
@dxavx
dxavx / exec.go
Created February 22, 2020 10:31
Exec linux command
import (
"os"
"os/exec"
)
func wget(url, filepath string) error {
// run shell `wget URL -O filepath`
cmd := exec.Command("wget", url, "-O", filepath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
@dxavx
dxavx / timeout.go
Created January 12, 2020 21:02
timer for long-term operations
package main
import (
"fmt"
"time"
)
func main() {
// at 1, the timeout will be executed, at 3-the operation will be performed
timer := time.NewTimer(3 * time.Second)
@dxavx
dxavx / tick.go
Created January 12, 2020 20:57
time tick
package main
import (
"fmt"
"time"
)
func main() {
ticker := time.NewTicker(time.Second)
i := 0
@dxavx
dxavx / select_3.go
Created January 12, 2020 20:51
sending data with a cancellation channel
package main
import "fmt"
func main() {
cancelCh := make(chan struct{})
dataCh := make(chan int)
go func(cancelCh chan struct{}, dataCh chan int) {
val := 0