Skip to content

Instantly share code, notes, and snippets.

@farhany
farhany / muslc-static.txt
Created July 12, 2019 19:06
static build with musl (alpine) for go
CC=$(which musl-gcc) go build --ldflags '-w -linkmode external -extldflags "-static"' server.go
// Source: https://www.reddit.com/r/golang/comments/4cxrcv/whats_the_proper_way_to_build_golang_apps_for/
@farhany
farhany / FIRE.PAS
Created June 20, 2019 03:40 — forked from specht/FIRE.PAS
program firetest;
{ Classic fire animation using VGA mode 13h and colors 0 to 63... wee !!! }
uses Crt, VGA;
var i, heat: Integer;
quit: Boolean;
c: Char;
@farhany
farhany / gist:2ede31c2dcdeede5744688a17e810008
Created June 11, 2019 06:53 — forked from schmichael/gist:7379338
Transparently compress and upload a file in golang
package main
import (
"bufio"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
// Source:
// Go Playground: https://play.golang.org/p/KjBCcudT1JF
package main
import (
"bytes"
"crypto/md5"
"encoding/hex"
"io"
@farhany
farhany / exec.go
Created May 30, 2019 04:31 — forked from danesparza/exec.go
Go exec.Command example
package main
import (
"bytes"
"fmt"
"os/exec"
"strings"
)
func main() {
@farhany
farhany / check.go
Created May 22, 2019 18:26 — 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"); !os.IsNotExist(err) {
// path/to/whatever exists
}
@farhany
farhany / go-bench
Created May 14, 2019 20:02
Go benchmark memory
Source: https://github.com/kkdai/pubsub/blob/master/.travis.yml
- $HOME/gopath/bin/goveralls -coverprofile=coverage.cov -service=travis-ci
- go test -bench=. -benchmem .
- sh ./install_all_cmd.sh
Great article on subject:
https://medium.freecodecamp.org/useful-tricks-you-might-not-know-about-git-stash-e8a9490f0a1a
@farhany
farhany / multipart_upload.go
Created April 28, 2019 08:54 — forked from mattetti/multipart_upload.go
Example of doing a multipart upload in Go (golang)
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
@farhany
farhany / docker-cmdline
Last active April 28, 2019 01:33
docker cmdline - useful commands
# Get IP
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
# Remove stopped images/etc
docker system prune
docker image prune
docker volume prune