This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"path" | |
"github.com/blevesearch/bleve/v2" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func funcName() string { | |
pc, _, _, _ := runtime.Caller(1) | |
nm := runtime.FuncForPC(pc).Name() | |
dt := strings.Split(nm, ".") | |
return dt[len(dt)-1] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the most simple web server in go | |
package main | |
import ( | |
"net/http" | |
) | |
func main() { | |
http.Handle("/", http.FileServer(http.Dir("/tmp"))) | |
http.ListenAndServe(":8080", nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
src="${1?:No filename specified}" | |
dst="${src%.*}.$(basename ${0})" | |
echo "Converting '${src}' to '${dst}'" | |
[ -f "${src}" ] || { echo "Source file '${src}' not found"; exit 1; } | |
some_command "${src}" "${dst}" | |
[ -f "${dst}" ] || { echo "Destination file '${dst}' not found"; exit 1; } | |
rm -f "${src}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"math" | |
"time" | |
"github.com/faiface/pixel" | |
"github.com/faiface/pixel/imdraw" | |
"github.com/faiface/pixel/pixelgl" | |
"golang.org/x/image/colornames" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get cert from acme / letsencrypto auto cert manager | |
// usage: go run getacme.go hostname | |
package main | |
import ( | |
"crypto/tls" | |
"crypto/x509" | |
"fmt" | |
"log" | |
"net/http" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval "$(go tool dist list | awk -v FS=/ -v BIN=stc '{ print "GOOS=" $1 " GOARCH=" $2 " go build -o out/" BIN "-" $2 "-" gensub(/windows/, "windows.exe", "g", $1) }' )" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// generate index file under gcs bucket prefix (non recursive, one level only) | |
package main | |
import ( | |
"context" | |
"flag" | |
"fmt" | |
"html" | |
"log" | |
"path/filepath" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
src="${1?:No src/file specified}" | |
dst="${2?:No dst/disk specified}" | |
bs=1m | |
diskutil unmountDisk "${dst}" | |
diskutil zeroDisk short "${dst}" | |
if [[ "${src}" == *.lz ]] | |
then | |
lzip -dcvv "${src}" | dd of="${dst}" bs=$bs | |
elif [[ "${src}" == *.xz ]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// easily create html form select/option with default selection (selected) and disabled | |
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
func selOpt(s string, f ...struct{ v, n string }) string { | |
var o []string |
NewerOlder