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
@Nick-Gabe
Nick-Gabe / Pombify.js
Last active January 6, 2024 01:57
Transforma uma string em pombês, e traduz para a língua dos humanos.
const pombify = (phrase) => {
return phrase
.split(' ')
.map((word) => {
const wordLetters = word.split('')
return wordLetters
.map((letter, index) => {
const charCode = letter.charCodeAt(0);
const binary = charCode
.toString(2)
@DavidWells
DavidWells / github-proxy-client.js
Last active March 15, 2024 08:28
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
// original inspiration via https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
@DavidWells
DavidWells / javascript-proxy-as-rest-client.js
Last active May 12, 2024 14:24
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
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
@IgorFachini
IgorFachini / convertStringBoolean.js
Last active February 21, 2022 20:06
JavaScript: Convert string boolean to boolean, suports objects, arrays recursivelly.
/**
* Convert string booleans to boolean
* @param {Array, Object, String} date
* @returns {Array, Object, String, Boolean}
*/
const convertStringBoolean = (data) => {
if (Array.isArray(data)) return data.map(d => convertStringBoolean(d))
if (typeof data === 'object') {
for (const key in data) {
data[key] = convertStringBoolean(data[key])
const delayPromiseToTest = (timeout = 1000, error = null) => new Promise((resolve, reject) => { setTimeout(() => error instanceof Error ? reject(error) :resolve(), timeout) })
@webdeb
webdeb / Hasura Keycloak.md
Last active October 29, 2022 19:03
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

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

@jgraber
jgraber / gist:02a020aae576d7b235c62d4c104da551
Created February 22, 2019 12:47 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
@getify
getify / 1.js
Last active March 19, 2023 08:32
tag function for formatting console.log(..) statements
function logger(strings,...values) {
var str = "";
for (let i = 0; i < strings.length; i++) {
if (i > 0) {
if (values[i-1] && typeof values[i-1] == "object") {
if (values[i-1] instanceof Error) {
if (values[i-1].stack) {
str += values[i-1].stack;
continue;
}

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).