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
const condition = true;
const App = () => (
<div>
<h1>This is always visible</h1>
{
condition && (
<div>
<h2>Show me</h2>
<p>Description</p>
const memoize = (fn) => {
let cache = {}, key;
return (...args) => {
key = JSON.stringify(args);
return cache[key] || (cache[key] = fn.call(null, ...args));
}
};
@luan0ap
luan0ap / results.md
Last active September 16, 2019 17:29 — forked from getify/1.js
tag function for formatting console.log(..) statements
var v = 42;
var o = { a: 1, b: [2,3,4] };

logger`This is my value: ${v} and another: ${o}`;
// This is my value: 42 and another: {"a":1,"b":[2,3,4]}
try {
@luan0ap
luan0ap / combinatorial-analysis.js
Created September 21, 2018 15:55 — forked from calimaborges/combinatorial-analysis.js
Array combinations, permutations and arrangements
// permutation: Permutação
// P(n) = n!
// Exemplo: número de anagramas da palavra LIVRO = P(5) = n!
// Possibilidades de uma fila de 25 pessoas = P(25) = 25!
// combination: Combinação
// C(p,n) = = n! / p!(n - p)!
// Exemplo: formar comissão de 3 pessoas escolhidas entre 10 pessoas. C(3,10) = 10! / 3!(10 - 3)!
// arrangement: Arranjo
@luan0ap
luan0ap / 0 básico.md
Last active January 31, 2020 03:30 — forked from threepointone/0 basics.md
css-in-js - em português

Uma série de posts sobre CSS in JS

0. Estilos como objetos

Primeiramente, um exercicio. Podemos representar o CSS como texto puro? Bora tentar:

let redText = { color: 'red' };

Show de bola, deve ser claro o que este código acima deve "fazer" né. então bora tentar de novo:

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

@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)
})
@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 / 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 / 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
*