Skip to content

Instantly share code, notes, and snippets.

View lxfontes's full-sized avatar
🌋

Lucas Fontes lxfontes

🌋
View GitHub Profile
@lxfontes
lxfontes / slog_wasi.go
Created August 19, 2024 13:36
wasi slog
package main
// logger := slog.New(DefaultOptions().NewHandler())
// a 'context' attribute will be promote to wasilog 'context' field
// logger = logger.With("context", "Get")
//
// logger.Info("Hello world")
// logger.Warn("Hello world 1", "key", "value")
// logger.Info("Hello world 2", slog.String("key", "value"))
// logger.Info("Hello world 3", slog.Any("key", 123), slog.String("context", "SomethingElse"))
@lxfontes
lxfontes / ed25519-nats.go
Created July 23, 2024 18:48
nkeys ed25519 jwt algorithm
package secrets
import (
"errors"
"fmt"
jwt "github.com/golang-jwt/jwt/v5"
"github.com/nats-io/nkeys"
)
@lxfontes
lxfontes / listener.go
Created January 10, 2024 16:09
GCP Pubsub Listener
package main
// example
// go run ./main.go <gcp-project-name> <pubsub-subscription-name> | jq -r .payload.source.table
import (
"context"
"fmt"
"os"
"os/signal"
@lxfontes
lxfontes / pr.yaml
Created December 7, 2023 18:55
github action on pull request comment
name: "QA commands"
on:
issue_comment:
types: [created]
jobs:
deploy:
runs-on: ubuntu-latest
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/qa')
package main
import (
"fmt"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
@lxfontes
lxfontes / swap.go
Created November 26, 2019 18:49
go atomic swappointer
package main
import (
"fmt"
"sync/atomic"
"unsafe"
)
type thing struct {
name string
package main
import (
"encoding/json"
"fmt"
)
type Thing1 struct {
String string `json:"meow"`
}
@lxfontes
lxfontes / godoc.vim
Created November 9, 2018 23:33
Create godoc for function
" adapted from https://github.com/fatih/dotfiles/blob/master/vimrc
" create a go doc comment based on the word under the cursor
function! s:create_go_doc_comment()
norm "zyiw
execute ":norm O// "
norm "zp
execute ":norm A ..."
endfunction
nnoremap <leader>ui :<C-u>call <SID>create_go_doc_comment()<CR>
@lxfontes
lxfontes / github-ssh-auth.go
Created October 31, 2018 23:55
golang ssh server with github authentication
package main
import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
@lxfontes
lxfontes / main.go
Created March 8, 2018 04:01
etcd internal state sync
package main
import (
"context"
"log"
"time"
"github.com/coreos/etcd/client"
)