Skip to content

Instantly share code, notes, and snippets.

View dlisboa's full-sized avatar

Diogo Lisboa dlisboa

View GitHub Profile
@dlisboa
dlisboa / 55-bytes-of-css.md
Created October 7, 2025 15:21 — forked from JoeyBurzynski/55-bytes-of-css.md
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
@dlisboa
dlisboa / index.html
Created September 15, 2025 13:38
Styling <details>: Horizontal Accordion (no animation)
<script>
document.documentElement.dataset.embed = window.location.search.includes('type=embed') ? "yep" : "nope";
</script>
<main>
<h1>Styling <code>&lt;details&gt;</code>: Horizontal Accordion <em>(no animation)</em></h1>
<h2>Demo</h2>
<div id="demo">
@dlisboa
dlisboa / selectbox.js
Created September 12, 2025 18:38
Javascript selection box / mouse up/down/move
// by goo - https://www.gurukhalsa.me/
// https://news.ycombinator.com/item?id=45219644
// creates a selection box like on Desktop OSes
(() => { let startX, startY, box, dragging = false;
const style = document.createElement('style');
style.textContent = `
.___selection-box {
position: absolute;
@dlisboa
dlisboa / index.html
Last active September 9, 2025 23:47
React-in-HTML with JSX
<!-- just serve this with Caddy and access browser -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="importmap">
{
@dlisboa
dlisboa / safer_enums.go
Last active October 3, 2024 20:45
Safer enums
package main
// inspiration: https://threedots.tech/post/safer-enums-in-go/
import "fmt"
// don't use `type Role string` as it can accept any string
type Role struct {
s string
}
@dlisboa
dlisboa / recoverer.go
Created August 27, 2024 19:59
Recover go middleware
func Recoverer(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
body, e := io.ReadAll(r.Body)
if e != nil {
body = []byte("recoverer: body unreadable")
}
slog.Error("panic",
slog.String("path", u.Path),
@dlisboa
dlisboa / Justfile
Last active August 21, 2024 21:13
Using a tools.go mod for dev dependencies
default:
just --list
export GOBIN := `echo $PWD/bin`
@devsetup:
echo "installing dev dependencies at $GOBIN ..."
go install -C ./tools github.com/golangci/golangci-lint/cmd/golangci-lint
go install -C ./tools github.com/cespare/reflex
@dlisboa
dlisboa / client.go
Created August 12, 2024 17:24
GOB encoding through TCP
package main
import (
"encoding/gob"
"fmt"
"log"
"net"
"time"
)
@dlisboa
dlisboa / options_struct.go
Created August 8, 2024 13:09
Option struct with default values
package main
import (
"fmt"
"time"
)
type Config struct {
Timeout time.Duration
Name string
@dlisboa
dlisboa / set_build_vars.go
Last active August 14, 2024 19:18
Set global variables on build time in Go
package main
import "fmt"
// set these vars on build time:
// go build -ldflags "-X main.version=v1.2.3 -X main.commit=$(git rev-parse --short HEAD) -X main.date=$(date -u '+%Y-%m-%dT%H:%M:%S')" -o foo -v ./foo.go
var (
service = "some-service"
version string
commit string