Skip to content

Instantly share code, notes, and snippets.

View henriquegogo's full-sized avatar

Henrique Gogó henriquegogo

View GitHub Profile
@henriquegogo
henriquegogo / dynasync.js
Last active March 25, 2024 20:42
Request dynamically from server instead of call a link
["click", "submit"].forEach((eventType) => {
window.addEventListener(eventType, (ev) => {
// Initialize variables from element that triggered the event
const {
target, action, href = action, method = ev.target._method?.value, ...data
} = Object.fromEntries([...ev.target.attributes].map((attr) => [
attr.name.replace(/^data-/, ""), attr.value
]));
// Default behavior if target is not defined or is not a selector
@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 / highlight.js
Last active December 17, 2022 05:08
Syntax highlighter
// Syntax highliter
// License: MIT
// Author: henriquegogo
// Description: A small generic highlighter easy to plug and use in any code sample.
// Works better with JavaScript, C, Python and HTML
function highlight(selector) {
document.body.innerHTML += `
<style>${selector} span * { color: inherit !important }</style>
`;
document.querySelectorAll(selector).forEach((element) => {
@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
@henriquegogo
henriquegogo / sac.hp12c
Last active October 11, 2021 01:28
HP Calculators Programs - SAC for 12c | TVM for 42s
// Constant Amortization System for HP12C (Platinum)
// Author: Henrique Gogó (henriquegogo@gmail.com)
//
// Instructions: enter n, i and PV values and set FV as 0.
// Set register 9 if you want to get an specific payment number.
//
// After program ends, the result saved in registers will be:
// X: current payment value
// FV: remaining amount to pay
// PMT: amortization value (fixed)
@henriquegogo
henriquegogo / qemu-create.sh
Last active June 28, 2020 04:00
Scripts to create and run qemu VMs
qemu-img create -f qcow2 "$@" 80G
@henriquegogo
henriquegogo / speechListenSpeak.js
Created June 25, 2020 15:50
Speech recognition and speak using native browser API
let recognition = new webkitSpeechRecognition();
recognition.lang = 'pt-BR';
recognition.onresult = ({ results }) => {
const transcript = results[0][0].transcript;
speechSynthesis.speak(new SpeechSynthesisUtterance(transcript));
}
recognition.start();
@henriquegogo
henriquegogo / .eslintrc.json
Last active April 16, 2020 14:40
Eslint config for all projects
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:jest/recommended",