Skip to content

Instantly share code, notes, and snippets.

View Hiweus's full-sized avatar
🏠
Working from home

Andre Alves Leocadio Hiweus

🏠
Working from home
View GitHub Profile
@Hiweus
Hiweus / index.html
Created August 4, 2023 13:26
Demo SSE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
@Hiweus
Hiweus / AsyncButton.js
Last active July 23, 2023 04:47
React components
import { useState } from 'react'
import { Button, Spinner } from 'react-bootstrap'
function AsyncButton({ onClick, children, externalLoading = false, ...props }) {
const [internalLoading, setInternalLoading] = useState(false)
const handleClick = async () => {
setInternalLoading(true)
await onClick?.()
setInternalLoading(false)
@Hiweus
Hiweus / README.md
Last active March 30, 2023 02:11
Fetch last elements on table in each group

Fetch the last messages in each group by the attribute name

SELECT m1.*
FROM messages m1 LEFT JOIN messages m2
 ON (m1.name = m2.name AND m1.id < m2.id)
WHERE m2.id IS NULL;
@Hiweus
Hiweus / masks.js
Last active December 29, 2022 12:45
Methods to format masks in javascript, the second one is more generic to be implemented in any language
/*
* the first implementation is simpler but not much smart because, if a pattern long than value is passed
* to function all remaining pattern will be write to outputValue and not crop immediately
* for all purposes use second function, the first one is only a option more compact for understanding
*/
function makeString(value, pattern) {
let position = 0
return pattern.replace(/#/g, () => {
if(position >= value.length) {
return ''
const camelToSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
function mapFieldsToStorageName(name) {
const map = new Map()
map.set('userId', 'owner_id')
return map.get(name) ?? camelToSnakeCase(name)
}
function generateQuery(tableName, filters, ordering, options) {
const values = []

Configure nginx to use ssl

Generating certificates

# generate .crt and .key files
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt

# generate strong Diffie-Hellman group
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

To create a custom mouse script in nautilus just put your script in ~/.local/share/nautilus/scripts/ and make sure it's executable.

@Hiweus
Hiweus / abandonadoPorVoce.whatsapp.js
Created May 3, 2022 15:50
Script para enviar pelo whatsapp a musica inteira "Abandonada por você" linha por linha
var linhas = `Abandonada por você
Tenho tentado te esquecer
No fim da tarde, uma paixão
No fim da noite, uma ilusão
No fim de tudo, a solidão
Apaixonada por você
Tenho tentado não sofrer
Lendo antigas poesias
Rindo em novas companhias
E chorando por você

Problems i faced with JEST

Jest slow on WSL2

I moved my project from Windows Desktop to Linux Home and the tests became faster.

Jest not watching file changes on WSL2

This is related to watchman and inotify, i just moved my project from Windows Desktop to Linux home and watch mode start to work. This ocours because inotify doesn't work correctly ousite a linux file system. Issue Here

Watch mode scripts npm

Sometimes packages like Nodemon, Mocha who watch changes on files to perform some actions doesnt work correctly 🤕.

All these packages use CHOKIDAR library to watch file changes, to fix this behaviour on chokidar set environment variable CHOKIDAR_USEPOLLING=true.

# Linux