Skip to content

Instantly share code, notes, and snippets.

View smallnest's full-sized avatar

smallnest smallnest

View GitHub Profile
@smallnest
smallnest / benchmark_timers.go
Created January 14, 2021 10:09 — forked from draveness/benchmark_timers.go
Benchmark Golang Timers
package main
import (
"fmt"
"sort"
"sync"
"testing"
"time"
)
@smallnest
smallnest / LearnGoIn5mins.md
Created January 14, 2021 03:40 — forked from prologic/LearnGoIn5mins.md
Learn Go in ~5mins
@smallnest
smallnest / piping.go
Created December 27, 2020 05:33 — forked from dagoof/piping.go
piping exec.Cmd in golang (example finds most recently modified file that is not directory or executable)
package main
import (
"os"
"exec"
)
func pipe_commands(commands ...*exec.Cmd) ([]byte, os.Error) {
for i, command := range commands[:len(commands) - 1] {
out, err := command.StdoutPipe()
if err != nil {
@smallnest
smallnest / main.go
Created December 25, 2020 07:43 — forked from Skarlso/main.go
Golang SSH connection with hostkey verification
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"golang.org/x/crypto/ssh"
kh "golang.org/x/crypto/ssh/knownhosts"
@smallnest
smallnest / sshclient.go
Created December 25, 2020 03:43 — forked from josephspurrier/sshclient.go
Golang SSH Client
package main
import (
"bufio"
"io/ioutil"
"os/signal"
//"syscall"
"fmt"
"log"
"os"
@smallnest
smallnest / sshclient.go
Created December 25, 2020 03:43 — forked from Mebus/sshclient.go
Golang SSH Client
package main
import (
"bufio"
"io/ioutil"
"os/signal"
//"syscall"
"fmt"
"log"
"os"
git config --global credential.modalPrompt false
```go
func isNil(i interface{}) bool {
return i == nil || reflect.ValueOf(i).IsNil()
}
```
better:
```go
func isNilFixed(i interface{}) bool {
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/pprof"
"strconv"
"sync"
# human readable /proc/net/netstat
# https://sa-chernomor.livejournal.com/9858.html
cat /proc/net/netstat | \
awk '(f==0) { i=1; while ( i<=NF) {n[i] = $i; i++ }; f=1; next} \
(f==1){ i=2; while ( i<=NF){ printf "%s = %d\n", n[i], $i; i++}; f=0} '