Skip to content

Instantly share code, notes, and snippets.

View smallnest's full-sized avatar

smallnest smallnest

View GitHub Profile
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/pprof"
"strconv"
"sync"
```go
func isNil(i interface{}) bool {
return i == nil || reflect.ValueOf(i).IsNil()
}
```
better:
```go
func isNilFixed(i interface{}) bool {
git config --global credential.modalPrompt false
@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"
@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 / 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 / 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 / LearnGoIn5mins.md
Created January 14, 2021 03:40 — forked from prologic/LearnGoIn5mins.md
Learn Go in ~5mins
@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 / scratch_server.go
Created April 23, 2021 02:05 — forked from jschaf/scratch_server.go
A Go web server from scratch using syscalls
package main
// Simple, single-threaded server using system calls instead of the net library.
//
// Omitted features from the go net package:
//
// - TLS
// - Most error checking
// - Only supports bodies that close, no persistent or chunked connections
// - Redirects