Skip to content

Instantly share code, notes, and snippets.

View vncsna's full-sized avatar
🏡
Working from home

Vinicius Aguiar vncsna

🏡
Working from home
View GitHub Profile
@vncsna
vncsna / find-icon.sh
Last active February 3, 2024 14:13
Find icons by name in linux
#!/bin/bash
icon_name="$1"
icon_directory="/usr/share/icons"
find "$icon_directory" -name "*$icon_name*"
@vncsna
vncsna / postgresql_indexes.sql
Created January 10, 2024 13:58
PostgreSQL Size of Indexes
-- Reference
-- https://stackoverflow.com/questions/46470030/postgresql-index-size-and-value-number
SELECT
i.relname "Table Name"
, indexrelname "Index Name"
, pg_size_pretty(pg_total_relation_size(relid)) As "Total Size"
, pg_size_pretty(pg_indexes_size(relid)) as "Total Size of all Indexes"
, pg_size_pretty(pg_relation_size(relid)) as "Table Size"
, pg_size_pretty(pg_relation_size(indexrelid)) "Index Size"
@vncsna
vncsna / pydantic_decorators_v2.py
Last active January 8, 2024 19:55
Pydantic Decorators V2
# PROS: Easy to use in CRUDs
# CONS: Invalid autocompletion
from inspect import isclass
from pydantic import BaseModel, create_model
from pydantic_core import SchemaSerializer, SchemaValidator
def omit(*fields):
@vncsna
vncsna / postgres_queries_and_commands.sql
Created October 17, 2023 12:02 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@vncsna
vncsna / logger.py
Last active September 24, 2023 19:01 — forked from AlonsoMackenlly/settings_logging.py
Loguru with Django
# Reference
# https://github.com/Delgan/loguru/issues/302
from logging import __file__, Handler, LogRecord, currentframe
from sys import stdout, stderr
class InterceptHandler(Handler):
def emit(self, record: LogRecord):
# Get corresponding Loguru level if it exists
try:
@vncsna
vncsna / access_postgresql_with_docker.md
Created July 18, 2023 17:38 — forked from MauricioMoraes/access_postgresql_with_docker.md
Allow Docker Container Access to Host's Postgres Database on linux (ubuntu)

You have to do 2 things in order to allow your container to access your host's postgresql database

  1. Make your postgresql listen to an external ip address
  2. Let this client ip (your docker container) access your postgresql database with a given user

Obs: By "Host" here I mean "the server where docker is running on".

Make your postgresql listen to an external ip address

Find your postgresql.conf (in case you don't know where it is)

$ sudo find / -type f -name postgresql.conf

@vncsna
vncsna / .config.md
Last active December 4, 2023 19:29
aws-vault-sso-config
  • Please retrieve information from AWS

image

  • Then configure the profile on .aws/config
    • Remember to delete previous credentials
[default]
output=json
@vncsna
vncsna / py-comp-to-js.md
Created December 10, 2022 14:11 — forked from dschep/py-comp-to-js.md
Python Comprehensions to JS

Python list & dict comprehensions translated to JavasScript

Comprehensions are a really useful feature of Python that aren't available in JavaScript (or many languages). These concepts of course can be tranlsated into using map instead. But especially the dictionaries are a bit trickier.

Lists / Arrays

>>> foobar = range(5)
>>> [x + 1 for x in foobar]
[1, 2, 3, 4, 5]
@vncsna
vncsna / SOS.md
Created May 30, 2022 13:21 — forked from vodik/SOS.md
_Never_ -Sy when installing!

Once upon a time there was a user that wanted to install firefox.

The user tried to do pacman -S firefox but it didn't work. The all mighty pacman reported that firefox-3.2.4-1.i686.pkg.tar.gz could not be found on his mirror. So the user tried pacman -Sy firefox. It worked and the user rejoiced since he could once again go and troll /h/.

But all was not good. The user had made a grave error!

See, when the user told the almighty pacman to -Sy firefox, pacman did

@vncsna
vncsna / create_ts_index.py
Created November 25, 2021 15:09
Create a `index.ts`
# Usage `python create_ts_index.py <folder-name>`
# TODO: Convert to bash script
import sys
from pathlib import Path
def create_index(rootpath):
rootpath = Path(rootpath)
indexpath = rootpath / "index.ts"