Skip to content

Instantly share code, notes, and snippets.

View tenox7's full-sized avatar

Antoni Sawicki tenox7

View GitHub Profile
@tenox7
tenox7 / disvc.sh
Last active January 13, 2025 04:55
Disable SysV Service
ds() { n=$(echo $1 | sed -e 's/^S/s/'); mv $1 $n; }
@tenox7
tenox7 / replace.go
Created January 11, 2025 21:52
Replace all characters with something
func replaceChars(str, repl, with string) string {
var oldnew []string
for _, char := range repl {
oldnew = append(oldnew, string(char), with)
}
return strings.NewReplacer(oldnew...).Replace(str)
}
@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"