Skip to content

Instantly share code, notes, and snippets.

View renatoargh's full-sized avatar
🚀

Renato Gama renatoargh

🚀
View GitHub Profile
@renatoargh
renatoargh / naive-cypto.ts
Last active March 22, 2023 16:22
Naive crypto algorithm
import { randomBytes } from 'crypto'
const initCircularBuffer = (buffer: Buffer) => {
let index = 0;
return (): number => {
if (index >= buffer.length) {
index = 0;
}
@renatoargh
renatoargh / output.txt
Last active March 13, 2023 21:18
UUID plus timestamp to ULID
┌──────────────┬────────────────────────────────────────┐
│ (index) │ Values │
├──────────────┼────────────────────────────────────────┤
│ timestamp │ 1678742260622 │
│ uuid │ 'f0df59ea-bfe2-43a8-98d4-8213348daeb6' │
│ ulid │ '01GVEDC2WE8EM9HN422CT8VBNP' │
│ decodedTime │ 1678742260622 │
│ originalUuid │ '0186DCD6-0B8E-43A8-98D4-8213348DAEB6' │
└──────────────┴────────────────────────────────────────┘
@renatoargh
renatoargh / rate-limiter.ts
Last active December 21, 2022 13:36
Simple TypeScript+DynamoDB rate limiter
import { DateTime, DateTimeUnit, DurationLike } from "luxon";
import { deburr, kebabCase } from "lodash";
import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
import {
ConditionalCheckFailedException,
DynamoDBClient,
UpdateItemCommand,
} from "@aws-sdk/client-dynamodb";
const client = new DynamoDBClient({ region: 'sa-east-1' })
@renatoargh
renatoargh / docker-compose.yml
Created August 4, 2022 13:15
Basic Flink docker compose setup
version: '3'
services:
flink-jobmanager:
image: flink:1.7
platform: linux/x86_64
container_name: flink-jobmanager
command:
- "jobmanager"
ports:
@renatoargh
renatoargh / mod11.js
Last active May 27, 2022 21:44
Algoritmo para cálculo do dígito verificador via mod11 em JavaScript
//valor:
// string contendo os números a terem seu mod11 calculado.
//restornarResto:
// boleano indicando se deve ser retornado o apenas o resto do multiplicatório ou o resultado da subtração por 11.
//multiplicadores:
// conjunto de números que multiplicarão ciclicamente o valor de entrada.
function mod11(valor, retornarResto, multiplicadores){
@renatoargh
renatoargh / new-mac.md
Last active April 29, 2022 05:34
New Mac Installation Checklist

General

  • chrome
  • 1pass
  • intelliJ COMMUNITY (ou Ultimate)
  • vscode
    • enable settings sync with github
  • dropbox
  • spectable
  • skype
  • teamviewer
const sleep = async (timeout: number = 1000) =>
// tslint:disable-next-line:no-string-based-set-timeout
new Promise((res) => setTimeout(res, timeout));
/**
* A test-only utility that executes a function until a given condition is met.
* Useful to wait for asynchronous operations to complete on integration tests.
* If the condition is never met (`condition` never returns `true`) then tests will eventually timeout accordin to
* the test framework timeout settings.
* @param task Asynchronous function that will be repeatedly executed until the the desired `condition` is met.
import { isUndefined } from "lodash";
export abstract class Cloneable<T> {
public clone(newValues: Partial<T> = {}): T {
const clone = new (this.constructor as new () => T)();
const newValuesWithNestedClones = Object.getOwnPropertyNames(clone)
.reduce((partial, propertyName) => {
const property = Object.getOwnPropertyDescriptor(clone, propertyName) as PropertyDescriptor;
const isCloneable = property.value instanceof Cloneable;
const isNotProvided = isUndefined(
@renatoargh
renatoargh / config.yml
Created February 12, 2021 21:52 — forked from sjparkinson/config.yml
Deploy a Fastly service using Terraform and CircleCI 2.0.
version: 2
jobs:
validate_terraform:
docker:
- image: hashicorp/terraform
steps:
- checkout
- run:
name: Validate Terraform Formatting
@renatoargh
renatoargh / juros.js
Last active January 22, 2021 23:57
Fórmula para cálculo do valor da parcela com juros compostos, de acordo com regra do banco central: https://www3.bcb.gov.br/CALCIDADAO/publico/calcularFinanciamentoPrestacoesFixas.do
var valorFinanciado = 100,
parcelas = 10,
juros = 0.1, //ao mês
cf = juros/(1 - (1 / Math.pow(1 + juros, parcelas))),
valorDaParcela = cf * valorFinanciado;
console.log(valorDaParcela);