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 / .newsboat-config
Created May 16, 2019 23:51
Newsboat config file
browser w3m
# Newsboat colour scheme to work with the Nord palette
# from Arctic Studios - https://github.com/arcticicestudio/nord
# Tested with the iTerm2 Nord terminal colour scheme
# https://github.com/arcticicestudio/nord-iterm2
# though should work with any terminal using the palette
color background color236 default
color listnormal color248 default
@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 / personClass.lua
Last active September 5, 2022 13:39
Simple Lua Class
#!./bin/lua
Person = {} do
setmetatable(Person, { __index = string }) -- Optional. Inheritance
local personMessage;
function Person.new(name, age)
local self = setmetatable({}, { __index = Person })
@henriquegogo
henriquegogo / useSqlite3.lua
Last active August 8, 2022 12:45
LuaSQL-SQLite3 example
#!./bin/lua
local driver = require('luasql.sqlite3')
local env = driver.sqlite3()
local db = env:connect('db.sqlite')
db:execute[[
CREATE TABLE generic(
key varchar(50),
value varchar(150)
@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)