Skip to content

Instantly share code, notes, and snippets.

View tgmarinho's full-sized avatar
💻
read my blog: tgmarinho.com

Thiago Marinho tgmarinho

💻
read my blog: tgmarinho.com
View GitHub Profile
// https://twitter.com/sseraphini/status/1521845452529979395
// by https://github.com/fersilva16
import { useRef } from 'react';
export const useStepCount = () => {
const stepCount = useRef<number>();
stepCount.current = 0;
@tgmarinho
tgmarinho / destructuring.js
Created April 15, 2022 04:43 — forked from mikaelbr/destructuring.js
Complete collection of JavaScript destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@tgmarinho
tgmarinho / test-delayed-webhook.js
Created April 14, 2022 16:05
est-delayed-webhook hasura
const express = require('express')
const app = express()
const port = process.env.PORT || 3000;
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
const DynamicActionButtons = ({
payment,
isBuyer,
isSeller,
isNewlyCreated,
}: DynamicPaymentComponentProp) => {
const { loadingAuth, signIn } = useAuth()
const buttonsToBeDisplayed: JSX.Element[] = []
@tgmarinho
tgmarinho / batchCursor.ts
Created March 25, 2022 22:37 — forked from sibelius/batchCursor.ts
Mongo cursor processing - let you select a strategy of how to process elements of a Cursor so you can iterate through all items
/*
* Usage
* let cursor = Test.find().sort({ name: 1 }).cursor();
const get = makeGen(cursor, 100);
let first100 = await get.next();
console.log(first100.value.length);
https://gist.github.com/lineus/3f7d826a21796129db968d6590c93faa
*/
export async function* batchCursor(c, n) {
const cursor = c;
@tgmarinho
tgmarinho / .gitconfig
Created March 10, 2022 00:10
gitconfig
cat .gitconfig 1 ↵ tgmarinho@Thiagos-MacBook-Pro
[user]
name = Thiago Marinho
email = [email protected]
[core]
editor = code
longpaths = true
[diff]
tool = meld
[difftool "meld"]
@tgmarinho
tgmarinho / isEscrowAddressValid.ts
Created February 22, 2022 01:21
valid address
import { ethers } from 'ethers'
export const isEscrowAddressValid = (param: string) => {
try {
ethers.utils.getAddress(param)
return true
} catch (error) {
return false
}
}
@tgmarinho
tgmarinho / transformSVGInBase64.ts
Created February 22, 2022 01:21
transformSVGInBase64
import { Buffer } from 'buffer'
export const transformSVGInBase64 = (svgFile: string) => {
const imageInBase64 = Buffer.from(svgFile).toString('base64')
const imageReadyToTagImg = 'data:image/svg+xml;base64,' + imageInBase64
return imageReadyToTagImg
}
@tgmarinho
tgmarinho / stringToUtf16Bytes.ts
Created February 22, 2022 01:20
stringToUtf16Bytes
export function stringToUtf16Bytes(escrowId: string) {
const bytes = []
for (let position = 0; position < escrowId.length; position++) {
const code = escrowId.charCodeAt(position) // x00-xFFFF
bytes.push(code & 255, code >> 8) // low, high
}
return bytes
}