Skip to content

Instantly share code, notes, and snippets.

@ymgyt
ymgyt / context.go
Created October 4, 2017 15:53 — forked from iamralch/context.go
An example that illustrates how to work with https://godoc.org/golang.org/x/net/context
package main
import (
"bufio"
"fmt"
"os"
"strings"
"time"
"golang.org/x/net/context"
@ymgyt
ymgyt / safebuffer.go
Created October 4, 2017 10:25 — forked from arkan/safebuffer.go
Golang: Buffer is a goroutine safe bytes.Buffer
package safebuffer
import (
"bytes"
"sync"
)
// Buffer is a goroutine safe bytes.Buffer
type Buffer struct {
buffer bytes.Buffer
@ymgyt
ymgyt / safebuffer.go
Created October 4, 2017 10:25 — forked from arkan/safebuffer.go
Golang: Buffer is a goroutine safe bytes.Buffer
package safebuffer
import (
"bytes"
"sync"
)
// Buffer is a goroutine safe bytes.Buffer
type Buffer struct {
buffer bytes.Buffer
@ymgyt
ymgyt / check.go
Created October 4, 2017 05:44 — forked from mattes/check.go
Check if file or directory exists in Golang
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
// path/to/whatever does not exist
}
if _, err := os.Stat("/path/to/whatever"); err == nil {
// path/to/whatever exists
}
@ymgyt
ymgyt / subcommand.go
Created September 28, 2017 08:34 — forked from iamralch/subcommand.go
flag package: subcommand example
package main
import (
"flag"
"fmt"
"os"
)
func main() {
askCommand := flag.NewFlagSet("ask", flag.ExitOnError)
,_---~~~~~----._
_,,_,*^____ _____``*g*\"*,
/ __/ /' ^. / \ ^@q f
[ @f | @)) | | @)) l 0 _/
\`/ \~____ / __ \_____/ \
| _l__l_ I
} [______] I
] | | | |
] ~ ~ |
| |
@ymgyt
ymgyt / sshremote.go
Created September 1, 2017 05:35 — forked from josephspurrier/sshremote.go
Golang Remote Execution
package main
/*
// Example
sci := ServerConnInfo{
"127.0.0.1",
"22",
"ubuntu",
`key.pem`,
}
@ymgyt
ymgyt / ipcalc.go
Created July 11, 2017 04:36 — forked from kotakanbe/ipcalc.go
get all IP address from CIDR in golang
package main
import (
"net"
"os/exec"
"github.com/k0kubun/pp"
)
func Hosts(cidr string) ([]string, error) {