Skip to content

Instantly share code, notes, and snippets.

View tenox7's full-sized avatar

Antoni Sawicki tenox7

View GitHub Profile
@tenox7
tenox7 / bleve_txt.go
Created May 15, 2024 06:15
example of how to index and search a directory of text files using bleve
package main
import (
"fmt"
"log"
"os"
"path"
"github.com/blevesearch/bleve/v2"
)
@tenox7
tenox7 / funcname.go
Created June 7, 2023 11:18
returns caller name
func funcName() string {
pc, _, _, _ := runtime.Caller(1)
nm := runtime.FuncForPC(pc).Name()
dt := strings.Split(nm, ".")
return dt[len(dt)-1]
}
// 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)
@tenox7
tenox7 / convert
Last active July 9, 2023 09:36
universal convert shell script, name it as a destination extension, eg. 'jpg'
#!/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}"
@tenox7
tenox7 / pixclock.go
Created May 9, 2022 08:10
golang pixel lib clock
package main
import (
"math"
"time"
"github.com/faiface/pixel"
"github.com/faiface/pixel/imdraw"
"github.com/faiface/pixel/pixelgl"
"golang.org/x/image/colornames"
@tenox7
tenox7 / getacme.go
Last active March 31, 2024 13:09
get cert from acme / letsencrypto auto cert manager
// 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"
@tenox7
tenox7 / goBuildAll
Last active February 19, 2022 22:59
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) }' )"
// generate index file under gcs bucket prefix (non recursive, one level only)
package main
import (
"context"
"flag"
"fmt"
"html"
"log"
"path/filepath"
@tenox7
tenox7 / ddpv.sh
Last active July 14, 2022 13:37
fast macOS dd with progress bar, umount and erase dst disk
#!/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 ]]
@tenox7
tenox7 / htmlSelOpt.go
Last active October 15, 2021 07:13
HTML Select Option Generator in Go
// 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