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
@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
}
@tgmarinho
tgmarinho / groupBy.ts
Created February 22, 2022 01:20
group by in typescript
export const groupBy = <T, K extends keyof any>(
array: T[],
getKey: (item: T) => K
) =>
array.reduce((acc, current) => {
const group = getKey(current)
if (!acc[group]) acc[group] = []
acc[group].push(current)
return acc
}, {} as Record<K, T[]>)
@tgmarinho
tgmarinho / addressFormat.ts
Created February 22, 2022 01:19
address format eth
const reduceAddress = (address: string) => {
// it's an ens
if (address.includes('.')) return address
const start = address.substring(0, 6)
const middle = '...'
const end = address.substring(address.length - 4)
return `${start}${middle}${end}`
}
@tgmarinho
tgmarinho / countdown.ts
Created February 22, 2022 01:18
countdown function
import { intervalToDuration, formatDuration } from 'date-fns'
export const countdownChallengePeriod = (expires: Date) => {
const start = new Date().getTime()
const end = expires.getTime()
const durations = intervalToDuration({
start,
end,
})
@tgmarinho
tgmarinho / howto.md
Created February 12, 2022 16:40 — forked from electricg/howto.md
How to setup Gandi.net domain routing to Heroku

How to setup Gandi.net domain routing to Heroku

TODO: setup SSL.


This is a quick guide on how to setup domain and infinite subdomains, in a case where, for example, you may have one subdomain for each client.

Starting from this http://stackoverflow.com/a/39646701