Skip to content

Instantly share code, notes, and snippets.

View eoguvo's full-sized avatar
🔥
A todo vapor

Gustavo Henrique eoguvo

🔥
A todo vapor
  • Itu, São Paulo, Brazil
View GitHub Profile
const jwt = require('jsonwebtoken')
const dotenv = require('dotenv').config();
const authConfig = process.env.AUTH
module.exports = (req, res, next) => {
const authHeader = req.headers.authorization
if (!authHeader){
return res.status(401).send({error: 'No token provided'})
}
@eoguvo
eoguvo / Util.js
Created February 3, 2021 17:19
Generic Util
class Util {
static #defaultFormart = Intl.NumberFormat("en-us", {
currency: "BRL",
style: "currency"
});
static formatDate(date) {
let d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + (d.getDate() + 1),
@eoguvo
eoguvo / DeferNextScript.jsx
Created February 4, 2021 00:46
DeferNextScript to improve performance in FCP and LCP
import { NextScript } from 'next/document';
function dedupe(bundles) {
const files = new Set();
const kept = [];
for (const bundle of bundles) {
if (files.has(bundle.file)) continue;
files.add(bundle.file);
kept.push(bundle);
@eoguvo
eoguvo / usePersistedState.js
Created February 6, 2021 01:26
useState with localStorage
import { useState, useEffect } from 'react';
function usePersistedState(key, initialState) {
const [state, setState] = useState(() => {
if(typeof window === 'undefined') return initialState;
const storageValue = localStorage.getItem(key);
if (storageValue) {
return JSON.parse(storageValue);
} else {
export const results = [
{
"adult": false,
"backdrop_path": "/pcDc2WJAYGJTTvRSEIpRZwM3Ola.jpg",
"genre_ids": [
28,
12,
14,
878
],
const path = require('path');
module.exports = {
mode: 'production',
entry: path.resolve(__dirname, 'src', 'main.js'),
output: {
path: path.resolve(__dirname, 'public', 'assets', 'js'),
filename: 'bundle.js'
},
module: {
@eoguvo
eoguvo / main.cpp
Created June 7, 2021 22:41
alguns snippets de algoritmo e competicao para a obi
#include <bits/stdc++.h>
#define endl "\n"
/*
esse macro serve para performance
apenas inserir um \n eh mais
performatico que chamar uma stream
pra quebrar a linha
*/
int main() {
@eoguvo
eoguvo / database.util.ts
Created July 27, 2021 22:50
An filter proxy to db
import { Pool } from "pg";
import 'dotenv/config'
const db = new Pool({
connectionString: process.env.DATABASE_URL,
ssl: process.env.NODE_ENV === "development" ? false : {
rejectUnauthorized: false
}
});
@eoguvo
eoguvo / methods.util.ts
Last active August 18, 2021 00:35
util methods to manipulate object in typescript
type Obj = {[key: string]: string|number}
const omit = curry(<T extends Obj>(names: Array<string>, obj: T): T => {
let result: T = {} as T;
let index: Obj = {};
names.forEach(name=> {
index[name] = 1;
});
# backup
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
# restore
cat your_dump.sql | docker exec -i your-db-container psql -U postgres