Skip to content

Instantly share code, notes, and snippets.

View henriquegogo's full-sized avatar

Henrique Soares henriquegogo

View GitHub Profile
@henriquegogo
henriquegogo / memalloc.c
Created September 18, 2026 01:10
Arena Allocator
#ifndef MEMALLOC_H
#define MEMALLOC_H
#include <stddef.h>
#include <stdlib.h>
typedef struct {
char *data;
size_t size;
size_t offset;
@henriquegogo
henriquegogo / selfhosting.md
Last active October 20, 2026 12:38
Self hosting services in a local network

Mail server (postfix + dovecot)

A full functional mail server to be used in a local network.

Installation

sudo apt install postfix dovecot-imapd
@henriquegogo
henriquegogo / dialog.html
Last active July 29, 2025 21:46
Compact format of "request and render to..."
<dialog onclick="this.close()">
<iframe name="modal" onload="this.contentDocument.body.innerHTML.trim() ? (
this.style.height = 0, this.parentElement.showModal(),
this.style.height = this.contentDocument.body.scrollHeight + 'px'
) : this.parentElement.close()"></iframe>
</dialog>
@henriquegogo
henriquegogo / shell-server.sh
Created June 30, 2025 13:40
Shell Web Server
#!/bin/sh
port=8000
echo "Starting server on port $port..."
while true; do
echo "HTTP/1.1 200 OK
Content-Type: text/plain
@henriquegogo
henriquegogo / lsp-standalone.sh
Created May 19, 2025 20:59
Invoke code completion using only the terminal
#!/bin/bash
CODE='console.'
INIT='{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":1,"rootUri":null,"capabilities":{}}}'
INITIALIZED='{"jsonrpc":"2.0","method":"initialized","params":{}}'
DIDOPEN="{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/didOpen\",\"params\":{\"textDocument\":{\"uri\":\"file:///dev/null\",\"languageId\":\"typescript\",\"version\":1,\"text\":\"$CODE\"}}}"
COMPLETION="{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"textDocument/completion\",\"params\":{\"textDocument\":{\"uri\":\"file:///dev/null\"},\"position\":{\"line\":0,\"character\":${#CODE}}}}"
{
@henriquegogo
henriquegogo / custele.js
Last active March 14, 2025 21:01
Custom Elements from Template. Use <slot /> for variables.
document.querySelectorAll('template[id]').forEach(({id, content}) =>
customElements.define(id, class extends HTMLElement {
constructor() {
super().attachShadow({mode: 'open'}).appendChild(content.cloneNode(true));
[...this.attributes].forEach(({name, value}) => {
const span = document.createElement('span');
this.appendChild(Object.assign(span, {slot: name})).textContent = value;
this.removeAttribute(name)
this.shadowRoot.querySelectorAll(`[${name}]`).forEach(el =>
!el.getAttribute(name) && el.setAttribute(name, value));
@henriquegogo
henriquegogo / index.html
Last active February 10, 2025 02:31
Request a partial and replace the iframe
<iframe hidden onload="this.replaceWith(...contentDocument.body.children)" src="head.html"></iframe>
@henriquegogo
henriquegogo / ftw.html
Last active April 4, 2025 02:28
Form The Win!
<script>
function formRequest(method) {
const action = event.target.action;
event.preventDefault();
fetch(action, { method, body: new FormData(event.target) })
.then(res => res.redirected && (location.href = res.url));
}
const PUT = formRequest.bind(null, "PUT");
const DELETE = formRequest.bind(null, "DELETE");
</script>
@henriquegogo
henriquegogo / orchestrator.go
Created September 29, 2024 04:27
Sender / Receiver through socket
package main
import (
"fmt"
"net"
"os"
"sync"
"time"
)
@henriquegogo
henriquegogo / kamby.scm
Last active November 20, 2024 13:32
Kamby Language in Scheme. Usage: $ scheme kamby.scm < sample.ka
(define (tokenize script-text)
(let ((tkns (list "")) (in-str? #f))
(define (append-str! str)
(set-car! tkns (string-append (car tkns) str)))
(define (add-tkn! . strs)
(if (string=? (car tkns) "") (set! tkns (cdr tkns)))
(set! tkns (append (reverse strs) tkns)))