Skip to content

Instantly share code, notes, and snippets.

View valexandersaulys's full-sized avatar

Vincent Alexander Saulys valexandersaulys

View GitHub Profile
@valexandersaulys
valexandersaulys / audit_log.go
Created July 30, 2024 02:04
Audit Log in Gorm
package models
// https://aayushacharya.com.np/blog/audit-log-gorm/
// couldn't get it to work, error inlined towards bottom
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"gorm.io/datatypes"
@valexandersaulys
valexandersaulys / index.html
Created July 17, 2024 02:03
Dead Simple Multi-Step Form with Animate.css effects in Go Language HTML Template
{{define "all"}}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Document</title>
<link href="/static/output.css" rel="stylesheet"/>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link
rel="stylesheet"
@valexandersaulys
valexandersaulys / main.go
Created July 10, 2024 21:35
Example of completely async worker
package main
import (
"embed"
"fmt"
"github.com/go-chi/chi/v5"
"html/template"
"io/fs"
"net/http"
"strconv"
@valexandersaulys
valexandersaulys / README.md
Last active July 10, 2024 14:33
Protocol Buffers

Scattering of thoughts for my eyes (and maybe others?)

To install

eget protocolbuffers/protobuf
# dumps it out in the local directory

General Call Pattern

@valexandersaulys
valexandersaulys / index.html
Created June 22, 2024 23:26
Expanding Text via Sliding
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Document</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="my-4 mx-auto max-w-2xl">
<div class="text-3xl font-bold underline">
@valexandersaulys
valexandersaulys / README.md
Last active June 22, 2024 16:03
Vanilla Javascript Modal (+SurrealJS) detached from the Button

It's deeply annoying that most vanilla javascript modal examples either involve some library, some css framework, or are poorly written. This is my crack at this. Unlike many, this will only load the event at startup (courtesy of surreal.js), remove the event listener once its done (to prevent pile-up), and allow for the modal content to be detached from the button.

Why isn't this easier to find?!

Might expand this to include an HTMX example at some point

@valexandersaulys
valexandersaulys / linux-setup.sh
Created May 18, 2024 20:13 — forked from dhh/linux-setup.sh
linux-setup.sh
# CLI
sudo apt update -y
sudo apt install -y \
git curl btop \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc2 \
libvips imagemagick libmagickwand-dev mupdf mupdf-tools \
redis-tools sqlite3 libsqlite3-0 libmysqlclient-dev \
rbenv apache2-utils
@valexandersaulys
valexandersaulys / README.md
Last active May 15, 2024 01:18
Calling Golang from within C

Much help from this Stackoverflow answer

# generate a self-contained static Go library
go build -ldflag "-s -w" -buildmode=c-archive my_lib.go

# check for the header files my_lib.h and my_lib.a in the directory
ls -ltah my_lib*

# then compile the c program
@valexandersaulys
valexandersaulys / README.md
Last active May 15, 2024 01:17
Calling C code from within Golang

Assumes you have raylib installed.

I found the official cgo docs to be a bit lacking. Specifically on how to get the right include and header files in the path. This alleviates it.

Paths found via pkg-config --libs --cflags raylib. Alternatively you can drop in // #cgo pkg-config: raylib and it will work.

Go appears to be smart about what it inclues and doesn't include. Therefore, if you only pull in one function it does not pull in every function and library from the include file.

Structs can be accesessed in Go via C.struct_YourStruct. See here for more information. Unions get more hairy but its also possible.

@valexandersaulys
valexandersaulys / README.md
Created April 24, 2024 13:47
Raise Nginx Proxy