Skip to content

Instantly share code, notes, and snippets.

View renatoargh's full-sized avatar
🚀

Renato Gama renatoargh

🚀
View GitHub Profile
@renatoargh
renatoargh / output.json
Created April 17, 2024 16:18
Generates a truth table out of arbritrary array elements
[
["1", "A", "X"],
["1", "A", "Y"],
["1", "B", "X"],
["1", "B", "Y"],
["2", "A", "X"],
["2", "A", "Y"],
["2", "B", "X"],
["2", "B", "Y"]
]
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body style="margin: 0px;">
<script type="text/javascript">
// Behringer Keys
const KEYS = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab', 'A', 'Bb', 'B'];
const maxKeys = KEYS.length
@renatoargh
renatoargh / autocomplete.md
Last active February 5, 2024 17:49
Fazer o auto complete do Java funcionar no VSCode:

Fazer o auto complete do Java funcionar no VSCode:

  1. Instalar SDKMAN (https://sdkman.io/)
  2. Rodar sdk ls java e copiar o `identifier`` desejado (ultima coluna a esquerda)
  3. Rodar sdk install java :identifier
  4. Rodar sdk home java :identifier | pbcopy para copiar o local da instalação da versão especifica do Java (:javaPath) que vc instalou pelo sdkman
  5. No VSCode clicar em "Preferencer -> Settings", filtrar por "java.configuration.runtimes" então clicar em "Edit in settings.json" e colar o seguinte (substitua as variaveis):
  "java.configuration.runtimes": [
@renatoargh
renatoargh / README.md
Last active January 9, 2024 18:59
Using temporary AWS STS credentials with AWS CLI and 1password

Summary

For those using 1password and AWS CLI, here is a cool trick to take advantage of 1pass and use temporary STS credentials instead of hardcoding long lived AWS creds, which are sensitive, on your /.aws/credentials file.

If MFA is enforced on AWS, this script will be very convenient once only STS credentials are accepted in this case.

Requirements

  1. Node.js installed
  2. AWS CLI installed
type Leaf<T> = z.infer<ReturnType<typeof LeafSchema<z.ZodType<T>>>>
type NumberLeaf = Leaf<number>
const getLeafValue = <T>(leaf: Leaf<T>) => leaf.value;
const test = { 'value': 123 };
const val = getLeafValue(test);
@renatoargh
renatoargh / node-jose-example.ts
Created April 27, 2023 04:32
Example for RSA-OAEP-256 with A128CBC-HS256 encryption/decryption using node-jose
import { JWE, JWK } from "node-jose";
async function main() {
const originalPayload = 'this is a test with a short payload, but long payloads are also supported';
console.log('> Original payload:', originalPayload);
// We generate an RSA key to be used with the RSA-OAEP-256 algorithm
const key = await JWK.createKey("RSA", 2048, {
alg: "RSA-OAEP-256", // Key encryption algorithm
@renatoargh
renatoargh / node-jose-example.ts
Last active April 13, 2023 21:38
RSA 4096 Assymmetric key encrypt/decrypt example
import { JWK, JWE } from 'node-jose';
const store = JWK.createKeyStore()
const alphaKey = await JWK.createKey("RSA", 4096, {
kid: '258df19c-f3bf-4f39-8829-a9adbd97d7d7',
alg: 'RSA-OAEP-256',
use: 'enc',
expires_on: Math.floor(new Date().valueOf() / 1000),
})
@renatoargh
renatoargh / kms-public-key-encryption-example.ts
Created April 13, 2023 13:48
Shows how to retrieve a public key from KMS, encrypt a random string outside of AWS, decrypt using the Decrypt command and to format the key as JWK
const { createPublicKey, publicEncrypt } = require('crypto')
import {
KMSClient,
DecryptCommand,
GetPublicKeyCommand,
} from '@aws-sdk/client-kms'
// Change the next 2 lines
const keyId = '00000000-0000-0000-0000-000000000000';
@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' │
└──────────────┴────────────────────────────────────────┘