Skip to content

Instantly share code, notes, and snippets.

View jgonfsbl's full-sized avatar
🏠
Working remote

Jonathan González jgonfsbl

🏠
Working remote
View GitHub Profile
@jgonfsbl
jgonfsbl / Method 1
Last active January 5, 2025 05:26
This solution requires to enable the File Watchers component, which is built in in the IDE, and perform this configuration:
import sys
import re
import datetime
def update_timestamp(filepath):
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()
# Regex: group(1) = __updated__ = " , group(2) = old date/time, group(3) = closing quote
pattern = r'(__updated__\s*=\s*["\'])(.*?)(["\'])'
@jgonfsbl
jgonfsbl / dockerfile with poetry (alpine base).docker
Created November 16, 2024 10:18
This dockerfile with Alpine base uses Poetry for dependency management instead of the traditional PIP.
#
# Dockerfile for an Alpine based Python container
#
# Originally developer in 2020 by Jonathan Gonzalez <jgonf@safebytelabs.com>
# Licensed under the Mozilla Public License 2.0
#
FROM python:3.12.2-alpine3.19
LABEL maintainer="Jonathan Gonzalez <jgonf@safebytelabs.com>"
ARG GIT_BRANCH
@jgonfsbl
jgonfsbl / Convert date and time with datetime to formats like dd-mm-yyyy.py
Created November 13, 2024 10:41
Convert a date like '2025-05-11T21:34:08.165483' to format like dd/mm/aaaa in Python using datetime library
from datetime import datetime
# Fecha original en formato ISO 8601
original_date = '2025-05-11T21:34:08.165483'
# Convertir la fecha a un objeto datetime
date_obj = datetime.fromisoformat(original_date)
# Formatear la fecha al formato dd/mm/aaaa
formatted_date = date_obj.strftime('%d/%m/%Y')
import re
from pathlib import Path
init_file = Path("src/cosper/__init__.py")
pyproject_file = Path("pyproject.toml")
# Read the version from __init__.py
try:
version_match = re.search(r'__version__ = "(.*?)"', init_file.read_text())
except FileNotFoundError:
@jgonfsbl
jgonfsbl / How to build multistage Docker container images.md
Last active June 15, 2024 23:52
The three commands you need to use either in your local computer or in your development pipeline to build multistage Docker container images.

How-To build multistage Docker container images

Local build

docker build \
  -f iac/docker/dockerfile.alpine \
  --build-arg VERSION=`cat src/mypkg/__init__.py | grep version | awk '{ print $3 }' |  tr -d '"'` \
  --build-arg GIT_BRANCH=`git branch --show-current` \

MISSION Act as Professor Synapse, a conductor of expert agents. Your job is to support me in accomplishing my goals by gathering context, then you MUST init:

Synapse_CoR = "(emoji): I am an expert in [role&domain]. I know [context]. I will reason step-by-step to determine the best course of action to achieve [goal]. I can use [tools] and [relevant frameworks] to help in this process. I will help you accomplish your goal by following these steps: [reasoned steps] My task ends when [completion]. [first step, question]"

INSTRUCTIONS

  1. 🧙🏾‍♂️, gather context, relevant information and clarify my goals by asking questions
  2. Once confirmed you are MANDATED to init Synapse_CoR
@jgonfsbl
jgonfsbl / Makefile for Sqitch.mak
Last active July 5, 2024 08:13
Makefile for managing database migrations using Sqitch
################################################################################
###
### Makefile for managing database migrations using Sqitch
### v.1.0.0
### Author: Jonathan Gonzalez <jgonf@safebytelabs.com>
### Creation date: 2024-04-01
### Last update: 2024-06-18
### License: MPL-2.0
###
################################################################################
@jgonfsbl
jgonfsbl / Script for DevContainer server use.sh
Last active May 20, 2024 13:53
Automates the user creation and environment setup for later use in remote dev container server
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <username>"
exit 1
fi
USERNAME="$1"
NEXT_UID=$(awk -F: '{uid[$3]}; END {for (i=3001;;i++) if (!(i in uid)) {print i; exit}}' /etc/passwd)
@jgonfsbl
jgonfsbl / app.py
Created May 16, 2024 14:11
Simple yet powerful input/output schema (data) valiadation
# -*- coding: utf-8 -*-
""" TEST """
from schema import UserSchema
from flask import Flask, jsonify, request
from marshmallow import ValidationError
app = Flask(__name__)
@jgonfsbl
jgonfsbl / redis_conn_pool.py
Last active May 14, 2024 22:04
Functional approach
from database.redis import initialize_pool, get_connection, release_connection, destroy_pool
# Initialize the pool with a specific size
initialize_pool(size=5)
def main() -> None:
"""main block"""
try:
conn = get_connection()