Skip to content

Instantly share code, notes, and snippets.

View hlubek's full-sized avatar

Christopher Hlubek hlubek

View GitHub Profile
@hlubek
hlubek / handler__handler.go
Last active September 17, 2024 12:48
Testing OpenTelemetry in Go with test helpers
package handler
// Handler handles commands
type Handler struct {
db *sql.DB
instrumentation instrumentation
}
type Deps struct {
@hlubek
hlubek / nginx.conf
Created August 12, 2021 12:17
Nginx reverse proxy with caching for Next.js with imgproxy
# Based on https://steveholgado.com/nginx-for-nextjs/
# - /var/cache/nginx sets a directory to store the cached assets
# - levels=1:2 sets up a two‑level directory hierarchy as file access speed can be reduced when too many files are in a single directory
# - keys_zone=STATIC:10m defines a shared memory zone for cache keys named “STATIC” and with a size limit of 10MB (which should be more than enough unless you have thousands of files)
# - inactive=7d is the time that items will remain cached without being accessed (7 days), after which they will be removed
# - use_temp_path=off tells NGINX to write files directly to the cache directory and avoid unnecessary copying of data to a temporary storage area first
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;
upstream nextjs_upstream {
@hlubek
hlubek / main.go
Created July 18, 2023 17:03
Polymorphic JSON marshal / unmarshal in Go with different types
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type Something interface{}
@hlubek
hlubek / notes.md
Created February 9, 2023 08:17
macMini install notes
  • English as language in macOS install
  • FileVault activated
  • Logged in with Apple-Id ****
  • Installed Homebrew via Curl script
  • asdf installed via Homebrew
  • asdf Ruby plugin installed
  • Ruby 2.7.6 installed globally with asdf
  • Gem xcode-installed globally for Ruby 2.7.6
  • XCode installed via xcversion install 13.3.1
  • Gitlab Runner installed via brew install gitlab-runner
@hlubek
hlubek / main.go
Created January 17, 2023 12:45
Example for using http.NewResponseController in Go 1.20
package main
import (
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
run:
concurrency: 4
timeout: 5m
# Do not fail, we check the output for errors with severity "critical"
issues-exit-code: 0
tests: true
output:
format: line-number
@hlubek
hlubek / recyclable_reader.go
Created November 21, 2022 17:05
A reader that buffers what it read and can be "recycled" to read again from the beginning
type recyclableReader struct {
originalReader io.Reader
teeReader io.Reader
buffer *bytes.Buffer
}
func newRecyclableReader(file io.Reader) *recyclableReader {
buffer := new(bytes.Buffer)
teeReader := io.TeeReader(file, buffer)
@hlubek
hlubek / gist:86cd6cca0cb4ce18fae5f36a0c1a8795
Created December 22, 2021 08:17
go-popcount benchmark on Apple M1 (arm64)
goos: darwin
goarch: arm64
pkg: github.com/barakmich/go-popcount
BenchmarkCountBytes/32-10 314055555 3.808 ns/op 8402.63 MB/s
BenchmarkCountBytes/128-10 378914162 3.167 ns/op 40410.70 MB/s
BenchmarkCountBytes/1K-10 82149579 14.22 ns/op 72006.56 MB/s
BenchmarkCountBytes/16K-10 5750053 208.5 ns/op 78598.68 MB/s
BenchmarkCountBytes/128K-10 727538 1636 ns/op 80130.24 MB/s
BenchmarkCountBytes/1M-10 92504 12951 ns/op 80963.91 MB/s
BenchmarkCountBytes/16M-10 4234 253830 ns/op 66096.21 MB/s
@hlubek
hlubek / gist:e1957c8bb128b5242670ef2c8c419643
Created February 15, 2021 11:31
Cardano Test Pool Metadata
{
"name": "MyFirstTestPool",
"description": "The pool that tests all the pools",
"ticker": "TSTCL",
"homepage": "https://teststakepool.com"
}
@hlubek
hlubek / Dockerfile
Created October 22, 2020 06:39
Go timezone bug (fixed in master) with current Alpine tzdata
FROM golang:1.15 as builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -o bin/test
# ---