Skip to content

Instantly share code, notes, and snippets.

View diomalta's full-sized avatar
🎁
Dream, throw yourself in, risk everything you can, live!

Diego Malta diomalta

🎁
Dream, throw yourself in, risk everything you can, live!
View GitHub Profile
@diomalta
diomalta / ssh_key_aws_terraform.tf
Created July 1, 2021 15:21
AWS - SSH key generated by terraform
variable "key_name" {
type = string
default = "manager_rsa"
}
# Creates a private key and saves it in Terraform state without encryption
# https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key
resource "tls_private_key" "rsa_key" {
algorithm = "RSA"
rsa_bits = 4096
@diomalta
diomalta / TypedArray(Uint8Array)ToString.ts
Last active November 20, 2020 02:02
Transform Uint8Array to type string
function decodeUint8(bufferArray: Uint8Array) {
return bufferArray
.reduce((acc, buffer) => acc.concat(String.fromCharCode(buffer)), "");
};
@diomalta
diomalta / StringToTypedArray(Uint8Array).ts
Last active November 20, 2020 02:00
Transform string to type Uint8Array
function encodeUint8(str: string) {
const buffer = str
.split("")
.reduce((acc,char) => [
...acc,
char.charCodeAt(0) >>> 8,
char.charCodeAt(0) & 0xff
],
[]);
SELECT
query,
calls,
total_time::integer,
max_time::integer,
rows,
100.0 * shared_blks_hit / nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
FROM pg_stat_statements
ORDER BY total_time DESC LIMIT 5;
SELECT reltuples FROM pg_class WHERE oid = 'my_schema.my_table'::regclass;
// Const of PHI 1,618034
function randomNumber() {
const randomSeed = (new Date()).getTime();
return parseInt((Math.random() * 100) % 16180339 * randomSeed, 10);
}
const routes = require('express').Router()
const UserController = require('../app/controllers/UserController')
const AuthController = require('../app/controllers/AuthController')
// Authentication routes
routes.post('/signin', AuthController.store)
// User routes
routes.post('/', UserController.store)
@diomalta
diomalta / config.js
Last active September 16, 2021 00:18
const dotenv = require('dotenv');
dotenv.config({
path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
});
module.exports = {
secret: process.env.APP_SECRET,
env: process.env.NODE_ENV,
token: process.env.JWT_SECRET,
module.exports = {
userSuccess: 'Usuário foi criado com sucesso',
userError: 'Usuário não pode ser criado',
userNotFound: 'Usuário não encontrado',
userAlreadyExist: 'Usuário já existe na nossa base de dados'
}
const moment = require('moment');
module.exports = (date) => (date === undefined && !moment(date, moment.ISO_8601, true).isValid());