Skip to content

Instantly share code, notes, and snippets.

View luan0ap's full-sized avatar
👁️‍🗨️
Looking for a job

Luan AP luan0ap

👁️‍🗨️
Looking for a job
View GitHub Profile
@luan0ap
luan0ap / javascript-proxy-as-rest-client.js
Created February 8, 2022 18:56 — forked from DavidWells/javascript-proxy-as-rest-client.js
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
// also see https://github.com/fastify/manifetch
// also see https://github.com/flash-oss/allserver
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
return async function(id = "") {
const response = await fetch(`${url}/${key}/${id}`)

Full socket.io client and server example

Last updated: 2021-02-21, tested with socket.io v3.1.1

This is the simplest implementation you will find for a client/server WebSockets architecture using socket.io.

To see a full explanation, read my answer on SO here: https://stackoverflow.com/a/24232050/778272.

If you're looking for examples using frameworks, check these links:

@luan0ap
luan0ap / remover-acentos.js
Created April 7, 2021 12:12 — forked from marioluan/remover-acentos.js
Funcao marota para remover acentos de strings. Foi utilizado expressao regular em cima de caracteres representados na base hexadecimal.
/**
* Remove acentos de caracteres
* @param {String} stringComAcento [string que contem os acentos]
* @return {String} [string sem acentos]
*/
function removerAcentos( newStringComAcento ) {
var string = newStringComAcento;
var mapaAcentosHex = {
a : /[\xE0-\xE6]/g,
e : /[\xE8-\xEB]/g,
@luan0ap
luan0ap / app.js
Created January 27, 2021 12:22 — forked from marshallswain/app.js
Authenticate on feathers-socketio connection with header
const socketio = require('feathers-socketio')
const authOnSocketConnect = require('./authenticate-on-socket-connect')
// ... Setup your Feathers app code or use the generator then replace the socketio registration with this
// When you register the feathers-socketio plugin, use the utility
app.configure(socketio(function (io) {
// Get Socket.io headers
io.on('connection', function (socket) {
authOnSocketConnect({ app, socket })
@luan0ap
luan0ap / Hasura Keycloak.md
Created October 20, 2020 13:58 — forked from webdeb/Hasura Keycloak.md
Basic Keycloak Script Mapper to provide Hasura claims

Steps to provide Hasura Claims in Keycloak generated JWT

  1. Create your realm / client
  2. Inside client configuration go to "Mappers"
  3. Click on "Create"
  4. Name it "hasura"
  5. Choose Mapper Type "Script Mapper"
  6. Add following script to demonstrate how it works
@luan0ap
luan0ap / json_sanitize.js
Created May 25, 2020 19:07 — forked from Gimcrack/json_sanitize.js
Sanitize Json String
/**
* Given you have a JSON string that represents a single object (not array).
* SanitizeJsonString will attempt to correct the JSON syntax allowing
* it to be parsed.
*/
/**
* Sanitize user input before attempting to parse the JSON
*
@luan0ap
luan0ap / README-Template.md
Created June 5, 2019 14:09 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@luan0ap
luan0ap / how-to-squash-commits-in-git.md
Last active June 6, 2019 06:45 — forked from patik/how-to-squash-commits-in-git.md
Como realizar squash commits no GIT - translated pt_BR

Squashing Git Commits

O caminho fácil e flexível

Este método evita conflitos durante eo merge, se você tem que periódicamente fazer pull da master em sua branch. Também da a oportuniadade de realizar squash em mais de um commit ou para re-organizar seu código completamente em diferentes commits (ex: se você terminou seu trabalho em três diferente features mas os commits não foram consecutivos).

*Nota: Você não pode usar esse método se você pretende abrir um Pull Request para realizer merge da sua branch. Esse método requer commits diretamente na master.

Troque para a branch master e certifique-se de estar tudo atualizado:

@luan0ap
luan0ap / uuid.js
Last active May 23, 2019 20:13 — forked from fabiorecife/gist:faa0badf35e33062e0ff
uuid - javascript
const uid = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0
const v = c === 'x' ? r : r & 0x3 | 0x8
return v.toString(16)
})

good doc! some quick answers -

It seems like act() is being recommended for wrapping all state updates in React tests, but is it necessary to use it everywhere if you can use waitForElement to turn the whole test async?

This is a very good question, and something I grappled with earlier. A couple of things that stood out for me -

  • waiting for an element is indeed pretty close to what a user's experience is like; ie - a user 'waits' for the form to show itself, after which they fill it in and click a button, then 'wait' for the success screen etc. Ultimately, act() makes this test stronger - it'll ensure that effects, and queued promises, have been flushed before you interact with the element. wrapping waitForElement with act() (the async version, ie), will make this invisible to the user, but with the guarantee that their UI is 'stable'.

  • I couldn't assume that all tests would use waitForElement. For example, using timers is common for testing transitions and such. In these scenarios too, ac