Skip to content

Instantly share code, notes, and snippets.

View henriquegogo's full-sized avatar

Henrique Gogó henriquegogo

View GitHub Profile
@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)))
@henriquegogo
henriquegogo / ElementBuilder.js
Last active April 3, 2025 20:20
Create HTML Elements with arguments and nested children
const ElementBuilder = new Proxy({}, { get: (_, tagName) => (...args) => {
const element = Object.assign(document.createElement(tagName), ...args);
element.append(...args.filter(arg => arg.constructor !== Object));
return element;
}});
const EventHandler = (element, fn) => Object.assign(element || {}, {
update: (...newProps) => element.replaceWith(fn(...newProps)),
listen: (eventType, handler) => (element.dataset.event = "", element)
.addEventListener(eventType, ({ detail }) => handler(detail)),
@henriquegogo
henriquegogo / useDebounce.ts
Last active June 16, 2023 14:22
Create a debounce hook to wait a textfield change and dispatch an event after specific milliseconds
export function useDebounce(handler: (value: string) => void, millisec: number = 500) {
const [value, setValue] = useState('');
useEffect(() => {
const timeoutId = setTimeout(() => handler(value), millisec);
return () => clearTimeout(timeoutId);
}, [value, handler, millisec]);
return setValue;
}
@henriquegogo
henriquegogo / love.lua
Last active April 10, 2022 08:24
Lua LÖVE file reference for autocomplete
-- takes all
love = {
audio = {
getActiveEffects = function(...) end, --Gets a list of the names of the currently enabled effects.
getActiveSourceCount = function(...) end, --Gets the current number of simultaneously playing sources.
getDistanceModel = function(...) end, --Returns the distance attenuation model.
getDopplerScale = function(...) end, --Gets the global scale factor for doppler effects.
getEffect = function(...) end, --Gets the settings associated with an effect.
getMaxSceneEffects = function(...) end, --Gets the maximum number of active effects.
getMaxSourceEffects = function(...) end, --Gets the maximum number of active Effects for each Source.
@henriquegogo
henriquegogo / .xinitrc.keycode
Created March 19, 2022 04:46
Remap key in linux
xmodmap -e "keycode 49 = apostrophe quotedbl bar bar bar"
@henriquegogo
henriquegogo / .bashrc-fluidsynth
Last active February 15, 2022 14:23
Autoload fluidsynth. Copy to .bashrc
#!/bin/bash
# Add these lines in .bashrc and set Raspberry Pi to auto login
if [ ! -f /tmp/fluidsynth-bootloaded ]; then
touch /tmp/fluidsynth-bootloaded
killall fluidsynth
fluidsynth -a alsa -g 1 /usr/share/sounds/sf2/default-GM.sf2 -o midi.autoconnect=1 -c 4
fi