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 / Dockerfile
Last active July 25, 2020 09:12 — forked from olivx/docker_basic.md
Guia definitivo de Docker
ARG PYTHON_VERSION='3.8'
# set base image (host OS)
FROM python:3.8
ENV PYTHONUNBUFFERED 1
# set the working directory in the container
WORKDIR /code
@rg3915
rg3915 / methods.py
Created May 25, 2018 21:27 — forked from dunossauro/methods.py
Exemplo de como funcionam os decoradores de classe para o @rg3915
"""
Respondendo a questões feitas no grupo da live de Python.
"""
class Teste:
bananas_cls = 5 # Variável de classe
def __init__(self):
"""Método que inicia a instância."""
self.bananas_self = 10 # Variável de instância
@rg3915
rg3915 / teste_bulk_update.py
Created August 1, 2018 01:34 — forked from luzfcb/teste_bulk_update.py
Django bulk_update
# https://github.com/aykut/django-bulk-update
from django_bulk_update.helper import bulk_update
from minhaapp.models import MeuModelo
queryset_meumodelo = MeuModelo.objects.all()
# limpa os dados
for meumodelo_obj in queryset_meumodelo:
@rg3915
rg3915 / data_table.js
Last active August 9, 2018 19:45 — forked from olivx/data_table.js
search date data-table
// Bootstrap datepicker
$('.input-daterange input').each(function() {
$(this).datepicker('clearDates');
});
// Set up your table
table = $('#my-table').DataTable({
paging: false,
info: false
});
@rg3915
rg3915 / views.py
Created August 23, 2018 00:48 — forked from robsonsilv4/views.py
Django override get_form on CreateView
class MyModelAdd(CreateView):
model = MyModel
def get_form(self):
type_form = self.request.GET.get('type')
if type_form == 'pf':
self.form_class = PFForm
else:
self.form_class = PJForm
return super(MyModelAdd, self).get_form()
@rg3915
rg3915 / convert_string_types.py
Last active February 21, 2024 18:45 — forked from dunossauro/convert_string_types.py
Conversão de strings em tipos válidos do Python usando ast literal_eval by @dunossauro - python ast
from ast import literal_eval
def convert_to_type(input_data):
try:
return literal_eval(input_data)
except (ValueError, SyntaxError):
return input_data
@rg3915
rg3915 / filter_applicants.py
Created September 22, 2018 00:11 — forked from olivx/filter_applicants.py
filter_applicants multiples elements separator per ', ' example with Q() object
def add_q_object(self, keyword, q_object, query_parm):
for key in keyword:
kwargs = {query_parm: key.strip()}
q_object.add(Q(**kwargs), q_object.OR)
def filter_applicants(self, _queryset=None):
my_applicants = _queryset
@rg3915
rg3915 / django_orm_optimization_cheat_sheet.py
Last active August 26, 2023 15:51 — forked from levidyrek/django_orm_optimization_cheat_sheet.py
Django ORM optimization cheat sheet
"""
Django ORM Optimization Tips
Caveats:
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
"""
# ---------------------------------------------------------------------------
@rg3915
rg3915 / example_current_user.py
Last active April 29, 2025 17:37 — forked from vinidmpereira/example_current_user.py
get_current_user middleware. current user
"""
This should be a separate file, i usually install it on the maind django project folder.
"""
from threading import local
from django.utils.deprecation import MiddlewareMixin
_user = local()
@rg3915
rg3915 / api-restful.py
Created July 2, 2019 20:22
Flask api Rest
from flask import Flask
from flask_restful import Api, Resource, reqparse
app = Flask(__name__)
api = Api(app)
transactions = [
{