Skip to content

Instantly share code, notes, and snippets.

View mariocesar's full-sized avatar

Mario-César mariocesar

View GitHub Profile
https://skribbl.io/?ulCNu5we
@mariocesar
mariocesar / README.md
Created June 16, 2024 15:19
Useful oneliners that I often forget. #terminal #python #shell

direnv

List all the available functions in the standard lib:

direnv stdlib | grep -o -E "^(\w+)\(\)"

This small snippet can be implemented in your Django project to handle locks. It is particularly useful for replacing Redis locks, reducing dependency overhead. To use this snippet, simply copy and adapted to your Django project.

The hash_string function is used to convert a string value into a numerical hash value, as PostgreSQL advisory lock mechanism requires an integer.

Tested on Python3.11 and Django4

Learn more about advisory locks in:

@mariocesar
mariocesar / ruff.toml
Created May 6, 2024 17:03
My ruff toml configuration with useful defaults and rules
exclude = ["docs/*", "*/migrations/*", ".git/*"]
line-length = 100
indent-width = 4
target-version = "py311"
[lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"N", # pep8-naming
@mariocesar
mariocesar / parsing_commands.py
Last active May 2, 2024 03:38
An example on how to Parse commands from Slack using argparse
import argparse
import shlex
from typing import List, Optional, TypedDict
class Command(TypedDict):
prefix: str
name: str
args: List[str]
@mariocesar
mariocesar / README.md
Last active April 12, 2024 14:09
Prueba de revisión. Code Challenge. Programming Skills

Instrucciones para el candidato

Adjunto encontrarás un script de Python llamado script.py y un archivo CSV llamado data.csv.

  1. El archivo data.csv contiene datos de productos con las siguientes columnas: product_id, name, category_name, price, quantity.
  2. El script script.py carga los datos del archivo CSV, calcula la media, el promedio y la moda de los precios de los productos agrupados por categoría, y muestra los resultados en la consola.
  3. Tu tarea es revisar el código del script script.py y proponer cambios, mejoras o identificar cualquier problema, similar a lo que harías en una revisión a un Merge Request.
  4. Prepara tus comentarios, sugerencias y mejoras propuestas para discutirlas durante la siguiente entrevista.

El objetivo de este ejercicio es evaluar tus habilidades para identificar problemas, proponer mejoras y más que todo comunicar tus ideas de manera efectiva.

@mariocesar
mariocesar / main.yml
Created May 7, 2023 20:11
My espanso triggers configuration
matches:
- trigger: "!today"
replace: "{{mydate}}"
vars:
- name: mydate
type: date
params:
format: "%d/%m/%Y"
- trigger: "!now"
@mariocesar
mariocesar / README.md
Created April 5, 2023 14:20
A simple daemon script that I used for debugging running Docker containers in AWS ECS.

Outputs

{"name": "worker", "level": "INFO", "message": "Service start", "timestamp": "2023-04-05 14:04:48.974687279", "ip": "172.17.0.2", "pid": 7}
{"name": "worker", "level": "INFO", "message": "ping", "timestamp": "2023-04-05 14:04:48.975945036", "ip": "172.17.0.2", "pid": 7}
{"name": "worker", "level": "INFO", "message": "Received signal: SIGTERM", "timestamp": "2023-04-05 14:04:53.979013322", "ip": "172.17.0.2", "pid": 7}
{"name": "worker", "level": "INFO", "message": "Stopping", "timestamp": "2023-04-05 14:04:53.980930837", "ip": "172.17.0.2", "pid": 7}
@mariocesar
mariocesar / README.md
Last active April 5, 2023 14:18
Docker command and utils.

Useful Docker commands

Show all the files in a docker volume, use: docker-list-volume-contents volume_name

function docker-list-volume-contents() {
    docker run --rm -v ${1}:/data -it alpine find /data -type f
}