Skip to content

Instantly share code, notes, and snippets.

View rg3915's full-sized avatar
🏠
Working from home

Regis Santos rg3915

🏠
Working from home
View GitHub Profile
@rg3915
rg3915 / views.py
Created February 21, 2024 01:59
Cria e Edita PessoaFisica e PessoaJuridica com OneToOne com Cliente e usando o mesmo formulário
class ClienteCreateView(CreateView):
model = Cliente
template_name = 'clientes/cliente_form.html'
form_class = ClienteForm
success_url = reverse_lazy('listar_clientes')
def form_valid(self, form):
"""
If the form is valid, save the associated model.
https://ccbv.co.uk/projects/Django/5.0/django.views.generic.edit/CreateView/#form_valid
@rg3915
rg3915 / README.md
Last active February 18, 2024 19:04
Create folders files with Python in command line

Create folders, subfolders and file in command line with Python and Shell Script.

Install

sudo cp create_folders_files.py /usr/bin/
sudo cp mkf.sh /usr/bin/mkf
sudo chmod +x /usr/bin/mkf
@rg3915
rg3915 / api.py
Last active June 15, 2024 17:10
Retorna Estado choices Django Ninja API TextChoices
from ninja import Router, Schema
router = Router()
# models.py
class EstadoChoices(models.TextChoices):
AC = 'AC', 'Acre'
AL = 'AL', 'Alagoas'
AP = 'AP', 'Amapá'
AM = 'AM', 'Amazonas'
@rg3915
rg3915 / create_folder_files.sh
Created February 3, 2024 21:33
Create one folder and files inner this folder with Shell script. Create folder and files with Shell script.
#!/bin/bash
: << 'COMMENT'
Create one folder and files inner this folder.
Example
$ source teste.sh "folder1/{file1.txt,file2.txt}" "folder2/{file3.txt,file4.txt}"
COMMENT
@rg3915
rg3915 / README.md
Created January 26, 2024 13:50
commit

Escrever mensagens de commit claras e informativas é uma prática crucial para manter um histórico de código legível e compreensível. Aqui estão alguns exemplos de mensagens de commit para diferentes tipos de alterações em um projeto Python:

Exemplos de Mensagens de Commit:

  1. Feature: Adição de funcionalidade para calcular a média de uma lista:

    Adiciona função calculate_media() para calcular a média de uma lista de números
    
  2. Bugfix: Correção do erro ao tentar calcular média de lista vazia:

@rg3915
rg3915 / unpack.py
Created January 25, 2024 19:59
unpack dict Python
def unpack_product_info(**kwargs):
"""
Desempacota um dicionário contendo informações sobre um produto em variáveis.
Parâmetros:
- kwargs (dict): Dicionário com chaves 'produto', 'título' e 'preço'.
Retorna:
- Tupla: Variáveis desempacotadas (produto, título, preço).
"""
@rg3915
rg3915 / README.md
Last active January 13, 2024 04:27 — forked from vallahor/README.md
Given a txt file with a tree structure of directories/files generate a sh with necessary commands to generate that file tree

sh from txt contains tree structure of directories and files

How to create sh commands from txt file contains tree structure of directories and files?

This program convert tree structure of directories and files generate a sh with necessary commands to generate that file tree.

He read input.txt and convert to output.sh.

This is result:

@rg3915
rg3915 / README.md
Created January 2, 2024 13:11
Django-seed my fork

pip install git+https://github.com/rg3915/django-seed.git@main

@rg3915
rg3915 / README.md
Last active December 14, 2023 23:25
@rg3915
rg3915 / namedtuple_example.py
Created November 29, 2023 06:01
namedtuple example
from collections import namedtuple
data = ('Regis', 'Santos', '[email protected]')
first_name, last_name, email = data
print(first_name, last_name, email)
Person = namedtuple('Person', ['first_name', 'last_name', 'email'])
person = Person(*data)
print(person.first_name)